namespace ChillConnect
{
    public class GameMenuUICtrl : BaseUICtrl
    {
        private GameMenuUI ui;
        private GameMenuModel model;

        private uint openUIMsg = UICtrlMsg.GameMenuUI_Open;
        private uint closeUIMsg = UICtrlMsg.GameMenuUI_Close;

        #region 生命周期

        protected override void OnInit()
        {
        }

        protected override void OnDispose()
        {
        }

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

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

        #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);
        }

        protected override void RemoveListener()
        {
            uiCtrlDispatcher.RemoveListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.RemoveListener(closeUIMsg, CloseUI);
        }

        #endregion
    }
}