5 protected float m_fAdjustmentStep;
8 [
Attribute(
desc:
"If action should wait for player to use their scroll wheel in order to change value")]
9 protected bool m_bManualAdjustment;
12 [
Attribute(
desc:
"Determines if this action will start from the begining when max value is reached - or from the other side if Adjustment Step is below 0")]
13 protected bool m_bLoopAction;
16 [
Attribute(defvalue:
"SelectAction",
desc:
"Input action for increase")]
17 protected string m_sActionIncrease;
21 protected string m_sActionDecrease;
25 protected string m_sActionStartSoundEvent;
29 protected string m_sActionCanceledSoundEvent;
33 protected string m_sMovementSoundEvent;
37 protected string m_sMovementStopSoundEvent;
40 protected float m_fTargetValue;
43 protected bool m_bIsAdjustedByPlayer;
46 protected SoundComponent m_SoundComponent;
49 protected float m_fLerpLast;
52 protected AudioHandle m_MovementAudioHandle;
56 bool IsManuallyAdjusted()
58 return m_bManualAdjustment;
62 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
64 m_SoundComponent = SoundComponent.Cast(pOwnerEntity.FindComponent(SoundComponent));
65 if (GetActionDuration() != 0)
66 m_fAdjustmentStep /= Math.AbsFloat(GetActionDuration());
70 override bool CanBeShownScript(IEntity user)
72 if (!m_bLoopAction && !m_bManualAdjustment)
74 if (m_fAdjustmentStep > 0 && GetCurrentValue() >= GetMaximumValue())
77 if (m_fAdjustmentStep < 0 && GetCurrentValue() <= GetMinimumValue())
86 void ToggleActionBypass()
92 override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity,
float timeSlice)
94 if (!m_bManualAdjustment)
95 HandleAction(timeSlice);
99 override void OnActionStart(IEntity pUserEntity)
106 if (!m_bIsAdjustedByPlayer)
109 m_fTargetValue = Math.InverseLerp(GetMinimumValue(), GetMaximumValue(), GetCurrentValue());
110 if (!GetActionDuration())
111 ToggleActionBypass();
113 if (!m_bManualAdjustment)
116 if (!m_sActionIncrease.IsEmpty())
117 GetGame().GetInputManager().AddActionListener(m_sActionIncrease, EActionTrigger.VALUE, HandleAction);
119 if (!m_sActionDecrease.IsEmpty())
120 GetGame().GetInputManager().AddActionListener(m_sActionDecrease, EActionTrigger.VALUE, HandleActionDecrease);
124 override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
130 if (!m_bIsAdjustedByPlayer)
133 m_bIsAdjustedByPlayer =
false;
135 if (!m_bManualAdjustment)
138 if (!m_sActionIncrease.IsEmpty())
139 GetGame().GetInputManager().RemoveActionListener(m_sActionIncrease, EActionTrigger.VALUE, HandleAction);
141 if (!m_sActionDecrease.IsEmpty())
142 GetGame().GetInputManager().RemoveActionListener(m_sActionDecrease, EActionTrigger.VALUE, HandleActionDecrease);
148 void HandleAction(
float value)
153 if (m_bManualAdjustment)
154 value /= Math.AbsFloat(value);
156 value *= m_fAdjustmentStep;
158 m_fTargetValue += value;
161 if (value > 0 &&
float.AlmostEqual(GetCurrentValue(), GetMaximumValue()))
162 m_fTargetValue = GetMinimumValue();
163 else if (value < 0 &&
float.AlmostEqual(GetCurrentValue(), GetMinimumValue()))
164 m_fTargetValue = GetMaximumValue();
167 if (
float.AlmostEqual(m_fTargetValue, GetCurrentValue(), Math.AbsFloat(m_fAdjustmentStep)))
171 m_fTargetValue = Math.Floor(m_fTargetValue / m_fAdjustmentStep) * m_fAdjustmentStep;
174 m_fTargetValue = Math.Clamp(m_fTargetValue, GetMinimumValue(), GetMaximumValue());
176 if (!
float.AlmostEqual(m_fTargetValue, GetCurrentValue()))
177 SetSendActionDataFlag();
183 void HandleActionDecrease(
float value)
185 HandleAction(-value);
190 void PlayMovementAndStopSound(
float lerp)
195 if (m_fLerpLast == lerp)
198 if (
float.AlmostEqual(lerp, 1))
200 if (!
float.AlmostEqual(m_fLerpLast, 1))
203 if (m_sMovementStopSoundEvent !=
string.Empty)
207 else if (
float.AlmostEqual(lerp, 0))
209 if (!
float.AlmostEqual(m_fLerpLast, 0))
212 if (m_sMovementStopSoundEvent !=
string.Empty)
218 if (
m_SoundComponent.IsFinishedPlaying(m_MovementAudioHandle) && m_sMovementStopSoundEvent !=
string.Empty)
227 override bool HasLocalEffectOnlyScript()
234 override bool CanBroadcastScript()
242 override protected bool OnSaveActionData(ScriptBitWriter writer)
244 float lerp = Math.Lerp(GetMinimumValue(), GetMaximumValue(), m_fTargetValue);
245 writer.WriteFloat01(lerp);
249 PlayMovementAndStopSound(lerp);
258 override protected bool OnLoadActionData(ScriptBitReader reader)
260 if (m_bIsAdjustedByPlayer)
264 reader.ReadFloat01(lerp);
266 m_fTargetValue = Math.InverseLerp(GetMinimumValue(), GetMaximumValue(), lerp);
269 PlayMovementAndStopSound(lerp);