using BingoBrain.Core;

namespace BingoBrain
{
    public class ReadyBingoUICtrl : BaseUICtrl
    {
        private ReadyBingoUI ui;
        private ReadyBingoModel model;

        private uint openUIMsg = 0;
        private uint closeUIMsg = 0;

        #region 生命周期

        protected override void OnInit()
        {
        }

        protected override void OnDispose()
        {
        }

        public override void OpenUI(object args = null)
        {
            if (ui == null)
            {
                ui = new ReadyBingoUI(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()
        {
            AppDispatcher.Instance.AddListener(CsjInfoC.UI_DisplayLoadingUI, OpenUI);
            AppDispatcher.Instance.AddListener(CsjInfoC.UI_HideLoadingUI, OnHideLoading);
        }

        protected override void RemoveListener()
        {
            AppDispatcher.Instance.RemoveListener(CsjInfoC.UI_DisplayLoadingUI, OpenUI);
            AppDispatcher.Instance.RemoveListener(CsjInfoC.UI_HideLoadingUI, OnHideLoading);
        }

        #endregion

        private void OnHideLoading(object obj)
        {
            if (ui == null) return;
            ui.CheckAgree();
        }
    }
}