Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_GearShiftInfo.c
Go to the documentation of this file.
1 // Will print every change to gear shift; CLI -scrDefine DEBUG_GEARSHIFT
2 //#define DEBUG_GEARSHIFT
3 
5 {
6  protected CarControllerComponent m_pCarController;
7  protected CarControllerComponent_SA m_pCarController_SA;
8 
9  protected SCR_InfoDisplayExtended m_pParentDisplayExtended;
10 
11  // Widgets
12  ref SCR_VehicleGearShiftWidgets m_Widgets;
13 
14  protected int m_iFutureGear;
15  protected int m_iCurrentGear;
16  protected EVehicleDrivingAssistanceMode m_eDrivingAssistance;
17  protected bool m_bAutomaticGearbox;
18 
19  //------------------------------------------------------------------------------------------------
21  string GetGearSymbol(bool automatic, int gear, int gearCount)
22  {
23  if (gear < EVehicleGearboxGear.REVERSE)
24  return " ";
25  else if (gear >= gearCount)
26  return " ";
27  else if (gear == EVehicleGearboxGear.REVERSE)
28  return "R";
29  else if (gear == EVehicleGearboxGear.NEUTRAL)
30  return "N";
31  else if (automatic)
32  return "D";
33  else
34  return (gear-1).ToString();
35  }
36 
37  //------------------------------------------------------------------------------------------------
39  void GetGearboxModeDisplay(bool automatic, int futureGear, int currentGear)
40  {
41  int gearCount = 0;
43  {
44  VehicleWheeledSimulation simulation = m_pCarController.GetSimulation();
45  if (simulation)
46  gearCount = simulation.GearboxGearsCount();
47  }
48  else
49  {
50  VehicleWheeledSimulation_SA simulation = m_pCarController_SA.GetSimulation();
51  if (simulation)
52  gearCount = simulation.GearboxGearsCount();
53  }
54 
55  if (automatic)
56  {
57  futureGear = EVehicleGearboxGear.NEUTRAL;
58  currentGear = Math.ClampInt(currentGear, EVehicleGearboxGear.REVERSE, EVehicleGearboxGear.FORWARD);
59  }
60  else
61  {
62  futureGear = Math.ClampInt(futureGear, EVehicleGearboxGear.REVERSE, gearCount);
63  }
64 
65  int lowerGear = Math.ClampInt(futureGear - 1, EVehicleGearboxGear.REVERSE, gearCount);
66  int middleGear = lowerGear + 1;
67  int upperGear = middleGear + 1;
68 
69  string lower = GetGearSymbol(automatic, lowerGear, gearCount);
70  string future = GetGearSymbol(automatic, middleGear, gearCount);
71  string upper = GetGearSymbol(automatic, upperGear, gearCount);
72 
73  m_Widgets.m_LowerSelectedText.SetText(lower);
74  m_Widgets.m_LowerText.SetText(lower);
75  m_Widgets.m_MiddleSelectedText.SetText(future);
76  m_Widgets.m_MiddleText.SetText(future);
77  m_Widgets.m_UpperSelectedText.SetText(upper);
78  m_Widgets.m_UpperText.SetText(upper);
79 
80  m_Widgets.m_LowerSelected.SetVisible(currentGear == lowerGear);
81  m_Widgets.m_Lower.SetVisible(currentGear != lowerGear);
82  m_Widgets.m_MiddleSelected.SetVisible(currentGear == middleGear);
83  m_Widgets.m_Middle.SetVisible(currentGear != middleGear);
84  m_Widgets.m_UpperSelected.SetVisible(currentGear == upperGear);
85  m_Widgets.m_Upper.SetVisible(currentGear != upperGear);
86 
87  #ifdef DEBUG_GEARSHIFT
88  string spacer1 = " ";
89  string spacer2 = " ";
90  string spacer3 = " ";
91  string spacer4 = " ";
92 
93  if (currentGear == lowerGear)
94  {
95  spacer1 = "[";
96  spacer2 = "]";
97  }
98  else if (currentGear == middleGear)
99  {
100  spacer2 = "[";
101  spacer3 = "]";
102  }
103  else if (currentGear == upperGear)
104  {
105  spacer3 = "[";
106  spacer4 = "]";
107  }
108 
109  PrintFormat("%1%2%3%4%5%6%7", spacer1, lower, spacer2, future, spacer3, upper, spacer4);
110  #endif
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  private void ScalePaddings(Widget widget, float scale)
115  {
116  if (!widget)
117  return;
118 
119  Widget parent = widget.GetParent();
120 
121  if (!(OverlayWidget.Cast(parent) || HorizontalLayoutWidget.Cast(parent) || VerticalLayoutWidget.Cast(parent)))
122  return;
123 
124  float left;
125  float top;
126  float right;
127  float bottom;
128 
129  AlignableSlot.GetPadding(widget, left, top, right, bottom);
130  AlignableSlot.SetPadding(widget, left * scale, top * scale, right * scale, bottom * scale);
131  }
132 
133  //------------------------------------------------------------------------------------------------
134  override void Scale(TextWidget widget, float scale)
135  {
136  if (!widget)
137  return;
138 
139  float width;
140  float height;
141 
142  widget.GetTextSize(width, height);
143 
144  height = Math.Round(height * scale);
145  int size = height;
146 
147  widget.SetExactFontSize(size);
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  private void ScaleChildren(Widget widget)
152  {
153  Widget child = widget.GetChildren();
154 
155  while (child)
156  {
157  ScaleChildren(child);
158 
159  ScalePaddings(child, m_fWidgetScale);
160 
161  TextWidget text = TextWidget.Cast(child);
162  ImageWidget image = ImageWidget.Cast(child);
163 
164  if (text)
165  Scale(text, m_fWidgetScale);
166 
167  if (image)
168  Scale(image, m_fWidgetScale);
169 
170  child = child.GetSibling();
171  }
172  }
173 
174  //------------------------------------------------------------------------------------------------
176  override event void DisplayUpdate(IEntity owner, float timeSlice)
177  {
178  if (!m_wRoot)
179  return;
180 
182  {
183  if (!m_pCarController)
184  return;
185 
186  EVehicleDrivingAssistanceMode drivingAssistance = CarControllerComponent.GetDrivingAssistanceMode();
187 
188  bool assistanceChanged = m_eDrivingAssistance != drivingAssistance;
189 
190  if (assistanceChanged)
191  {
192  #ifdef DEBUG_GEARSHIFT
193  PrintFormat("Gear assistance changed from %1 -> %2", m_eDrivingAssistance, drivingAssistance);
194  #endif
195 
196  m_eDrivingAssistance = drivingAssistance;
197 
198  bool show = drivingAssistance != EVehicleDrivingAssistanceMode.FULL;
199 
200  Show(show);
201 
202  if (m_pParentDisplayExtended)
203  m_pParentDisplayExtended.Show(show);
204 
205  if (!show)
206  return;
207  }
208 
209  bool automatic = drivingAssistance == EVehicleDrivingAssistanceMode.PARTIAL || m_pCarController.HasAutomaticGearbox();
210 
211  bool automaticChanged = m_bAutomaticGearbox != automatic;
212 
213  if (automaticChanged)
214  {
215  #ifdef DEBUG_GEARSHIFT
216  PrintFormat("Gearbox manual vs. automatic changed! automatic: %1", automaticChanged);
217  #endif
218 
219  m_bAutomaticGearbox = automatic;
220  }
221 
222  int futureGear = m_pCarController.GetFutureGear();
223  int currentGear = m_pCarController.GetCurrentGear();
224 
225  // Prevent unneeded execution and UI updates, if gears didn't change
226  if (!assistanceChanged && futureGear == m_iFutureGear && currentGear == m_iCurrentGear)
227  return;
228 
229  m_iFutureGear = futureGear;
230  m_iCurrentGear = currentGear;
231 
232  GetGearboxModeDisplay(automatic, futureGear, currentGear);
233  }
234  else
235  {
236  if (!m_pCarController_SA)
237  return;
238 
239  EVehicleDrivingAssistanceMode drivingAssistance = CarControllerComponent_SA.GetDrivingAssistanceMode();
240 
241  bool assistanceChanged = m_eDrivingAssistance != drivingAssistance;
242 
243  if (assistanceChanged)
244  {
245  #ifdef DEBUG_GEARSHIFT
246  PrintFormat("Gear assistance changed from %1 -> %2", m_eDrivingAssistance, drivingAssistance);
247  #endif
248 
249  m_eDrivingAssistance = drivingAssistance;
250 
251  bool show = drivingAssistance != EVehicleDrivingAssistanceMode.FULL;
252 
253  Show(show);
254 
255  if (m_pParentDisplayExtended)
256  m_pParentDisplayExtended.Show(show);
257 
258  if (!show)
259  return;
260  }
261 
262  bool automatic = drivingAssistance == EVehicleDrivingAssistanceMode.PARTIAL || m_pCarController_SA.HasAutomaticGearbox();
263 
264  bool automaticChanged = m_bAutomaticGearbox != automatic;
265 
266  if (automaticChanged)
267  {
268  #ifdef DEBUG_GEARSHIFT
269  PrintFormat("Gearbox manual vs. automatic changed! automatic: %1", automaticChanged);
270  #endif
271 
272  m_bAutomaticGearbox = automatic;
273  }
274 
275  int futureGear = m_pCarController_SA.GetFutureGear();
276  int currentGear = m_pCarController_SA.GetCurrentGear();
277 
278  // Prevent unneeded execution and UI updates, if gears didn't change
279  if (!assistanceChanged && futureGear == m_iFutureGear && currentGear == m_iCurrentGear)
280  return;
281 
282  m_iFutureGear = futureGear;
283  m_iCurrentGear = currentGear;
284 
285  GetGearboxModeDisplay(automatic, futureGear, currentGear);
286  }
287 
288  }
289 
290  //------------------------------------------------------------------------------------------------
291  override bool DisplayStartDrawInit(IEntity owner)
292  {
293  // Terminate if widget already exists
294  if (m_wRoot)
295  return false;
296 
297  // Should probably kill the display if there is no controller
299  {
300  if (!m_pCarController)
301  return false;
302  }
303  else
304  {
305  if (!m_pCarController_SA)
306  return false;
307  }
308 
309  // Fallback to avoid the need to fill-in always the same layout filename
310  if (m_LayoutPath == "")
311  m_LayoutPath = "{5FBB1623E3CD1DF2}UI/layouts/HUD/VehicleInfo/VehicleGearShift.layout";
312 
313  if (m_pParentDisplay)
314  m_pParentDisplayExtended = SCR_InfoDisplayExtended.Cast(m_pParentDisplay);
315 
316  return true;
317  }
318 
319  //------------------------------------------------------------------------------------------------
321  override void DisplayStartDraw(IEntity owner)
322  {
323  if (!m_wRoot)
324  return;
325 
327  m_Widgets.Init(m_wRoot);
328 
329  ScaleChildren(m_wRoot);
330 
331  m_iFutureGear = -1;
332  m_iCurrentGear = -1;
333  m_eDrivingAssistance = -1;
334  m_bAutomaticGearbox = false;
335  }
336 
337  //------------------------------------------------------------------------------------------------
339  override void DisplayInit(IEntity owner)
340  {
341  if (m_wRoot)
342  m_wRoot.RemoveFromHierarchy();
343 
345  m_pCarController = CarControllerComponent.Cast(owner.FindComponent(CarControllerComponent));
346  else
347  m_pCarController_SA = CarControllerComponent_SA.Cast(owner.FindComponent(CarControllerComponent_SA));
348 
349  }
350 };
EVehicleGearboxGear
EVehicleGearboxGear
Definition: SCR_VehicleGearCondition.c:1
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_BaseVehicleInfo
Base class for all vehicle UI state and damage indicators.
Definition: SCR_BaseVehicleInfo.c:28
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Widgets
ref SCR_VoNOverlay_ElementWidgets m_Widgets
Definition: SCR_VonDisplay.c:3
Show
override void Show(WorkspaceWidget pWorkspace, Widget pToolTipWidget, float desiredPosX, float desiredPosY)
Definition: SCR_ScriptedWidgetTooltip.c:55
SCR_VehicleGearShiftWidgets
Definition: SCR_VehicleGearShiftWidgets.c:4
GetIsClientAuthority
override bool GetIsClientAuthority()
Definition: game.c:268
EVehicleDrivingAssistanceMode
EVehicleDrivingAssistanceMode
Player vehicle driving assistance modes. Individual features may become separate options in future.
Definition: EVehicleDrivingAssistanceMode.c:13
SCR_GearShiftInfo
Definition: SCR_GearShiftInfo.c:4
m_pParentDisplay
protected SCR_InfoDisplay m_pParentDisplay
Definition: SCR_InfoDisplay.c:70