using System;
using FairyGUI;
using FGUI.Img_02;
using Spine.Unity;

namespace ChillConnect
{
    public class OpenBgUI : BaseUI
    {
        private OpenBgUICtrl ctrl;
        private OpenBgModel model;
        private com_loadingBg ui;
        private Action closeCallback;

        public OpenBgUI(OpenBgUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.OpenBgUI;
            this.ctrl = ctrl;
        }

        protected override void SetUIInfo(UIInfo uiInfo)
        {
            uiInfo.packageName = "Img_02";
            uiInfo.assetName = "com_loadingBg";
            uiInfo.layerType = UILayerType.Background;
            uiInfo.isNeedOpenAnim = false;
            uiInfo.isNeedCloseAnim = false;
            uiInfo.isNeedUIMask = true;
        }

        #region 生命周期

        protected override void OnInit()
        {
        }

        protected override void OnClose()
        {
            // CommonHelper.FadeOut(ui);
        }

        protected override void AddListener()
        {
            // UICtrlDispatcher.Instance.AddListener(UICtrlMsg.GameLoginUI_Open, OpenLogin);
        }

        protected override void RemoveListener()
        {
            // UICtrlDispatcher.Instance.RemoveListener(UICtrlMsg.GameLoginUI_Open, OpenLogin);
        }

        private void OpenLogin(object args)
        {
            // ui.icon_logo.TweenFade(0, 0.1f);
        }

        protected override void OnBind()
        {
            ui = baseUI as com_loadingBg;
        }

        protected override void OnOpenBefore(object args)
        {
            // var sk = FXManager.Instance.SetFx<SkeletonAnimation>(baseUI.GetChild("bg_parent") as GGraph, Fx_Type.fx_login, ref closeCallback);
            // sk.state.SetAnimation(0, "animation", false);


            var sk = FXManager.Instance.SetFx<SkeletonAnimation>(ui.leaves_anim, Fx_Type.fx_login_bird, ref closeCallback);
            sk.state.SetAnimation(0, "animation", true);
            var sk1 = FXManager.Instance.SetFx<SkeletonAnimation>(ui.light_anim, Fx_Type.fx_login_light, ref closeCallback);
            sk1.state.SetAnimation(0, "liziguang1", true);
        }

        protected override void OnOpen(object args)
        {
            // CommonHelper.FadeIn(ui);
        }

        #endregion
    }
}