69 lines
2.7 KiB
C#
69 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace AlicizaX.UI.Runtime
|
|
{
|
|
|
|
internal static class UIStateMachine
|
|
{
|
|
private static readonly Dictionary<UIState, HashSet<UIState>> _validTransitions = new()
|
|
{
|
|
[UIState.Uninitialized] = new() { UIState.CreatedUI },
|
|
[UIState.CreatedUI] = new() { UIState.Loaded, UIState.Destroying },
|
|
[UIState.Loaded] = new() { UIState.Initialized, UIState.Destroying },
|
|
[UIState.Initialized] = new() { UIState.Opening, UIState.Destroying },
|
|
[UIState.Opening] = new() { UIState.Opened, UIState.Closing, UIState.Destroying },
|
|
[UIState.Opened] = new() { UIState.Closing, UIState.Destroying },
|
|
[UIState.Closing] = new() { UIState.Opening, UIState.Closed, UIState.Destroying },
|
|
[UIState.Closed] = new() { UIState.Opening, UIState.Destroying },
|
|
[UIState.Destroying] = new() { UIState.Destroyed },
|
|
[UIState.Destroyed] = new() { }
|
|
};
|
|
|
|
public static bool IsValidTransition(UIState from, UIState to)
|
|
{
|
|
return _validTransitions.TryGetValue(from, out var validStates) && validStates.Contains(to);
|
|
}
|
|
|
|
public static bool ValidateTransition(string uiName, UIState from, UIState to)
|
|
{
|
|
if (IsValidTransition(from, to))
|
|
return true;
|
|
|
|
Log.Error($"[UI] Invalid state transition for {uiName}: {from} -> {to}");
|
|
return false;
|
|
}
|
|
|
|
|
|
public static HashSet<UIState> GetValidNextStates(UIState currentState)
|
|
{
|
|
return _validTransitions.TryGetValue(currentState, out var states)
|
|
? states
|
|
: new HashSet<UIState>();
|
|
}
|
|
|
|
public static string GetStateDescription(UIState state)
|
|
{
|
|
return state switch
|
|
{
|
|
UIState.Uninitialized => "Not yet created",
|
|
UIState.CreatedUI => "UI logic created, awaiting resource load",
|
|
UIState.Loaded => "Resources loaded, awaiting initialization",
|
|
UIState.Initialized => "Initialized, ready to open",
|
|
UIState.Opening => "Opening transition is running",
|
|
UIState.Opened => "Currently visible and active",
|
|
UIState.Closing => "Closing transition is running",
|
|
UIState.Closed => "Hidden but cached",
|
|
UIState.Destroying => "Being destroyed",
|
|
UIState.Destroyed => "Fully destroyed",
|
|
_ => "Unknown state"
|
|
};
|
|
}
|
|
|
|
public static bool IsDisplayActive(UIState state)
|
|
{
|
|
return state == UIState.Opening || state == UIState.Opened || state == UIState.Closing;
|
|
}
|
|
}
|
|
}
|