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

193 lines
5.4 KiB
C#
Raw Normal View History

2023-11-21 13:31:06 +08:00
2023-11-21 15:30:03 +08:00
using System;
2023-11-21 13:31:06 +08:00
using System.Collections.Generic;
2024-01-24 15:42:01 +08:00
using System.Linq;
2023-11-21 13:31:06 +08:00
using Cysharp.Threading.Tasks;
public partial class UIManager
{
2024-01-24 15:42:01 +08:00
private List<UIWindow> _uiWindowStack = new List<UIWindow>(8);
public List<UIWindow> UiWindowStack => _uiWindowStack;
2023-11-21 13:31:06 +08:00
2024-01-24 15:42:01 +08:00
#region StackAPI
public bool CheckIsWindowInStack(UIWindow window)
{
if (_uiWindowStack.Contains(window))
{
return true;
}
return false;
}
public UIWindow GetLast()
{
if (_uiWindowStack.Count > 0)
{
return _uiWindowStack.Last();
}
return null;
}
public UIWindow GetLastFullScreen()
{
if (_uiWindowStack.Count > 0)
{
for (int i = _uiWindowStack.Count - 1; i >= 0; i--)
{
if (CheckWindowIsFullScreen(_uiWindowStack[i]))
{
return _uiWindowStack[i];
}
}
}
return null;
}
2023-11-21 13:31:06 +08:00
public void PushWindow(UIWindow window)
{
2024-01-26 16:06:42 +08:00
if (window != null)
2023-11-21 13:31:06 +08:00
{
2024-01-24 15:42:01 +08:00
if (_uiWindowStack.Contains(window))
{
DebugUtil.LogError($"{window.WindowName} exists in UIWindowStack!!!");
return;
}
_uiWindowStack.Add(window);
2023-11-21 13:31:06 +08:00
}
}
public UIWindow PopWindow()
{
if (_uiWindowStack.Count > 0)
{
2024-01-24 15:42:01 +08:00
var window = _uiWindowStack.Last();
_uiWindowStack.Remove(window);
return window;
2023-11-21 13:31:06 +08:00
}
return null;
}
public UIWindow PopWindow(string checkWindowName)
{
if (_uiWindowStack.Count > 0)
{
2024-01-24 15:42:01 +08:00
var window = _uiWindowStack.Last();
2023-11-21 13:31:06 +08:00
if (string.IsNullOrEmpty(checkWindowName) || checkWindowName.Equals(window.WindowName))
{
2024-01-24 15:42:01 +08:00
_uiWindowStack.Remove(window);
return window;;
2023-11-21 13:31:06 +08:00
}
}
return null;
}
2024-01-24 15:42:01 +08:00
public void ForceRemoveWindow(UIWindow window)
{
if (_uiWindowStack.Contains(window))
{
_uiWindowStack.Remove(window);
}
}
2024-01-24 16:48:01 +08:00
public void ClearHideStack(params string[] windowName)
{
for(int i = _uiWindowStack.Count - 1; i >=0 ; i--)
2024-01-24 16:48:01 +08:00
{
if (!windowName.Contains(_uiWindowStack[i].WindowName))
{
_uiWindowStack[i].CloseWindow(UIWindowCloseType.ForceDestroy);
_uiWindowStack.RemoveAt(i);
2024-01-24 16:48:01 +08:00
}
}
}
2023-11-21 13:31:06 +08:00
public void ClearHideStack()
{
2024-01-24 15:42:01 +08:00
for(int i = 0; i < _uiWindowStack.Count; i++)
{
_uiWindowStack[i].CloseWindow(UIWindowCloseType.ForceDestroy);
}
2023-11-21 13:31:06 +08:00
_uiWindowStack.Clear();
}
2024-01-24 15:42:01 +08:00
#endregion
2023-11-21 13:31:06 +08:00
2023-11-21 15:30:03 +08:00
public static async UniTask<UIWindow> AnimSwitchWindow(UIWindow hideWindow, UIWindowCloseType closeType, string showWindowName, object data = null)
2023-11-21 13:31:06 +08:00
{
if (hideWindow != null)
{
await hideWindow.AnimHide();
}
var showWindow = await UIManager.Instance.OpenWindow(showWindowName, data);
if (showWindow != null)
{
await showWindow.AnimShow();
}
2023-11-21 13:31:06 +08:00
2023-11-21 16:22:19 +08:00
if (hideWindow != null)
{
hideWindow.CloseWindow(closeType);
}
2023-11-21 13:31:06 +08:00
return showWindow;
}
2024-01-15 16:19:09 +08:00
public static async UniTask<UIWindow> AnimSwitchWindow(UIWindow hideWindow, UIWindowCloseType closeType, UIWindow showWindow, object data = null)
2023-11-21 13:31:06 +08:00
{
if (hideWindow != null)
{
await hideWindow.AnimHide();
}
if (showWindow != null)
{
2024-01-15 16:19:09 +08:00
if (showWindow.IsOpen())
{
showWindow.OpenWindow(data);
}
else
{
showWindow.ShowWindow();
}
2023-11-21 13:31:06 +08:00
await showWindow.AnimShow();
}
2023-11-21 16:22:19 +08:00
if (hideWindow != null)
{
hideWindow.CloseWindow(closeType);
}
2023-11-21 13:31:06 +08:00
return showWindow;
}
2023-11-21 15:30:03 +08:00
//常规的关闭一个最后打开的界面
public static async UniTask NormalCloseWindow(UIWindow hideWindow, String showWindowStr, Object data = null)
{
var window = Instance.PopWindow();
2024-01-26 16:06:42 +08:00
if (window == null)
2023-11-21 15:30:03 +08:00
{
hideWindow.OnBack();
return;
}
await AnimSwitchWindow(hideWindow, UIWindowCloseType.HideAndDestroy, showWindowStr, data);
2023-11-21 15:30:03 +08:00
}
public static async UniTask NormalCloseWindow(UIWindow hideWindow, Object data = null)
{
var showWindow = Instance.PopWindow();
2024-01-26 16:06:42 +08:00
if (showWindow == null)
2023-11-21 15:30:03 +08:00
{
hideWindow.OnBack();
return;
}
await AnimSwitchWindow(hideWindow, UIWindowCloseType.HideAndDestroy, showWindow, data);
2023-11-21 15:30:03 +08:00
}
2023-11-21 13:31:06 +08:00
}