(client) feat:窗口新增独占、占用输入属性,添加部分行为树节点和工作类
This commit is contained in:
@ -10,12 +10,10 @@ namespace Base
|
||||
{
|
||||
public class UIInputControl : Utils.MonoSingleton<UIInputControl>, ITickUI
|
||||
{
|
||||
// 存储窗口及其激活键的字典
|
||||
public Dictionary<KeyCode, UIBase> UIwindowKeys = new();
|
||||
// 存储没有激活键的窗口列表
|
||||
private List<UIBase> noKeyWindows = new();
|
||||
private List<UIBase> allWindows = new(); // 新增:所有窗口的集合
|
||||
|
||||
// 每帧更新逻辑
|
||||
public void TickUI()
|
||||
{
|
||||
foreach (var kvp in UIwindowKeys)
|
||||
@ -27,16 +25,19 @@ namespace Base
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Init()
|
||||
{
|
||||
UIwindowKeys.Clear();
|
||||
noKeyWindows.Clear();
|
||||
allWindows.Clear(); // 清空所有窗口集合
|
||||
|
||||
var uiInstances = Resources.FindObjectsOfTypeAll<UIBase>();
|
||||
|
||||
foreach (var uiBase in uiInstances)
|
||||
{
|
||||
allWindows.Add(uiBase); // 添加到所有窗口集合
|
||||
|
||||
var key = uiBase.actionButton;
|
||||
if (key == KeyCode.None)
|
||||
{
|
||||
@ -44,42 +45,55 @@ namespace Base
|
||||
uiBase.Hide();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (UIwindowKeys.ContainsKey(key))
|
||||
{
|
||||
Debug.LogWarning($"Key '{key}' is already assigned to another window. Skipping...");
|
||||
continue;
|
||||
}
|
||||
|
||||
UIwindowKeys[key] = uiBase;
|
||||
uiBase.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleWindowActivation(UIBase targetWindow, bool isFunctionCall = false)
|
||||
|
||||
private void HandleWindowActivation(UIBase targetWindow)
|
||||
{
|
||||
bool wasTargetVisible = targetWindow.IsVisible;
|
||||
bool anyOtherWindowOpen = false;
|
||||
bool shouldCloseExclusive = false;
|
||||
bool exclusiveWindowWasOpen = false;
|
||||
|
||||
// 遍历所有窗口(包括有键和无键窗口)
|
||||
foreach (var kvp in UIwindowKeys.Concat(noKeyWindows.Select(w => new KeyValuePair<KeyCode, UIBase>(KeyCode.None, w))))
|
||||
// 第一次遍历:检查是否有需要关闭的独占窗口
|
||||
foreach (var window in allWindows)
|
||||
{
|
||||
if (kvp.Value == targetWindow)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (window == targetWindow) continue;
|
||||
|
||||
if (kvp.Value.IsVisible)
|
||||
if (window.IsVisible && window.exclusive)
|
||||
{
|
||||
if (!wasTargetVisible || isFunctionCall) // 只在目标窗口要打开时才关闭其他窗口
|
||||
// 记录有独占窗口打开且需要关闭
|
||||
shouldCloseExclusive = true;
|
||||
exclusiveWindowWasOpen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 第二次遍历:根据条件关闭窗口
|
||||
foreach (var window in allWindows)
|
||||
{
|
||||
if (window == targetWindow) continue;
|
||||
|
||||
if (window.IsVisible)
|
||||
{
|
||||
// 关闭所有独占窗口(无论是新窗口打开还是关闭)
|
||||
// 或当目标窗口是独占窗口时关闭所有其他窗口
|
||||
if (window.exclusive || targetWindow.exclusive || shouldCloseExclusive)
|
||||
{
|
||||
kvp.Value.Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
anyOtherWindowOpen = true; // 记录是否有其他窗口打开
|
||||
window.Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 切换目标窗口状态
|
||||
if (wasTargetVisible)
|
||||
{
|
||||
targetWindow.Hide();
|
||||
@ -89,10 +103,27 @@ namespace Base
|
||||
targetWindow.Show();
|
||||
}
|
||||
|
||||
bool currentWindowState = !wasTargetVisible || anyOtherWindowOpen;
|
||||
if (Base.Clock.Instance.Pause != currentWindowState)
|
||||
// 更新暂停状态(优化版)
|
||||
UpdatePauseState(exclusiveWindowWasOpen, targetWindow);
|
||||
}
|
||||
|
||||
private void UpdatePauseState(bool exclusiveWindowWasOpen, UIBase targetWindow)
|
||||
{
|
||||
bool needPause = false;
|
||||
|
||||
foreach (var window in allWindows)
|
||||
{
|
||||
Base.Clock.Instance.Pause = currentWindowState;
|
||||
if (window.IsVisible && window.needPause)
|
||||
{
|
||||
needPause = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 只在状态改变时更新
|
||||
if (Base.Clock.Instance.Pause != needPause)
|
||||
{
|
||||
Base.Clock.Instance.Pause = needPause;
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,7 +155,7 @@ namespace Base
|
||||
return;
|
||||
}
|
||||
|
||||
HandleWindowActivation(window, true); // 调用内部逻辑处理,标记为函数调用
|
||||
HandleWindowActivation(window); // 调用内部逻辑处理,标记为函数调用
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -139,7 +170,7 @@ namespace Base
|
||||
return;
|
||||
}
|
||||
|
||||
HandleWindowActivation(window, true); // 调用内部逻辑处理,标记为函数调用
|
||||
HandleWindowActivation(window); // 调用内部逻辑处理,标记为函数调用
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -154,7 +185,7 @@ namespace Base
|
||||
return;
|
||||
}
|
||||
|
||||
HandleWindowActivation(window, true); // 调用内部逻辑处理,标记为函数调用
|
||||
HandleWindowActivation(window); // 调用内部逻辑处理,标记为函数调用
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -186,4 +217,5 @@ namespace Base
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user