summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/ThronefallUIElement.cs
blob: e2c9d648377fbb7529ccb4d5f2df3c087eceedba (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using UnityEngine;
using UnityEngine.Events;

public abstract class ThronefallUIElement : MonoBehaviour
{
	public enum NavigationDirection
	{
		Right,
		Left,
		Up,
		Down
	}

	public enum SelectionState
	{
		Default,
		Focussed,
		Selected,
		FocussedAndSelected
	}

	protected SelectionState currentState;

	protected SelectionState previousState;

	public bool ignoreMouse;

	public bool autoSelectOnFocus;

	public bool cannotBeSelected;

	public ThronefallUIElement leftNav;

	public ThronefallUIElement rightNav;

	public ThronefallUIElement topNav;

	public ThronefallUIElement botNav;

	public UnityEvent onSelectionStateChange = new UnityEvent();

	public UnityEvent onApply = new UnityEvent();

	public UnityEvent<NavigationDirection> onEmptyNavigate = new UnityEvent<NavigationDirection>();

	public SelectionState CurrentState => currentState;

	public SelectionState PreviousState => previousState;

	public virtual bool dragable => false;

	public void Apply()
	{
		if (!SceneTransitionManager.instance.SceneTransitionIsRunning)
		{
			onApply.Invoke();
			OnApply();
		}
	}

	public void Select()
	{
		SetState(SelectionState.Selected);
	}

	public void Focus()
	{
		SetState(SelectionState.Focussed);
	}

	public void FocusAndSelect()
	{
		SetState(SelectionState.FocussedAndSelected);
	}

	public void Clear()
	{
		SetState(SelectionState.Default);
	}

	public void HardStateSet(SelectionState selectionState)
	{
		currentState = selectionState;
		previousState = selectionState;
		OnHardStateSet(selectionState);
	}

	protected abstract void OnApply();

	protected abstract void OnClear();

	protected abstract void OnSelect();

	protected abstract void OnFocus();

	protected abstract void OnFocusAndSelect();

	protected abstract void OnHardStateSet(SelectionState selectionState);

	private void SetState(SelectionState state)
	{
		if (state != currentState)
		{
			previousState = currentState;
			currentState = state;
			switch (currentState)
			{
			case SelectionState.Default:
				OnClear();
				break;
			case SelectionState.Focussed:
				OnFocus();
				break;
			case SelectionState.Selected:
				OnSelect();
				break;
			case SelectionState.FocussedAndSelected:
				OnFocusAndSelect();
				break;
			}
			onSelectionStateChange.Invoke();
		}
	}

	public ThronefallUIElement TryNavigate(NavigationDirection direction)
	{
		if (SceneTransitionManager.instance.SceneTransitionIsRunning)
		{
			return this;
		}
		ThronefallUIElement thronefallUIElement = null;
		switch (direction)
		{
		case NavigationDirection.Down:
			thronefallUIElement = botNav;
			break;
		case NavigationDirection.Up:
			thronefallUIElement = topNav;
			break;
		case NavigationDirection.Left:
			thronefallUIElement = leftNav;
			break;
		case NavigationDirection.Right:
			thronefallUIElement = rightNav;
			break;
		}
		if ((bool)thronefallUIElement && !thronefallUIElement.gameObject.activeInHierarchy)
		{
			return thronefallUIElement.TryNavigate(direction);
		}
		onEmptyNavigate.Invoke(direction);
		return thronefallUIElement;
	}

	public virtual void OnDrag(Vector2 mousePosition)
	{
	}

	public virtual void OnDragEnd()
	{
	}

	public virtual void OnDragStart()
	{
	}
}