namespace ChillConnect
{
    public class ArrowGameUICtrl : BaseUICtrl
    {
        private ArrowGameUI ui;
        private ArrowGameModel model;

        private uint openUIMsg = UICtrlMsg.ArrowGameUI_Open;
        private uint closeUIMsg = UICtrlMsg.ArrowGameUI_Close;

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

        protected override void OnDispose()
        {
        }

        public override void OpenUI(object args = null)
        {
            if (ui == null)
            {
                ui = new ArrowGameUI(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.Instance.AddListener(GameMsg.Update101, OnUpdate101);
            GameDispatcher.Instance.AddListener(GameMsg.Update102, OnUpdate102);
        }
        protected override void RemoveListener()
        {
            uiCtrlDispatcher.RemoveListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.RemoveListener(closeUIMsg, CloseUI);
            
            GameDispatcher.Instance.RemoveListener(GameMsg.Update101, OnUpdate101);
            GameDispatcher.Instance.RemoveListener(GameMsg.Update102, OnUpdate102);

        }
        
        private void OnUpdate101(object obj)
        {
            ui?.OnUpdate101(obj);
        }
        

        private void OnUpdate102(object obj)
        {
            ui?.OnUpdate102(obj);
        }



        protected override void AddServerListener()
        {

        }
        protected override void RemoveServerListener()
        {

        }
        #endregion
    }
}