using FairyGUI;
using Spine.Unity;
using System;

namespace ScrewsMaster
{
    public class OpenBgUI : BaseUI
    {
        private OpenBgUICtrl ctrl;
        private OpenBgModel model;
        private FGUI.A001_bigImg.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 = "A001_bigImg";
            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 FGUI.A001_bigImg.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", true);
            // var bg = FXManager.Instance.SetFx<SkeletonAnimation>(ui.bg_parent, Fx_Type.fx_title, ref closeCallback);
            // bg.state.SetAnimation(0, "animation", true);
            var light = FXManager.Instance.SetFx<SkeletonAnimation>(ui.light_parent, Fx_Type.fx_title_light, ref closeCallback);
            light.state.SetAnimation(0, "animation", true);
        }

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

        #endregion
    }
}