Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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 string m_sFrequencyTextOverwrite;
9 protected int m_iTransceiverNumber;
10 protected string m_sChannelText;
11 protected string m_sChannelTextOverwrite;
12
14 protected SCR_GadgetComponent m_GadgetComp;
15
16 //------------------------------------------------------------------------------------------------
22
23 //------------------------------------------------------------------------------------------------
26 {
28 }
29
30 //------------------------------------------------------------------------------------------------
33 {
34 return m_iFrequency;
35 }
36
37 //------------------------------------------------------------------------------------------------
39 SCR_GadgetComponent GetGadget()
40 {
41 return m_GadgetComp;
42 }
43
44 //------------------------------------------------------------------------------------------------
46 {
47 InventoryItemComponent itemComponent = InventoryItemComponent.Cast(m_GadgetComp.GetOwner().FindComponent(InventoryItemComponent));
48 if (!itemComponent)
49 return null;
50
51 return itemComponent.GetUIInfo();
52 }
53
54 //------------------------------------------------------------------------------------------------
57 {
58 return m_GadgetComp.GetType() == EGadgetType.RADIO_BACKPACK;
59 }
60
61 //------------------------------------------------------------------------------------------------
62 void SetRadioEntry(notnull BaseTransceiver transceiver, int number, SCR_GadgetComponent gadgetComp)
63 {
64 m_RadioTransceiver = transceiver;
65 m_iTransceiverNumber = number;
66 m_GadgetComp = gadgetComp;
67 }
68
69 //------------------------------------------------------------------------------------------------
70 void SetChannelText(string channel)
71 {
72 m_sChannelText = channel;
73 }
74
75 //------------------------------------------------------------------------------------------------
76 void SetFrequencyTextOverwrite(string text)
77 {
79 }
80
81 //------------------------------------------------------------------------------------------------
82 void SetChannelTextOverwrite(string text)
83 {
85 }
86
87 //------------------------------------------------------------------------------------------------
88 override void InitEntry()
89 {
90 SetCustomLayout("{033302D7C8158EF8}UI/layouts/HUD/VON/VONEntry.layout");
91
92 SetUsable(m_RadioTransceiver.GetRadio().IsPowered());
93
95
96 if (m_sChannelTextOverwrite.IsEmpty())
97 {
99 }
100 else
101 {
103 }
104 }
105
106 //------------------------------------------------------------------------------------------------
107 override void AdjustEntryModif(int modifier)
108 {
109 if (!IsUsable() && modifier != 0)
110 return;
111
113 return;
114
115 // Get & adjust frequency
116 m_iFrequency = m_RadioTransceiver.GetFrequency();
117 int minFreq = m_RadioTransceiver.GetMinFrequency();
118 int maxFreq = m_RadioTransceiver.GetMaxFrequency();
119
120 // TODO sound temp here until moved to radio level
121 if ( (modifier > 0 && m_iFrequency == maxFreq) || (modifier < 0 && m_iFrequency == minFreq) )
122 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RADIO_CHANGEFREQUENCY_ERROR);
123 else if (modifier != 0)
124 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RADIO_CHANGEFREQUENCY);
125
126 m_iFrequency = m_iFrequency + (modifier * m_RadioTransceiver.GetFrequencyResolution());
127 m_iFrequency = Math.ClampInt(m_iFrequency, minFreq, maxFreq);
128
129 m_RadioTransceiver.SetFrequency(m_iFrequency);
130
131 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)
132 m_sText = fFrequency.ToString(3, 1) + " " + LABEL_FREQUENCY_UNITS;
133 }
134
135 //------------------------------------------------------------------------------------------------
136 override void AdjustEntry(int modifier)
137 {
138 if (!GetGame().GetGameMode())
139 return;
140
142 SCR_FactionManager factionMgr = SCR_FactionManager.Cast(GetGame().GetFactionManager());
143 if ( !groupManager || !factionMgr || !m_RadioTransceiver)
144 return;
145
146 SCR_Faction playerFaction = SCR_Faction.Cast(factionMgr.SGetPlayerFaction(GetGame().GetPlayerController().GetPlayerId()));
147 if (!playerFaction)
148 return;
149
150 int factionFreq = playerFaction.GetFactionRadioFrequency();
151 int currentFreq = m_RadioTransceiver.GetFrequency();
152
153 array<SCR_AIGroup> groups = groupManager.GetPlayableGroupsByFaction(playerFaction);
154 if (!groups || groups.IsEmpty())
155 return;
156
157 int newFreq;
158
159 if (currentFreq == factionFreq) // if platoon frequency
160 {
161 if (modifier == -1)
162 newFreq = groups[0].GetRadioFrequency(); // go to first squad freq
163 else
164 return; // top freq in list
165 }
166 else // non platoon frequency
167 {
168 int count = groups.Count();
169 if (modifier == 1 && currentFreq == groups[0].GetRadioFrequency()) // input up from first group frequency to platoon, if its not zero
170 {
171 if (factionFreq != 0)
172 newFreq = factionFreq;
173 else
174 return; // top freq in list
175 }
176 else if (modifier == -1 && currentFreq == groups[count - 1].GetRadioFrequency()) // input down from last group frequency to platoon, if its not zero
177 {
178 return; // last freq in the list
179 }
180 else
181 {
182 bool isMatched;
183
184 for (int i = 0; i < count; i++)
185 {
186 if (currentFreq == groups[i].GetRadioFrequency())
187 {
188 if (modifier == 1)
189 newFreq = groups[i-1].GetRadioFrequency();
190 else
191 newFreq = groups[i+1].GetRadioFrequency();
192
193 isMatched = true;
194 break;
195 }
196 }
197
198 if (!isMatched)
199 newFreq = groups[0].GetRadioFrequency();
200 }
201 }
202
203 m_iFrequency = newFreq;
204 m_RadioTransceiver.SetFrequency(m_iFrequency);
205
206 float fFrequency = Math.Round(m_iFrequency / 10); // Format the frequency text
207 fFrequency = fFrequency / 100;
208 m_sText = fFrequency.ToString(3, 1) + " " + LABEL_FREQUENCY_UNITS;
209
210 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RADIO_FREQUENCY_CYCLE);
211 }
212
213 //------------------------------------------------------------------------------------------------
214 override void ToggleEntry()
215 {
216 // Constructor allows the entry to not have m_RadioTransceiver assigned
218 return;
219
220 BaseRadioComponent radio = m_RadioTransceiver.GetRadio();
221
222 SetUsable(!radio.IsPowered());
223 radio.SetPower(IsUsable());
224
226
227 if (IsUsable())
228 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RADIO_TURN_OFF);
229 else
230 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RADIO_TURN_ON);
231 }
232
233 //------------------------------------------------------------------------------------------------
235 {
236 // Constructor allows the entry to not have m_RadioTransceiver assigned
238 return false;
239
240 bool state = !m_RadioTransceiver.IsMuted();
241 m_RadioTransceiver.SetMuteState(state);
242 SetMuted(state);
243
244 return state;
245 }
246
247 //------------------------------------------------------------------------------------------------
249 {
250 // Constructor allows the entry to not have m_RadioTransceiver assigned
252 return true;
253
254 // m_RadioTransceiver can't be used directly if this is called on a entry that is not the active entry.
255 BaseTransceiver transceiver = m_RadioTransceiver.GetRadio().GetTransceiver(m_iTransceiverNumber - 1);
256 if (!transceiver)
257 return true;
258
259 return transceiver.IsMuted();
260 }
261
262 //------------------------------------------------------------------------------------------------
263 override string GetIconResource()
264 {
266 return string.Empty;
267
268
269 IEntity entity = m_RadioTransceiver.GetRadio().GetOwner();
270 // Item will be available, since Transceiver should not exist without RadioComponent
271
273 if (!pInvItemComponent)
274 return string.Empty;
275
276 ItemAttributeCollection pInvItemAttributes = pInvItemComponent.GetAttributes();
277 if (!pInvItemAttributes)
278 return string.Empty;
279
280 UIInfo uiInfo = pInvItemAttributes.GetUIInfo();
281 if (!uiInfo)
282 return string.Empty;
283
284 return uiInfo.GetIconPath();
285 }
286
287 //------------------------------------------------------------------------------------------------
289 {
290 return ECommMethod.SQUAD_RADIO;
291 }
292
293 //------------------------------------------------------------------------------------------------
295 override void Update()
296 {
297 super.Update();
298
300 if (!entryComp) // first update procs when this is not fetchable yet
301 return;
302
303 if (!m_RadioTransceiver) // TODO can happen for unclear reasons, temp fix
304 {
305 SCR_VONController vonContr = SCR_VONController.Cast(GetGame().GetPlayerController().FindComponent(SCR_VONController));
306 if (vonContr)
307 vonContr.RemoveEntry(this);
308
309 return;
310 }
311
312 entryComp.SetTransceiverText("CH" + m_iTransceiverNumber.ToString());
313 if (m_sFrequencyTextOverwrite.IsEmpty())
314 {
315 entryComp.SetFrequencyText(m_sText);
316 }
317 else
318 {
320 }
322 entryComp.SetActiveIcon(m_bIsActive);
323 entryComp.SetMuteIcon(m_bIsMuted);
324
325 BaseRadioComponent radio = m_RadioTransceiver.GetRadio();
326 SetUsable(radio.IsPowered());
327 entryComp.SetPowerIcon(IsUsable());
328
329 if (m_bIsActive)
330 {
331 entryComp.SetTransceiverOpacity(1);
332
333 if (m_bIsSelected)
334 entryComp.SetFrequencyColor(Color.FromInt(GUIColors.ORANGE_BRIGHT.PackToInt()));
335 else
336 entryComp.SetFrequencyColor(Color.FromInt(GUIColors.ORANGE.PackToInt()));
337 }
338 else
339 {
340 entryComp.SetTransceiverOpacity(0.5);
341
342 if (m_bIsSelected)
343 entryComp.SetFrequencyColor(Color.FromInt(GUIColors.ORANGE_BRIGHT.PackToInt()));
344 else
345 entryComp.SetFrequencyColor(Color.FromInt(Color.WHITE));
346 }
347 }
348};
ECommMethod
Definition ECommMethod.c:8
ArmaReforgerScripted GetGame()
Definition game.c:1398
int GetRadioFrequency()
SCR_BaseGameMode GetGameMode()
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition Color.c:13
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
int GetFactionRadioFrequency()
void SetCustomLayout(ResourceName layout)
ref SCR_SelectionMenuEntryComponent m_EntryComponent
void SetFrequencyColor(Color color)
void SetTransceiverText(string text)
void SetPowerIcon(bool state)
void SetChannelText(string text)
void SetTransceiverOpacity(float alpha)
void SetFrequencyText(string text)
void SetActiveIcon(bool state)
void SetMuteIcon(bool state)
Voice over network entry data class, used for management of communication methods.
Definition SCR_VONEntry.c:4
string m_sText
Definition SCR_VONEntry.c:9
void SetMuted(bool state)
Activate entry.
void SetUsable(bool state)
Usable entry.
bool m_bIsActive
Definition SCR_VONEntry.c:6
bool IsUsable()
Is usable entry.
bool m_bIsSelected
Definition SCR_VONEntry.c:8
bool m_bIsMuted
Definition SCR_VONEntry.c:7
VONEntry class for radio entries.
void SetChannelText(string channel)
override void AdjustEntry(int modifier)
override string GetIconResource()
override ECommMethod GetVONMethod()
string m_sFrequencyTextOverwrite
void SetChannelTextOverwrite(string text)
UIInfo GetUIInfo()
int m_iTransceiverNumber
BaseTransceiver GetTransceiver()
Associated transceiver.
override void Update()
Update entry visuals.
SCR_GadgetComponent GetGadget()
Gadget component associated with this entry.
string m_sChannelTextOverwrite
SCR_GadgetComponent m_GadgetComp
int m_iFrequency
override void ToggleEntry()
void SetRadioEntry(notnull BaseTransceiver transceiver, int number, SCR_GadgetComponent gadgetComp)
override void InitEntry()
bool ToggleMuteEntry()
void SetFrequencyTextOverwrite(string text)
string m_sChannelText
bool GetIsMuted()
int GetTransceiverNumber()
Associated transceiver id - starts with 1.
override void AdjustEntryModif(int modifier)
bool IsLongRange()
Is long range backpack radio type.
BaseTransceiver m_RadioTransceiver
int GetEntryFrequency()
Local frequency getter since atm the transceiver getter is delayed (network?) and not sufficient for ...
static string GetKnownChannel(int frequency)
Definition SCR_VONMenu.c:39
UIInfo - allows to define UI elements.
Definition UIInfo.c:14
proto external PlayerController GetPlayerController()
proto external int GetPlayerId()