Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SimpleKeybindDialogUI.c
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------------
2 class SCR_SimpleKeybindDialogUI : SCR_KeybindDialogBase
3 {
4  protected ref InputBinding m_Binding;
5  protected SCR_KeybindActionDisplayRowComponent m_ActionDisplayRow;
6  protected RichTextWidget m_wActionName;
7  protected SizeLayoutWidget m_wActionRowSize;
8  protected Widget m_wActionRowWrapper;
9  protected RichTextWidget m_wCloseHint;
10 
11  protected bool m_bShowOverrideWarning;
12 
13  protected ref ScriptInvokerVoid m_OnKeyCaptured;
14 
15  protected const string CLOSE_HINT = "#AR-Settings_KeybindSimple_CloseHint";
16 
17  protected const string ACTION_MENU_BACK_KEYBIND = "MenuBackKeybind";
18  protected const string ACTION_DISPLAY_ROOT = "KeybindActionDisplayRow";
19 
20  //------------------------------------------------------------------------------------------------
21  override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
22  {
23  super.OnMenuOpen(preset);
24 
25  if (m_Binding)
26  GetGame().GetInputManager().AddActionListener(ACTION_MENU_BACK_KEYBIND, EActionTrigger.DOWN, CancelCapture);
27 
28  m_ActionDisplayRow = SCR_KeybindActionDisplayRowComponent.FindComponentInHierarchy(m_wRoot);
29 
30  m_wActionName = RichTextWidget.Cast(m_wRoot.FindAnyWidget("ActionName"));
31  if (m_wActionName)
32  m_wActionName.SetText(m_sDisplayName);
33 
34  m_wActionRowSize = SizeLayoutWidget.Cast(m_wRoot.FindAnyWidget("ActionDisplayRowSize"));
35  m_wActionRowWrapper = m_wRoot.FindAnyWidget("ActionMainHorizontalLayout");
36  m_wCloseHint = RichTextWidget.Cast(m_wRoot.FindAnyWidget("CloseHintText"));
37  if (m_wCloseHint && m_SettingsKeybindModule)
38  {
39  string device = m_SettingsKeybindModule.GetKeyboardDeviceString();
40  if (m_eDevice == EInputDeviceType.GAMEPAD)
41  device = m_SettingsKeybindModule.GetGamepadDeviceString();
42 
43  string actionText = string.Format(
44  "<action name='%1' scale='%2' state='%3'/>",
45  ACTION_MENU_BACK_KEYBIND,
46  UIConstants.ACTION_DISPLAY_ICON_SCALE_VERY_BIG,
47  UIConstants.GetActionDisplayStateAttribute(SCR_EActionDisplayState.NON_INTERACTABLE_HINT)
48  );
49 
50  m_wCloseHint.SetText(WidgetManager.Translate(CLOSE_HINT, actionText));
51  }
52 
53  SetMessageColor(Color.FromInt(UIColors.NEUTRAL_ACTIVE_STANDBY.PackToInt()));
54  GetMessageWidget().SetVisible(m_bShowOverrideWarning);
55 
56  // Wait a frame for the action name text to be initialized, we need it's screen size
57  GetGame().GetCallqueue().Call(SetupActionDisplayFrameSkip);
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  override void OnMenuUpdate(float tDelta)
62  {
63  super.OnMenuUpdate(tDelta);
64 
65  if (!m_Binding)
66  return;
67 
68  if (m_Binding.GetCaptureState() == EInputBindingCaptureState.IDLE)
69  {
70  m_Binding.Save();
71 
72  if (m_OnKeyCaptured)
73  m_OnKeyCaptured.Invoke(); //TODO: there is no "capturing cancelled" state nor check. This will be called upon closing the dialog as well. FIX
74 
75  Close();
76  }
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  protected void SetupActionDisplayFrameSkip()
81  {
82  GetGame().GetCallqueue().Call(SetupActionDisplay);
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  // Calculate Size allotted to action displays
87  protected void SetupActionDisplay()
88  {
89  if (!m_wActionRowSize || !m_wActionName || !m_ActionDisplayRow || !m_wActionRowWrapper || !m_SettingsKeybindModule)
90  return;
91 
92  float textX, textY, wrapperX, wrapperY;
93  m_wActionName.GetScreenSize(textX, textY);
94  m_wActionRowWrapper.GetScreenSize(wrapperX, wrapperY);
95 
96  m_wActionRowSize.SetWidthOverride(GetGame().GetWorkspace().DPIUnscale(wrapperX - textX));
97  m_ActionDisplayRow.CreateActionDisplays(m_Entry, m_SettingsKeybindModule, m_eDevice);
98  }
99 
100  //------------------------------------------------------------------------------------------------
101  protected void CancelCapture()
102  {
103  GetGame().GetInputManager().RemoveActionListener(ACTION_MENU_BACK_KEYBIND, EActionTrigger.DOWN, CancelCapture);
104  m_Binding.CancelCapture(); //TODO: capture is started by the row component but ended by the dialog. FIX
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  ScriptInvokerVoid GetOnKeyCaptured()
109  {
110  if (!m_OnKeyCaptured)
111  m_OnKeyCaptured = new ScriptInvokerVoid();
112 
113  return m_OnKeyCaptured;
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  void SCR_SimpleKeybindDialogUI(SCR_KeyBindingEntry entry, string displayName, string actionName, InputBinding binding, EInputDeviceType device, bool showOverrideWarning)
118  {
119  Setup(entry, displayName, actionName, device);
120  m_Binding = binding;
121  m_bShowOverrideWarning = showOverrideWarning;
122  }
123 }
m_sDisplayName
protected string m_sDisplayName
Definition: SCR_KeybindDialogs.c:39
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
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Entry
SCR_MapJournalUI m_Entry
SetMessageColor
bool SetMessageColor(Color color)
Definition: SCR_ScriptedWidgetTooltip.c:282
UIColors
Definition: Constants.c:16
SCR_ConfigurableDialogUiPreset
Configuration for a dialog.
Definition: SCR_ConfigurableDialogUI.c:809
SCR_SimpleKeybindDialogUI
Definition: SCR_SimpleKeybindDialogUI.c:2
m_eDevice
protected EInputDeviceType m_eDevice
Definition: SCR_KeybindDialogs.c:41
SCR_KeybindActionDisplayRowComponent
Definition: SCR_KeybindActionDisplayRowComponent.c:7
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9