25class SCR_RadioProcAnimCtx
40class SCR_RadioComponent : SCR_GadgetComponent
43 protected int m_iRadioCategory;
45 [
Attribute(
"0", UIWidgets.ComboBox,
"Radio type",
"", ParamEnumArray.FromEnum(ERadioType),
category:
"Radio")]
46 protected int m_iRadioType;
48 protected bool m_bIsPowered =
true;
49 protected BaseRadioComponent m_BaseRadioComp;
53 protected bool m_bSignalInit =
false;
54 protected int m_iSignalPower = -1;
55 protected int m_iSignalChannelKhz = -1;
56 protected int m_iSignalChannelMhz = -1;
59 protected ref array<ref SCR_RadioProcAnimCtx> m_aProcAnims =
new array<ref SCR_RadioProcAnimCtx>();
60 protected bool m_bAnimInProgress;
66 m_BaseRadioComp.SetPower( !m_BaseRadioComp.IsPowered() );
67 m_bIsPowered = m_BaseRadioComp.IsPowered();
69 PlayerController pc =
GetGame().GetPlayerController();
72 SCR_VONController vonController = SCR_VONController.Cast(pc.FindComponent(SCR_VONController));
75 array<ref SCR_VONEntry> entries = {};
76 vonController.GetVONEntries(entries);
78 foreach (SCR_VONEntry entry : entries)
80 SCR_VONEntryRadio radioEntry = SCR_VONEntryRadio.Cast(entry);
82 if (radio == m_BaseRadioComp)
83 entry.SetUsable(radio.IsPowered());
90 if ( m_iRadioType == ERadioType.ANPRC68 || ERadioType.ANPRC77 )
91 SetKnobAnim(m_iSignalPower, 1, 0.3,
false);
95 if ( m_iRadioType == ERadioType.ANPRC68 || ERadioType.ANPRC77 )
96 SetKnobAnim(m_iSignalPower, 0, 0.3,
false);
106 if (!m_BaseRadioComp.IsPowered() || m_bAnimInProgress)
113 int freq = tsv.GetFrequency();
114 int freqMax = tsv.GetMaxFrequency();
115 int freqMin = tsv.GetMinFrequency();
117 if ( ( freq + tsv.GetFrequencyResolution() ) > freqMax &&
direction)
119 else if ( ( freq - tsv.GetFrequencyResolution() ) < freqMin && !
direction)
124 freq += tsv.GetFrequencyResolution();
126 freq -= tsv.GetFrequencyResolution();
128 tsv.SetFrequency(freq);
133 if ( m_iRadioType != ERadioType.ANPRC68 )
135 targetAngle = GetKnobAngle(EFreqUnit.MHZ);
136 SetKnobAnim(m_iSignalChannelMhz, targetAngle, 0.3,
true);
139 targetAngle = GetKnobAngle(EFreqUnit.KHZ);
140 SetKnobAnim(m_iSignalChannelKhz, targetAngle, 0.3,
false);
150 protected float GetKnobAngle(EFreqUnit freqUnit)
152 int step, stepsCount;
155 stepsCount = GetKnobAnimStepCount(freqUnit);
160 step = (tsv.GetMinFrequency() - tsv.GetFrequency()) * -1;
163 if (m_iRadioType == ERadioType.ANPRC68)
166 currentStep = step/tsv.GetFrequencyResolution();
169 else if (freqUnit == EFreqUnit.MHZ)
172 currentStep = Math.Floor(step/1000);
186 if ((step/50) % 2 == 0)
191 step = Math.Floor(step/100);
192 currentStep = currentStep + (step * 2);
195 return currentStep * (360/stepsCount);
205 protected void UpdateKnobState()
221 m_SignalManager.SetSignalValue( m_iSignalChannelKhz, GetKnobAngle(EFreqUnit.KHZ) );
223 if ( m_iRadioType != ERadioType.ANPRC68 )
224 m_SignalManager.SetSignalValue( m_iSignalChannelMhz, GetKnobAngle(EFreqUnit.MHZ) );
233 protected void SetKnobAnim(
int signal,
float targetAngle,
float speed,
bool clumpAnim)
238 SCR_RadioProcAnimCtx animCtx =
new SCR_RadioProcAnimCtx();
239 animCtx.sAnimSignal = signal;
241 animCtx.fEndVal = targetAngle;
242 animCtx.fAnimSpeed = speed;
243 animCtx.fTimeSlice = 0;
244 animCtx.bInProgress =
true;
246 m_aProcAnims.Insert(animCtx);
250 m_bAnimInProgress =
true;
258 protected void AnimKnob(
float timeSlice)
262 for (
int i = 0; i < m_aProcAnims.Count(); i++ )
264 SCR_RadioProcAnimCtx animCtx = m_aProcAnims[i];
268 if (animCtx.bInProgress)
272 animCtx.fTimeSlice += timeSlice / animCtx.fAnimSpeed;
275 if ( animCtx.fTimeSlice >= 1 )
277 animCtx.bInProgress =
false;
278 newAngle = animCtx.fEndVal;
283 if ( Math.AbsFloat(animCtx.fStartVal - animCtx.fEndVal) > 180 )
285 if ( animCtx.fStartVal < 0)
286 animCtx.fStartVal += 360;
288 animCtx.fStartVal -= 360;
291 float lerp = Math.Lerp(animCtx.fStartVal, animCtx.fEndVal, animCtx.fTimeSlice);
300 m_bAnimInProgress =
false;
301 m_aProcAnims.Clear();
310 protected int GetKnobAnimStepCount(EFreqUnit freqUnit)
312 if ( m_iRadioType == ERadioType.ANPRC68 )
316 else if ( m_iRadioType == ERadioType.R148 )
318 if (freqUnit == EFreqUnit.MHZ)
323 else if ( m_iRadioType == ERadioType.ANPRC77 )
325 if (freqUnit == EFreqUnit.MHZ)
336 protected void InitSignals()
343 if (m_iSignalPower != -1 && m_iSignalChannelKhz != -1 && m_iSignalChannelMhz != -1)
344 m_bSignalInit =
true;
354 super.ModeSwitch(mode, charOwner);
363 super.ActivateGadgetUpdate();
365 InventoryItemComponent itemComponent = InventoryItemComponent.Cast(
GetOwner().FindComponent(InventoryItemComponent));
367 itemComponent.ActivateOwner(
true);
373 super.DeactivateGadgetUpdate();
375 InventoryItemComponent itemComponent = InventoryItemComponent.Cast(
GetOwner().FindComponent(InventoryItemComponent));
377 itemComponent.ActivateOwner(
false);
381 override void UpdateVisibility(EGadgetMode mode)
384 super.UpdateVisibility(mode);
391 return EGadgetType.RADIO_BACKPACK;
393 return EGadgetType.RADIO;
398 ERadioType GetRadioType()
414 BaseRadioComponent GetRadioComponent()
416 return m_BaseRadioComp;
420 override void Update(
float timeSlice)
423 if (!m_bAnimInProgress)
435 super.OnPostInit(owner);
438 m_BaseRadioComp = BaseRadioComponent.Cast(owner.
FindComponent(BaseRadioComponent));
439 if (!m_BaseRadioComp)
440 Print(
"SCR_RadioEntity: Failed acquiring BaseRadioComponent",
LogLevel.WARNING);
ArmaReforgerScripted GetGame()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
override bool IsVisibleEquipped()
override void ActivateGadgetUpdate()
override void DeactivateGadgetUpdate()
SCR_GadgetComponentClass ANPRC68
SCR_GadgetComponentClass R148
enum ERadioCategory KHZ
Frequency unit prefix.
enum ERadioCategory ANPRC77
ERadioCategory
Radio slot.
SignalsManagerComponent m_SignalManager
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
BaseTransceiver GetTransceiver()
Associated transceiver.
IEntity GetOwner()
Owner entity of the fuel tank.
BaseRadioComponentClass BaseTransceiver
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
SCR_FieldOfViewSettings Attribute