
using FGUI.ZM_Common_01;
using UnityEngine;
using FairyGUI;

namespace RedHotRoast
{
    public class ChatNumberUI : BaseUI
    {
        private ChatNumberUICtrl ctrl;
        private ChatNumberModel model;
        private FGUI.LG_AIchat.com_ChatNumber ui;

        public ChatNumberUI(ChatNumberUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.ChatNumberUI;
            this.ctrl = ctrl;
        }

        protected override void SetUIInfo(UIInfo uiInfo)
        {
            uiInfo.packageName = "LG_AIchat";
            uiInfo.assetName = "com_ChatNumber";
            uiInfo.layerType = UILayerType.Popup;
            uiInfo.isNeedOpenAnim = false;
            uiInfo.isNeedCloseAnim = false;
            uiInfo.isNeedUIMask = true;
        }

        #region 生命周期
        protected override void OnInit()
        {
            //model = ModuleManager.Instance.GetModel(ModelConst.ChatNumberModel) as ChatNumberModel;
        }

        protected override void OnClose()
        {
        }

        protected override void OnBind()
        {
            ui = baseUI as FGUI.LG_AIchat.com_ChatNumber;
        }

        protected override void OnOpenBefore(object args)
        {
            InitView();

        }

        protected override void OnOpen(object args)
        {
        }

        protected override void OnHide()
        {
        }

        protected override void OnDisplay(object args)
        {
        }
        #endregion

        #region 消息
        protected override void AddListener()
        {

        }
        protected override void RemoveListener()
        {

        }
        #endregion

        //初始化页面逻辑
        private void InitView()
        {
            ui.btn_close.SetClick(() =>
            {
                CtrlCloseUI();
            });
             int[] array = GameHelper.GetCommonModel().CoinsAccess;
            ui.text_coins.SetVar("coin", array[0].ToString()).FlushVars();
            ui.text_coins.SetVar("num", array[1].ToString()).FlushVars();
            ui.text_ads.SetVar("num", GameHelper.GetCommonModel().AdAccess.ToString()).FlushVars();
            ui.btn_coins.title = array[0].ToString();
            ui.btn_coins.SetClick(() =>
            {
                if (DataMgr.Coin.Value >= array[0])
                {
                    DataMgr.Coin.Value -= array[0];
                    DataMgr.ChatNumber.Value += array[1];
                    GameDispatcher.Instance.Dispatch(GameMsg.AddChatNum);
                    GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
                    CtrlCloseUI();
                    GameHelper.ShowTips("more_message", true);
                }
                else GameHelper.ShowTips("no_enough_gold", true);
            });

            ui.btn_watch.SetClick(() =>
            {
                GameHelper.ShowVideoAd("TaskReward", (issuccess) =>
                {
                    if (issuccess)
                    {
                        DataMgr.ChatNumber.Value += GameHelper.GetCommonModel().AdAccess;
                        GameDispatcher.Instance.Dispatch(GameMsg.AddChatNum);
                        CtrlCloseUI();
                        GameHelper.ShowTips("more_message", true);
                    }
                });
            });
        }
    }
}