Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapRadialUI.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
4 typedef ScriptInvokerBase<ScriptInvokerEntrySelectedMethod> ScriptInvokerMenuEntrySelected;
5 
6 //------------------------------------------------------------------------------------------------
7 void ScriptInvokerEntryPerformedMethod(SCR_SelectionMenuEntry entry, float worldPos[2]);
9 typedef ScriptInvokerBase<ScriptInvokerEntryPerformedMethod> ScriptInvokerMenuEntryPerformed;
10 
11 //------------------------------------------------------------------------------------------------
14 {
15  [Attribute()]
16  protected ref SCR_RadialMenuController m_RadialController;
17 
18  [Attribute()]
19  protected ref SCR_RadialMenu m_RadialMenu;
20 
21  protected SCR_MapCursorModule m_CursorModule;
22  protected SCR_MapRadialDisplay m_Display;
23 
24  protected bool m_bRefresh;
25  protected bool m_bEntriesUpdate = false; // entries updated instead of entry selected
26 
27  protected vector m_vMenuWorldPos;
28 
29  protected ref ScriptInvokerVoid m_OnMenuInit = new ScriptInvokerVoid(); // used to fill in entries after map open;
30  protected ref ScriptInvokerMenuEntrySelected m_OnEntrySelected = new ScriptInvokerMenuEntrySelected();
31  protected ref ScriptInvokerMenuEntryPerformed m_OnEntryPerformed = new ScriptInvokerMenuEntryPerformed();
32 
33  //------------------------------------------------------------------------------------------------
35  ScriptInvokerVoid GetOnMenuInitInvoker()
36  {
37  return m_OnMenuInit;
38  }
39 
40  //------------------------------------------------------------------------------------------------
42  ScriptInvokerMenuEntrySelected GetOnEntrySelectedInvoker()
43  {
44  return m_OnEntrySelected;
45  }
46 
47  //------------------------------------------------------------------------------------------------
49  ScriptInvokerMenuEntryPerformed GetOnEntryPerformedInvoker()
50  {
51  return m_OnEntryPerformed;
52  }
53 
54  //------------------------------------------------------------------------------------------------
56  SCR_RadialMenuController GetRadialController()
57  {
58  return m_RadialController;
59  }
60 
61  //------------------------------------------------------------------------------------------------
63  SCR_MapRadialDisplay GetRadialDisplay()
64  {
65  return m_Display;
66  }
67 
68  //------------------------------------------------------------------------------------------------
70  static SCR_MapRadialUI GetInstance()
71  {
72  SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
73  if (!mapEntity)
74  return null;
75 
76  return SCR_MapRadialUI.Cast(mapEntity.GetMapUIComponent(SCR_MapRadialUI));
77  }
78 
79  //------------------------------------------------------------------------------------------------
81  vector GetMenuWorldPosition()
82  {
83  m_vMenuWorldPos[1] = GetGame().GetWorld().GetSurfaceY(m_vMenuWorldPos[0], m_vMenuWorldPos[2]);
84 
85  return m_vMenuWorldPos;
86  }
87 
88  //------------------------------------------------------------------------------------------------
92  protected void OnInputMenuOpen(float value, EActionTrigger reason)
93  {
94  if (m_CursorModule.GetCursorState() & EMapCursorState.CS_PAN) // dont open + pan at the same time
95  return;
96 
97  if (m_RadialMenu && m_RadialMenu.IsOpened())
98  return;
99 
100  m_RadialController.OnInputOpen();
101  }
102 
103  //------------------------------------------------------------------------------------------------
107  protected void InputOpenMenu(SCR_RadialMenuController controller, bool hasControl)
108  {
109  if (!hasControl)
110  {
111  m_RadialController.Control(m_MapEntity, m_RadialMenu);
112 
113  SCR_HUDManagerComponent hud = GetGame().GetHUDManager();
114  m_Display = SCR_MapRadialDisplay.Cast(hud.FindInfoDisplay(SCR_MapRadialDisplay));
115  m_RadialMenu.SetMenuDisplay(m_Display);
116  }
117  else if (m_RadialMenu.IsOpened()) // TODO proper close here
118  return;
119 
120  if (m_RadialMenu.GetEntryCount() == 0 || !m_CursorModule.HandleContextualMenu()) // map side conditions to open
121  m_RadialController.SetEnableControl(false);
122  else
123  m_RadialController.SetEnableControl(true);
124  }
125 
126  //------------------------------------------------------------------------------------------------
129  protected void OnControllerTakeControl(SCR_RadialMenuController controller)
130  {
131  m_RadialMenu = m_RadialController.GetRadialMenu();
132  m_RadialMenu.GetOnSelect().Insert(OnEntrySelected);
133  m_RadialMenu.GetOnPerform().Insert(OnEntryPerformed);
134  m_RadialMenu.GetOnOpen().Insert(OpenMenu);
135  m_RadialMenu.GetOnClose().Insert(CloseMenu);
136 
137  m_RadialMenu.ClearEntries();
138 
139  m_OnMenuInit.Invoke(); // fill menu entries
140  }
141 
142  //------------------------------------------------------------------------------------------------
145  protected void OnControllerChanged(SCR_RadialMenuController controller)
146  {
147  m_RadialMenu = m_RadialController.GetRadialMenu();
148  m_RadialMenu.GetOnSelect().Remove(OnEntrySelected);
149  m_RadialMenu.GetOnPerform().Remove(OnEntryPerformed);
150  m_RadialMenu.GetOnOpen().Remove(OpenMenu);
151  m_RadialMenu.GetOnClose().Remove(CloseMenu);
152  }
153 
154  //------------------------------------------------------------------------------------------------
157  bool OpenMenu()
158  {
159  SCR_VONController controllerVON = SCR_VONController.Cast(GetGame().GetPlayerController().FindComponent(SCR_VONController));
160  if (controllerVON)
161  {
162  SCR_VONMenu menuVON = controllerVON.GetVONMenu();
163  if (menuVON)
164  menuVON.SetMenuDisabled(true);
165  }
166 
167  float wX, wY, sX, sY;
168  m_MapEntity.GetMapCursorWorldPosition(wX, wY);
169  m_MapEntity.WorldToScreen(wX, wY, sX, sY);
170  m_MapEntity.PanSmooth(sX, sY);
171 
172  m_vMenuWorldPos[0] = wX;
173  m_vMenuWorldPos[2] = wY;
174 
175  m_CursorModule.ForceCenterCursor();
176 
177  return true;
178  }
179 
180  //------------------------------------------------------------------------------------------------
182  void CloseMenu()
183  {
184  SCR_VONController controllerVON = SCR_VONController.Cast(GetGame().GetPlayerController().FindComponent(SCR_VONController));
185  if (controllerVON)
186  {
187  SCR_VONMenu menuVON = controllerVON.GetVONMenu();
188  if (menuVON)
189  menuVON.SetMenuDisabled(false);
190  }
191 
192  m_CursorModule.HandleContextualMenu(true);
193  }
194 
195  //------------------------------------------------------------------------------------------------
200  void OnEntrySelected(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry, int entryID)
201  {
202  m_OnEntrySelected.Invoke(entry, entryID);
203  }
204 
205  //------------------------------------------------------------------------------------------------
209  void OnEntryPerformed(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry)
210  {
211  float wX, wY;
212  float worldPos[2];
213  m_MapEntity.GetMapCenterWorldPosition(wX, wY);
214  worldPos[0] = wX;
215  worldPos[1] = wY;
216 
217  m_OnEntryPerformed.Invoke(entry, worldPos);
218  }
219 
220  //------------------------------------------------------------------------------------------------
224  void InsertCustomRadialEntry(SCR_SelectionMenuEntry entry, SCR_SelectionMenuCategoryEntry category = null)
225  {
226  if (category)
227  category.AddEntry(entry);
228  else
229  m_RadialMenu.AddEntry(entry);
230  }
231 
232  //------------------------------------------------------------------------------------------------
236  void InsertCustomRadialCategory(SCR_SelectionMenuCategoryEntry entry, SCR_SelectionMenuCategoryEntry parent = null)
237  {
238  if (parent)
239  parent.AddEntry(entry);
240  else
241  m_RadialMenu.AddCategoryEntry(entry);
242  }
243 
244  //------------------------------------------------------------------------------------------------
249  SCR_SelectionMenuEntry AddRadialEntry(string name, SCR_SelectionMenuCategoryEntry category = null)
250  {
252  entry.SetName(name);
253 
254  if (category)
255  category.AddEntry(entry);
256  else
257  m_RadialMenu.AddEntry(entry);
258 
259  return entry;
260  }
261 
262  //------------------------------------------------------------------------------------------------
267  SCR_SelectionMenuCategoryEntry AddRadialCategory(string name, SCR_SelectionMenuCategoryEntry parent = null)
268  {
270  entry.SetName(name);
271 
272  if (parent)
273  parent.AddEntry(entry);
274  else
275  m_RadialMenu.AddCategoryEntry(entry);
276 
277  return entry;
278  }
279 
280  //------------------------------------------------------------------------------------------------
283  void RemoveRadialEntry(SCR_SelectionMenuEntry entry)
284  {
285  m_RadialMenu.RemoveEntry(entry);
286  }
287 
288  //------------------------------------------------------------------------------------------------
289  // OVERRIDES
290  //------------------------------------------------------------------------------------------------
291 
292  //------------------------------------------------------------------------------------------------
293  override void Update(float timeSlice)
294  {
295  if (m_RadialMenu)
296  m_RadialMenu.Update(timeSlice);
297  }
298 
299  //------------------------------------------------------------------------------------------------
300  override void OnMapOpen(MapConfiguration config)
301  {
302  super.OnMapOpen(config);
303 
305 
306  m_RadialController.GetOnInputOpen().Insert(InputOpenMenu);
307  m_RadialController.GetOnTakeControl().Insert(OnControllerTakeControl);
308  m_RadialController.GetOnControllerChanged().Insert(OnControllerChanged);
309 
310  GetGame().GetInputManager().AddActionListener("MapContextualMenu", EActionTrigger.UP, OnInputMenuOpen);
311  }
312 
313  //------------------------------------------------------------------------------------------------
314  override void OnMapClose(MapConfiguration config)
315  {
316  GetGame().GetInputManager().RemoveActionListener("MapContextualMenu", EActionTrigger.UP, OnInputMenuOpen);
317 
318  m_RadialController.GetOnInputOpen().Remove(InputOpenMenu);
319  m_RadialController.GetOnTakeControl().Remove(OnControllerTakeControl);
320  m_RadialController.GetOnControllerChanged().Remove(OnControllerChanged);
321 
322  if (m_RadialController.HasControl())
323  {
324  if (m_RadialMenu.IsOpened()) // close event is unregistered below so close manually here
325  CloseMenu();
326 
327  OnControllerChanged(null);
328  m_RadialController.StopControl(true);
329  }
330 
331  super.OnMapClose(config);
332  }
333 
334  //------------------------------------------------------------------------------------------------
335  // constructor
336  void SCR_MapRadialUI()
337  {
338  m_bHookToRoot = true;
339  }
340 }
SCR_HUDManagerComponent
Definition: SCR_HUDManagerComponent.c:23
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
EMapCursorState
EMapCursorState
Map cursor state.
Definition: SCR_MapConstants.c:39
ScriptInvokerEntryPerformedMethod
func ScriptInvokerEntryPerformedMethod
Definition: SCR_MapRadialUI.c:8
SCR_RadialMenuController
Definition: SCR_RadialMenuController.c:8
SCR_SelectionMenuCategoryEntry
Definition: SCR_SelectionMenuCategory.c:6
SCR_MapRadialUI
2D map radial menu UI
Definition: SCR_MapRadialUI.c:13
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
func
func
Definition: SCR_AIThreatSystem.c:5
m_CursorModule
protected SCR_MapCursorModule m_CursorModule
Definition: SCR_MapDrawingUI.c:181
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
SCR_SelectionMenu
Definition: SCR_SelectionMenu.c:6
SCR_MapCursorModule
Map cursor behavior and mode setup.
Definition: SCR_MapCursorModule.c:39
ScriptInvokerMenuEntrySelected
ScriptInvokerBase< ScriptInvokerEntrySelectedMethod > ScriptInvokerMenuEntrySelected
Definition: SCR_MapRadialUI.c:4
ScriptInvokerEntrySelectedMethod
func ScriptInvokerEntrySelectedMethod
Definition: SCR_MapRadialUI.c:3
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
m_RadialMenu
protected SCR_RadialMenu m_RadialMenu
Definition: SCR_PlayerControllerCommandingComponent.c:17
SCR_MapRadialDisplay
Info display within hud manager of player controller.
Definition: SCR_MapRadialDisplay.c:4
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
ScriptInvokerMenuEntryPerformed
ScriptInvokerBase< ScriptInvokerEntryPerformedMethod > ScriptInvokerMenuEntryPerformed
Definition: SCR_MapRadialUI.c:9
SCR_SelectionMenuEntry
Definition: SCR_SelectionMenuEntry.c:7
SCR_VONMenu
Definition: SCR_VONMenu.c:3
SCR_MapUIBaseComponent
Definition: SCR_MapUIBaseComponent.c:3
SCR_RadialMenu
Definition: SCR_RadialMenu.c:8
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180