Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AdvancedKeybindDialogUI.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
2class SCR_AdvancedKeybindDialogUI: SCR_KeybindDialogBase
3{
5
6 protected string m_sActionPreset;
7 protected SCR_EActionPrefixType m_eActionPrefixType;
8 protected int m_iSelectedKeybind;
9
10 protected SCR_ModularButtonComponent m_FocusedBindRowButton;
11 protected ref array<SCR_ModularButtonComponent> m_aBindRowButtons = {};
12
14
15 protected const ResourceName KEYBIND_ROW_LAYOUT_PATH = "{25888355688EE402}UI/layouts/Menus/SettingsMenu/BindingMenu/AdvancedKeybindActionRow.layout";
16
17 //------------------------------------------------------------------------------------------------
19 {
20 super.OnMenuOpen(preset);
21
22 SetTitle(m_sDisplayName);
23
24 m_Select = FindButton("Select");
25 if (m_Select)
26 {
27 m_Select.m_OnActivated.Insert(OnSelectButton);
28 m_Select.SetVisible(false, false);
29 }
30
31 SCR_InputButtonComponent button = FindButton("Reset");
32 if (button)
33 button.m_OnActivated.Insert(ResetBindings);
34
35 button = FindButton("DeleteBind");
36 if (button)
37 button.m_OnActivated.Insert(DeleteSelectedBind);
38
39 button = FindButton("UnbindAll");
40 if (button)
41 button.m_OnActivated.Insert(UnbindAction);
42
47
50 }
51
52 //------------------------------------------------------------------------------------------------
53 // Reselect correct keybind row
54 protected void ReselectRow()
55 {
56 if (!m_aBindRowButtons.IsIndexValid(m_iSelectedKeybind))
57 return;
58
60 GetGame().GetWorkspace().SetFocusedWidget(m_FocusedBindRowButton.GetRootWidget());
62 }
63
64 //-----------------------------------------------------------------------------------------------
65 protected void ShowBindsForAction()
66 {
67 Widget contentWidget = m_wRoot.FindAnyWidget("ScrollContent");
68 if (!contentWidget)
69 return;
70
71 //clear the content so we prevent duplicates
72 Widget children = contentWidget.GetChildren();
73 while (children)
74 {
75 contentWidget.RemoveChild(children);
76 children = contentWidget.GetChildren();
77 }
78
79 int bindCount = m_SettingsKeybindModule.GetActionBindCount(m_sActionName, m_sActionPreset, m_eDevice);
80 /* TODO: no keybind is sometimes considered a binding and shows the confilcting bindings message. FIX
81 // Fallback to force showing the No Keybind message if there are no bindings
82 if (bindCount == 0)
83 UnbindAction();
84 */
85 m_aBindRowButtons.Clear();
87 SCR_ModularButtonComponent rowModularButtonComponent;
88 Widget rowWidget;
89 for (int i = 0; i < bindCount; i++)
90 {
91 rowWidget = GetGame().GetWorkspace().CreateWidgets(KEYBIND_ROW_LAYOUT_PATH, contentWidget);
92 if (!rowWidget)
93 continue;
94
96 if (!rowComponent)
97 continue;
98
100
101 rowModularButtonComponent = SCR_ModularButtonComponent.FindComponent(rowWidget);
102 if (!rowModularButtonComponent)
103 continue;
104
105 m_aBindRowButtons.Insert(rowModularButtonComponent);
106 rowModularButtonComponent.m_OnClicked.Insert(OnKeybindRowClick);
107 rowModularButtonComponent.m_OnFocus.Insert(OnKeybindRowFocus);
108 rowModularButtonComponent.m_OnFocusLost.Insert(OnKeybindRowFocusLost);
109 }
110 }
111
112 //-----------------------------------------------------------------------------------------------
114 {
116
117 // Select the last row
119 ReselectRow();
120 }
121
122 //-----------------------------------------------------------------------------------------------
123 protected void SetSelectedKeybind(notnull SCR_ModularButtonComponent modularButtonComp)
124 {
125 Widget root = modularButtonComp.GetRootWidget();
126 if (!root)
127 return;
128
130 if (!advancedKeybindComponent)
131 return;
132
133 m_iSelectedKeybind = advancedKeybindComponent.GetKeybindIndex();
134
135 // Visual update, show border on selected and remove from others
136 foreach (SCR_ModularButtonComponent comp : m_aBindRowButtons)
137 {
138 comp.SetToggled(comp == modularButtonComp, false);
139 }
140 }
141
142 //-----------------------------------------------------------------------------------------------
143 protected void ResetBindings()
144 {
146
148
150 ReselectRow();
151
152 //SCR_AnalyticsApplication.GetInstance().ChangeKeybind(m_sActionName, m_sActionPreset);
153 }
154
155 //-----------------------------------------------------------------------------------------------
156 protected void DeleteSelectedBind()
157 {
159
161
162 // Select the row immediately above
163 m_iSelectedKeybind = Math.Clamp(m_iSelectedKeybind - 1, 0, m_aBindRowButtons.Count() - 1);
164 ReselectRow();
165 }
166
167 //-----------------------------------------------------------------------------------------------
168 protected void StartCapturingKeybind()
169 {
170 m_SettingsKeybindModule.StartCaptureForAction(m_sActionName, m_sActionPreset, EInputDeviceType.KEYBOARD, true);
171
173 m_Entry,
176 m_SettingsKeybindModule.GetInputBindings(),
177 EInputDeviceType.KEYBOARD,
178 false
179 );
180
181 if (!dialog)
182 return;
183
185 }
186
187 //-----------------------------------------------------------------------------------------------
188 protected void UnbindAction()
189 {
191
193
195 ReselectRow();
196 }
197
198 //-----------------------------------------------------------------------------------------------
199 protected void SetupCaptureButton()
200 {
201 ButtonWidget buttonWidget = ButtonWidget.Cast(m_wRoot.FindAnyWidget("AddKeybind"));
202 if (!buttonWidget)
203 return;
204
205 SCR_ModularButtonComponent buttonComp = SCR_ModularButtonComponent.Cast(buttonWidget.FindHandler(SCR_ModularButtonComponent));
206 if (!buttonComp)
207 return;
208
209 buttonComp.SetEnabled(!m_sActionPreset.IsEmpty());
210 buttonComp.m_OnClicked.Insert(StartCapturingKeybind);
211 }
212
213 //-----------------------------------------------------------------------------------------------
214 protected void SetupPrefixesCombo()
215 {
216 m_wPrefixesCombo = m_wRoot.FindAnyWidget("ActionPrefixCombo");
217 if (!m_wPrefixesCombo)
218 {
219 Print("SCR_AdvancedKeybindDialogUI: Action prefix combo widget was not found", LogLevel.WARNING);
220 return;
221 }
222
224 if (!comboBoxComponent)
225 return;
226
227 array<ref SCR_KeyBindingFilter> filters = m_SettingsKeybindModule.GetFilters(m_eActionPrefixType);
228
229 foreach (SCR_KeyBindingFilter filter : filters)
230 {
231 comboBoxComponent.AddItem(filter.m_sFilterDisplayName);
232 }
233
234 comboBoxComponent.m_OnChanged.Insert(OnPrefixesComboChanged);
235 }
236
237 //-----------------------------------------------------------------------------------------------
238 protected void SetupBindsCombo()
239 {
240 Widget systemBindCombo = m_wRoot.FindAnyWidget("SystemKeyCombo");
241 if (!systemBindCombo)
242 {
243 Print("SCR_AdvancedKeybindDialogUI: System key combo widget was not found", LogLevel.WARNING);
244 }
245
246 SCR_ComboBoxComponent comboBoxComponent = SCR_ComboBoxComponent.Cast(systemBindCombo.FindHandler(SCR_ComboBoxComponent));
247 if (!comboBoxComponent)
248 return;
249
250 array<ref SCR_KeyBindingBind> binds = m_SettingsKeybindModule.GetCustomBinds();
251 foreach (SCR_KeyBindingBind bind : binds)
252 {
253 comboBoxComponent.AddItem(bind.m_sBindDisplayName);
254 }
255
256 comboBoxComponent.m_OnChanged.Insert(OnBindsComboChanged);
257 }
258
259 //-----------------------------------------------------------------------------------------------
260 protected void SetupCombinationCombo()
261 {
262 Widget combinationBindCombo = m_wRoot.FindAnyWidget("ComboKeyCombo");
263 if (!combinationBindCombo)
264 {
265 Print("SCR_AdvancedKeybindDialogUI: Combination key combo widget was not found", LogLevel.WARNING);
266 return;
267 }
268
269 SCR_ComboBoxComponent comboBoxComponent = SCR_ComboBoxComponent.Cast(combinationBindCombo.FindHandler(SCR_ComboBoxComponent));
270 if (!comboBoxComponent)
271 return;
272
273 array<ref SCR_KeyBindingCombo> combos = m_SettingsKeybindModule.GetCustomComboKeys();
274 foreach (SCR_KeyBindingCombo combo : combos)
275 {
276 comboBoxComponent.AddItem(combo.m_sComboDisplayName);
277 }
278
279 comboBoxComponent.m_OnChanged.Insert(OnCombinationComboChanged);
280 }
281
282 //-----------------------------------------------------------------------------------------------
291
292 //-----------------------------------------------------------------------------------------------
293 protected void OnBindsComboChanged(SCR_ComboBoxComponent component, int index)
294 {
295 m_SettingsKeybindModule.AddKeybindToActionByIndex(m_sActionName, m_sActionPreset, index);
296
298
299 // Select the last row
301 ReselectRow();
302 }
303
304 //------------------------------------------------------------------------------------------------
306 {
308
310
311 ReselectRow();
312 }
313
314 //------------------------------------------------------------------------------------------------
315 protected void OnSelectButton(SCR_InputButtonComponent button, string action)
316 {
319
320 m_Select.SetVisible(false, false);
321 }
322
323 //-----------------------------------------------------------------------------------------------
324 protected void OnKeybindRowClick(notnull SCR_ModularButtonComponent modularButtonComp)
325 {
326 if (m_FocusedBindRowButton && GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE)
328 }
329
330 //------------------------------------------------------------------------------------------------
331 protected void OnKeybindRowFocus(SCR_ModularButtonComponent comp)
332 {
334
335 Widget root = comp.GetRootWidget();
336 if (!root)
337 return;
338
340 if (advancedKeybindComponent)
341 advancedKeybindComponent.StartScrolling();
342
343 if (m_Select && m_iSelectedKeybind != advancedKeybindComponent.GetKeybindIndex())
344 m_Select.SetVisible(true, false);
345 }
346
347 //------------------------------------------------------------------------------------------------
348 protected void OnKeybindRowFocusLost(SCR_ModularButtonComponent comp)
349 {
351
352 if (m_Select)
353 m_Select.SetVisible(false, false);
354
355 Widget root = comp.GetRootWidget();
356 if (!root)
357 return;
358
360 if (advancedKeybindComponent)
361 advancedKeybindComponent.StopScrolling();
362 }
363
364 //------------------------------------------------------------------------------------------------
365 void SCR_AdvancedKeybindDialogUI(SCR_KeyBindingEntry entry, string displayName, string actionName, string actionPreset, SCR_EActionPrefixType prefixType)
366 {
367 Setup(entry, displayName, actionName, EInputDeviceType.KEYBOARD);
368 m_sActionPreset = actionPreset;
369 m_eActionPrefixType = prefixType;
370 }
371}
ArmaReforgerScripted GetGame()
Definition game.c:1398
InputManager GetInputManager()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Widget m_wRoot
EInputDeviceType m_eDevice
SCR_SettingsManagerKeybindModule m_SettingsKeybindModule
class SCR_KeybindDialogs m_Entry
string m_sActionName
Definition Math.c:13
static SCR_AdvancedActionRowComponent FindComponentInHierarchy(notnull Widget w)
void Init(string actionName, string actionPreset, int index, SCR_SettingsManagerKeybindModule settingsKeybindModule, EInputDeviceType device)
ref array< SCR_ModularButtonComponent > m_aBindRowButtons
void OnKeybindRowClick(notnull SCR_ModularButtonComponent modularButtonComp)
void OnKeybindRowFocusLost(SCR_ModularButtonComponent comp)
void OnCombinationComboChanged(SCR_ComboBoxComponent component, int index)
SCR_ModularButtonComponent m_FocusedBindRowButton
override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
void OnPrefixesComboChanged(SCR_ComboBoxComponent component, int index)
void SetSelectedKeybind(notnull SCR_ModularButtonComponent modularButtonComp)
void OnKeybindRowFocus(SCR_ModularButtonComponent comp)
void SCR_AdvancedKeybindDialogUI(SCR_KeyBindingEntry entry, string displayName, string actionName, string actionPreset, SCR_EActionPrefixType prefixType)
void OnBindsComboChanged(SCR_ComboBoxComponent component, int index)
void OnSelectButton(SCR_InputButtonComponent button, string action)
override int AddItem(string item, bool last=false, Managed data=null)
static SCR_SimpleKeybindDialogUI CreateSimpleKeybindDialog(SCR_KeyBindingEntry entry, string displayName, string actionName, InputBinding binding, EInputDeviceType device, bool showOverrideWarning=true)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
@ Setup
Definition TestStage.c:15