Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VONRadialDisplay.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  PREVIOUS = 0,
6  NEXT
7 }
8 
9 //------------------------------------------------------------------------------------------------
10 class SCR_CompareGroupRadioFreq : SCR_SortCompare<SCR_AIGroup>
11 {
12  override static int Compare(SCR_AIGroup left, SCR_AIGroup right)
13  {
14  return left.GetRadioFrequency() < right.GetRadioFrequency();
15  }
16 };
17 
18 //------------------------------------------------------------------------------------------------
22 {
23  const ref Color ORANGE = new Color(1.0, 0.5, 0, 0.05); // TODO placeholder before visual concept is done
24 
25  protected Widget m_wFrequencyDisplay; // group frequency list within the center of the menu
26 
27  protected TextWidget m_aChannelDisplay[3];
28  protected ImageWidget m_aIconDisplay[3];
29  protected TextWidget m_aFrequencyDisplay[3];
30 
31  protected Widget m_wSizeLayout;
32  protected ItemPreviewWidget m_wPreviewItem;
33  protected IEntity m_Item;
34  protected PreviewRenderAttributes m_PreviewAttributes;
35 
36  //------------------------------------------------------------------------------------------------
38  void UpdateFrequencyList(notnull SCR_VONEntryRadio entry)
39  {
40  SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
41  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
42  if (!groupManager || !factionManager)
43  {
44  SetFrequenciesVisible(false);
45  return;
46  }
47 
48  Faction playerFaction = factionManager.GetLocalPlayerFaction();
49  if (!playerFaction)
50  {
51  SetFrequenciesVisible(false);
52  return;
53  }
54 
55  array<SCR_AIGroup> playableGroups = {};
56  array<SCR_AIGroup> playableGroupsOrigin = groupManager.GetPlayableGroupsByFaction(playerFaction);
57  if (!playableGroupsOrigin)
58  {
59  SetFrequenciesVisible(false);
60  return;
61  }
62 
63  int groupCount = playableGroups.Copy(playableGroupsOrigin);
64  SCR_Sorting<SCR_AIGroup, SCR_CompareGroupRadioFreq>.HeapSort(playableGroups);
65 
66  int matchID = -2; // -1 for platoon, 0+ for groups
67  SCR_Faction milFaction = SCR_Faction.Cast(playerFaction);
68  if (!milFaction || milFaction.GetFactionRadioFrequency() == 0 || groupCount == 0)
69  {
70  SetFrequenciesVisible(false);
71  return;
72  }
73 
74  int frequency = entry.GetEntryFrequency();
75 
76  if (milFaction.GetFactionRadioFrequency() == frequency)
77  {
78  m_aChannelDisplay[EVONMenuTable.CURRENT].SetColor(GUIColors.ORANGE);
79  m_aIconDisplay[EVONMenuTable.CURRENT].SetColor(GUIColors.ORANGE);
80  m_aFrequencyDisplay[EVONMenuTable.CURRENT].SetColor(GUIColors.ORANGE);
81  SetFrequencyDisplay(EVONMenuTable.CURRENT, null, milFaction);
82  matchID = -1;
83  }
84  else
85  {
86  foreach (int i, SCR_AIGroup group : playableGroups)
87  {
88  if (group.GetRadioFrequency() == frequency)
89  {
90  m_aChannelDisplay[EVONMenuTable.CURRENT].SetColor(GUIColors.ORANGE);
91  m_aIconDisplay[EVONMenuTable.CURRENT].SetColor(GUIColors.ORANGE);
92  m_aFrequencyDisplay[EVONMenuTable.CURRENT].SetColor(GUIColors.ORANGE);
93  SetFrequencyDisplay(EVONMenuTable.CURRENT, group);
94  matchID = i;
95  }
96  }
97  }
98 
99  switch (matchID)
100  {
101  case -2: // no match, current frequency to default
102  SetFrequencyDisplay(EVONMenuTable.PREVIOUS, null, milFaction);
103  SetFrequencyDisplay(EVONMenuTable.CURRENT, playableGroups[0]);
104 
105  if (groupCount > 1)
106  SetFrequencyDisplay(EVONMenuTable.NEXT, playableGroups[1]);
107  else
108  ClearDisplayLine(EVONMenuTable.NEXT);
109 
110  m_aChannelDisplay[EVONMenuTable.CURRENT].SetColor(GUIColors.ENABLED);
111  m_aIconDisplay[EVONMenuTable.CURRENT].SetColor(GUIColors.ENABLED);
112  m_aFrequencyDisplay[EVONMenuTable.CURRENT].SetColor(GUIColors.ENABLED);
113  break;
114 
115  case -1: // match found, set next/prev frequencies
116  SetFrequencyDisplay(EVONMenuTable.NEXT, playableGroups[0]);
117  ClearDisplayLine(EVONMenuTable.PREVIOUS);
118  break;
119 
120  case 0:
121  SetFrequencyDisplay(EVONMenuTable.PREVIOUS, null, milFaction);
122 
123  if (groupCount > 1)
124  SetFrequencyDisplay(EVONMenuTable.NEXT, playableGroups[1]);
125  else
126  ClearDisplayLine(EVONMenuTable.NEXT);
127 
128  break;
129 
130  default:
131  SetFrequencyDisplay(EVONMenuTable.PREVIOUS, playableGroups[matchID - 1]);
132 
133  if (groupCount > matchID + 1)
134  SetFrequencyDisplay(EVONMenuTable.NEXT, playableGroups[matchID + 1]);
135  else
136  ClearDisplayLine(EVONMenuTable.NEXT);
137  }
138  }
139 
140  //------------------------------------------------------------------------------------------------
145  protected void SetFrequencyDisplay(EVONMenuTable line, SCR_AIGroup group, SCR_Faction milFaction = null)
146  {
147  if (milFaction)
148  {
149  m_aChannelDisplay[line].SetText("#AR-Comm_PlatoonChannel");
150  m_aFrequencyDisplay[line].SetText((milFaction.GetFactionRadioFrequency() * 0.001).ToString() + " #AR-VON_FrequencyUnits_MHz");
151  }
152  else
153  {
154  string company, platoon, squad, character, format;
155  group.GetCallsigns(company, platoon, squad, character, format);
156  m_aChannelDisplay[line].SetTextFormat(format, company, platoon, squad, character);
157  m_aFrequencyDisplay[line].SetText((group.GetRadioFrequency()*0.001).ToString() + " #AR-VON_FrequencyUnits_MHz ");
158  }
159 
160  m_aChannelDisplay[line].SetVisible(true);
161  m_aIconDisplay[line].SetVisible(true);
162  m_aFrequencyDisplay[line].SetVisible(true);
163  }
164 
165  //------------------------------------------------------------------------------------------------
166  protected void ClearDisplayLine(EVONMenuTable line)
167  {
168  m_aChannelDisplay[line].SetVisible(false);
169  m_aIconDisplay[line].SetVisible(false);
170  m_aFrequencyDisplay[line].SetVisible(false);
171  }
172 
173  //------------------------------------------------------------------------------------------------
176  void MarkSegmentBackground(int id)
177  {
178  foreach ( SCR_RadialMenuSegmentComponent comp : m_aSegments )
179  {
180  comp.GetBackgroundWidget().SetColor(Color.FromInt(Color.BLACK));
181  }
182 
183  if (m_aSegments.IsIndexValid(id))
184  m_aSegments[id].GetBackgroundWidget().SetColor(ORANGE);
185  }
186 
187  //------------------------------------------------------------------------------------------------
189  void SetPreviewItem(IEntity item)
190  {
191  // Visibility
192  m_wPreviewItem.SetVisible(item != null);
193 
194  m_Item = item;
195  if (!item)
196  return;
197 
198  // Get manager and render preview
199  ChimeraWorld world = ChimeraWorld.CastFrom(item.GetWorld());
200  if (!world)
201  return;
202 
203  ItemPreviewManagerEntity manager = world.GetItemPreviewManager();
204  if (!manager)
205  return;
206 
207  // Set rendering and preview properties
208  SetupPreviewAttributes(m_PreviewAttributes);
209  manager.SetPreviewItem(m_wPreviewItem, item, m_PreviewAttributes);
210  m_wPreviewItem.SetResolutionScale(1, 1);
211  }
212 
213  //------------------------------------------------------------------------------------------------
215  protected void SetupPreviewAttributes(out PreviewRenderAttributes preview)
216  {
217  if (!m_Item)
218  return;
219 
220  InventoryItemComponent inventoryItem = InventoryItemComponent.Cast(m_Item.FindComponent(InventoryItemComponent));
221  if (!inventoryItem)
222  return;
223 
224  preview = SCR_VONPreviewAttributes.Cast(inventoryItem.FindAttribute(SCR_VONPreviewAttributes));
225  }
226 
227  //------------------------------------------------------------------------------------------------
228  void FadeItemPreview(bool state = true)
229  {
230  if (state)
231  {
232  m_wPreviewItem.SetOpacity(0);
233  AnimateWidget.Opacity(m_wPreviewItem, 1, 1/0.3);
234  }
235  }
236 
237  //------------------------------------------------------------------------------------------------
239  void SetFrequenciesVisible(bool state)
240  {
241  if (state)
242  AnimateWidget.Opacity(m_wFrequencyDisplay, 1, 1/0.3);
243  else
244  AnimateWidget.Opacity(m_wFrequencyDisplay, 0, 1/0.3);
245  }
246 
247  //------------------------------------------------------------------------------------------------
248  override protected void OnMenuEntryPerform(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry)
249  {
250  // TODO this is mostly overridden to avoid secondary resize animation in the parent class
251 
252  if (m_wSelectedIndicatorFeedback)
253  {
254  m_wSelectedIndicatorFeedback.SetOpacity(0);
255 
256  if (!AnimateWidget.IsAnimating(m_wSelectedIndicatorFeedback))
257  {
258  WidgetAnimationOpacity anim = AnimateWidget.Opacity(m_wSelectedIndicatorFeedback, CHANGE_CONTENT_OPACITY, UIConstants.FADE_RATE_FAST);
259  anim.SetRepeat(true);
260  anim.GetOnCycleCompleted().Insert(OnEntrySizeAnimCycleCompleted);
261  }
262  }
263  }
264 
265  //------------------------------------------------------------------------------------------------
266  override void DisplayStartDraw(IEntity owner)
267  {
268  super.DisplayStartDraw(owner);
269 
270  m_wFrequencyDisplay = GetRootWidget().FindAnyWidget("FrequencyDisplay");
271 
272  m_aChannelDisplay[EVONMenuTable.PREVIOUS] = TextWidget.Cast(m_wFrequencyDisplay.FindAnyWidget("ChannelUp"));
273  m_aChannelDisplay[EVONMenuTable.CURRENT] = TextWidget.Cast(m_wFrequencyDisplay.FindAnyWidget("ChannelCurrent"));
274  m_aChannelDisplay[EVONMenuTable.NEXT] = TextWidget.Cast(m_wFrequencyDisplay.FindAnyWidget("ChannelDown"));
275 
276  m_aIconDisplay[EVONMenuTable.PREVIOUS] = ImageWidget.Cast(m_wFrequencyDisplay.FindAnyWidget("IconUp"));
277  m_aIconDisplay[EVONMenuTable.CURRENT] = ImageWidget.Cast(m_wFrequencyDisplay.FindAnyWidget("IconCurrent"));
278  m_aIconDisplay[EVONMenuTable.NEXT] = ImageWidget.Cast(m_wFrequencyDisplay.FindAnyWidget("IconDown"));
279 
280  m_aFrequencyDisplay[EVONMenuTable.PREVIOUS] = TextWidget.Cast(m_wFrequencyDisplay.FindAnyWidget("FrequencyUp"));
281  m_aFrequencyDisplay[EVONMenuTable.CURRENT] = TextWidget.Cast(m_wFrequencyDisplay.FindAnyWidget("FrequencyCurrent"));
282  m_aFrequencyDisplay[EVONMenuTable.NEXT] = TextWidget.Cast(m_wFrequencyDisplay.FindAnyWidget("FrequencyDown"));
283 
284  m_wPreviewItem = ItemPreviewWidget.Cast(GetRootWidget().FindAnyWidget("ItemPreview"));
285  m_wSizeLayout = GetRootWidget().FindAnyWidget("SizeRTW");
286 
287  SetFrequenciesVisible(false);
288  }
289 };
ChimeraWorld
Definition: ChimeraWorld.c:12
EVONMenuTable
EVONMenuTable
Definition: SCR_VONRadialDisplay.c:2
ORANGE
@ ORANGE
Definition: SCR_BaseVehicleInfo.c:21
SCR_RadialMenuDisplay
Definition: SCR_RadialMenuDisplay.c:7
m_Item
NewsFeedItem m_Item
Definition: SCR_NewsSubMenu.c:2
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
Compare
SCR_VONRadialDisplay Compare
Definition: SCR_ContentBrowser_AddonsSubMenu.c:1612
PreviewRenderAttributes
Definition: PreviewRenderAttributes.c:12
NEXT
NEXT
Definition: SCR_VONRadialDisplay.c:5
SCR_VONEntryRadio
VONEntry class for radio entries.
Definition: SCR_VONEntryRadio.c:3
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
PREVIOUS
PREVIOUS
Definition: SCR_VONRadialDisplay.c:2
SCR_SelectionMenu
Definition: SCR_SelectionMenu.c:6
SCR_VONPreviewAttributes
Render widget preview attributes for VON menu.
Definition: SCR_VONPreviewAttributes.c:3
CURRENT
CURRENT
Definition: SCR_VONRadialDisplay.c:3
SCR_VONRadialDisplay
Info display within hud manager of player controller.
Definition: SCR_VONRadialDisplay.c:21
InventoryItemComponent
Definition: InventoryItemComponent.c:12
Faction
Definition: Faction.c:12
SCR_GroupsManagerComponent
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_GroupsManagerComponent.c:1320
SCR_AIGroup
Definition: SCR_AIGroup.c:68
ItemPreviewWidget
Definition: ItemPreviewWidget.c:12
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
SCR_SelectionMenuEntry
Definition: SCR_SelectionMenuEntry.c:7
SCR_RadialMenuSegmentComponent
Definition: SCR_RadialMenuSegmentComponent.c:4
SCR_Faction
Definition: SCR_Faction.c:6
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