using BingoBrain.Core;
using BingoBrain.HotFix;

namespace BingoBrain
{
    public class H5UICtrl : BaseUICtrl
    {
        private H5UI ui;
        private H5Model model;

        private uint openUIMsg = SkinInfo.H5UI_Open;
        private uint closeUIMsg = SkinInfo.H5UI_Close;

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

        protected override void OnDispose()
        {
        }

        public override void OpenUI(object args = null)
        {
            if (ui == null)
            {
                ui = new H5UI(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);
            gameDispatcher.AddListener(BingoInfo.H5ViewClickBtn, OnH5ClickBtn);
        }
        protected override void RemoveListener()
        {
            uiCtrlDispatcher.RemoveListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.RemoveListener(closeUIMsg, CloseUI);
            gameDispatcher.RemoveListener(BingoInfo.H5ViewClickBtn, OnH5ClickBtn);
        }
        void OnH5ClickBtn(object arg)
        {
            ui?.ClickBtn((string)arg);
        }
        protected override void AddServerListener()
        {

        }
        protected override void RemoveServerListener()
        {

        }
        #endregion
    }
}