NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIManager.Stack.cs

128 lines
3.5 KiB
C#
Raw Normal View History

2025-12-22 16:55:56 +08:00
using System;
using System.Collections.Generic;
2023-11-21 13:31:06 +08:00
2025-12-22 16:55:56 +08:00
public partial class UIManager
{
#region Stack Management - 委托给 UINavigationManager
/// <summary>
/// 导航栈(只读,用于兼容旧代码)
/// </summary>
public List<UIWindow> UiWindowStack => UINavigationManager.Instance.NavigationStack;
/// <summary>
/// 检查窗口是否在栈中
/// </summary>
public bool CheckIsWindowInStack(UIWindow window)
{
return UINavigationManager.Instance.IsWindowInStack(window);
}
2023-11-21 13:31:06 +08:00
2025-12-22 16:55:56 +08:00
/// <summary>
/// 获取栈顶窗口
/// </summary>
public UIWindow GetLast()
2023-11-21 13:31:06 +08:00
{
2025-12-22 16:55:56 +08:00
return UINavigationManager.Instance.GetTopWindow();
}
2023-11-21 13:31:06 +08:00
2025-12-22 16:55:56 +08:00
/// <summary>
/// 获取栈顶的全屏窗口
/// </summary>
public UIWindow GetLastFullScreen()
{
return UINavigationManager.Instance.GetTopFullScreenWindow();
}
2024-01-24 15:42:01 +08:00
2025-12-22 16:55:56 +08:00
/// <summary>
/// 入栈(兼容方法,推荐使用 UINavigationManager)
/// </summary>
[Obsolete("Use UINavigationManager.HandleWindowOpen instead")]
public void PushWindow(UIWindow window)
{
UINavigationManager.Instance.HandleWindowOpen(window, UIStackMode.Stackable);
}
2024-01-24 15:42:01 +08:00
2025-12-22 16:55:56 +08:00
/// <summary>
/// 出栈
/// </summary>
public UIWindow PopWindow()
{
return PopWindow(null);
}
2024-01-24 15:42:01 +08:00
2025-12-22 16:55:56 +08:00
/// <summary>
/// 出栈(带窗口名检查)
/// </summary>
public UIWindow PopWindow(string checkWindowName)
{
var top = UINavigationManager.Instance.GetTopWindow();
if (top != null && (string.IsNullOrEmpty(checkWindowName) || checkWindowName == top.WindowName))
2024-01-24 15:42:01 +08:00
{
2025-12-22 16:55:56 +08:00
UINavigationManager.Instance.HandleWindowClose(top);
return top;
2024-01-24 15:42:01 +08:00
}
2025-12-22 16:55:56 +08:00
return null;
}
2024-01-24 15:42:01 +08:00
2025-12-22 16:55:56 +08:00
/// <summary>
/// 强制移除窗口(从栈中移除但不关闭)
/// </summary>
public void ForceRemoveWindow(UIWindow window)
{
UINavigationManager.Instance.HandleWindowClose(window);
}
2024-01-24 15:42:01 +08:00
2025-12-22 16:55:56 +08:00
/// <summary>
/// 清空栈(保留指定窗口)
/// </summary>
public void ClearHideStack(params string[] windowName)
{
var stack = UINavigationManager.Instance.NavigationStack;
2024-01-24 15:42:01 +08:00
2025-12-22 16:55:56 +08:00
// 倒序遍历,避免索引问题
for (int i = stack.Count - 1; i >= 0; i--)
2023-11-21 13:31:06 +08:00
{
2025-12-22 16:55:56 +08:00
var window = stack[i];
// 检查是否是要保留的窗口
bool shouldKeep = false;
for (int j = 0; j < windowName.Length; j++)
2023-11-21 13:31:06 +08:00
{
2025-12-22 16:55:56 +08:00
if (window.WindowName == windowName[j])
2024-01-24 15:42:01 +08:00
{
2025-12-22 16:55:56 +08:00
shouldKeep = true;
break;
2024-01-24 15:42:01 +08:00
}
2023-11-21 13:31:06 +08:00
}
2025-12-22 16:55:56 +08:00
if (!shouldKeep)
2023-11-21 13:31:06 +08:00
{
2025-12-22 16:55:56 +08:00
// 先从栈移除,再关闭窗口
UINavigationManager.Instance.HandleWindowClose(window);
window.CloseWindow(UIWindowCloseType.ForceDestroy);
2024-01-24 16:48:01 +08:00
}
}
2025-12-22 16:55:56 +08:00
}
/// <summary>
/// 清空所有栈
/// </summary>
public void ClearHideStack()
{
var stack = UINavigationManager.Instance.NavigationStack;
2024-01-24 16:48:01 +08:00
2025-12-22 16:55:56 +08:00
// 先复制列表,避免在遍历时修改集合
var windowsToClose = new List<UIWindow>(stack);
UINavigationManager.Instance.Clear();
// 再关闭所有窗口
for (int i = 0; i < windowsToClose.Count; i++)
2023-11-21 13:31:06 +08:00
{
2025-12-22 16:55:56 +08:00
windowsToClose[i].CloseWindow(UIWindowCloseType.ForceDestroy);
2023-11-21 13:31:06 +08:00
}
}
2025-12-22 16:55:56 +08:00
#endregion
}