using FairyGUI;
using FGUI.A000_common;

namespace ScrewsMaster
{
    public class RewardboxUI : BaseUI
    {
        private RewardboxUICtrl ctrl;
        private RewardboxModel model;
        private FGUI.G008_reward.com_rewardbox ui;

        public RewardboxUI(RewardboxUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.RewardboxUI;
            this.ctrl = ctrl;
        }

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

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

        protected override void OnClose()
        {
            GameHelper.showGameUI = true;
        }

        protected override void OnBind()
        {
            ui = baseUI as FGUI.G008_reward.com_rewardbox;
        }

        protected override void OnOpenBefore(object args)
        {

            if (GameHelper.IsGiftSwitch()) ui.switchgift.selectedIndex = 1;
            else ui.switchgift.selectedIndex = 0;
            // (ui.btn_lookad as btn_tabad).color.selectedIndex = btn_tabad.Color_green;
            float[] cash_array = GameHelper.GetRewardValue(2);
            ui.btn_lookad.SetClick(() =>
           {
               GameHelper.ShowVideoAd("reward_lobby", isSuccess =>
               {
                   if (isSuccess)
                   {
                       GameDispatcher.Instance.Dispatch(GameMsg.Ad_success, cash_array[0]);
                       UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.RewardboxUI_Close);
                   }
               });

           });
            ui.btn_close.SetClick(() =>
            {
                UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.RewardboxUI_Close);
                GameHelper.AddInterAdNumber();
            });
            ui.gold_text.text = string.Format(ui.gold_text.text, cash_array[0]);
                        if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig<CommonModel>().PiggyBankSwitch == 1) (ui.btn_lookad.GetChild("img_saveingpot") as GImage).visible = true;
            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()
        {

        }
    }
}