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