Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MenuActionsComponent.c
Go to the documentation of this file.
1 
4 void ScriptInvokerActionMethod(string name, float multiplier);
6 typedef 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 ScriptInvokerAction m_OnAction;
20 
21  //------------------------------------------------------------------------------------------------
22  override void HandlerAttached(Widget w)
23  {
24  super.HandlerAttached(w);
25 
26  AddActionListenersDelayed(m_iDelay);
27 
28  SCR_MenuHelper().GetOnMenuFocusLost().Insert(OnMenuDeactivated);
29  SCR_MenuHelper().GetOnMenuHide().Insert(OnMenuDeactivated);
30  SCR_MenuHelper().GetOnMenuClose().Insert(OnMenuDeactivated);
31  }
32 
33  //------------------------------------------------------------------------------------------------
34  override void HandlerDeattached(Widget w)
35  {
36  super.HandlerDeattached(w);
37 
38  RemoveActionListeners();
39 
40  SCR_MenuHelper().GetOnMenuFocusLost().Remove(OnMenuDeactivated);
41  SCR_MenuHelper().GetOnMenuHide().Remove(OnMenuDeactivated);
42  SCR_MenuHelper().GetOnMenuClose().Remove(OnMenuDeactivated);
43  }
44 
45  //------------------------------------------------------------------------------------------------
46  // Owner Menu Events
47  //------------------------------------------------------------------------------------------------
48  //------------------------------------------------------------------------------------------------
49  protected void OnMenuDeactivated(ChimeraMenuBase menu)
50  {
51  if (menu == ChimeraMenuBase.GetOwnerMenu(m_wRoot))
52  RemoveActionListeners();
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  // Events
57  //------------------------------------------------------------------------------------------------
58  //------------------------------------------------------------------------------------------------
60  protected void OnAction(float multiplier)
61  {
63  if (!m_wRoot.IsVisible())
64  return;
65 
66  InputManager inputManager = GetGame().GetInputManager();
67  foreach (SCR_MenuActionPreset action : m_aActions)
68  {
69  if (inputManager.GetActionTriggered(action.m_sActionName) && m_OnAction)
70  m_OnAction.Invoke(action.m_sActionName, multiplier);
71  }
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  // Action Listeners
76  //------------------------------------------------------------------------------------------------
77  //------------------------------------------------------------------------------------------------
80  protected void AddActionListenersDelayed(int delay)
81  {
83  return;
84 
85  GetGame().GetCallqueue().CallLater(AddActionListeners, delay);
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  protected void AddActionListeners()
90  {
91  GetGame().GetCallqueue().Remove(AddActionListeners);
92 
94  return;
95 
96  m_bHasActionListeners = true;
97 
98  InputManager inputManager = GetGame().GetInputManager();
99  string name;
100  EActionTrigger trigger;
101  foreach (SCR_MenuActionPreset action : m_aActions)
102  {
103  name = action.m_sActionName;
104  trigger = action.m_eActionTrigger;
105  inputManager.AddActionListener(name, trigger, OnAction);
106  }
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  protected void RemoveActionListeners()
111  {
112  GetGame().GetCallqueue().Remove(AddActionListeners);
113 
115  return;
116 
117  m_bHasActionListeners = false;
118 
119  InputManager inputManager = GetGame().GetInputManager();
120  string name;
121  EActionTrigger trigger;
122  foreach (SCR_MenuActionPreset action : m_aActions)
123  {
124  name = action.m_sActionName;
125  trigger = action.m_eActionTrigger;
126  inputManager.RemoveActionListener(name, trigger, OnAction);
127  }
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  void ActivateActions()
132  {
133  AddActionListenersDelayed(m_iDelay);
134  }
135 
136  //------------------------------------------------------------------------------------------------
137  void DeactivateActions()
138  {
139  RemoveActionListeners();
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  // Utility
144  //------------------------------------------------------------------------------------------------
145  //------------------------------------------------------------------------------------------------
146  array<ref SCR_MenuActionPreset> GetActions()
147  {
148  return m_aActions;
149  }
150 
151  //------------------------------------------------------------------------------------------------
152  ScriptInvokerAction GetOnAction()
153  {
154  if (!m_OnAction)
156 
157  return m_OnAction;
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  static SCR_MenuActionsComponent FindComponent(Widget w)
162  {
163  return SCR_MenuActionsComponent.Cast(w.FindHandler(SCR_MenuActionsComponent));
164  }
165 }
166 
167 //------------------------------------------------------------------------------------------------
170 class SCR_MenuActionPreset
171 {
172  [Attribute()]
173  string m_sActionName;
174 
175  [Attribute("4", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EActionTrigger))]
176  EActionTrigger m_eActionTrigger;
177 }
178 
ChimeraMenuBase
Constant variables used in various menus.
Definition: ChimeraMenuBase.c:70
m_bHasActionListeners
protected bool m_bHasActionListeners
Definition: SCR_MenuActionsComponent.c:13
m_iDelay
protected int m_iDelay
Definition: SCR_MenuActionsComponent.c:11
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
m_aActions
ref SCR_SortedArray< SCR_BaseEditorAction > m_aActions
Definition: SCR_BaseActionsEditorComponent.c:8
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_sActionName
protected string m_sActionName
Definition: SCR_ActionsRadialMenuEditorComponent.c:24
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_OnAction
protected ref ScriptInvokerAction m_OnAction
Definition: SCR_MenuActionsComponent.c:15
func
func
Definition: SCR_AIThreatSystem.c:5
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_MenuHelper
Definition: SCR_MenuHelper.c:15
BaseContainerProps
SCR_MenuActionsComponent SCR_ScriptedWidgetComponent BaseContainerProps()
Configuration for an action.
SCR_MenuActionsComponent
Definition: SCR_MenuActionsComponent.c:9
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7
ScriptInvokerActionMethod
func ScriptInvokerActionMethod
Definition: SCR_MenuActionsComponent.c:5
SCR_BaseContainerCustomTitleField
SCR_MenuActionsComponent SCR_ScriptedWidgetComponent SCR_BaseContainerCustomTitleField("m_sActionName")
Definition: SCR_MenuActionsComponent.c:169
ScriptInvokerAction
ScriptInvokerBase< ScriptInvokerActionMethod > ScriptInvokerAction
Definition: SCR_MenuActionsComponent.c:6