using DG.Tweening;

namespace ChillConnect
{
    public class GameResultUICtrl : BaseUICtrl
    {
        private GameResultUI ui;
        private GameResultModel model;

        private uint openUIMsg = UICtrlMsg.LevelSuccessUI_Open;
        private uint closeUIMsg = UICtrlMsg.LevelSuccessUI_Close;

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

        protected override void OnDispose()
        {
        }

        private object m_data;
        public override void OpenUI(object args = null)
        {
            if (ui == null)
            {
                ui = new GameResultUI(this);
                ui.Open(args);
            }
            else
            {
                m_data ??= args;
            }
        }

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

            if (m_data != null)
            {
                DOVirtual.DelayedCall(0.2f, () =>
                {
                    OpenUI(m_data);
                    m_data = 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
    }
}