74 lines
1.8 KiB
C#
74 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace FlowScope.UI
|
|
{
|
|
internal sealed class UILayer
|
|
{
|
|
private readonly Stack<UIPanelRecord> _stack = new();
|
|
private readonly Dictionary<Type, UIPanelRecord> _cachedPanels = new();
|
|
|
|
public UILayer(string name, Canvas canvas, int sortOrder, PanelStrategy strategy)
|
|
{
|
|
Name = name;
|
|
Canvas = canvas;
|
|
Strategy = strategy;
|
|
Canvas.sortingOrder = sortOrder;
|
|
}
|
|
|
|
public string Name { get; }
|
|
public Canvas Canvas { get; }
|
|
public PanelStrategy Strategy { get; }
|
|
public int Count => _stack.Count;
|
|
|
|
public void Push(UIPanelRecord record)
|
|
{
|
|
record.IsOpen = true;
|
|
_stack.Push(record);
|
|
}
|
|
|
|
public UIPanelRecord Peek()
|
|
{
|
|
return _stack.Peek();
|
|
}
|
|
|
|
public UIPanelRecord Pop()
|
|
{
|
|
var record = _stack.Pop();
|
|
record.IsOpen = false;
|
|
return record;
|
|
}
|
|
|
|
public bool TryGetCached(Type panelType, out UIPanelRecord record)
|
|
{
|
|
return _cachedPanels.TryGetValue(panelType, out record);
|
|
}
|
|
|
|
public void Cache(UIPanelRecord record)
|
|
{
|
|
_cachedPanels[record.PanelType] = record;
|
|
}
|
|
|
|
public void RemoveCached(Type panelType)
|
|
{
|
|
_cachedPanels.Remove(panelType);
|
|
}
|
|
|
|
public bool ContainsOpen(Type panelType, out UIPanelRecord record)
|
|
{
|
|
foreach (var current in _stack)
|
|
{
|
|
if (current.PanelType == panelType)
|
|
{
|
|
record = current;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
record = null;
|
|
return false;
|
|
}
|
|
}
|
|
}
|