summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/Thronefall/ControlMapButton.cs
blob: 9693730187d89317d026d356b75f2441837c54bc (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using System.Collections.Generic;
using I2.Loc;
using Rewired;
using TMPro;
using UnityEngine;

public class ControlMapButton : MonoBehaviour
{
	public enum AxisMode
	{
		Button,
		Positive,
		Negative
	}

	public TFUITextButton target;

	public GameObject selectionIndicator;

	public TextMeshProUGUI displayKeyboard;

	public TextMeshProUGUI displayMouse;

	public TextMeshProUGUI displayController;

	private AxisMode axisMode;

	private InputAction actionToMap;

	private KeyRebinder targetRebinder;

	private ActionElementMap keyMap;

	private ActionElementMap mouseMap;

	private ActionElementMap joystickMap;

	private string descriptor
	{
		get
		{
			if (axisMode == AxisMode.Positive)
			{
				return actionToMap.name + " Positive";
			}
			if (axisMode == AxisMode.Negative)
			{
				return actionToMap.name + " Negative";
			}
			return actionToMap.name;
		}
	}

	private void Start()
	{
		selectionIndicator.SetActive(value: false);
		target.onApply.AddListener(OnApply);
		target.onSelectionStateChange.AddListener(UpdateSelectionIndicator);
	}

	public void SetData(InputAction _action, KeyRebinder _rebinder, AxisMode _axisMode)
	{
		axisMode = _axisMode;
		targetRebinder = _rebinder;
		actionToMap = _action;
		Refresh();
		target.SetOriginalString(LocalizationManager.GetTermTranslation("Controls/" + descriptor));
	}

	public void Refresh()
	{
		UpdateMappings();
		UpdateLabels();
	}

	private void UpdateMappings()
	{
		keyMap = null;
		mouseMap = null;
		joystickMap = null;
		List<ActionElementMap> list = new List<ActionElementMap>();
		if (targetRebinder.KeyboardMap != null)
		{
			list = new List<ActionElementMap>(targetRebinder.KeyboardMap.GetElementMapsWithAction(actionToMap.id));
		}
		List<ActionElementMap> list2 = new List<ActionElementMap>();
		if (targetRebinder.MouseMap != null)
		{
			list2 = new List<ActionElementMap>(targetRebinder.MouseMap.GetElementMapsWithAction(actionToMap.id));
		}
		List<ActionElementMap> list3 = new List<ActionElementMap>();
		if (targetRebinder.JoystickMap != null)
		{
			list3 = new List<ActionElementMap>(targetRebinder.JoystickMap.GetElementMapsWithAction(actionToMap.id));
		}
		for (int num = list.Count - 1; num >= 0; num--)
		{
			ActionElementMap actionElementMap = list[num];
			switch (axisMode)
			{
			case AxisMode.Negative:
				if (actionElementMap.axisContribution != Pole.Negative)
				{
					list.RemoveAt(num);
				}
				break;
			case AxisMode.Positive:
				if (actionElementMap.axisContribution != 0)
				{
					list.RemoveAt(num);
				}
				break;
			}
		}
		for (int num2 = list2.Count - 1; num2 >= 0; num2--)
		{
			ActionElementMap actionElementMap2 = list2[num2];
			switch (axisMode)
			{
			case AxisMode.Negative:
				if (actionElementMap2.axisContribution != Pole.Negative)
				{
					list2.RemoveAt(num2);
				}
				break;
			case AxisMode.Positive:
				if (actionElementMap2.axisContribution != 0)
				{
					list2.RemoveAt(num2);
				}
				break;
			}
		}
		for (int num3 = list3.Count - 1; num3 >= 0; num3--)
		{
			ActionElementMap actionElementMap3 = list3[num3];
			switch (axisMode)
			{
			case AxisMode.Negative:
				if (actionElementMap3.axisContribution != Pole.Negative)
				{
					list3.RemoveAt(num3);
				}
				break;
			case AxisMode.Positive:
				if (actionElementMap3.axisContribution != 0)
				{
					list3.RemoveAt(num3);
				}
				break;
			}
		}
		if (list.Count > 0)
		{
			keyMap = list[0];
		}
		if (list2.Count > 0)
		{
			mouseMap = list2[0];
		}
		if (list3.Count > 0)
		{
			joystickMap = list3[0];
		}
	}

	private void UpdateLabels()
	{
		string text = ((keyMap != null) ? keyMap.elementIdentifierName : "﹘");
		string text2 = ((mouseMap != null) ? mouseMap.elementIdentifierName : "﹘");
		string text3 = ((joystickMap == null) ? "﹘" : joystickMap.elementIdentifierName);
		displayKeyboard.text = text;
		displayMouse.text = text2;
		displayController.text = text3;
	}

	private void OnApply()
	{
		targetRebinder.TriggerRebind(actionToMap, keyMap, mouseMap, joystickMap, axisMode);
	}

	private void UpdateSelectionIndicator()
	{
		if (target.CurrentState == ThronefallUIElement.SelectionState.Selected)
		{
			selectionIndicator.SetActive(value: true);
		}
		else
		{
			selectionIndicator.SetActive(value: false);
		}
	}
}