
namespace ChillConnect
{
    public class WheelViewUICtrl : BaseUICtrl
    {
        private readonly uint closeUIMsg = UICtrlMsg.WheelUI_Close;
        private WheelViewModel model;

        private readonly uint openUIMsg = UICtrlMsg.WheelUI_Open;
        private WheelViewUI ui;

        private void OnSignInUI_Display(object obj)
        {
            if (obj != null)
            {
                var isShow = (bool)obj;
                if (isShow)
                    ui?.Display();
                else
                    ui?.Hide();
            }
        }

        #region 生命周期

        protected override void OnInit()
        {
        }

        protected override void OnDispose()
        {
        }

        public override void OpenUI(object args = null)
        {
            if (ui == null)
            {
                ui = new WheelViewUI(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);
        }

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

        protected override void AddServerListener()
        {
        }

        protected override void RemoveServerListener()
        {
        }

        #endregion
    }
}