

namespace ChillConnect
{
    public class FXWndUICtrl : BaseUICtrl
    {
        private FXWndUI ui;
        private FXWndModel model;

        private uint openUIMsg = UICtrlMsg.FXWndUI_Open;
        private uint closeUIMsg = UICtrlMsg.FXWndUI_Close;

        private bool isOpen = false;

        #region 生命周期
        protected override void OnInit()
        {

        }

        protected override void OnDispose()
        {
        }

        public override void OpenUI(object args = null)
        {
            if (ui == null || ui.isClose)
            {
                ui = new FXWndUI(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);
            uiCtrlDispatcher.AddListener(UICtrlMsg.PlayUIFX, PlayFx);


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

        private void PlayFx(object obj)
        {
            if (!isOpen)
            {
                OpenUI();
            }
            FxPlayData fxType = (FxPlayData)obj;
            ui.PlayFx(fxType);

        }



        protected override void AddServerListener()
        {

        }
        protected override void RemoveServerListener()
        {

        }
        #endregion


    }

}