using Godot; using System.Collections.Generic; using System.Xml; using Microsoft.Extensions.DependencyInjection; namespace BITKit; /// /// 基本UX面板接口,定义了基本的UX面板功能 /// /// ⭐同步打开与关闭 /// ⭐异步打开与关闭 /// ⭐当前可见状态 /// ⭐基本UI导航回调 public interface IUXPanel { /// /// 该面板是否具有动画 /// bool IsAnimate { get; } /// /// 该面板的索引(入口,Key) /// string Index { get; } /// /// 该面板是否启用指针 /// bool AllowCursor { get; } /// /// 该面板是否启用玩家输入 /// bool AllowInput { get; } void Entry(); void Exit(); } /// /// 基本UX服务(GUI管理器),主要通过加载叠加面板实现 /// /// 使用方式: /// /// public partial class UXService : Control { private static UXService Singleton; /// /// 在构造函数中注入依赖 /// public UXService() { BITApp.ServiceCollection.AddSingleton(this); Singleton = this; } /// /// 注册面板,加入注册队列 /// /// UX面板 public static void Register(IUXPanel panel) { RegistryQueue.Enqueue(panel); } /// /// 注销面板 /// /// UX面板 public static void UnRegister(IUXPanel panel) { } public static void Open() where T : IUXPanel { } public static void Open(IUXPanel panel) => EnableQueue.Push(panel); public static void Open(Control control) { } public static void Open(string name) { } /// /// 内部注册面板队列 /// private static readonly Queue RegistryQueue = new(); /// /// 已注册面板字典 /// private static readonly Dictionary Panels = new(); /// /// 等待启用的面板队列 /// private static readonly Stack EnableQueue = new(); /// /// 已启用面板 /// private static readonly Stack EnabledPanels = new(); /// /// 等待隐藏的面板 /// private static readonly Stack WActivatedPanels = new(); /// /// 正在播放过渡动画的面板 /// private static readonly Stack TransitionPanles = new(); private void _Entry(IUXPanel panel) { } public override void _Process(double delta) { if (TransitionPanles.Count is not 0) return; while (RegistryQueue.TryDequeue(out var result)) { Panels.Add(result.Index, result); result.Exit(); } if (EnableQueue.TryPop(out var next)) { while (EnabledPanels.TryPop(out var enabledPanel)) { enabledPanel.Exit(); } next.Entry(); EnabledPanels.Push(next); return; } } }