25 class SCR_RadioProcAnimCtx
40 class SCR_RadioComponent : SCR_GadgetComponent
43 private int m_iRadioCategory;
45 [
Attribute(
"0", UIWidgets.ComboBox,
"Radio type",
"", ParamEnumArray.FromEnum(ERadioType),
category:
"Radio")]
46 private int m_iRadioType;
48 private bool m_bIsPowered =
true;
49 private 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 private ref array<ref SCR_RadioProcAnimCtx> m_aProcAnims =
new array<ref SCR_RadioProcAnimCtx>();
60 private bool m_bAnimInProgress;
66 m_BaseRadioComp.SetPower( !m_BaseRadioComp.IsPowered() );
67 m_bIsPowered = m_BaseRadioComp.IsPowered();
71 if ( m_iRadioType == ERadioType.ANPRC68 || ERadioType.ANPRC77 )
72 SetKnobAnim(m_iSignalPower, 1, 0.3,
false);
76 if ( m_iRadioType == ERadioType.ANPRC68 || ERadioType.ANPRC77 )
77 SetKnobAnim(m_iSignalPower, 0, 0.3,
false);
87 if (!m_BaseRadioComp.IsPowered() || m_bAnimInProgress)
91 string strDown =
"DOWN";
97 int freq = tsv.GetFrequency();
98 int freqMax = tsv.GetMaxFrequency();
99 int freqMin = tsv.GetMinFrequency();
101 if ( ( freq + tsv.GetFrequencyResolution() ) > freqMax &&
direction)
103 else if ( ( freq - tsv.GetFrequencyResolution() ) < freqMin && !
direction)
108 freq += tsv.GetFrequencyResolution();
110 freq -= tsv.GetFrequencyResolution();
113 PlayerController pc =
GetGame().GetPlayerController();
116 RadioHandlerComponent rhc = RadioHandlerComponent.Cast(pc.FindComponent(RadioHandlerComponent));
119 rhc.SetFrequency(tsv, freq);
126 if ( m_iRadioType != ERadioType.ANPRC68 )
128 targetAngle = GetKnobAngle(EFreqUnit.MHZ);
129 SetKnobAnim(m_iSignalChannelMhz, targetAngle, 0.3,
true);
132 targetAngle = GetKnobAngle(EFreqUnit.KHZ);
133 SetKnobAnim(m_iSignalChannelKhz, targetAngle, 0.3,
false);
143 private float GetKnobAngle(EFreqUnit freqUnit)
145 int step, stepsCount;
148 stepsCount = GetKnobAnimStepCount(freqUnit);
153 step = (tsv.GetMinFrequency() - tsv.GetFrequency()) * -1;
156 if (m_iRadioType == ERadioType.ANPRC68)
159 currentStep = step/tsv.GetFrequencyResolution();
162 else if (freqUnit == EFreqUnit.MHZ)
165 currentStep = Math.Floor(step/1000);
179 if ((step/50) % 2 == 0)
184 step = Math.Floor(step/100);
185 currentStep = currentStep + (step * 2);
188 return currentStep * (360/stepsCount);
198 private void UpdateKnobState()
214 m_SignalManager.SetSignalValue( m_iSignalChannelKhz, GetKnobAngle(EFreqUnit.KHZ) );
216 if ( m_iRadioType != ERadioType.ANPRC68 )
217 m_SignalManager.SetSignalValue( m_iSignalChannelMhz, GetKnobAngle(EFreqUnit.MHZ) );
226 private void SetKnobAnim(
int signal,
float targetAngle,
float speed,
bool clumpAnim)
231 SCR_RadioProcAnimCtx animCtx =
new SCR_RadioProcAnimCtx();
232 animCtx.sAnimSignal = signal;
234 animCtx.fEndVal = targetAngle;
235 animCtx.fAnimSpeed = speed;
236 animCtx.fTimeSlice = 0;
237 animCtx.bInProgress =
true;
239 m_aProcAnims.Insert(animCtx);
243 m_bAnimInProgress =
true;
251 private void AnimKnob(
float timeSlice)
255 for (
int i = 0; i < m_aProcAnims.Count(); i++ )
257 SCR_RadioProcAnimCtx animCtx = m_aProcAnims[i];
261 if (animCtx.bInProgress)
265 animCtx.fTimeSlice += timeSlice / animCtx.fAnimSpeed;
268 if ( animCtx.fTimeSlice >= 1 )
270 animCtx.bInProgress =
false;
271 newAngle = animCtx.fEndVal;
276 if ( Math.AbsFloat(animCtx.fStartVal - animCtx.fEndVal) > 180 )
278 if ( animCtx.fStartVal < 0)
279 animCtx.fStartVal += 360;
281 animCtx.fStartVal -= 360;
284 float lerp = Math.Lerp(animCtx.fStartVal, animCtx.fEndVal, animCtx.fTimeSlice);
293 m_bAnimInProgress =
false;
294 m_aProcAnims.Clear();
303 private int GetKnobAnimStepCount(EFreqUnit freqUnit)
305 if ( m_iRadioType == ERadioType.ANPRC68 )
309 else if ( m_iRadioType == ERadioType.R148 )
311 if (freqUnit == EFreqUnit.MHZ)
316 else if ( m_iRadioType == ERadioType.ANPRC77 )
318 if (freqUnit == EFreqUnit.MHZ)
329 protected void InitSignals()
336 if (m_iSignalPower != -1 && m_iSignalChannelKhz != -1 && m_iSignalChannelMhz != -1)
337 m_bSignalInit =
true;
345 override void ModeSwitch(EGadgetMode mode, IEntity charOwner)
347 super.ModeSwitch(mode, charOwner);
356 super.ActivateGadgetUpdate();
360 itemComponent.ActivateOwner(
true);
366 super.DeactivateGadgetUpdate();
370 itemComponent.ActivateOwner(
false);
377 super.UpdateVisibility(mode);
384 return EGadgetType.RADIO_BACKPACK;
386 return EGadgetType.RADIO;
390 override bool CanBeHeld()
408 return m_BaseRadioComp;
412 override void Update(
float timeSlice)
415 if (!m_bAnimInProgress)
427 super.OnPostInit(owner);
430 m_BaseRadioComp = BaseRadioComponent.Cast(owner.FindComponent(BaseRadioComponent));
431 if (!m_BaseRadioComp)
432 Print(
"SCR_RadioEntity: Failed acquiring BaseRadioComponent", LogLevel.WARNING);
435 m_SignalManager = SignalsManagerComponent.Cast(owner.FindComponent( SignalsManagerComponent ) );