using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HomeInfoControl : MonoBehaviour
{
    private Text cashTv, fruitNumTv, songProgressTv;
    private Image songProgress;
    private void Awake()
    {
        cashTv = transform.Find("Top/WithDraw/CashNumTv").transform.GetComponent<Text>();
        fruitNumTv = transform.Find("Top/ForFruit/FruitNumTv").transform.GetComponent<Text>();
        songProgressTv = transform.Find("Top/SongProgress/ProgressTv").transform.GetComponent<Text>();
        songProgress = transform.Find("Top/SongProgress/ProgressBar").transform.GetComponent<Image>();
    }




    // Start is called before the first frame update
    void Start()
    {
#if UNITY_EDITOR
        AppConfig.Instance.InitProgect(true);
#endif
        GetHomeInfo();
        //获取下一组要生成的水果的音符
        //GameController.GetInstance().GetNextNoteList(0);
        //GameController.GetInstance().GetWithdrawList(1);
        //GameController.GetInstance().GetWithdrawList(3);
        GameController.GetInstance().GetSongsList(1);
        GetNextNoteList(0);
        //UIMgr.GetInstance().ShowPanel<MusicPanel>(E_Layer.mid);
        //UIMgr.GetInstance().ShowPanel<MusicPanel>(E_Layer.mid);

    }





    private void GetHomeInfo()
    {
        HttpTool.Instance._Get("app/v1/watermelon/info", null, new Action<WatermelonInfoBean>((result) =>
        {
            cashTv.text = "¥" + result.available;
            fruitNumTv.text = result.count + "个";
        }), new Action<string, string>((code, msg) =>
        {
            Debug.unityLogger.Log("首页信息 " + code + " msg " + msg);
        }));
    }

    public void GetNextNoteList(int song_id)
    {
        Dictionary<string, object> paras = new Dictionary<string, object>();
        paras.Add("song_id", song_id);
        HttpTool.Instance._Get("app/v1/watermelon/notes", paras, new Action<List<string>>((result) =>
        {
            mNotesList.Clear();
            mNotesList = result;

            Debug.unityLogger.Log("音符列表"+mNotesList.Count);
            //StartCoroutine(FlyNote());
            StartCoroutine(AudioManager.Instance.LoadAudio("https://dccqcdn.tingmall.com/wx_dccq/%E6%AD%8C%E6%89%8B/11/%E9%86%92%E4%B8%8D%E6%9D%A5%E7%9A%84%E6%A2%A6-%E5%9B%9E%E5%B0%8F%E4%BB%99.wav"));
        }), new Action<string, string>((code, msg) =>
        {
            Debug.unityLogger.Log("获取下一组生成的球 " + code + " msg " + msg);
        }));
    }
    private List<string> mNotesList=new List<string>();
    private int PlayNoteIndex=0;

    private IEnumerator FlyNote()
    {
        while (true)
        {
            yield return new WaitForSeconds(2f);
            if (mNotesList.Count > PlayNoteIndex)
            {
                StartCoroutine(AudioManager.Instance.LoadAudio(mNotesList[PlayNoteIndex]));
                PlayNoteIndex++;
            }
        }
    }



}
