breakpoint
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace BITKit;
|
||||
namespace BITKit.UX;
|
||||
|
||||
public partial class UXPanel : Control, IUXPanel
|
||||
{
|
||||
@@ -10,29 +10,33 @@ public partial class UXPanel : Control, IUXPanel
|
||||
[Export] private bool allowInput;
|
||||
[Export] private bool isStartPanel;
|
||||
public bool IsAnimate => isAnimate;
|
||||
public bool IsValid { get; set; }
|
||||
public string Index => _index;
|
||||
public bool AllowCursor => allowCursor;
|
||||
|
||||
public bool AllowInput => allowInput;
|
||||
|
||||
private string _index;
|
||||
public virtual void OnEntry(){}
|
||||
public virtual void Entry()
|
||||
{
|
||||
Show();
|
||||
OnEntry();
|
||||
//OnEntry();
|
||||
}
|
||||
|
||||
public virtual void Exit()
|
||||
{
|
||||
Hide();
|
||||
OnExit();
|
||||
//OnExit();
|
||||
}
|
||||
|
||||
public virtual void OnExit(){}
|
||||
public event Action OnEntry;
|
||||
public event Action OnExit;
|
||||
|
||||
|
||||
//public virtual void OnExit(){}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
IsValid = true;
|
||||
_index = GetType().FullName == typeof(UXPanel).FullName ? Name : GetType().FullName;
|
||||
UXService.Register(this);
|
||||
|
||||
@@ -49,9 +53,6 @@ public partial class UXPanel : Control, IUXPanel
|
||||
public override void _ExitTree()
|
||||
{
|
||||
UXService.UnRegister(this);
|
||||
IsValid = false;
|
||||
}
|
||||
// protected override void Dispose(bool disposing)
|
||||
// {
|
||||
// UXService.UnRegister(this);
|
||||
// }
|
||||
}
|
||||
|
@@ -4,43 +4,9 @@ using System.Linq;
|
||||
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();
|
||||
}
|
||||
namespace BITKit.UX;
|
||||
|
||||
/// <summary>
|
||||
/// 基本UX服务(GUI管理器),主要通过加载叠加面板实现
|
||||
/// </summary>
|
||||
/// <para>使用方式:</para>
|
||||
///
|
||||
///
|
||||
public partial class UXService : Control
|
||||
public partial class UXService : Control, IUXService
|
||||
{
|
||||
private static UXService Singleton;
|
||||
|
||||
@@ -53,19 +19,13 @@ public partial class UXService : Control
|
||||
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)
|
||||
{
|
||||
UnRegistryQueue.Enqueue(panel);
|
||||
@@ -131,11 +91,7 @@ public partial class UXService : Control
|
||||
|
||||
private static InitializationState InitializationState;
|
||||
|
||||
private void _Entry(IUXPanel panel)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (TransitionPanles.Count is not 0) return;
|
||||
@@ -169,4 +125,10 @@ public partial class UXService : Control
|
||||
EnabledPanels.Push(next);
|
||||
History.Push(next);
|
||||
}
|
||||
void IUXService.Register(IUXPanel panel)=>Register(panel);
|
||||
void IUXService.UnRegister(IUXPanel panel)=>UnRegister(panel);
|
||||
void IUXService.Entry<T>() => Open<T>();
|
||||
void IUXService.Return() => Return();
|
||||
void IUXService.Entry(IUXPanel panel) => Open(panel);
|
||||
void IUXService.Entry(string panelName) => Open(panelName);
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using BITKit.UX;
|
||||
|
||||
namespace BITKit;
|
||||
|
||||
|
82
BITKit/Scripts/UX/UXTabViewService.cs
Normal file
82
BITKit/Scripts/UX/UXTabViewService.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
[Tool]
|
||||
public partial class UXTabViewService : Control
|
||||
{
|
||||
[ExportCategory(Constant.Header.Settings)]
|
||||
[Export(PropertyHint.Range, "0,100,1")]
|
||||
private int currentIndex
|
||||
{
|
||||
get=>_currentIndex;
|
||||
set => SetIndex(value);
|
||||
}
|
||||
[Export] private int initialIndex;
|
||||
[ExportCategory(Constant.Header.Components)]
|
||||
[Export] private Array<Button> tabs;
|
||||
[Export] private TabContainer tabContainer;
|
||||
private ButtonGroup _buttonGroup;
|
||||
|
||||
private int _currentIndex;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (_isReady is false) return;
|
||||
_buttonGroup = new ButtonGroup();
|
||||
|
||||
for (var i = 0; i < tabs.Count; i++)
|
||||
{
|
||||
var tab = tabs[i];
|
||||
var _i = i;
|
||||
tab.Pressed += () => { SetIndex(_i); };
|
||||
}
|
||||
|
||||
var index = (Engine.IsEditorHint(), currentIndex, initialIndex) switch
|
||||
{
|
||||
(true,_,_)=>currentIndex,
|
||||
(false,_,>-1)=>initialIndex,
|
||||
(_,_,-1)=>-1,
|
||||
_ => -1
|
||||
};
|
||||
SetIndex(index);
|
||||
}
|
||||
|
||||
private void SetIndex(int value)
|
||||
{
|
||||
if (_isReady is false) return;
|
||||
if (value < 0) return;
|
||||
|
||||
EnsureConfiguration();
|
||||
|
||||
value = Mathf.Clamp(value, 0, tabContainer.GetChildCount() -1 );
|
||||
|
||||
_currentIndex = value;
|
||||
tabContainer.CurrentTab = value;
|
||||
|
||||
foreach (var tab in tabs)
|
||||
{
|
||||
tab.ButtonPressed = false;
|
||||
}
|
||||
if (tabs.TryGetElementAt(value, out var button))
|
||||
{
|
||||
button.ButtonPressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureConfiguration()
|
||||
{
|
||||
if (_isReady is false) return;
|
||||
tabContainer.TabsVisible = false;
|
||||
|
||||
foreach (var tab in tabs)
|
||||
{
|
||||
tab.ButtonGroup = _buttonGroup;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isReady => IsNodeReady() && tabContainer is not null & tabs is not null;
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@ using Godot.Collections;
|
||||
|
||||
namespace BITKit;
|
||||
[Tool]
|
||||
[Obsolete("see UXTabContainerService")]
|
||||
public partial class UXWindowService : Control
|
||||
{
|
||||
[Export] private Array<Button> tabs;
|
||||
@@ -34,7 +35,6 @@ public partial class UXWindowService : Control
|
||||
//if(window.Visible is true && window != x)
|
||||
x.Hide();
|
||||
}
|
||||
|
||||
var index = windows.IndexOf(window as Control);
|
||||
if (index is not -1)
|
||||
{
|
||||
|
Reference in New Issue
Block a user