Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VONMenu.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
4{
5 [Attribute()]
7
8 [Attribute()]
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 //------------------------------------------------------------------------------------------------
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 SCR_GroupTaskManagerComponent groupTaskManager = SCR_GroupTaskManagerComponent.GetInstance();
69 if (!groupTaskManager || !groupTaskManager.IsEnabledAssigningFrequencies())
70 return string.Empty;
71
72 SCR_Task foundTask = groupTaskManager.GetTaskByFrequency(milFaction, frequency);
73 if (foundTask)
74 return groupTaskManager.GetTaskTranslatedName(foundTask);
75
76 return string.Empty;
77 }
78
79 //------------------------------------------------------------------------------------------------
82 {
83 entry.SetName(entry.GetDisplayText());
84
85 if (category)
86 category.AddEntry(entry);
87 else
88 m_RadialMenu.AddEntry(entry);
89
90 entry.InitEntry();
91 }
92
93 //------------------------------------------------------------------------------------------------
96 {
97 entry.SetName(entry.GetName());
98 m_RadialMenu.AddCategoryEntry(entry);
99 }
100
101 //------------------------------------------------------------------------------------------------
103 protected int GetGroupedRadioIndex(notnull SCR_VONEntryRadio entry)
104 {
105 // TODO support for more than 2 transceivers
106
107 array<ref SCR_VONEntry> entries = {};
108 m_VONController.GetVONEntries(entries);
109 SCR_VONEntryRadio radioEntry;
110 BaseRadioComponent radioComp = entry.GetTransceiver().GetRadio();
111
112 foreach (int i, SCR_VONEntry entryVON : entries)
113 {
114 if (entry == entryVON)
115 continue;
116
117 radioEntry = SCR_VONEntryRadio.Cast(entryVON);
118 if (radioEntry && radioEntry.GetTransceiver().GetRadio() == radioComp)
119 return i;
120 }
121
122 return -1;
123 }
124
125 //------------------------------------------------------------------------------------------------
127 protected array<SCR_VONEntryRadio> GetGroupedEntries(notnull SCR_VONEntryRadio entry)
128 {
129 array<SCR_VONEntryRadio> grouped = {};
130 array<ref SCR_VONEntry> entries = {};
131 m_VONController.GetVONEntries(entries);
132 SCR_VONEntryRadio radioEntry;
133 BaseRadioComponent radioComp = entry.GetTransceiver().GetRadio();
134
135 foreach (SCR_VONEntry entryVON : entries)
136 {
137 if (entry == entryVON)
138 continue;
139
140 radioEntry = SCR_VONEntryRadio.Cast(entryVON);
141 if (radioEntry && radioEntry.GetTransceiver().GetRadio() == radioComp)
142 grouped.Insert(radioEntry);
143 }
144
145 return grouped;
146 }
147
148 //------------------------------------------------------------------------------------------------
150 protected void OnInputOpenMenu(SCR_RadialMenuController controller, bool hasControl)
151 {
152 /*if (!m_RadialMenu.HasDisplay()) // TODO currently has to be called after control, sequencing needs adjusting
153 {
154 SCR_HUDManagerComponent hud = GetGame().GetHUDManager();
155 m_Display = SCR_VONRadialDisplay.Cast(hud.FindInfoDisplay(SCR_VONRadialDisplay));
156 m_RadialMenu.SetMenuDisplay(m_Display);
157 }*/
158
159 if (!hasControl && !m_bIsDisabled)
160 {
162
165 m_RadialMenu.SetMenuDisplay(m_Display);
166 }
167 else if (m_bIsDisabled || m_RadialMenu.IsOpened())
168 {
169 m_RadialMenu.Close();
170 m_RadialController.SetEnableControl(false);
171 return;
172 }
173
174 m_RadialController.SetEnableControl(true);
175
176 if (!m_VONController.GetVONComponent())
177 {
178 if (!m_VONController.AssignVONComponent())
179 {
180 m_RadialController.SetEnableControl(false);
181 return;
182 }
183 }
184
185 if (m_VONController.GetVONEntryCount() == 0)
186 {
187 m_RadialController.SetEnableControl(false);
188 return;
189 }
190
191 m_RadialMenu.ClearEntries();
192
193 array<ref SCR_VONEntry> entries = {};
194 m_VONController.GetVONEntries(entries);
195
196 foreach (SCR_VONEntry entry : entries)
197 {
198 AddRadialEntry(entry);
199 }
200
201 if (m_RadialMenu.GetEntryCount() < 8 && m_RadialMenu.GetEntryCount() % 2 != 0)
202 {
203 SCR_VONEntry dummy = new SCR_VONEntry();
204 dummy.Enable(false);
205 dummy.SetIcon("{FDD5423E69D007F8}UI/Textures/Icons/icons_wrapperUI-128.imageset", "VON_radio");
206 AddRadialEntry(dummy);
207 }
208 }
209
210 //------------------------------------------------------------------------------------------------
213 {
214 m_RadialMenu.GetOnPerform().Insert(OnEntryPerformed);
215 m_RadialMenu.GetOnSelect().Insert(OnEntrySelected);
216 m_RadialMenu.GetOnOpen().Insert(OnOpenMenu);
217 m_RadialMenu.GetOnClose().Insert(OnCloseMenu);
218 }
219
220 //------------------------------------------------------------------------------------------------
222 protected void OnControllerChanged(SCR_RadialMenuController controller, bool hasControl)
223 {
224 m_RadialMenu.GetOnPerform().Remove(OnEntryPerformed);
225 m_RadialMenu.GetOnSelect().Remove(OnEntrySelected);
226 m_RadialMenu.GetOnOpen().Remove(OnOpenMenu);
227 m_RadialMenu.GetOnClose().Remove(OnCloseMenu);
228 }
229
230 //------------------------------------------------------------------------------------------------
232 protected void OnOpenMenu(SCR_SelectionMenu menu)
233 {
234 InputManager inputMgr = GetGame().GetInputManager();
235 inputMgr.AddActionListener("VONMenuTuneFrequency", EActionTrigger.VALUE, ActionTuneFrequency);
236 inputMgr.AddActionListener("VONMenuCycleChannel", EActionTrigger.VALUE, ActionCycleChannel);
237 inputMgr.AddActionListener("VONMenuAction", EActionTrigger.DOWN, OnMenuToggle);
238 inputMgr.AddActionListener("VONMenuMuteAction", EActionTrigger.DOWN, OnMenuMuteToggle);
239 }
240
241 //------------------------------------------------------------------------------------------------
243 protected void OnCloseMenu(SCR_SelectionMenu menu)
244 {
245 InputManager inputMgr = GetGame().GetInputManager();
246 inputMgr.RemoveActionListener("VONMenuTuneFrequency", EActionTrigger.VALUE, ActionTuneFrequency);
247 inputMgr.RemoveActionListener("VONMenuCycleChannel", EActionTrigger.VALUE, ActionCycleChannel);
248 inputMgr.RemoveActionListener("VONMenuAction", EActionTrigger.DOWN, OnMenuToggle);
249 inputMgr.RemoveActionListener("VONMenuMuteAction", EActionTrigger.DOWN, OnMenuMuteToggle);
250 }
251
252 //------------------------------------------------------------------------------------------------
255 {
256 m_VONController.SetEntryActive(SCR_VONEntry.Cast(entry), true);
257
258 m_RadialMenu.UpdateEntries();
259 }
260
261 //------------------------------------------------------------------------------------------------
263 protected void OnEntrySelected(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry, int id)
264 {
265 if (m_SelectedEntry)
266 m_SelectedEntry.SetSelected(false);
267
268 m_SelectedEntry = SCR_VONEntry.Cast(entry);
269 if (m_SelectedEntry)
270 m_SelectedEntry.SetSelected(true);
271
272 SCR_VONEntryRadio selected = SCR_VONEntryRadio.Cast(entry);
273 if (selected)
274 {
275 int grouped = GetGroupedRadioIndex(selected);
276 m_Display.MarkSegmentBackground(grouped);
277 m_Display.UpdateFrequencyList(selected);
278
279 if (!m_LastSelectedEntry || m_LastSelectedEntry.GetTransceiver().GetRadio() != selected.GetTransceiver().GetRadio())
280 {
281 m_Display.SetPreviewItem(selected.GetGadget().GetOwner());
282 m_Display.FadeItemPreview();
283 }
284
285 m_LastSelectedEntry = selected;
286 }
287 else
288 {
289 m_Display.MarkSegmentBackground(-1);
290 m_Display.SetFrequenciesVisible(false);
291
292 m_Display.SetPreviewItem(null);
293 m_LastSelectedEntry = null;
294 }
295
296 m_RadialMenu.UpdateEntries();
297 }
298
299 //------------------------------------------------------------------------------------------------
301 protected void OnActiveEntriesChanged(SCR_VONEntry entry, bool isActive)
302 {
303 m_RadialMenu.UpdateEntries();
304 }
305
306 //------------------------------------------------------------------------------------------------
307 // ACTION LISTENER CALLBACKS
308 //------------------------------------------------------------------------------------------------
309 protected void OnAdjustEntry(int input, bool isModif)
310 {
311 if (!m_RadialMenu.GetSelectionEntry())
312 return;
313
314 m_Display.SetFrequenciesVisible(true);
316
317 SCR_VONEntry entry = SCR_VONEntry.Cast(m_RadialMenu.GetSelectionEntry());
318
319 if (isModif)
320 entry.AdjustEntryModif(input);
321 else
322 entry.AdjustEntry(input);
323
324
325 SCR_VONEntryRadio radioEntry = SCR_VONEntryRadio.Cast(entry);
326 if (radioEntry)
327 {
328 m_Display.UpdateFrequencyList(radioEntry);
329 radioEntry.SetChannelText(GetKnownChannel(radioEntry.GetEntryFrequency()));
330 radioEntry.Update();
331 }
332 }
333
334 //------------------------------------------------------------------------------------------------
336 protected void ActionTuneFrequency(float value, EActionTrigger reason)
337 {
338 if (value == 0)
339 return;
340
341 if (value < 0)
342 OnAdjustEntry(-1, true);
343 else if (value > 0)
344 OnAdjustEntry(1, true);
345 }
346
347 //------------------------------------------------------------------------------------------------
349 protected void ActionCycleChannel(float value, EActionTrigger reason)
350 {
351 if (value == 0)
352 return;
353
354 if (value < 0)
355 OnAdjustEntry(-1, false);
356 else if (value > 0)
357 OnAdjustEntry(1, false);
358 }
359
360 //------------------------------------------------------------------------------------------------
362 protected void OnMenuToggle(float value, EActionTrigger reason)
363 {
364 if (!m_RadialMenu.GetSelectionEntry())
365 return;
366
367 SCR_VONEntry.Cast(m_RadialMenu.GetSelectionEntry()).ToggleEntry();
368 SCR_VONEntryRadio radioEntry = SCR_VONEntryRadio.Cast(m_RadialMenu.GetSelectionEntry());
369 if (!radioEntry)
370 return;
371
372 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
373
374 //radioEntry.Update();
375
376 array<SCR_VONEntryRadio> grouped = GetGroupedEntries(radioEntry); //radio transceiver grouping
377 foreach (SCR_VONEntryRadio entry : grouped)
378 {
379 //entry.Update(); // currently toggle will turn the entire radio off so just update the grouped transceiver here
380 }
381 }
382
383 //------------------------------------------------------------------------------------------------
385 protected void OnMenuMuteToggle(float value, EActionTrigger reason)
386 {
387 SCR_SelectionMenuEntry selectedMenuEntry = m_RadialMenu.GetSelectionEntry();
388 if (!selectedMenuEntry)
389 return;
390
391 SCR_VONEntryRadio selectedRadioEntry = SCR_VONEntryRadio.Cast(selectedMenuEntry);
392 if (!selectedRadioEntry)
393 return;
394
395 bool isMuted = selectedRadioEntry.ToggleMuteEntry();
396 SCR_VONEntry vonEntry = SCR_VONEntry.Cast(m_RadialMenu.GetSelectionEntry());
397 if (isMuted)
398 {
399 // Select another entry that is not muted
400 array<ref SCR_SelectionMenuEntry> entries = m_RadialMenu.GetEntries();
401 SCR_VONEntryRadio radioEntry;
402 foreach (SCR_SelectionMenuEntry entry : entries)
403 {
404 if (entry == selectedMenuEntry)
405 continue;
406
407 radioEntry = SCR_VONEntryRadio.Cast(entry);
408 if (!radioEntry || radioEntry.GetIsMuted())
409 continue;
410
411 m_VONController.SetEntryActive(SCR_VONEntry.Cast(entry), true);
412 break;
413 }
414 }
415
417 }
418
419 //------------------------------------------------------------------------------------------------
420 // TODO temporary function to update through calllater since it cant be called with overloaded methods
421 protected void UpdateEntries()
422 {
423 m_RadialMenu.UpdateEntries();
424 }
425
426 //------------------------------------------------------------------------------------------------
428 void Update(float timeSlice)
429 {
430 if (!m_RadialMenu)
431 return;
432
433 m_RadialMenu.Update(timeSlice);
434
435 if (m_RadialMenu.IsOpened() && m_fAdjustCooldown > 0)
436 m_fAdjustCooldown -= timeSlice;
437
438 if (m_FrequencyListTimer > 0)
439 {
440 m_FrequencyListTimer -= timeSlice;
441 if (m_FrequencyListTimer <= 0)
442 m_Display.SetFrequenciesVisible(false);
443 }
444
445 }
446
447 //------------------------------------------------------------------------------------------------
448 void Init(SCR_VONController controllerVON)
449 {
450 m_VONController = controllerVON;
451
452 m_VONController.GetOnEntriesActiveChangedInvoker().Insert(OnActiveEntriesChanged);
453
454 m_RadialController.GetOnInputOpen().Insert(OnInputOpenMenu);
455 m_RadialController.GetOnTakeControl().Insert(OnControllerTakeControl);
456 m_RadialController.GetOnControllerChanged().Insert(OnControllerChanged);
457 }
458};
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GroupTaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_Task(IEntitySource src, IEntity parent)
Definition SCR_Task.c:1938
Input management system for user interactions.
int GetFactionRadioFrequency()
SCR_InfoDisplay FindInfoDisplay(typename type)
Return hud component of given type.
static SCR_HUDManagerComponent GetHUDManager()
Voice over network entry data class, used for management of communication methods.
Definition SCR_VONEntry.c:4
void AdjustEntryModif(int modifier)
void ToggleEntry()
Toggle entry such as radio on/off.
void AdjustEntry(int modifier)
VONEntry class for radio entries.
void SetChannelText(string channel)
BaseTransceiver GetTransceiver()
Associated transceiver.
override void Update()
Update entry visuals.
SCR_GadgetComponent GetGadget()
Gadget component associated with this entry.
bool ToggleMuteEntry()
bool GetIsMuted()
int GetEntryFrequency()
Local frequency getter since atm the transceiver getter is delayed (network?) and not sufficient for ...
void OnActiveEntriesChanged(SCR_VONEntry entry, bool isActive)
SCR_VONController event.
void OnEntryPerformed(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry)
SCR_RadialMenu event.
static string GetKnownChannel(int frequency)
Definition SCR_VONMenu.c:39
SCR_VONRadialDisplay m_Display
Definition SCR_VONMenu.c:20
SCR_VONController m_VONController
Definition SCR_VONMenu.c:21
void OnEntrySelected(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry, int id)
SCR_RadialMenu event.
bool m_bIsDisabled
Definition SCR_VONMenu.c:13
SCR_RadialMenu GetRadialMenu()
Definition SCR_VONMenu.c:24
void AddRadialEntry(notnull SCR_VONEntry entry, SCR_SelectionMenuCategoryEntry category=null)
Add simple entry.
Definition SCR_VONMenu.c:81
void UpdateEntries()
void OnCloseMenu(SCR_SelectionMenu menu)
SCR_RadialMenu event.
void ActionCycleChannel(float value, EActionTrigger reason)
Menu item configuration callback.
SCR_VONEntry m_SelectedEntry
Definition SCR_VONMenu.c:18
void SetMenuDisabled(bool state)
Definition SCR_VONMenu.c:30
void Init(SCR_VONController controllerVON)
array< SCR_VONEntryRadio > GetGroupedEntries(notnull SCR_VONEntryRadio entry)
Get sibling transceiver entries when there are more in a single device.
void OnControllerChanged(SCR_RadialMenuController controller, bool hasControl)
SCR_RadialMenuController event.
bool m_bIsModifierActive
Definition SCR_VONMenu.c:14
void OnControllerTakeControl(SCR_RadialMenuController controller)
SCR_RadialMenuController event.
float m_FrequencyListTimer
Definition SCR_VONMenu.c:16
ref SCR_RadialMenuController m_RadialController
Definition SCR_VONMenu.c:6
SCR_VONEntryRadio m_LastSelectedEntry
Definition SCR_VONMenu.c:19
void OnAdjustEntry(int input, bool isModif)
void OnMenuToggle(float value, EActionTrigger reason)
Entry toggle callback.
void AddRadialCategory(notnull SCR_SelectionMenuCategoryEntry entry)
Add simple category.
Definition SCR_VONMenu.c:95
int GetGroupedRadioIndex(notnull SCR_VONEntryRadio entry)
Get sibling transceiver indeces when there are more in a single device.
const float ADJUST_COOLDOWN
Definition SCR_VONMenu.c:11
void OnMenuMuteToggle(float value, EActionTrigger reason)
Entry toggle callback.
ref SCR_RadialMenu m_RadialMenu
Definition SCR_VONMenu.c:9
void OnInputOpenMenu(SCR_RadialMenuController controller, bool hasControl)
SCR_RadialMenuController event.
void Update(float timeSlice)
frame update
float m_fAdjustCooldown
Definition SCR_VONMenu.c:15
void OnOpenMenu(SCR_SelectionMenu menu)
SCR_RadialMenu event.
void ActionTuneFrequency(float value, EActionTrigger reason)
Menu item configuration callback.
Info display within hud manager of player controller.
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()
EActionTrigger
proto external int GetPlayerId()