-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAccessStateManager.cs
More file actions
105 lines (93 loc) · 2.86 KB
/
AccessStateManager.cs
File metadata and controls
105 lines (93 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using UnityEngine;
using MelonLoader;
namespace GladiatorManagerAccess
{
/// <summary>
/// Central state manager for accessibility handlers.
/// Solves the core problem: the same keys (arrows, Enter, Escape) need to do
/// different things depending on what's currently active.
/// </summary>
public static class AccessStateManager
{
public enum State
{
None,
MainMenu,
Home,
Barracks,
Inventory,
Shop,
Finance,
Help,
Options,
CharacterCreation,
TeamSelection,
Combat,
League,
Records,
WeekEndSummary,
Popup,
SaveScreen,
PerkScreen
}
public static State Current { get; private set; } = State.None;
public static bool IsBattleDoneThisWeek { get; set; } = false;
public static event Action<State, State> OnStateChanged;
/// <summary>
/// Try to enter a new state. Automatically exits the previous state if one is active.
/// </summary>
/// <returns>true if state was entered successfully</returns>
public static bool TryEnter(State state)
{
if (state == State.None)
{
return false;
}
if (Current == state)
{
return true; // Already in this state
}
// Auto-exit previous state if one is active
if (Current != State.None)
{
var previousState = Current;
Current = State.None;
OnStateChanged?.Invoke(previousState, State.None);
}
var oldState = Current;
Current = state;
DebugLogger.LogState($"Entered {state}");
OnStateChanged?.Invoke(oldState, state);
return true;
}
/// <summary>
/// Exit from a state. Only exits if currently in that state.
/// </summary>
public static void Exit(State state)
{
if (Current != state) return;
var oldState = Current;
Current = State.None;
DebugLogger.LogState($"Exited {state}");
OnStateChanged?.Invoke(oldState, State.None);
}
/// <summary>
/// Force exit from any state.
/// </summary>
public static void ForceReset()
{
if (Current != State.None)
{
var oldState = Current;
Current = State.None;
DebugLogger.LogState($"Force reset from {oldState}");
OnStateChanged?.Invoke(oldState, State.None);
}
}
public static bool IsIn(State state)
{
return Current == state;
}
}
}