readme
This commit is contained in:
144
BITKit/Scripts/UX/UXService.cs
Normal file
144
BITKit/Scripts/UX/UXService.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
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; }
|
||||
void Entry();
|
||||
void Exit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 基本UX服务(GUI管理器),主要通过加载叠加面板实现
|
||||
/// </summary>
|
||||
/// <para>使用方式:</para>
|
||||
///
|
||||
///
|
||||
public partial class UXService : Control
|
||||
{
|
||||
private static UXService Singleton;
|
||||
|
||||
/// <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)
|
||||
{
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内部注册面板队列
|
||||
/// </summary>
|
||||
private static readonly Queue<IUXPanel> RegistryQueue = new();
|
||||
|
||||
/// <summary>
|
||||
/// 已注册面板字典
|
||||
/// </summary>
|
||||
private static readonly Dictionary<string, IUXPanel> Panels = new();
|
||||
|
||||
/// <summary>
|
||||
/// 等待启用的面板队列
|
||||
/// </summary>
|
||||
private static readonly Stack<IUXPanel> EnableQueue = new();
|
||||
|
||||
/// <summary>
|
||||
/// 已启用面板
|
||||
/// </summary>
|
||||
private static readonly Stack<IUXPanel> EnabledPanels = new();
|
||||
|
||||
/// <summary>
|
||||
/// 等待隐藏的面板
|
||||
/// </summary>
|
||||
private static readonly Stack<IUXPanel> WActivatedPanels = new();
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 正在播放过渡动画的面板
|
||||
/// </summary>
|
||||
private static readonly Stack<IUXPanel> 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user