File size: 3,999 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class TutorialKeybinds extends ScriptedWidgetEventHandler
{
	protected Widget						m_Root;
	protected Widget						m_DetailsRoot;
	
	protected TutorialsMenu					m_Menu;
	
	void TutorialKeybinds(Widget parent, TutorialsMenu menu)
	{
		m_Root							= GetGame().GetWorkspace().CreateWidgets(GetLayoutName(), parent);
		
		m_Menu							= menu;
		
		int actionCount;
		int actionMax = 80;
		
		int column_index = 0;
		int item_index;
		string output = "";
		string option_text = "";
		TIntArray actions = new TIntArray;
		GetUApi().GetActiveInputs(actions);
		
		actionCount = actions.Count();
		for (int i = 0; i < actionCount; i++)
		{
			UAInput input		= GetUApi().GetInputByID(actions.Get(i));
			if (input)
			{
				if (item_index < actionMax)
				{
					output = "";
					option_text = "";
					GetGame().GetInput().GetActionDesc(actions.Get(i), option_text);
					if (SetElementTitle(input, EUAINPUT_DEVICE_KEYBOARDMOUSE, output))
					{
						column_index		= Math.Floor(item_index / 21);
						Widget w			= GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/tutorials/xbox/keybindings_panels/keybinding_panel.layout", m_Root.FindAnyWidget("container" + column_index));
						Widget spacer		= w.FindWidget("Spacer");
						TextWidget name		= TextWidget.Cast(w.FindWidget("KeybindName"));
						TextWidget mod		= TextWidget.Cast(spacer.FindWidget("KeybindModifier"));
						TextWidget value	= TextWidget.Cast(spacer.FindWidget("KeybindButton"));
						
						string modifier_text = "";
						name.SetText(option_text);
						value.SetText(output);
						
						if (SetElementModifier(input, modifier_text))
						{
							mod.SetText(modifier_text);
						}
						
						name.Update();
						mod.Update();
						value.Update();
						spacer.Update();
						
						item_index++;
					}
				}
				else
				{
					option_text = "";
					GetGame().GetInput().GetActionDesc(actions[i], option_text);
					ErrorEx("input action " + option_text + " index out of bounds!",ErrorExSeverity.INFO);
				}
			}
		}
		
		m_Root.SetHandler(this);
	}
	
	//! assemble all active bindings at widget element
	bool SetElementTitle(UAInput pInput, int iDeviceFlags, out string output)
	{
		int a, i, countbind = 0;
	
		for (a = 0; a < pInput.AlternativeCount(); a++)
		{
			pInput.SelectAlternative(a);
			if (pInput.IsCombo())
			{
				if (pInput.BindingCount() > 0)
				{
					if (pInput.Binding(0) != 0 && pInput.CheckBindDevice(0,iDeviceFlags))
					{
						if (countbind > 0)
							output += ", ";
						
						output += GetUApi().GetButtonName(pInput.Binding(0));
						countbind++;
						
						for (i = 1; i < pInput.BindingCount(); i++)
						{
							if (pInput.Binding(i) != 0)
							{
								output += " + " + GetUApi().GetButtonName(pInput.Binding(i));
								countbind++;
							}
						}
						
					}
				}
			}
			else
			{
				if (pInput.BindingCount() > 0)
				{
					if (pInput.Binding(0) != 0 && pInput.CheckBindDevice(0,iDeviceFlags))
					{
						if (countbind > 0)
							output += ", ";

						output += GetUApi().GetButtonName(pInput.Binding(0));
						countbind++;
					}
				}
			}
			
		}
		
		return (countbind > 0);
	}
	
	//! Determine the active limiter of the bindings (currently unreliable, multiple limiters can be active on key combos!)
	bool SetElementModifier(UAInput pInput, out string output)
	{
		if (pInput.IsLimited())
		{
			if (pInput.IsPressLimit())
			{
				output = "#keybind_press";
			}
			if (pInput.IsReleaseLimit())
			{
				output = "#keybind_release";
			}
			if (pInput.IsHoldLimit())
			{
				output = "#keybind_hold";
			}
			if (pInput.IsHoldBeginLimit())
			{
				output = "#keybind_holdbegin";
			}
			if (pInput.IsClickLimit())
			{
				output = "#keybind_click";
			}
			if (pInput.IsDoubleClickLimit())
			{
				output = "#keybind_doubletap";
			}
			
			return true;
		}
		else
		{
			return false;
		}
	}
	
	void ~TutorialKeybinds()
	{
		
	}
	
	string GetLayoutName()
	{
		return "gui/layouts/new_ui/tutorials/xbox/keybinds_tab.layout";
	}
}