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

128 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
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);
}
/// <summary>
/// 获取栈顶窗口
/// </summary>
public UIWindow GetLast()
{
return UINavigationManager.Instance.GetTopWindow();
}
/// <summary>
/// 获取栈顶的全屏窗口
/// </summary>
public UIWindow GetLastFullScreen()
{
return UINavigationManager.Instance.GetTopFullScreenWindow();
}
/// <summary>
/// 入栈(兼容方法,推荐使用 UINavigationManager
/// </summary>
[Obsolete("Use UINavigationManager.HandleWindowOpen instead")]
public void PushWindow(UIWindow window)
{
UINavigationManager.Instance.HandleWindowOpen(window, UIStackMode.Stackable);
}
/// <summary>
/// 出栈
/// </summary>
public UIWindow PopWindow()
{
return PopWindow(null);
}
/// <summary>
/// 出栈(带窗口名检查)
/// </summary>
public UIWindow PopWindow(string checkWindowName)
{
var top = UINavigationManager.Instance.GetTopWindow();
if (top != null && (string.IsNullOrEmpty(checkWindowName) || checkWindowName == top.WindowName))
{
UINavigationManager.Instance.HandleWindowClose(top);
return top;
}
return null;
}
/// <summary>
/// 强制移除窗口(从栈中移除但不关闭)
/// </summary>
public void ForceRemoveWindow(UIWindow window)
{
UINavigationManager.Instance.HandleWindowClose(window);
}
/// <summary>
/// 清空栈(保留指定窗口)
/// </summary>
public void ClearHideStack(params string[] windowName)
{
var stack = UINavigationManager.Instance.NavigationStack;
// 倒序遍历,避免索引问题
for (int i = stack.Count - 1; i >= 0; i--)
{
var window = stack[i];
// 检查是否是要保留的窗口
bool shouldKeep = false;
for (int j = 0; j < windowName.Length; j++)
{
if (window.WindowName == windowName[j])
{
shouldKeep = true;
break;
}
}
if (!shouldKeep)
{
// 先从栈移除,再关闭窗口
UINavigationManager.Instance.HandleWindowClose(window);
window.CloseWindow(UIWindowCloseType.ForceDestroy);
}
}
}
/// <summary>
/// 清空所有栈
/// </summary>
public void ClearHideStack()
{
var stack = UINavigationManager.Instance.NavigationStack;
// 先复制列表,避免在遍历时修改集合
var windowsToClose = new List<UIWindow>(stack);
UINavigationManager.Instance.Clear();
// 再关闭所有窗口
for (int i = 0; i < windowsToClose.Count; i++)
{
windowsToClose[i].CloseWindow(UIWindowCloseType.ForceDestroy);
}
}
#endregion
}