Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AdvancedKeybindDialogUI.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_AdvancedKeybindDialogUI: SCR_KeybindDialogBase
3 {
4  protected SCR_InputButtonComponent m_Select;
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 
13  protected Widget m_wPrefixesCombo;
14 
15  protected const ResourceName KEYBIND_ROW_LAYOUT_PATH = "{25888355688EE402}UI/layouts/Menus/SettingsMenu/BindingMenu/AdvancedKeybindActionRow.layout";
16 
17  //------------------------------------------------------------------------------------------------
18  override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
19  {
20  super.OnMenuOpen(preset);
21 
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 
43  SetupCaptureButton();
44  SetupPrefixesCombo();
45  SetupBindsCombo();
46  SetupCombinationCombo();
47 
48  ShowBindsForAction();
49  ReselectRow();
50  }
51 
52  //------------------------------------------------------------------------------------------------
53  override void OnMenuShow()
54  {
55  super.OnMenuShow();
56 
57  ShowBindsForAction();
58  ReselectRow();
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  override void OnMenuFocusGained()
63  {
64  super.OnMenuFocusGained();
65 
66  ReselectRow();
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  // Reselect correct keybind row
71  protected void ReselectRow()
72  {
73  if (!m_aBindRowButtons.IsIndexValid(m_iSelectedKeybind))
74  return;
75 
76  m_FocusedBindRowButton = m_aBindRowButtons[m_iSelectedKeybind];
77  GetGame().GetWorkspace().SetFocusedWidget(m_FocusedBindRowButton.GetRootWidget());
78  SetSelectedKeybind(m_aBindRowButtons[m_iSelectedKeybind]);
79  }
80 
81  //-----------------------------------------------------------------------------------------------
82  protected void ShowBindsForAction()
83  {
84  Widget contentWidget = m_wRoot.FindAnyWidget("ScrollContent");
85  if (!contentWidget)
86  return;
87 
88  //clear the content so we prevent duplicates
89  Widget children = contentWidget.GetChildren();
90  while (children)
91  {
92  contentWidget.RemoveChild(children);
93  children = contentWidget.GetChildren();
94  }
95 
96  int bindCount = m_SettingsKeybindModule.GetActionBindCount(m_sActionName, m_sActionPreset, m_eDevice);
97  /* TODO: no keybind is sometimes considered a binding and shows the confilcting bindings message. FIX
98  // Fallback to force showing the No Keybind message if there are no bindings
99  if (bindCount == 0)
100  UnbindAction();
101  */
102  m_aBindRowButtons.Clear();
103  SCR_AdvancedActionRowComponent rowComponent;
104  SCR_ModularButtonComponent rowModularButtonComponent;
105  Widget rowWidget;
106  for (int i = 0; i < bindCount; i++)
107  {
108  rowWidget = GetGame().GetWorkspace().CreateWidgets(KEYBIND_ROW_LAYOUT_PATH, contentWidget);
109  if (!rowWidget)
110  continue;
111 
112  rowComponent = SCR_AdvancedActionRowComponent.FindComponentInHierarchy(rowWidget);
113  if (!rowComponent)
114  continue;
115 
116  rowComponent.Init(m_sActionName, m_sActionPreset, i, m_SettingsKeybindModule, m_eDevice);
117 
118  rowModularButtonComponent = SCR_ModularButtonComponent.FindComponent(rowWidget);
119  if (!rowModularButtonComponent)
120  continue;
121 
122  m_aBindRowButtons.Insert(rowModularButtonComponent);
123  rowModularButtonComponent.m_OnClicked.Insert(OnKeybindRowClick);
124  rowModularButtonComponent.m_OnFocus.Insert(OnKeybindRowFocus);
125  rowModularButtonComponent.m_OnFocusLost.Insert(OnKeybindRowFocusLost);
126  }
127  }
128 
129  //-----------------------------------------------------------------------------------------------
130  protected void ShowBindsForCurrentAction()
131  {
132  ShowBindsForAction();
133 
134  // Select the last row
135  m_iSelectedKeybind = m_aBindRowButtons.Count() - 1;
136  ReselectRow();
137  }
138 
139  //-----------------------------------------------------------------------------------------------
140  protected void SetSelectedKeybind(notnull SCR_ModularButtonComponent modularButtonComp)
141  {
142  Widget root = modularButtonComp.GetRootWidget();
143  if (!root)
144  return;
145 
146  SCR_AdvancedActionRowComponent advancedKeybindComponent = SCR_AdvancedActionRowComponent.FindComponentInHierarchy(root);
147  if (!advancedKeybindComponent)
148  return;
149 
150  m_iSelectedKeybind = advancedKeybindComponent.GetKeybindIndex();
151 
152  // Visual update, show border on selected and remove from others
153  foreach (SCR_ModularButtonComponent comp : m_aBindRowButtons)
154  {
155  comp.SetToggled(comp == modularButtonComp, false);
156  }
157  }
158 
159  //-----------------------------------------------------------------------------------------------
160  protected void ResetBindings()
161  {
162  m_SettingsKeybindModule.ResetAction(m_sActionName, m_sActionPreset);
163 
164  ShowBindsForAction();
165 
166  m_iSelectedKeybind = 0;
167  ReselectRow();
168  }
169 
170  //-----------------------------------------------------------------------------------------------
171  protected void DeleteSelectedBind()
172  {
173  m_SettingsKeybindModule.DeleteActionBindByIndex(m_sActionName, m_iSelectedKeybind, m_sActionPreset);
174 
175  ShowBindsForAction();
176 
177  // Select the row immediately above
178  m_iSelectedKeybind = Math.Clamp(m_iSelectedKeybind - 1, 0, m_aBindRowButtons.Count() - 1);
179  ReselectRow();
180  }
181 
182  //-----------------------------------------------------------------------------------------------
183  protected void StartCapturingKeybind()
184  {
185  m_SettingsKeybindModule.StartCaptureForAction(m_sActionName, m_sActionPreset, EInputDeviceType.KEYBOARD, true);
186 
187  SCR_SimpleKeybindDialogUI dialog = SCR_KeybindDialogs.CreateSimpleKeybindDialog(
188  m_Entry,
191  m_SettingsKeybindModule.GetInputBindings(),
192  EInputDeviceType.KEYBOARD,
193  false
194  );
195 
196  if (!dialog)
197  return;
198 
199  dialog.GetOnKeyCaptured().Insert(ShowBindsForCurrentAction);
200  }
201 
202  //-----------------------------------------------------------------------------------------------
203  protected void UnbindAction()
204  {
205  m_SettingsKeybindModule.UnbindAction(m_sActionName, m_sActionPreset);
206 
207  ShowBindsForAction();
208 
209  m_iSelectedKeybind = 0;
210  ReselectRow();
211  }
212 
213  //-----------------------------------------------------------------------------------------------
214  protected void SetupCaptureButton()
215  {
216  ButtonWidget buttonWidget = ButtonWidget.Cast(m_wRoot.FindAnyWidget("AddKeybind"));
217  if (!buttonWidget)
218  return;
219 
220  SCR_ButtonTextComponent buttonComp = SCR_ButtonTextComponent.Cast(buttonWidget.FindHandler(SCR_ButtonTextComponent));
221  if (!buttonComp)
222  return;
223 
224  buttonComp.SetEnabled(!m_sActionPreset.IsEmpty());
225  buttonComp.m_OnClicked.Insert(StartCapturingKeybind);
226  }
227 
228  //-----------------------------------------------------------------------------------------------
229  protected void SetupPrefixesCombo()
230  {
231  m_wPrefixesCombo = m_wRoot.FindAnyWidget("ActionPrefixCombo");
232  if (!m_wPrefixesCombo)
233  {
234  Print("SCR_AdvancedKeybindDialogUI: Action prefix combo widget was not found", LogLevel.WARNING);
235  return;
236  }
237 
238  SCR_ComboBoxComponent comboBoxComponent = SCR_ComboBoxComponent.Cast(m_wPrefixesCombo.FindHandler(SCR_ComboBoxComponent));
239  if (!comboBoxComponent)
240  return;
241 
242  array<ref SCR_KeyBindingFilter> filters = m_SettingsKeybindModule.GetFilters(m_eActionPrefixType);
243 
244  foreach (SCR_KeyBindingFilter filter : filters)
245  {
246  comboBoxComponent.AddItem(filter.m_sFilterDisplayName);
247  }
248 
249  comboBoxComponent.m_OnChanged.Insert(OnPrefixesComboChanged);
250  }
251 
252  //-----------------------------------------------------------------------------------------------
253  protected void SetupBindsCombo()
254  {
255  Widget systemBindCombo = m_wRoot.FindAnyWidget("SystemKeyCombo");
256  if (!systemBindCombo)
257  {
258  Print("SCR_AdvancedKeybindDialogUI: System key combo widget was not found", LogLevel.WARNING);
259  }
260 
261  SCR_ComboBoxComponent comboBoxComponent = SCR_ComboBoxComponent.Cast(systemBindCombo.FindHandler(SCR_ComboBoxComponent));
262  if (!comboBoxComponent)
263  return;
264 
265  array<ref SCR_KeyBindingBind> binds = m_SettingsKeybindModule.GetCustomBinds();
266  foreach (SCR_KeyBindingBind bind : binds)
267  {
268  comboBoxComponent.AddItem(bind.m_sBindDisplayName);
269  }
270 
271  comboBoxComponent.m_OnChanged.Insert(OnBindsComboChanged);
272  }
273 
274  //-----------------------------------------------------------------------------------------------
275  protected void SetupCombinationCombo()
276  {
277  Widget combinationBindCombo = m_wRoot.FindAnyWidget("ComboKeyCombo");
278  if (!combinationBindCombo)
279  {
280  Print("SCR_AdvancedKeybindDialogUI: Combination key combo widget was not found", LogLevel.WARNING);
281  return;
282  }
283 
284  SCR_ComboBoxComponent comboBoxComponent = SCR_ComboBoxComponent.Cast(combinationBindCombo.FindHandler(SCR_ComboBoxComponent));
285  if (!comboBoxComponent)
286  return;
287 
288  array<ref SCR_KeyBindingCombo> combos = m_SettingsKeybindModule.GetCustomComboKeys();
289  foreach (SCR_KeyBindingCombo combo : combos)
290  {
291  comboBoxComponent.AddItem(combo.m_sComboDisplayName);
292  }
293 
294  comboBoxComponent.m_OnChanged.Insert(OnCombinationComboChanged);
295  }
296 
297  //-----------------------------------------------------------------------------------------------
298  protected void OnPrefixesComboChanged(SCR_ComboBoxComponent component, int index)
299  {
300  m_SettingsKeybindModule.SetFilterForActionByIndex(m_sActionName, m_sActionPreset, index, m_iSelectedKeybind, m_eActionPrefixType);
301 
302  ShowBindsForAction();
303 
304  ReselectRow();
305  }
306 
307  //-----------------------------------------------------------------------------------------------
308  protected void OnBindsComboChanged(SCR_ComboBoxComponent component, int index)
309  {
310  m_SettingsKeybindModule.AddKeybindToActionByIndex(m_sActionName, m_sActionPreset, index);
311 
312  ShowBindsForAction();
313 
314  // Select the last row
315  m_iSelectedKeybind = m_aBindRowButtons.Count() - 1;
316  ReselectRow();
317  }
318 
319  //------------------------------------------------------------------------------------------------
320  protected void OnCombinationComboChanged(SCR_ComboBoxComponent component, int index)
321  {
322  m_SettingsKeybindModule.AddComboToActionByIndex(m_sActionName, m_sActionPreset, index, m_iSelectedKeybind);
323 
324  ShowBindsForAction();
325 
326  ReselectRow();
327  }
328 
329  //------------------------------------------------------------------------------------------------
330  protected void OnSelectButton(SCR_InputButtonComponent button, string action)
331  {
332  if (m_FocusedBindRowButton)
333  SetSelectedKeybind(m_FocusedBindRowButton);
334 
335  m_Select.SetVisible(false, false);
336  }
337 
338  //-----------------------------------------------------------------------------------------------
339  protected void OnKeybindRowClick(notnull SCR_ModularButtonComponent modularButtonComp)
340  {
341  if (m_FocusedBindRowButton && GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE)
342  SetSelectedKeybind(m_FocusedBindRowButton);
343  }
344 
345  //------------------------------------------------------------------------------------------------
346  protected void OnKeybindRowFocus(SCR_ModularButtonComponent comp)
347  {
348  m_FocusedBindRowButton = comp;
349 
350  Widget root = comp.GetRootWidget();
351  if (!root)
352  return;
353 
354  SCR_AdvancedActionRowComponent advancedKeybindComponent = SCR_AdvancedActionRowComponent.FindComponentInHierarchy(root);
355  if (advancedKeybindComponent)
356  advancedKeybindComponent.StartScrolling();
357 
358  if (m_Select && m_iSelectedKeybind != advancedKeybindComponent.GetKeybindIndex())
359  m_Select.SetVisible(true, false);
360  }
361 
362  //------------------------------------------------------------------------------------------------
363  protected void OnKeybindRowFocusLost(SCR_ModularButtonComponent comp)
364  {
365  m_FocusedBindRowButton = null;
366 
367  if (m_Select)
368  m_Select.SetVisible(false, false);
369 
370  Widget root = comp.GetRootWidget();
371  if (!root)
372  return;
373 
374  SCR_AdvancedActionRowComponent advancedKeybindComponent = SCR_AdvancedActionRowComponent.FindComponentInHierarchy(root);
375  if (advancedKeybindComponent)
376  advancedKeybindComponent.StopScrolling();
377  }
378 
379  //------------------------------------------------------------------------------------------------
380  void SCR_AdvancedKeybindDialogUI(SCR_KeyBindingEntry entry, string displayName, string actionName, string actionPreset, SCR_EActionPrefixType prefixType)
381  {
382  Setup(entry, displayName, actionName, EInputDeviceType.KEYBOARD);
383  m_sActionPreset = actionPreset;
384  m_eActionPrefixType = prefixType;
385  }
386 }
m_sDisplayName
protected string m_sDisplayName
Definition: SCR_KeybindDialogs.c:39
SCR_ComboBoxComponent
Definition: SCR_ComboBoxComponent.c:1
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
m_SettingsKeybindModule
protected SCR_SettingsManagerKeybindModule m_SettingsKeybindModule
Definition: SCR_KeybindDialogs.c:43
Setup
protected void Setup(SCR_KeyBindingEntry entry, string displayName, string actionName, EInputDeviceType device)
Definition: SCR_KeybindDialogs.c:46
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_sActionName
protected string m_sActionName
Definition: SCR_ActionsRadialMenuEditorComponent.c:24
SCR_KeybindDialogs
Definition: SCR_KeybindDialogs.c:1
SCR_KeyBindingCombo
Definition: SCR_KeyBindingMenuConfig.c:124
m_Entry
SCR_MapJournalUI m_Entry
SCR_ButtonTextComponent
Definition: SCR_ButtonTextComponent.c:2
SCR_ConfigurableDialogUiPreset
Configuration for a dialog.
Definition: SCR_ConfigurableDialogUI.c:809
SCR_AdvancedActionRowComponent
Definition: SCR_AdvancedActionRowComponent.c:1
SCR_SimpleKeybindDialogUI
Definition: SCR_SimpleKeybindDialogUI.c:2
m_eDevice
protected EInputDeviceType m_eDevice
Definition: SCR_KeybindDialogs.c:41
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
SCR_AdvancedKeybindDialogUI
Definition: SCR_AdvancedKeybindDialogUI.c:2
FindButton
SCR_InputButtonComponent FindButton(string tag)
Returns a button with given tag.
Definition: SCR_BrowserHoverTooltipComponent.c:116
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1
SetTitle
override void SetTitle(string text)
Definition: SCR_ScenarioDialogs.c:178
SCR_KeyBindingFilter
Definition: SCR_KeyBindingMenuConfig.c:95