using System;

namespace ChillConnect
{
    public class BuygoldUICtrl : BaseUICtrl
    {
        private BuygoldUI ui;
        private BuygoldModel model;

        private uint openUIMsg = UICtrlMsg.BuygoldUI_Open;
        private uint closeUIMsg = UICtrlMsg.BuygoldUI_Close;

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

        protected override void OnDispose()
        {
        }

        public override void OpenUI(object args = null)
        {
            if (ui == null)
            {
                ui = new BuygoldUI(this);
                ui.Open(args);
            }
        }

        public override void CloseUI(object args = null)
        {
            if (ui != null && !ui.isClose)
            {
                ui.Close();
            }
            ui = null;
        }
        #endregion

        #region 消息
        public override uint GetOpenUIMsg(string uiName)
        {
            return openUIMsg;
        }
        public override uint GetCloseUIMsg(string uiName)
        {
            return closeUIMsg;
        }

        protected override void AddListener()
        {
            uiCtrlDispatcher.AddListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.AddListener(closeUIMsg, CloseUI);
            HallManager.Instance.UpdateSecondEvent += removeAdCountDown;
        }
        protected override void RemoveListener()
        {
            uiCtrlDispatcher.RemoveListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.RemoveListener(closeUIMsg, CloseUI);
        }
        public void removeAdCountDown()
        {
            int cd = SaveData.GetSaveObject().remove_ad_time - Convert.ToInt32(GameHelper.GetNowTime());
            if (cd <= 0)
            {
                SaveData.GetSaveObject().is_get_removead = false;
                SaveData.GetSaveObject().remove_ad_time = 0;
            }
        }
        protected override void AddServerListener()
        {

        }
        protected override void RemoveServerListener()
        {

        }
        #endregion
    }
}