using System;

using DG.Tweening;
using Newtonsoft.Json;
using Spine.Unity;
using UnityEngine;

namespace RedHotRoast
{
    public class OpenGameUI : BaseUI
    {
        private OpenGameUICtrl ctrl;
        private OpenGameModel model;
        private FGUI.ZM_Game_04.com_open ui;

        public OpenGameUI(OpenGameUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.OpenGameUI;
            this.ctrl = ctrl;
        }

        protected override void SetUIInfo(UIInfo uiInfo)
        {
            uiInfo.packageName = "ZM_Game_04";
            uiInfo.assetName = "com_open";
            uiInfo.layerType = UILayerType.Highest;
            uiInfo.isNeedOpenAnim = false;
            uiInfo.isNeedCloseAnim = false;
            uiInfo.isNeedUIMask = false;
        }

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

        protected override void OnClose()
        {

        }

        protected override void OnBind()
        {
            ui = baseUI as FGUI.ZM_Game_04.com_open;
        }

        protected override void OnOpenBefore(object args)
        {
            DOVirtual.DelayedCall(0.7f, () => { GameDispatcher.Instance.Dispatch(GameMsg.reset_game, args); });
            InitView();
            // DOVirtual.DelayedCall(0.2f, () =>
            // {
            //     if (GameHelper.GetLevel() - 1 < ConfigSystem.GetConfig<LevelUnlock>().Count&&GameHelper.IsGiftSwitch())
            //     {
            //         LevelUnlock levelUnlock_ = ConfigSystem.GetConfig<LevelUnlock>()[GameHelper.GetLevel() - 1];
            //         if (levelUnlock_.LeveType != 0)
            //         {
            //             if (!DataMgr.LevelUnlockList.Value.Contains(GameHelper.GetLevel() - 1))
            //             {
            //                 uiCtrlDispatcher.Dispatch(UICtrlMsg.UnlockLevelUI_Open, GameHelper.GetLevel() - 1);
            //             }
            //         }
            //     }
            // });



            if (AudioManager.Instance.IsOpenEffect)
            {
                AudioManager.Instance.PlayDynamicEffect(AudioConst.game_open);
            }
        }

        protected override void OnOpen(object args)
        {
        }

        protected override void OnHide()
        {
        }

        protected override void OnDisplay(object args)
        {
        }
        #endregion

        #region 消息
        protected override void AddListener()
        {

        }
        protected override void RemoveListener()
        {

        }
        #endregion
        private Action closeCallback;
        //初始化页面逻辑
        private void InitView()
        {

            string stage = GameHelper.gameType == 0 ? Language.GetContentParams("need_lv_text", GameHelper.GetLevel()) : "";

            ui.text_level.text = stage;


            DOVirtual.DelayedCall(1.5f, () =>
            {
                // ui.tips_node1.visible = true;
                // var open_bg = FXManager.Instance.SetFx<SkeletonAnimation>(ui.tips_node1, Fx_Type.fx_open_bg, ref closeCallback);
                // open_bg.state.SetAnimation(0, "animation", true);
                // ui.tips_node1.SetScale(1.25f, 1.25f);
                //
                // ui.tips_node.visible = true;
                // var open_game = FXManager.Instance.SetFx<SkeletonAnimation>(ui.tips_node, Fx_Type.fx_open, ref closeCallback);
                // open_game.state.SetAnimation(0, "animation", false);
                // open_game.state.Complete += (a) =>
                // {
                UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Close);
                // };
            
            });
        }
    }
}
