Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VONEntryRadio.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
4 {
5  const string LABEL_FREQUENCY_UNITS = "#AR-VON_FrequencyUnits_MHz";
6 
7  protected int m_iFrequency;
8  protected int m_iTransceiverNumber;
9  protected string m_sChannelText;
10 
11  protected BaseTransceiver m_RadioTransceiver;
12  protected SCR_GadgetComponent m_GadgetComp;
13 
14  //------------------------------------------------------------------------------------------------
16  BaseTransceiver GetTransceiver()
17  {
18  return m_RadioTransceiver;
19  }
20 
21  //------------------------------------------------------------------------------------------------
23  int GetTransceiverNumber()
24  {
25  return m_iTransceiverNumber;
26  }
27 
28  //------------------------------------------------------------------------------------------------
30  int GetEntryFrequency()
31  {
32  return m_iFrequency;
33  }
34 
35  //------------------------------------------------------------------------------------------------
37  SCR_GadgetComponent GetGadget()
38  {
39  return m_GadgetComp;
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  UIInfo GetUIInfo()
44  {
45  InventoryItemComponent itemComponent = InventoryItemComponent.Cast(m_GadgetComp.GetOwner().FindComponent(InventoryItemComponent));
46  if (!itemComponent)
47  return null;
48 
49  return itemComponent.GetUIInfo();
50  }
51 
52  //------------------------------------------------------------------------------------------------
54  bool IsLongRange()
55  {
56  return m_GadgetComp.GetType() == EGadgetType.RADIO_BACKPACK;
57  }
58 
59  //------------------------------------------------------------------------------------------------
60  void SetRadioEntry(notnull BaseTransceiver transceiver, int number, SCR_GadgetComponent gadgetComp)
61  {
62  m_RadioTransceiver = transceiver;
63  m_iTransceiverNumber = number;
64  m_GadgetComp = gadgetComp;
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  void SetChannelText(string channel)
69  {
70  m_sChannelText = channel;
71  }
72 
73  //------------------------------------------------------------------------------------------------
74  override void InitEntry()
75  {
76  SetCustomLayout("{033302D7C8158EF8}UI/layouts/HUD/VON/VONEntry.layout");
77 
78  SetUsable(m_RadioTransceiver.GetRadio().IsPowered());
79 
80  AdjustEntryModif(0);
81 
82  SetChannelText(SCR_VONMenu.GetKnownChannel(m_RadioTransceiver.GetFrequency()));
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  override void AdjustEntryModif(int modifier)
87  {
88  if (!IsUsable() && modifier != 0)
89  return;
90 
91  if (!m_RadioTransceiver)
92  return;
93 
94  // Get & adjust frequency
95  m_iFrequency = m_RadioTransceiver.GetFrequency();
96  int minFreq = m_RadioTransceiver.GetMinFrequency();
97  int maxFreq = m_RadioTransceiver.GetMaxFrequency();
98 
99  // TODO sound temp here until moved to radio level
100  if ( (modifier > 0 && m_iFrequency == maxFreq) || (modifier < 0 && m_iFrequency == minFreq) )
101  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RADIO_CHANGEFREQUENCY_ERROR);
102  else if (modifier != 0)
103  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RADIO_CHANGEFREQUENCY);
104 
105  m_iFrequency = m_iFrequency + (modifier * m_RadioTransceiver.GetFrequencyResolution());
106  m_iFrequency = Math.ClampInt(m_iFrequency, minFreq, maxFreq);
107 
108  RadioHandlerComponent rhc = RadioHandlerComponent.Cast(GetGame().GetPlayerController().FindComponent(RadioHandlerComponent));
109  if (rhc)
110  rhc.SetFrequency(m_RadioTransceiver, m_iFrequency); // Set new frequency
111  else
112  return;
113 
114  float fFrequency = Math.Round(m_iFrequency * 0.1) * 0.01; // Format the frequency text: round and convert to 2 digits with one possible decimal place (39500 -> 39.5)
115  m_sText = fFrequency.ToString(3, 1) + " " + LABEL_FREQUENCY_UNITS;
116  }
117 
118  //------------------------------------------------------------------------------------------------
119  override void AdjustEntry(int modifier)
120  {
121  if (!GetGame().GetGameMode())
122  return;
123 
125  SCR_FactionManager factionMgr = SCR_FactionManager.Cast(GetGame().GetFactionManager());
126  if ( !groupManager || !factionMgr || !m_RadioTransceiver)
127  return;
128 
129  SCR_Faction playerFaction = SCR_Faction.Cast(factionMgr.SGetPlayerFaction(GetGame().GetPlayerController().GetPlayerId()));
130  if (!playerFaction)
131  return;
132 
133  int factionFreq = playerFaction.GetFactionRadioFrequency();
134  int currentFreq = m_RadioTransceiver.GetFrequency();
135 
136  array<SCR_AIGroup> groups = groupManager.GetPlayableGroupsByFaction(playerFaction);
137  if (!groups || groups.IsEmpty())
138  return;
139 
140  int newFreq;
141 
142  if (currentFreq == factionFreq) // if platoon frequency
143  {
144  if (modifier == -1)
145  newFreq = groups[0].GetRadioFrequency(); // go to first squad freq
146  else
147  return; // top freq in list
148  }
149  else // non platoon frequency
150  {
151  int count = groups.Count();
152  if (modifier == 1 && currentFreq == groups[0].GetRadioFrequency()) // input up from first group frequency to platoon, if its not zero
153  {
154  if (factionFreq != 0)
155  newFreq = factionFreq;
156  else
157  return; // top freq in list
158  }
159  else if (modifier == -1 && currentFreq == groups[count - 1].GetRadioFrequency()) // input down from last group frequency to platoon, if its not zero
160  {
161  return; // last freq in the list
162  }
163  else
164  {
165  bool isMatched;
166 
167  for (int i = 0; i < count; i++)
168  {
169  if (currentFreq == groups[i].GetRadioFrequency())
170  {
171  if (modifier == 1)
172  newFreq = groups[i-1].GetRadioFrequency();
173  else
174  newFreq = groups[i+1].GetRadioFrequency();
175 
176  isMatched = true;
177  break;
178  }
179  }
180 
181  if (!isMatched)
182  newFreq = groups[0].GetRadioFrequency();
183  }
184  }
185 
186  m_iFrequency = newFreq;
187 
188  RadioHandlerComponent rhc = RadioHandlerComponent.Cast(GetGame().GetPlayerController().FindComponent(RadioHandlerComponent));
189  if (rhc)
190  rhc.SetFrequency(m_RadioTransceiver, m_iFrequency); // Set new frequency
191  else
192  return;
193 
194  float fFrequency = Math.Round(m_iFrequency / 10); // Format the frequency text
195  fFrequency = fFrequency / 100;
196  m_sText = fFrequency.ToString(3, 1) + " " + LABEL_FREQUENCY_UNITS;
197 
198  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RADIO_FREQUENCY_CYCLE);
199  }
200 
201  //------------------------------------------------------------------------------------------------
202  override void ToggleEntry()
203  {
204  // Constructor allows the entry to not have m_RadioTransceiver assigned
205  if (!m_RadioTransceiver)
206  return;
207 
208  BaseRadioComponent radio = m_RadioTransceiver.GetRadio();
209 
210  SetUsable(!radio.IsPowered());
211  radio.SetPower(IsUsable());
212 
213  AdjustEntryModif(0);
214 
215  if (IsUsable())
216  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RADIO_TURN_OFF);
217  else
218  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RADIO_TURN_ON);
219  }
220 
221  //------------------------------------------------------------------------------------------------
222  override string GetIconResource()
223  {
224  if (!m_RadioTransceiver)
225  return string.Empty;
226 
227 
228  IEntity entity = m_RadioTransceiver.GetRadio().GetOwner();
229  // Item will be available, since Transceiver should not exist without RadioComponent
230 
231  InventoryItemComponent pInvItemComponent = InventoryItemComponent.Cast(entity.FindComponent(InventoryItemComponent));
232  if (!pInvItemComponent)
233  return string.Empty;
234 
235  ItemAttributeCollection pInvItemAttributes = pInvItemComponent.GetAttributes();
236  if (!pInvItemAttributes)
237  return string.Empty;
238 
239  UIInfo uiInfo = pInvItemAttributes.GetUIInfo();
240  if (!uiInfo)
241  return string.Empty;
242 
243  return uiInfo.GetIconPath();
244  }
245 
246  //------------------------------------------------------------------------------------------------
247  override ECommMethod GetVONMethod()
248  {
249  return ECommMethod.SQUAD_RADIO;
250  }
251 
252  //------------------------------------------------------------------------------------------------
254  override void Update()
255  {
256  super.Update();
257 
258  SCR_VONEntryComponent entryComp = SCR_VONEntryComponent.Cast(m_EntryComponent);
259  if (!entryComp) // first update procs when this is not fetchable yet
260  return;
261 
262  if (!m_RadioTransceiver) // TODO can happen for unclear reasons, temp fix
263  {
264  SCR_VONController vonContr = SCR_VONController.Cast(GetGame().GetPlayerController().FindComponent(SCR_VONController));
265  if (vonContr)
266  vonContr.RemoveEntry(this);
267 
268  return;
269  }
270 
271  entryComp.SetTransceiverText("CH" + m_iTransceiverNumber.ToString());
272  entryComp.SetFrequencyText(m_sText);
273  entryComp.SetChannelText(m_sChannelText);
274  entryComp.SetActiveIcon(m_bIsActive);
275 
276  BaseRadioComponent radio = m_RadioTransceiver.GetRadio();
277  SetUsable(radio.IsPowered());
278  entryComp.SetPowerIcon(IsUsable());
279 
280  if (m_bIsActive)
281  {
282  entryComp.SetTransceiverOpacity(1);
283 
284  if (m_bIsSelected)
285  entryComp.SetFrequencyColor(Color.FromInt(GUIColors.ORANGE_BRIGHT.PackToInt()));
286  else
287  entryComp.SetFrequencyColor(Color.FromInt(GUIColors.ORANGE.PackToInt()));
288  }
289  else
290  {
291  entryComp.SetTransceiverOpacity(0.5);
292 
293  if (m_bIsSelected)
294  entryComp.SetFrequencyColor(Color.FromInt(GUIColors.ORANGE_BRIGHT.PackToInt()));
295  else
296  entryComp.SetFrequencyColor(Color.FromInt(Color.WHITE));
297  }
298  }
299 };
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
ItemAttributeCollection
Definition: ItemAttributeCollection.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
UIInfo
UIInfo - declare object, allows to define UI elements.
Definition: UIInfo.c:13
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
LABEL_FREQUENCY_UNITS
const string LABEL_FREQUENCY_UNITS
Definition: SCR_VonDisplay.c:67
SCR_VONEntryRadio
VONEntry class for radio entries.
Definition: SCR_VONEntryRadio.c:3
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
SCR_VONEntryComponent
Definition: SCR_VONEntryComponent.c:3
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
BaseTransceiver
Definition: BaseTransceiver.c:12
InventoryItemComponent
Definition: InventoryItemComponent.c:12
SCR_GroupsManagerComponent
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_GroupsManagerComponent.c:1320
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
m_bIsActive
SCR_HintSequenceComponentClass m_bIsActive
ECommMethod
ECommMethod
Definition: ECommMethod.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
GetPlayerId
proto external int GetPlayerId()
Definition: SCR_SpawnRequestComponent.c:39
m_sText
class SCR_BaseEditorAttribute m_sText
m_RadioTransceiver
BaseTransceiver m_RadioTransceiver
Definition: SCR_VonDisplay.c:18