Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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{
7
8 protected SCR_InfoDisplayExtended m_pParentDisplayExtended;
9
10 // Widgets
12
13 protected int m_iFutureGear;
14 protected int m_iCurrentGear;
16 protected bool m_bAutomaticGearbox;
17
18 //------------------------------------------------------------------------------------------------
20 string GetGearSymbol(bool automatic, int gear, int gearCount)
21 {
22 if (gear < EVehicleGearboxGear.REVERSE)
23 return " ";
24 else if (gear >= gearCount)
25 return " ";
26 else if (gear == EVehicleGearboxGear.REVERSE)
27 return "R";
28 else if (gear == EVehicleGearboxGear.NEUTRAL)
29 return "N";
30 else if (automatic)
31 return "D";
32 else
33 return (gear-1).ToString();
34 }
35
36 //------------------------------------------------------------------------------------------------
38 void GetGearboxModeDisplay(bool automatic, int futureGear, int currentGear)
39 {
40 int gearCount = 0;
41
42 VehicleWheeledSimulation simulation = m_pCarController.GetSimulation();
43 if (simulation)
44 gearCount = simulation.GearboxGearsCount();
45
46 if (automatic)
47 {
48 futureGear = EVehicleGearboxGear.NEUTRAL;
49 currentGear = Math.ClampInt(currentGear, EVehicleGearboxGear.REVERSE, EVehicleGearboxGear.FORWARD);
50 }
51 else
52 {
53 futureGear = Math.ClampInt(futureGear, EVehicleGearboxGear.REVERSE, gearCount);
54 }
55
56 int lowerGear = Math.ClampInt(futureGear - 1, EVehicleGearboxGear.REVERSE, gearCount);
57 int middleGear = lowerGear + 1;
58 int upperGear = middleGear + 1;
59
60 string lower = GetGearSymbol(automatic, lowerGear, gearCount);
61 string future = GetGearSymbol(automatic, middleGear, gearCount);
62 string upper = GetGearSymbol(automatic, upperGear, gearCount);
63
64 m_Widgets.m_LowerSelectedText.SetText(lower);
65 m_Widgets.m_LowerText.SetText(lower);
66 m_Widgets.m_MiddleSelectedText.SetText(future);
67 m_Widgets.m_MiddleText.SetText(future);
68 m_Widgets.m_UpperSelectedText.SetText(upper);
69 m_Widgets.m_UpperText.SetText(upper);
70
71 m_Widgets.m_LowerSelected.SetVisible(currentGear == lowerGear);
72 m_Widgets.m_Lower.SetVisible(currentGear != lowerGear);
73 m_Widgets.m_MiddleSelected.SetVisible(currentGear == middleGear);
74 m_Widgets.m_Middle.SetVisible(currentGear != middleGear);
75 m_Widgets.m_UpperSelected.SetVisible(currentGear == upperGear);
76 m_Widgets.m_Upper.SetVisible(currentGear != upperGear);
77
78 #ifdef DEBUG_GEARSHIFT
79 string spacer1 = " ";
80 string spacer2 = " ";
81 string spacer3 = " ";
82 string spacer4 = " ";
83
84 if (currentGear == lowerGear)
85 {
86 spacer1 = "[";
87 spacer2 = "]";
88 }
89 else if (currentGear == middleGear)
90 {
91 spacer2 = "[";
92 spacer3 = "]";
93 }
94 else if (currentGear == upperGear)
95 {
96 spacer3 = "[";
97 spacer4 = "]";
98 }
99
100 PrintFormat("%1%2%3%4%5%6%7", spacer1, lower, spacer2, future, spacer3, upper, spacer4);
101 #endif
102 }
103
104 //------------------------------------------------------------------------------------------------
105 private void ScalePaddings(Widget widget, float scale)
106 {
107 if (!widget)
108 return;
109
110 Widget parent = widget.GetParent();
111
112 if (!(OverlayWidget.Cast(parent) || HorizontalLayoutWidget.Cast(parent) || VerticalLayoutWidget.Cast(parent)))
113 return;
114
115 float left;
116 float top;
117 float right;
118 float bottom;
119
120 AlignableSlot.GetPadding(widget, left, top, right, bottom);
121 AlignableSlot.SetPadding(widget, left * scale, top * scale, right * scale, bottom * scale);
122 }
123
124 //------------------------------------------------------------------------------------------------
125 override void Scale(TextWidget widget, float scale)
126 {
127 if (!widget)
128 return;
129
130 float width;
131 float height;
132
133 widget.GetTextSize(width, height);
134
135 height = Math.Round(height * scale);
136 int size = height;
137
138 widget.SetExactFontSize(size);
139 }
140
141 //------------------------------------------------------------------------------------------------
142 private void ScaleChildren(Widget widget)
143 {
144 Widget child = widget.GetChildren();
145
146 while (child)
147 {
148 ScaleChildren(child);
149
150 ScalePaddings(child, m_fWidgetScale);
151
152 TextWidget text = TextWidget.Cast(child);
153 ImageWidget image = ImageWidget.Cast(child);
154
155 if (text)
156 Scale(text, m_fWidgetScale);
157
158 if (image)
159 Scale(image, m_fWidgetScale);
160
161 child = child.GetSibling();
162 }
163 }
164
165 //------------------------------------------------------------------------------------------------
167 override event void DisplayUpdate(IEntity owner, float timeSlice)
168 {
169 if (!m_wRoot)
170 return;
171
172 if (!m_pCarController)
173 return;
174
175 EVehicleDrivingAssistanceMode drivingAssistance = CarControllerComponent.GetDrivingAssistanceMode();
176
177 bool assistanceChanged = m_eDrivingAssistance != drivingAssistance;
178
179 if (assistanceChanged)
180 {
181 #ifdef DEBUG_GEARSHIFT
182 PrintFormat("Gear assistance changed from %1 -> %2", m_eDrivingAssistance, drivingAssistance);
183 #endif
184
185 m_eDrivingAssistance = drivingAssistance;
186
187 bool show = drivingAssistance != EVehicleDrivingAssistanceMode.FULL;
188
189 Show(show);
190
192 m_pParentDisplayExtended.Show(show);
193
194 if (!show)
195 return;
196 }
197
198 bool automatic = drivingAssistance == EVehicleDrivingAssistanceMode.PARTIAL || m_pCarController.HasAutomaticGearbox();
199
200 bool automaticChanged = m_bAutomaticGearbox != automatic;
201
202 if (automaticChanged)
203 {
204 #ifdef DEBUG_GEARSHIFT
205 PrintFormat("Gearbox manual vs. automatic changed! automatic: %1", automaticChanged);
206 #endif
207
208 m_bAutomaticGearbox = automatic;
209 }
210
211 int futureGear = m_pCarController.GetFutureGear();
212 int currentGear = m_pCarController.GetCurrentGear();
213
214 // Prevent unneeded execution and UI updates, if gears didn't change
215 if (!assistanceChanged && futureGear == m_iFutureGear && currentGear == m_iCurrentGear)
216 return;
217
218 m_iFutureGear = futureGear;
219 m_iCurrentGear = currentGear;
220
221 GetGearboxModeDisplay(automatic, futureGear, currentGear);
222 }
223
224 //------------------------------------------------------------------------------------------------
225 override bool DisplayStartDrawInit(IEntity owner)
226 {
227 // Terminate if widget already exists
228 if (m_wRoot)
229 return false;
230
231 // Should probably kill the display if there is no controller
232 if (!m_pCarController)
233 return false;
234
235 // Fallback to avoid the need to fill-in always the same layout filename
236 if (m_LayoutPath == "")
237 m_LayoutPath = "{5FBB1623E3CD1DF2}UI/layouts/HUD/VehicleInfo/VehicleGearShift.layout";
238
240 m_pParentDisplayExtended = SCR_InfoDisplayExtended.Cast(m_pParentDisplay);
241
242 return true;
243 }
244
245 //------------------------------------------------------------------------------------------------
247 override void DisplayStartDraw(IEntity owner)
248 {
249 if (!m_wRoot)
250 return;
251
252 m_Widgets = new SCR_VehicleGearShiftWidgets();
253 m_Widgets.Init(m_wRoot);
254
255 ScaleChildren(m_wRoot);
256
257 m_iFutureGear = -1;
258 m_iCurrentGear = -1;
260 m_bAutomaticGearbox = false;
261 }
262
263 //------------------------------------------------------------------------------------------------
265 override void DisplayInit(IEntity owner)
266 {
267 if (m_wRoot)
268 m_wRoot.RemoveFromHierarchy();
269
270 m_pCarController = CarControllerComponent.Cast(owner.FindComponent(CarControllerComponent));
271 }
272};
vector scale
int size
Widget m_wRoot
SCR_InfoDisplay m_pParentDisplay
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
Base class for all vehicle UI state and damage indicators.
ref SCR_VehicleGearShiftWidgets m_Widgets
string GetGearSymbol(bool automatic, int gear, int gearCount)
Present proper symbol for selected gear.
EVehicleDrivingAssistanceMode m_eDrivingAssistance
SCR_InfoDisplayExtended m_pParentDisplayExtended
CarControllerComponent m_pCarController
void GetGearboxModeDisplay(bool automatic, int futureGear, int currentGear)
Construct the string to be displayed in the window.
float Scale
Definition gameLib.c:128
override void Show()
Definition gameLib.c:262
EVehicleDrivingAssistanceMode
Player vehicle driving assistance modes. Individual features may become separate options in future.
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)