// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖

using Fantasy.Event;
using UnityEngine;
using NBC;

namespace NBF
{
    public struct LoadingShowParam
    {
        public int Style;
        public int StartProgress;

        public LoadingShowParam(int style, int startProgress)
        {
            StartProgress = startProgress;
            Style = style;
        }
    }

    public class OnLoadingProgressEvent : EventSystem<LoadingProgress>
    {
        protected override void Handler(LoadingProgress self)
        {
            LoadingPanel.SetProgress(self.Progress);
        }
    }

    public partial class LoadingPanel : UIPanel
    {
        public static readonly LoadingTask<LoadingPanel> LoadingTask = new();
        private static LoadingPanel _loadingPanel;

        public static void SetProgress(float progress)
        {
            if (_loadingPanel != null)
            {
                _loadingPanel.Progress.value = progress * 100;
            }
        }

        protected override void OnInit()
        {
            ContentPane.sortingOrder = UIDef.UIOrder.Loading;
            _loadingPanel = this;
            Progress.max = 100;
        }

        protected override void OnShow()
        {
            base.OnShow();
            Progress.value = 100;
        }

        protected override void OnHide()
        {
            base.OnHide();
        }

        protected override void OnDestroy()
        {
            base.OnDestroy();
        }
    }
}