Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VONMenu.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
4 {
5  [Attribute()]
6  protected ref SCR_RadialMenuController m_RadialController;
7 
8  [Attribute()]
9  protected ref SCR_RadialMenu m_RadialMenu;
10 
11  const float ADJUST_COOLDOWN = 0.175; // seconds
12 
13  protected bool m_bIsDisabled;
14  protected bool m_bIsModifierActive;
15  protected float m_fAdjustCooldown; // cooldown before you can cycle up/down by holding a button
16  protected float m_FrequencyListTimer; // timer before frequency list is hidden
17 
18  protected SCR_VONEntry m_SelectedEntry; // entry which is hovered or selected by controller
19  protected SCR_VONEntryRadio m_LastSelectedEntry; // last selected entry, to check if item preview should be reloaded
20  protected SCR_VONRadialDisplay m_Display; // cached display to allow external access
21  protected SCR_VONController m_VONController;
22 
23  //------------------------------------------------------------------------------------------------
24  SCR_RadialMenu GetRadialMenu()
25  {
26  return m_RadialMenu;
27  }
28 
29  //------------------------------------------------------------------------------------------------
30  void SetMenuDisabled(bool state)
31  {
32  m_bIsDisabled = state;
33  }
34 
35  //------------------------------------------------------------------------------------------------
39  static string GetKnownChannel(int frequency)
40  {
41  SCR_FactionManager factionMgr = SCR_FactionManager.Cast(GetGame().GetFactionManager());
42  if (!factionMgr)
43  return string.Empty;
44 
45  SCR_Faction milFaction = SCR_Faction.Cast(factionMgr.SGetPlayerFaction(GetGame().GetPlayerController().GetPlayerId()));
46  if (milFaction && milFaction.GetFactionRadioFrequency() == frequency)
47  return "#AR-Comm_PlatoonChannel";
48 
49  SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
50  if (!milFaction || !groupManager)
51  return string.Empty;
52 
53  array<SCR_AIGroup> playableGroups = groupManager.GetPlayableGroupsByFaction(milFaction);
54  if (!playableGroups)
55  return string.Empty;
56 
57  foreach (int i, SCR_AIGroup group : playableGroups)
58  {
59  if (group.GetRadioFrequency() == frequency)
60  {
61  string company, platoon, squad, character, format;
62  group.GetCallsigns(company, platoon, squad, character, format);
63 
64  return WidgetManager.Translate(format, company, platoon, squad, character);
65  }
66  }
67 
68  return string.Empty;
69  }
70 
71  //------------------------------------------------------------------------------------------------
73  void AddRadialEntry(notnull SCR_VONEntry entry, SCR_SelectionMenuCategoryEntry category = null)
74  {
75  entry.SetName(entry.GetDisplayText());
76 
77  if (category)
78  category.AddEntry(entry);
79  else
80  m_RadialMenu.AddEntry(entry);
81 
82  entry.InitEntry();
83  }
84 
85  //------------------------------------------------------------------------------------------------
87  void AddRadialCategory(notnull SCR_SelectionMenuCategoryEntry entry)
88  {
89  entry.SetName(entry.GetName());
90  m_RadialMenu.AddCategoryEntry(entry);
91  }
92 
93  //------------------------------------------------------------------------------------------------
95  protected int GetGroupedRadioIndex(notnull SCR_VONEntryRadio entry)
96  {
97  // TODO support for more than 2 transceivers
98 
99  array<ref SCR_VONEntry> entries = {};
100  m_VONController.GetVONEntries(entries);
101  SCR_VONEntryRadio radioEntry;
102  BaseRadioComponent radioComp = entry.GetTransceiver().GetRadio();
103 
104  foreach (int i, SCR_VONEntry entryVON : entries)
105  {
106  if (entry == entryVON)
107  continue;
108 
109  radioEntry = SCR_VONEntryRadio.Cast(entryVON);
110  if (radioEntry && radioEntry.GetTransceiver().GetRadio() == radioComp)
111  return i;
112  }
113 
114  return -1;
115  }
116 
117  //------------------------------------------------------------------------------------------------
119  protected array<SCR_VONEntryRadio> GetGroupedEntries(notnull SCR_VONEntryRadio entry)
120  {
121  array<SCR_VONEntryRadio> grouped = {};
122  array<ref SCR_VONEntry> entries = {};
123  m_VONController.GetVONEntries(entries);
124  SCR_VONEntryRadio radioEntry;
125  BaseRadioComponent radioComp = entry.GetTransceiver().GetRadio();
126 
127  foreach (SCR_VONEntry entryVON : entries)
128  {
129  if (entry == entryVON)
130  continue;
131 
132  radioEntry = SCR_VONEntryRadio.Cast(entryVON);
133  if (radioEntry && radioEntry.GetTransceiver().GetRadio() == radioComp)
134  grouped.Insert(radioEntry);
135  }
136 
137  return grouped;
138  }
139 
140  //------------------------------------------------------------------------------------------------
142  protected void OnInputOpenMenu(SCR_RadialMenuController controller, bool hasControl)
143  {
144  /*if (!m_RadialMenu.HasDisplay()) // TODO currently has to be called after control, sequencing needs adjusting
145  {
146  SCR_HUDManagerComponent hud = GetGame().GetHUDManager();
147  m_Display = SCR_VONRadialDisplay.Cast(hud.FindInfoDisplay(SCR_VONRadialDisplay));
148  m_RadialMenu.SetMenuDisplay(m_Display);
149  }*/
150 
151  if (!hasControl && !m_bIsDisabled)
152  {
153  m_RadialController.Control(GetGame().GetPlayerController(), m_RadialMenu);
154 
155  SCR_HUDManagerComponent hud = GetGame().GetHUDManager();
156  m_Display = SCR_VONRadialDisplay.Cast(hud.FindInfoDisplay(SCR_VONRadialDisplay));
157  m_RadialMenu.SetMenuDisplay(m_Display);
158  }
159  else if (m_bIsDisabled || m_RadialMenu.IsOpened())
160  {
161  m_RadialMenu.Close();
162  m_RadialController.SetEnableControl(false);
163  return;
164  }
165 
166  m_RadialController.SetEnableControl(true);
167 
168  if (!m_VONController.GetVONComponent())
169  {
170  if (!m_VONController.AssignVONComponent())
171  {
172  m_RadialController.SetEnableControl(false);
173  return;
174  }
175  }
176 
177  if (m_VONController.GetVONEntryCount() == 0)
178  {
179  m_RadialController.SetEnableControl(false);
180  return;
181  }
182 
183  m_RadialMenu.ClearEntries();
184 
185  array<ref SCR_VONEntry> entries = {};
186  m_VONController.GetVONEntries(entries);
187 
188  foreach (SCR_VONEntry entry : entries)
189  {
190  AddRadialEntry(entry);
191  }
192 
193  if (m_RadialMenu.GetEntryCount() < 8 && m_RadialMenu.GetEntryCount() % 2 != 0)
194  {
195  SCR_VONEntry dummy = new SCR_VONEntry();
196  dummy.Enable(false);
197  dummy.SetIcon("{FDD5423E69D007F8}UI/Textures/Icons/icons_wrapperUI-128.imageset", "VON_radio");
198  AddRadialEntry(dummy);
199  }
200  }
201 
202  //------------------------------------------------------------------------------------------------
204  protected void OnControllerTakeControl(SCR_RadialMenuController controller)
205  {
206  m_RadialMenu.GetOnPerform().Insert(OnEntryPerformed);
207  m_RadialMenu.GetOnSelect().Insert(OnEntrySelected);
208  m_RadialMenu.GetOnOpen().Insert(OnOpenMenu);
209  m_RadialMenu.GetOnClose().Insert(OnCloseMenu);
210  }
211 
212  //------------------------------------------------------------------------------------------------
214  protected void OnControllerChanged(SCR_RadialMenuController controller)
215  {
216  m_RadialMenu.GetOnPerform().Remove(OnEntryPerformed);
217  m_RadialMenu.GetOnSelect().Remove(OnEntrySelected);
218  m_RadialMenu.GetOnOpen().Remove(OnOpenMenu);
219  m_RadialMenu.GetOnClose().Remove(OnCloseMenu);
220  }
221 
222  //------------------------------------------------------------------------------------------------
224  protected void OnOpenMenu(SCR_SelectionMenu menu)
225  {
226  InputManager inputMgr = GetGame().GetInputManager();
227  inputMgr.AddActionListener("VONMenuTuneFrequency", EActionTrigger.VALUE, ActionTuneFrequency);
228  inputMgr.AddActionListener("VONMenuCycleChannel", EActionTrigger.VALUE, ActionCycleChannel);
229  inputMgr.AddActionListener("VONMenuAction", EActionTrigger.DOWN, OnMenuToggle);
230  }
231 
232  //------------------------------------------------------------------------------------------------
234  protected void OnCloseMenu(SCR_SelectionMenu menu)
235  {
236  InputManager inputMgr = GetGame().GetInputManager();
237  inputMgr.RemoveActionListener("VONMenuTuneFrequency", EActionTrigger.VALUE, ActionTuneFrequency);
238  inputMgr.RemoveActionListener("VONMenuCycleChannel", EActionTrigger.VALUE, ActionCycleChannel);
239  inputMgr.RemoveActionListener("VONMenuAction", EActionTrigger.DOWN, OnMenuToggle);
240  }
241 
242  //------------------------------------------------------------------------------------------------
244  protected void OnEntryPerformed(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry)
245  {
246  m_VONController.SetEntryActive(SCR_VONEntry.Cast(entry), true);
247 
248  m_RadialMenu.UpdateEntries();
249  }
250 
251  //------------------------------------------------------------------------------------------------
253  protected void OnEntrySelected(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry, int id)
254  {
255  if (m_SelectedEntry)
256  m_SelectedEntry.SetSelected(false);
257 
258  m_SelectedEntry = SCR_VONEntry.Cast(entry);
259  if (m_SelectedEntry)
260  m_SelectedEntry.SetSelected(true);
261 
262  SCR_VONEntryRadio selected = SCR_VONEntryRadio.Cast(entry);
263  if (selected)
264  {
265  int grouped = GetGroupedRadioIndex(selected);
266  m_Display.MarkSegmentBackground(grouped);
267  m_Display.UpdateFrequencyList(selected);
268 
269  if (!m_LastSelectedEntry || m_LastSelectedEntry.GetTransceiver().GetRadio() != selected.GetTransceiver().GetRadio())
270  {
271  m_Display.SetPreviewItem(selected.GetGadget().GetOwner());
272  m_Display.FadeItemPreview();
273  }
274 
275  m_LastSelectedEntry = selected;
276  }
277  else
278  {
279  m_Display.MarkSegmentBackground(-1);
280  m_Display.SetFrequenciesVisible(false);
281 
282  m_Display.SetPreviewItem(null);
283  m_LastSelectedEntry = null;
284  }
285 
286  m_RadialMenu.UpdateEntries();
287  }
288 
289  //------------------------------------------------------------------------------------------------
291  protected void OnActiveEntriesChanged(SCR_VONEntry entry, bool isActive)
292  {
293  m_RadialMenu.UpdateEntries();
294  }
295 
296  //------------------------------------------------------------------------------------------------
297  // ACTION LISTENER CALLBACKS
298  //------------------------------------------------------------------------------------------------
299  protected void OnAdjustEntry(int input, bool isModif)
300  {
301  if (!m_RadialMenu.GetSelectionEntry())
302  return;
303 
304  m_Display.SetFrequenciesVisible(true);
305  m_FrequencyListTimer = 3;
306 
307  SCR_VONEntry entry = SCR_VONEntry.Cast(m_RadialMenu.GetSelectionEntry());
308 
309  if (isModif)
310  entry.AdjustEntryModif(input);
311  else
312  entry.AdjustEntry(input);
313 
314 
315  SCR_VONEntryRadio radioEntry = SCR_VONEntryRadio.Cast(entry);
316  if (radioEntry)
317  {
318  m_Display.UpdateFrequencyList(radioEntry);
319  radioEntry.SetChannelText(GetKnownChannel(radioEntry.GetEntryFrequency()));
320  radioEntry.Update();
321  }
322  }
323 
324  //------------------------------------------------------------------------------------------------
326  protected void ActionTuneFrequency(float value, EActionTrigger reason)
327  {
328  if (value == 0)
329  return;
330 
331  if (value < 0)
332  OnAdjustEntry(-1, true);
333  else if (value > 0)
334  OnAdjustEntry(1, true);
335  }
336 
337  //------------------------------------------------------------------------------------------------
339  protected void ActionCycleChannel(float value, EActionTrigger reason)
340  {
341  if (value == 0)
342  return;
343 
344  if (value < 0)
345  OnAdjustEntry(-1, false);
346  else if (value > 0)
347  OnAdjustEntry(1, false);
348  }
349 
350  //------------------------------------------------------------------------------------------------
352  protected void OnMenuToggle(float value, EActionTrigger reason)
353  {
354  if (!m_RadialMenu.GetSelectionEntry())
355  return;
356 
357  SCR_VONEntry.Cast(m_RadialMenu.GetSelectionEntry()).ToggleEntry();
358  SCR_VONEntryRadio radioEntry = SCR_VONEntryRadio.Cast(m_RadialMenu.GetSelectionEntry());
359  if (!radioEntry)
360  return;
361 
362  GetGame().GetCallqueue().CallLater(UpdateEntries, 150); // TODO the radio getter IsPowered is workign with a strange delay, so update with a delay now and wait for transceivers to be powerable
363 
364  //radioEntry.Update();
365 
366  array<SCR_VONEntryRadio> grouped = GetGroupedEntries(radioEntry); //radio transceiver grouping
367  foreach (SCR_VONEntryRadio entry : grouped)
368  {
369  //entry.Update(); // currently toggle will turn the entire radio off so just update the grouped transceiver here
370  }
371  }
372 
373  //------------------------------------------------------------------------------------------------
374  // TODO temporary function to update through calllater since it cant be called with overloaded methods
375  protected void UpdateEntries()
376  {
377  m_RadialMenu.UpdateEntries();
378  }
379 
380  //------------------------------------------------------------------------------------------------
382  void Update(float timeSlice)
383  {
384  if (!m_RadialMenu)
385  return;
386 
387  m_RadialMenu.Update(timeSlice);
388 
389  if (m_RadialMenu.IsOpened() && m_fAdjustCooldown > 0)
390  m_fAdjustCooldown -= timeSlice;
391 
392  if (m_FrequencyListTimer > 0)
393  {
394  m_FrequencyListTimer -= timeSlice;
395  if (m_FrequencyListTimer <= 0)
396  m_Display.SetFrequenciesVisible(false);
397  }
398 
399  }
400 
401  //------------------------------------------------------------------------------------------------
402  void Init(SCR_VONController controllerVON)
403  {
404  m_VONController = controllerVON;
405 
406  m_VONController.GetOnEntriesActiveChangedInvoker().Insert(OnActiveEntriesChanged);
407 
408  m_RadialController.GetOnInputOpen().Insert(OnInputOpenMenu);
409  m_RadialController.GetOnTakeControl().Insert(OnControllerTakeControl);
410  m_RadialController.GetOnControllerChanged().Insert(OnControllerChanged);
411  }
412 };
SCR_HUDManagerComponent
Definition: SCR_HUDManagerComponent.c:23
SCR_RadialMenuController
Definition: SCR_RadialMenuController.c:8
SCR_SelectionMenuCategoryEntry
Definition: SCR_SelectionMenuCategory.c:6
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_VONEntryRadio
VONEntry class for radio entries.
Definition: SCR_VONEntryRadio.c:3
m_VONController
protected SCR_VONController m_VONController
Definition: SCR_VonDisplay.c:101
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
SCR_SelectionMenu
Definition: SCR_SelectionMenu.c:6
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_VONRadialDisplay
Info display within hud manager of player controller.
Definition: SCR_VONRadialDisplay.c:21
m_RadialMenu
protected SCR_RadialMenu m_RadialMenu
Definition: SCR_PlayerControllerCommandingComponent.c:17
SCR_GroupsManagerComponent
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_GroupsManagerComponent.c:1320
m_bIsDisabled
protected bool m_bIsDisabled
Definition: SCR_VONController.c:38
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
SCR_SelectionMenuEntry
Definition: SCR_SelectionMenuEntry.c:7
SCR_VONMenu
Definition: SCR_VONMenu.c:3
SCR_VONEntry
Voice over network entry data class, used for management of communication methods.
Definition: SCR_VONEntry.c:3
SCR_Faction
Definition: SCR_Faction.c:6
SCR_RadialMenu
Definition: SCR_RadialMenu.c:8
GetPlayerId
proto external int GetPlayerId()
Definition: SCR_SpawnRequestComponent.c:39
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180