Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BallisticTableDisplay.c
Go to the documentation of this file.
1class SCR_BallisticTableDisplay : SCR_InfoDisplayExtended
2{
3 [Attribute(desc: "Names of TextWidgets that show the current, next & previous range step.")]
4 protected ref array<string> m_aRangeListWidgetNames;
5
6 [Attribute("0", desc: "0 if first value that will be presented is meant to be the closest range")]
7 protected int m_iBallisticDataOffset;
8
9 [Attribute(desc: "Ballistic table (prototype)")]
10 protected ref array<ref SCR_BaseBallisticConfig> m_aBallisticConfigs;
11
12 [Attribute("TxtShellName")]
14
15
16 [Attribute("AmmoTypeIcon")]
18
19 [Attribute("%1 - %2")]
20 protected string m_sRangeTextFormat;
21
22 [Attribute("0.5", UIWidgets.Slider, "Time in seconds after which the Display should fade in", "0 100 0.1")]
23 protected float m_fFadeInDelay;
24
25 [Attribute("CharacterInspectTurn", desc: "Name of the action that will be used to switch to next shell")]
27
28 [Attribute("CharacterNextFireMode", desc: "Name of the action that will be used to switch number of charge rings")]
30
33 protected ref array<TextWidget> m_aRangeListWidgets = {};
34
36
38 protected float m_fTopElevationThreshold = -1;
39 protected float m_fBottomElevationThreshold = -1;
42
43 protected const string TEXT_EMPTY = "-";
44
45 //------------------------------------------------------------------------------------------------
53
54 //------------------------------------------------------------------------------------------------
56 {
57 return m_aBallisticConfigs.Count();
58 }
59
60 //------------------------------------------------------------------------------------------------
66
67 //------------------------------------------------------------------------------------------------
69 void ChangeShellType(float direction = 0)
70 {
71 if (direction == 0)
72 {
73 UpdateConfig(false);
74 return;
75 }
76
78 if (!currentConfig)
79 return;
80
81 int numberOfConfigs = m_aBallisticConfigs.Count() - 1;
82 int newConfigId = m_iSelectedBallisticConfig + direction;
83 SCR_BaseBallisticConfig replacementConfig;
84 while (newConfigId != m_iSelectedBallisticConfig)
85 {
86 if (newConfigId > numberOfConfigs)
87 newConfigId = 0;
88 else if (newConfigId < 0)
89 newConfigId = numberOfConfigs;
90
91 replacementConfig = m_aBallisticConfigs[newConfigId];
92 if (replacementConfig && replacementConfig.GetProjectilePrefab() != currentConfig.GetProjectilePrefab())
93 break;
94
95 newConfigId += direction;
96 }
97
98 if (newConfigId == m_iSelectedBallisticConfig)
99 return;
100
101 m_iSelectedBallisticConfig = newConfigId;
102 UpdateConfig();
103 }
104
105 //------------------------------------------------------------------------------------------------
108 {
109 if (direction == 0)
110 {
111 UpdateConfig(false);
112 return;
113 }
114
116 if (!currentConfig)
117 return;
118
119 int numberOfConfigs = m_aBallisticConfigs.Count() - 1;
120 int newConfigId = m_iSelectedBallisticConfig + direction;
121 SCR_BaseBallisticConfig replacementConfig;
122 while (newConfigId != m_iSelectedBallisticConfig)
123 {
124 if (newConfigId > numberOfConfigs)
125 newConfigId = 0;
126 else if (newConfigId < 0)
127 newConfigId = numberOfConfigs;
128
129 replacementConfig = m_aBallisticConfigs[newConfigId];
130 if (replacementConfig && replacementConfig.GetProjectilePrefab() == currentConfig.GetProjectilePrefab() && replacementConfig.GetProjectileInitSpeedCoef() != currentConfig.GetProjectileInitSpeedCoef())
131 break;
132
133 newConfigId += direction;
134 }
135
136 if (newConfigId == m_iSelectedBallisticConfig)
137 return;
138
139 m_iSelectedBallisticConfig = newConfigId;
140
142 }
143
144 //------------------------------------------------------------------------------------------------
146 protected void UpdateConfig(bool playSound = true)
147 {
150 UpdateBallisticInfo(GetMuzzleDirection().VectorToAngles());
151 if (m_aBallisticConfigs.IsEmpty())
152 return;
153
155 if (!config)
156 return;
157
160
161 if (m_wAmmoTypeIcon)
162 {
163 if (config.GetAmmoTypeImageSet().IsEmpty() || config.GetAmmoTypeQuadName().IsEmpty())
164 {
165 m_wAmmoTypeIcon.SetVisible(false);
166 }
167 else
168 {
169 m_wAmmoTypeIcon.SetVisible(true);
170 m_wAmmoTypeIcon.LoadImageFromSet(0, config.GetAmmoTypeImageSet(), config.GetAmmoTypeQuadName());
172 }
173 }
174
175 if (playSound)
176 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_FE_ITEM_CHANGE);
177 }
178
179 //------------------------------------------------------------------------------------------------
181 protected array<string> GetBallisticInfo(float elevation)
182 {
184 return null;
185
187 if (!config)
188 return null;
189
190 if (!config.IsGenerated())
191 {
192 if (!config.GenerateBallisticData())
193 {
195 return GetBallisticInfo(elevation);
196 }
197 }
198
199 SCR_BallisticData bd = SCR_BallisticData.s_aBallistics[config.GetBallisticDataId()];
200 if (!bd)
201 return null;
202
203 float angle = SCR_Math.ConvertFromRadians(elevation * Math.DEG2RAD, config.GetUnitType());
204
205 int id;
206 array<float> ballisticValues = bd.GetBallisticValuesForClosestAngle(angle, id, epsilonStep: 2);
207 if (id < 0 || !ballisticValues)
208 return null;
209
210 angle = SCR_Math.ConvertToRadians(ballisticValues[1], config.GetUnitType()) * Math.RAD2DEG;
211 bd.GetValues(id - 1, ballisticValues);
212 if (ballisticValues)
213 {
214 if (config.IsDirectFire())
215 m_fBottomElevationThreshold = SCR_Math.ConvertToRadians(ballisticValues[1], config.GetUnitType()) * Math.RAD2DEG;
216 else
217 m_fTopElevationThreshold = SCR_Math.ConvertToRadians(ballisticValues[1], config.GetUnitType()) * Math.RAD2DEG;
218 }
219
220 bd.GetValues(id + 1, ballisticValues);
221 if (ballisticValues)
222 {
223 if (config.IsDirectFire())
224 m_fTopElevationThreshold = SCR_Math.ConvertToRadians(ballisticValues[1], config.GetUnitType()) * Math.RAD2DEG;
225 else
226 m_fBottomElevationThreshold = SCR_Math.ConvertToRadians(ballisticValues[1], config.GetUnitType()) * Math.RAD2DEG;
227
230 else
232
234 }
235
236 array<string> textArray = {};
237 string rangeText, elevationText;
238 for (int i, count = m_aRangeListWidgets.Count(); i < count; i++)
239 {
240 if (bd.GetValues(id + i + m_iBallisticDataOffset, ballisticValues) < 1)
241 {
242 textArray.Insert(TEXT_EMPTY);
243 continue;
244 }
245
246 if (!ballisticValues)
247 {
248 textArray.Insert(TEXT_EMPTY);
249 continue;
250 }
251
252 rangeText = WidgetManager.Translate(UIConstants.VALUE_UNIT_METERS, ballisticValues[0].ToString(4, 0));
253 switch (config.GetUnitType())
254 {
255 case SCR_EOpticsAngleUnits.DEGREES:
256 elevationText = WidgetManager.Translate(UIConstants.VALUE_UNIT_DEGREES, ballisticValues[1].ToString(4, 0));
257 break;
258
259 default:
260 elevationText = WidgetManager.Translate(UIConstants.VALUE_UNIT_MILS, ballisticValues[1].ToString(4, 0));
261 break;
262 }
263
264 textArray.Insert(string.Format(m_sRangeTextFormat, rangeText, elevationText));
265 }
266
267 return textArray;
268 }
269 //------------------------------------------------------------------------------------------------
270 protected void UpdateBallisticInfo(vector aimRotation, bool forceRefresh = false)
271 {
272 if (m_aRangeListWidgets.IsEmpty())
273 return;
274
275 if (!forceRefresh && m_fBottomElevationThreshold > -1 && m_fTopElevationThreshold > -1 && aimRotation[1] < m_fTopElevationThreshold && aimRotation[1] > m_fBottomElevationThreshold)
276 return;
277
278 array<string> balisticInfo = GetBallisticInfo(aimRotation[1]);
279 if (!balisticInfo || balisticInfo.IsEmpty())
280 {
281 super.Show(false, 0);
282 return;
283 }
284
285 int balisticInfoCount = balisticInfo.Count() - 1;
286 foreach (int i, TextWidget widget : m_aRangeListWidgets)
287 {
288 if (!widget)
289 break;
290
291 if (i > balisticInfoCount)
292 {
293 widget.SetVisible(false);
294 continue;
295 }
296
297 widget.SetText(balisticInfo[i]);
298 widget.SetVisible(true);
299 }
300 }
301
302 //------------------------------------------------------------------------------------------------
305 {
306 BaseWeaponManagerComponent weaponManager = m_TurretController.GetWeaponManager();
307 if (!weaponManager)
308 return vector.Zero;
309
310 vector transform[4];
311 weaponManager.GetCurrentMuzzleTransform(transform);
312 return transform[2];
313 }
314
315 //------------------------------------------------------------------------------------------------
316 protected void SetupWidgets()
317 {
318 TextWidget widget;
319
320 foreach (string widgetName : m_aRangeListWidgetNames)
321 {
322 widget = TextWidget.Cast(m_wRoot.FindAnyWidget(widgetName));
323
324 if (widget)
325 m_aRangeListWidgets.Insert(widget);
326 }
327
330 }
331
332 //------------------------------------------------------------------------------------------------
336 protected void ShowDelay(bool show, float speed = UIConstants.FADE_RATE_INSTANT)
337 {
338 super.Show(show, speed);
339 }
340
341 //------------------------------------------------------------------------------------------------
342 override void Show(bool show, float speed = UIConstants.FADE_RATE_INSTANT, EAnimationCurve curve = EAnimationCurve.LINEAR)
343 {
344 if (m_AdditionalGameSettings && !m_AdditionalGameSettings.GetProjectileBallisticInfoVisibility())
345 {
347 super.Show(false);
348 return;
349 }
350
351 speed = UIConstants.FADE_RATE_DEFAULT;
352
353 // If it can be shown, do so after a delay to prevent it from fading in to early
354 if (m_bCanShow)
355 {
357 GetGame().GetCallqueue().CallLater(ShowDelay, m_fFadeInDelay * 1000, false, show, speed);
358 }
359 else
360 {
362 super.Show(show, speed);
363 }
364 }
365
366 //------------------------------------------------------------------------------------------------
367 override void DisplayUpdate(IEntity owner, float timeSlice)
368 {
369 UpdateBallisticInfo(GetMuzzleDirection().VectorToAngles());
370 }
371
372 //------------------------------------------------------------------------------------------------
373 protected override void OnSettingsChanged()
374 {
376 Show(m_AdditionalGameSettings.GetProjectileBallisticInfoVisibility());
377
378 super.OnSettingsChanged();
379 }
380
381 //------------------------------------------------------------------------------------------------
382 override void DisplayStopDraw(IEntity owner)
383 {
384 m_aRangeListWidgets.Clear();
385
387 m_AdditionalGameSettings.GetOnChangeAdditionalSettingsInvoker().Remove(OnSettingsChanged);
388
389 if (m_aBallisticConfigs.IsEmpty())
390 return;
391
394 }
395
396 //------------------------------------------------------------------------------------------------
397 protected void AddActionListeners()
398 {
399 InputManager inputMgr = GetGame().GetInputManager();
400 if (!inputMgr)
401 return;
402
403 inputMgr.AddActionListener(m_sChangeShellTypeActionName, EActionTrigger.DOWN, ChangeShellType);
404
406 inputMgr.AddActionListener(m_sChangeShellChargeActionName, EActionTrigger.DOWN, ChangeShellCharge);
407 }
408
409 //------------------------------------------------------------------------------------------------
410 protected void RemoveActionListeners()
411 {
412 InputManager inputMgr = GetGame().GetInputManager();
413 if (!inputMgr)
414 return;
415
416 inputMgr.RemoveActionListener(m_sChangeShellTypeActionName, EActionTrigger.DOWN, ChangeShellType);
417
419 inputMgr.RemoveActionListener(m_sChangeShellChargeActionName, EActionTrigger.DOWN, ChangeShellCharge);
420 }
421
422 //------------------------------------------------------------------------------------------------
423 override void DisplayStartDraw(IEntity owner)
424 {
426
429
432
433 m_AdditionalGameSettings.GetOnChangeAdditionalSettingsInvoker().Insert(OnSettingsChanged);
434
435 SetupWidgets();
437 if (m_aBallisticConfigs.IsEmpty())
438 return;
439
441 {
442 foreach (SCR_BaseBallisticConfig secondConfig : m_aBallisticConfigs)
443 {
444 if (config.GetProjectileInitSpeedCoef() == secondConfig.GetProjectileInitSpeedCoef())
445 continue;
446
447 if (config.GetProjectilePrefab() != secondConfig.GetProjectilePrefab())
448 continue;
449
451 break;
452 }
453
455 break;
456 }
457
459 }
460
461 //------------------------------------------------------------------------------------------------
465 {
466 if (SCR_SettingsSuperMenu.Cast(menu))
467 UpdateBallisticInfo(GetMuzzleDirection().VectorToAngles(), true);
468 }
469}
AddonBuildInfoTool id
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_AdditionalGameModeSettingsComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
vector direction
SCR_EOpticsAngleUnits
Widget m_wRoot
bool m_bCanShow
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
EAnimationCurve
Constant variables used in various menus.
proto external Managed FindComponent(typename typeName)
Input management system for user interactions.
Definition Math.c:13
array< float > GetBallisticValuesForClosestAngle(float angle, out int id=-1, float epsilon=0.1, float epsilonStep=2, float maxEpsilon=1000)
int GetValues(int id, out array< float > values)
void ShowDelay(bool show, float speed=UIConstants.FADE_RATE_INSTANT)
void ChangeShellType(float direction=0)
Method used to change what ballistic data is shown.
array< string > GetBallisticInfo(float elevation)
Set azimuth and elevation info.
override void DisplayStopDraw(IEntity owner)
ref array< TextWidget > m_aRangeListWidgets
void OnSettingsMenuClosed(ChimeraMenuBase menu)
ref array< ref SCR_BaseBallisticConfig > m_aBallisticConfigs
void ChangeShellCharge(float direction=0)
Method used to change what charge ring config is shown for current shell type.
vector GetMuzzleDirection()
Get muzzle rotation vector.
override void Show(bool show, float speed=UIConstants.FADE_RATE_INSTANT, EAnimationCurve curve=EAnimationCurve.LINEAR)
SCR_BaseBallisticConfig GetSelectedBallisticConfig()
override void DisplayStartDraw(IEntity owner)
override void DisplayUpdate(IEntity owner, float timeSlice)
bool GetHasDifferentChargeConfigs()
Returns true when this display has at least two configs for the same shell with different init speeds...
TurretControllerComponent m_TurretController
ref array< string > m_aRangeListWidgetNames
void UpdateConfig(bool playSound=true)
Method used to update currently displayed ballistic config.
void UpdateBallisticInfo(vector aimRotation, bool forceRefresh=false)
SCR_AdditionalGameModeSettingsComponent m_AdditionalGameSettings
SCR_EOpticsAngleUnits GetUnitType()
static float ConvertFromRadians(float radianAngleFrom, SCR_EOpticsAngleUnits toUnitType)
Definition SCR_Math.c:290
static float ConvertToRadians(float angleFrom, SCR_EOpticsAngleUnits fromUnitType)
Definition SCR_Math.c:323
static ScriptInvokerMenu GetOnMenuClose()
override void Show()
Definition gameLib.c:262
SCR_FieldOfViewSettings Attribute
EActionTrigger