Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AdjustSignalAction.c
Go to the documentation of this file.
2 {
4  [Attribute(defvalue: "0.1", desc: "Adjustment step [-1 to 1]", params: "-1 1 0.1")]
5  protected float m_fAdjustmentStep;
6 
8  [Attribute(desc: "If action should wait for player to use their scroll wheel in order to change value")]
9  protected bool m_bManualAdjustment;
10 
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;
14 
16  [Attribute(defvalue: "SelectAction", desc: "Input action for increase")]
17  protected string m_sActionIncrease;
18 
20  [Attribute(desc: "Input action for decrease")]
21  protected string m_sActionDecrease;
22 
24  [Attribute(desc: "Action start sound event name")]
25  protected string m_sActionStartSoundEvent;
26 
28  [Attribute(desc: "Action canceled sound event name")]
29  protected string m_sActionCanceledSoundEvent;
30 
32  [Attribute(desc: "Movement sound event name")]
33  protected string m_sMovementSoundEvent;
34 
36  [Attribute(desc: "Movement stop sound event name")]
37  protected string m_sMovementStopSoundEvent;
38 
40  protected float m_fTargetValue;
41 
43  protected bool m_bIsAdjustedByPlayer;
44 
46  protected SoundComponent m_SoundComponent;
47 
49  protected float m_fLerpLast;
50 
52  protected AudioHandle m_MovementAudioHandle;
53 
54  //------------------------------------------------------------------------------------------------
56  bool IsManuallyAdjusted()
57  {
58  return m_bManualAdjustment;
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
63  {
64  m_SoundComponent = SoundComponent.Cast(pOwnerEntity.FindComponent(SoundComponent));
65  if (GetActionDuration() != 0)
66  m_fAdjustmentStep /= Math.AbsFloat(GetActionDuration());
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  override bool CanBeShownScript(IEntity user)
71  {
72  if (!m_bLoopAction && !m_bManualAdjustment)
73  {
74  if (m_fAdjustmentStep > 0 && GetCurrentValue() >= GetMaximumValue())
75  return false;
76 
77  if (m_fAdjustmentStep < 0 && GetCurrentValue() <= GetMinimumValue())
78  return false;
79  }
80 
81  return true;
82  }
83 
84  //------------------------------------------------------------------------------------------------
86  void ToggleActionBypass()
87  {
88  HandleAction(1);
89  }
90 
91  //------------------------------------------------------------------------------------------------
92  override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
93  {
94  if (!m_bManualAdjustment)
95  HandleAction(timeSlice);
96  }
97 
98  //------------------------------------------------------------------------------------------------
99  override void OnActionStart(IEntity pUserEntity)
100  {
101  if (m_SoundComponent && m_sActionStartSoundEvent != string.Empty)
102  m_SoundComponent.SoundEvent(m_sActionStartSoundEvent);
103 
104  m_bIsAdjustedByPlayer = SCR_PlayerController.GetLocalControlledEntity() == pUserEntity;
105 
106  if (!m_bIsAdjustedByPlayer)
107  return;
108 
109  m_fTargetValue = Math.InverseLerp(GetMinimumValue(), GetMaximumValue(), GetCurrentValue());
110  if (!GetActionDuration())
111  ToggleActionBypass();
112 
113  if (!m_bManualAdjustment)
114  return;
115 
116  if (!m_sActionIncrease.IsEmpty())
117  GetGame().GetInputManager().AddActionListener(m_sActionIncrease, EActionTrigger.VALUE, HandleAction);
118 
119  if (!m_sActionDecrease.IsEmpty())
120  GetGame().GetInputManager().AddActionListener(m_sActionDecrease, EActionTrigger.VALUE, HandleActionDecrease);
121  }
122 
123  //------------------------------------------------------------------------------------------------
124  override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
125  {
126  // Play sound
127  if (m_SoundComponent && m_sActionCanceledSoundEvent != string.Empty)
128  m_SoundComponent.SoundEvent(m_sActionCanceledSoundEvent);
129 
130  if (!m_bIsAdjustedByPlayer)
131  return;
132 
133  m_bIsAdjustedByPlayer = false;
134 
135  if (!m_bManualAdjustment)
136  return;
137 
138  if (!m_sActionIncrease.IsEmpty())
139  GetGame().GetInputManager().RemoveActionListener(m_sActionIncrease, EActionTrigger.VALUE, HandleAction);
140 
141  if (!m_sActionDecrease.IsEmpty())
142  GetGame().GetInputManager().RemoveActionListener(m_sActionDecrease, EActionTrigger.VALUE, HandleActionDecrease);
143  }
144 
145  //------------------------------------------------------------------------------------------------
148  void HandleAction(float value)
149  {
150  if (value == 0)
151  return;
152 
153  if (m_bManualAdjustment)
154  value /= Math.AbsFloat(value);
155 
156  value *= m_fAdjustmentStep;
157 
158  m_fTargetValue += value;
159  if (m_bLoopAction)
160  {
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();
165  }
166 
167  if (float.AlmostEqual(m_fTargetValue, GetCurrentValue(), Math.AbsFloat(m_fAdjustmentStep)))
168  return;
169 
170  // Round to adjustment step
171  m_fTargetValue = Math.Floor(m_fTargetValue / m_fAdjustmentStep) * m_fAdjustmentStep;
172 
173  // Limit to min/max value
174  m_fTargetValue = Math.Clamp(m_fTargetValue, GetMinimumValue(), GetMaximumValue());
175 
176  if (!float.AlmostEqual(m_fTargetValue, GetCurrentValue()))
177  SetSendActionDataFlag();
178  }
179 
180  //------------------------------------------------------------------------------------------------
183  void HandleActionDecrease(float value)
184  {
185  HandleAction(-value);
186  }
187 
188  //------------------------------------------------------------------------------------------------
190  void PlayMovementAndStopSound(float lerp)
191  {
192  if (!m_SoundComponent)
193  return;
194 
195  if (m_fLerpLast == lerp)
196  return;
197 
198  if (float.AlmostEqual(lerp, 1))
199  {
200  if (!float.AlmostEqual(m_fLerpLast, 1))
201  {
202  m_SoundComponent.Terminate(m_MovementAudioHandle);
203  if (m_sMovementStopSoundEvent != string.Empty)
204  m_SoundComponent.SoundEvent(m_sMovementStopSoundEvent);
205  }
206  }
207  else if (float.AlmostEqual(lerp, 0))
208  {
209  if (!float.AlmostEqual(m_fLerpLast, 0))
210  {
211  m_SoundComponent.Terminate(m_MovementAudioHandle);
212  if (m_sMovementStopSoundEvent != string.Empty)
213  m_SoundComponent.SoundEvent(m_sMovementStopSoundEvent);
214  }
215  }
216  else
217  {
218  if (m_SoundComponent.IsFinishedPlaying(m_MovementAudioHandle) && m_sMovementStopSoundEvent != string.Empty)
219  m_MovementAudioHandle = m_SoundComponent.SoundEvent(m_sMovementSoundEvent);
220  }
221 
222  m_fLerpLast = lerp;
223  }
224 
225  //------------------------------------------------------------------------------------------------
227  override bool HasLocalEffectOnlyScript()
228  {
229  return false;
230  }
231 
232  //------------------------------------------------------------------------------------------------
234  override bool CanBroadcastScript()
235  {
236  return true;
237  }
238 
239  //------------------------------------------------------------------------------------------------
242  override protected bool OnSaveActionData(ScriptBitWriter writer)
243  {
244  float lerp = Math.Lerp(GetMinimumValue(), GetMaximumValue(), m_fTargetValue);
245  writer.WriteFloat01(lerp);
246 
247  SetSignalValue(m_fTargetValue);
248 
249  PlayMovementAndStopSound(lerp);
250 
251  return true;
252  }
253 
254  //------------------------------------------------------------------------------------------------
258  override protected bool OnLoadActionData(ScriptBitReader reader)
259  {
260  if (m_bIsAdjustedByPlayer)
261  return true;
262 
263  float lerp;
264  reader.ReadFloat01(lerp);
265 
266  m_fTargetValue = Math.InverseLerp(GetMinimumValue(), GetMaximumValue(), lerp);
267  SetSignalValue(m_fTargetValue);
268 
269  PlayMovementAndStopSound(lerp);
270 
271  return true;
272  }
273 }
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
SetSignalValue
proto external void SetSignalValue(int index, float value)
Set the signal with an index of.
m_SoundComponent
protected SoundComponent m_SoundComponent
Definition: SCR_RotorDamageManagerComponent.c:9
SCR_AdjustSignalAction
Definition: SCR_AdjustSignalAction.c:1
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
ScriptedSignalUserAction
This action will take care of the synchronization of the signal value.
Definition: ScriptedSignalUserAction.c:13