Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MenuActionsComponent.c
Go to the documentation of this file.
4void ScriptInvokerActionMethod(string name, float multiplier);
6typedef ScriptInvokerBase<ScriptInvokerActionMethod> ScriptInvokerAction;
7
8//------------------------------------------------------------------------------------------------
10{
11 [Attribute(desc: "Actions to be shown in the Tooltip")]
12 protected ref array<ref SCR_MenuActionPreset> m_aActions;
13
14 [Attribute("400", desc: "Action listeners activation delay")]
15 protected int m_iDelay;
16
17 protected bool m_bHasActionListeners;
18
19 protected ref array<SCR_MenuActionPreset> m_aPressActions = {};
20 protected ref array<SCR_MenuActionPreset> m_aValueActions = {};
21
23
24 //------------------------------------------------------------------------------------------------
25 override void HandlerAttached(Widget w)
26 {
27 super.HandlerAttached(w);
28
29 // Setup actions
30 foreach (SCR_MenuActionPreset action : m_aActions)
31 {
32 switch (action.m_eActionTrigger)
33 {
34 case EActionTrigger.UP:
35 case EActionTrigger.DOWN:
36 case EActionTrigger.PRESSED:
37 {
38 m_aPressActions.Insert(action);
39 break;
40 }
41
42 case EActionTrigger.VALUE:
43 {
44 m_aValueActions.Insert(action);
45 break;
46 }
47 }
48 }
49
51
52 SCR_MenuHelper().GetOnMenuFocusLost().Insert(OnMenuDeactivated);
53 SCR_MenuHelper().GetOnMenuHide().Insert(OnMenuDeactivated);
54 SCR_MenuHelper().GetOnMenuClose().Insert(OnMenuDeactivated);
55 }
56
57 //------------------------------------------------------------------------------------------------
58 override void HandlerDeattached(Widget w)
59 {
60 super.HandlerDeattached(w);
61
67 }
68
69 //------------------------------------------------------------------------------------------------
70 // Owner Menu Events
71 //------------------------------------------------------------------------------------------------
72 //------------------------------------------------------------------------------------------------
74 {
77 }
78
79 //------------------------------------------------------------------------------------------------
80 // Events
81 //------------------------------------------------------------------------------------------------
82 //------------------------------------------------------------------------------------------------
84 protected void OnAction(float multiplier, EActionTrigger reason)
85 {
87 if (!m_wRoot.IsVisible() || !m_OnAction)
88 return;
89
90 InputManager inputManager = GetGame().GetInputManager();
91
92 switch (reason)
93 {
94 case EActionTrigger.UP:
95 case EActionTrigger.DOWN:
96 case EActionTrigger.PRESSED:
97 {
98 foreach (SCR_MenuActionPreset action : m_aPressActions)
99 {
100 if (inputManager.GetActionTriggered(action.m_sActionName) && action.m_eInputMode == inputManager.GetLastUsedInputDevice())
101 {
102 m_OnAction.Invoke(action.m_sActionName, multiplier);
103
104 if (!action.m_sActivationSound.IsEmpty())
105 SCR_UISoundEntity.SoundEvent(action.m_sActivationSound);
106 }
107 }
108
109 break;
110 }
111
112 case EActionTrigger.VALUE:
113 {
114 foreach (SCR_MenuActionPreset action : m_aValueActions)
115 {
116 if (inputManager.GetActionValue(action.m_sActionName) != 0 && action.m_eInputMode == inputManager.GetLastUsedInputDevice())
117 m_OnAction.Invoke(action.m_sActionName, multiplier);
118 }
119
120 break;
121 }
122 }
123 }
124
125 //------------------------------------------------------------------------------------------------
126 // Action Listeners
127 //------------------------------------------------------------------------------------------------
128 //------------------------------------------------------------------------------------------------
129 //! Activate / deactivate in your menu. Tried calling this on focus gained / lost, but if the menu is not focused the component gets deactivated
130 //! As of now, if a button press closes a menu and that button's action is active in the menu below, it may get triggered immediatly, thus the delayed activation. This is already being investigated by the Enfusion guys
131 protected void AddActionListenersDelayed(int delay)
132 {
134 return;
135
136 GetGame().GetCallqueue().CallLater(AddActionListeners, delay);
137 }
138
139 //------------------------------------------------------------------------------------------------
140 protected void AddActionListeners()
141 {
142 GetGame().GetCallqueue().Remove(AddActionListeners);
143
145 return;
146
148
149 InputManager inputManager = GetGame().GetInputManager();
150 string name;
151 EActionTrigger trigger;
152 foreach (SCR_MenuActionPreset action : m_aActions)
153 {
154 name = action.m_sActionName;
155 trigger = action.m_eActionTrigger;
156 inputManager.AddActionListener(name, trigger, OnAction);
157 }
158 }
159
160 //------------------------------------------------------------------------------------------------
161 protected void RemoveActionListeners()
162 {
163 GetGame().GetCallqueue().Remove(AddActionListeners);
164
166 return;
167
168 m_bHasActionListeners = false;
169
170 InputManager inputManager = GetGame().GetInputManager();
171 string name;
172 EActionTrigger trigger;
173 foreach (SCR_MenuActionPreset action : m_aActions)
174 {
175 name = action.m_sActionName;
176 trigger = action.m_eActionTrigger;
177 inputManager.RemoveActionListener(name, trigger, OnAction);
178 }
179 }
180
181 //------------------------------------------------------------------------------------------------
187 //------------------------------------------------------------------------------------------------
189 {
191 }
193 //------------------------------------------------------------------------------------------------
194 // Utility
195 //------------------------------------------------------------------------------------------------
196 //------------------------------------------------------------------------------------------------
197 array<ref SCR_MenuActionPreset> GetActions()
198 {
199 return m_aActions;
200 }
201
202 //------------------------------------------------------------------------------------------------
204 {
205 if (!m_OnAction)
207
208 return m_OnAction;
209 }
210
211 //------------------------------------------------------------------------------------------------
216}
217
218//------------------------------------------------------------------------------------------------
221class SCR_MenuActionPreset
222{
223 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
224 // Overreliance on strings: UIs have hardcoded strings everywhere, often hidden in huge layouts and a myriad of components, making them hard to mantain. Furthermore, changing the hierarchy of a parent prefab will destroy of all these settings in children
225
226 [Attribute()]
227 string m_sActionName;
228
229 [Attribute(typename.EnumToString(EActionTrigger, EActionTrigger.PRESSED), UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EActionTrigger))]
230 EActionTrigger m_eActionTrigger;
231
232 [Attribute(SCR_SoundEvent.CLICK, UIWidgets.EditBox)]
233 string m_sActivationSound;
234
235 //---- REFACTOR NOTE END ----
236
237 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
238 // These should be flags: as of now, having the same action active on different input devices means adding multiple entries to the array of presets, making the component's setup needlessly bloated
239
240 [Attribute(typename.EnumToString(EInputDeviceType, EInputDeviceType.MOUSE), UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EInputDeviceType))]
241 EInputDeviceType m_eInputMode;
242
243 //---- REFACTOR NOTE END ----
244}
245
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref SCR_SortedArray< SCR_BaseEditorAction > m_aActions
void OnAction(float multiplier, EActionTrigger reason)
Bind this in your menu.
func ScriptInvokerActionMethod
void OnMenuDeactivated(ChimeraMenuBase menu)
SCR_MenuActionsComponent SCR_ScriptedWidgetComponent SCR_BaseContainerCustomTitleField("m_sActionName")
ScriptInvokerBase< ScriptInvokerActionMethod > ScriptInvokerAction
SCR_MenuActionsComponent SCR_ScriptedWidgetComponent BaseContainerProps()
Configuration for an action.
string m_sActionName
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Constant variables used in various menus.
static ChimeraMenuBase GetOwnerMenu(Widget w)
Returns parent menu of a widget.
Input management system for user interactions.
override void HandlerDeattached(Widget w)
void OnMenuDeactivated(ChimeraMenuBase menu)
override void HandlerAttached(Widget w)
void OnAction(float multiplier, EActionTrigger reason)
Bind this in your menu.
ref ScriptInvokerAction m_OnAction
static SCR_MenuActionsComponent FindComponent(Widget w)
ref array< SCR_MenuActionPreset > m_aPressActions
ref array< SCR_MenuActionPreset > m_aValueActions
ref array< ref SCR_MenuActionPreset > m_aActions
array< ref SCR_MenuActionPreset > GetActions()
static ScriptInvokerMenu GetOnMenuFocusLost()
static ScriptInvokerMenu GetOnMenuClose()
static ScriptInvokerMenu GetOnMenuHide()
SCR_FieldOfViewSettings Attribute
EActionTrigger