4 float m_fRingLabelOffset = 0.8;
5 int m_fRingLabelFontSize = 20;
6 ResourceName m_AnalogGauge =
"{54F7755D48B394FD}UI/Textures/VehicleInfo/AnalogGaugeImageset.imageset";
7 string m_sRingMarkSection =
"GaugeMarkSection";
8 string m_sRingMarkSubsection =
"GaugeMarkSubsection";
9 string m_sDefaultLayout =
"{00F28F3165DB7C83}UI/layouts/HUD/VehicleInfo/VehicleGauge_Default.layout";
12 string m_sOverlay =
"";
13 string m_sCustomNeedle =
"";
19 [
Attribute(
"270", UIWidgets.Slider,
"Gauge angular range (in degrees)",
"30 360 5")]
20 protected float m_fWidgetRange;
22 [
Attribute(
"0", UIWidgets.Slider,
"Gauge angular rotation (in degrees)",
"0 360 5")]
23 protected float m_fWidgetRotation;
25 [
Attribute(
"0.6", UIWidgets.Slider,
"Gauge global scale",
"0.25 2 0.05")]
26 protected float m_fWidgetScale;
30 [
Attribute(
"", UIWidgets.EditBox,
"Custom text (e.g. units or gauge name). Hidden if empty.")]
31 protected string m_sInfoText;
33 [
Attribute(
"0.5", UIWidgets.Slider,
"Units text anchor X-coordinate %-base of widget width.",
"0 1 0.05")]
34 protected float m_fInfoPosX;
36 [
Attribute(
"0.15", UIWidgets.Slider,
"Units text anchor Y-coordinate %-base of widget height.",
"0 1 0.05")]
37 protected float m_fInfoPosY;
39 [
Attribute(
"", UIWidgets.EditBox,
"Custom text (e.g. units or gauge name). Hidden if empty.")]
40 protected string m_sInfo2Text;
42 [
Attribute(
"0.5", UIWidgets.Slider,
"Units text anchor X-coordinate %-base of widget width.",
"0 1 0.05")]
43 protected float m_fInfo2PosX;
45 [
Attribute(
"0.85", UIWidgets.Slider,
"Units text anchor Y-coordinate %-base of widget height.",
"0 1 0.05")]
46 protected float m_fInfo2PosY;
49 [
Attribute(
"1", UIWidgets.SpinBox,
"Label value multiplier.")]
50 protected float m_fLabelValueMultiplier;
52 [
Attribute(
"0", UIWidgets.SpinBox,
"Label value precision.",
"-6 6 1")]
53 protected int m_iLabelValuePrecision;
55 [
Attribute(
"1", UIWidgets.CheckBox,
"Display absolute values on labels.")]
56 protected bool m_bAbsLabelValues;
58 [
Attribute(
"1", UIWidgets.CheckBox,
"Display label for ZERO value.")]
59 protected bool m_bShowLabel0;
61 [
Attribute(
"1", UIWidgets.CheckBox,
"Display label for MAX value.")]
62 protected bool m_bShowLabelMax;
64 [
Attribute(
"1", UIWidgets.CheckBox,
"Display label for MIN value; both MIN && ZERO needs to be checked.")]
65 protected bool m_bShowLabelMin;
70 protected TextWidget m_wInfo;
71 protected TextWidget m_wInfo2;
72 protected Widget m_wInfoAnchor;
73 protected Widget m_wInfo2Anchor;
75 protected ImageWidget m_wRing;
76 protected ImageWidget m_wBackground;
77 protected ImageWidget m_wNeedle;
78 protected ImageWidget m_wNeedleShadow;
79 protected ImageWidget m_wOverlay;
81 protected float m_fGaugeSizeX;
82 protected float m_fGaugeSizeY;
84 protected Widget m_wRingMarks;
85 protected Widget m_wRingLabels;
87 protected float m_fZeroValueRotation;
91 protected float GetValue()
98 protected float GetValuePerc(
float value)
112 protected void InitGauge(IEntity owner, out
bool bSuccess)
117 protected void CreateGauge(IEntity owner, out
bool bSuccess)
120 bSuccess = CreateGaugeRing(owner);
126 m_wNeedle = ImageWidget.Cast(
m_wRoot.FindAnyWidget(
"Needle"));
127 m_wNeedleShadow = ImageWidget.Cast(
m_wRoot.FindAnyWidget(
"NeedleShadow"));
128 bSuccess = CreateGaugeNeedle(owner, m_wNeedle, m_wNeedleShadow, m_pGaugeData.m_sCustomNeedle);
135 bSuccess = CreateGaugeOverlay(owner,
m_wOverlay, m_pGaugeData.m_sOverlay);
141 m_wInfo = TextWidget.Cast(
m_wRoot.FindAnyWidget(
"InfoText"));
142 m_wInfoAnchor =
m_wRoot.FindAnyWidget(
"InfoAnchor");
143 CreateGaugeInfoText(owner, m_wInfo, m_sInfoText, m_wInfoAnchor, m_fInfoPosX, m_fInfoPosY);
146 m_wInfo2 = TextWidget.Cast(
m_wRoot.FindAnyWidget(
"Info2Text"));
147 m_wInfo2Anchor =
m_wRoot.FindAnyWidget(
"Info2Anchor");
148 CreateGaugeInfoText(owner, m_wInfo2, m_sInfo2Text, m_wInfo2Anchor, m_fInfo2PosX, m_fInfo2PosY);
153 protected bool CreateGaugeRing(IEntity owner)
155 m_fZeroValueRotation = m_fWidgetRotation + (360 - m_fWidgetRange) / 2;
157 m_wRing = ImageWidget.Cast(
m_wRoot.FindAnyWidget(
"Ring"));
159 m_wRingMarks =
m_wRoot.FindAnyWidget(
"RingMarks");
160 m_wRingLabels =
m_wRoot.FindAnyWidget(
"RingLabels");
166 m_wRing.SetMaskProgress(m_fWidgetRange/360);
167 m_wRing.SetRotation(m_fZeroValueRotation);
168 Scale(m_wRing, m_fWidgetScale);
174 vector size = m_wRing.GetSize();
175 m_fGaugeSizeX = size[0];
176 m_fGaugeSizeY = size[1];
186 protected bool CreateGaugeNeedle(IEntity owner, ImageWidget wNeedle, ImageWidget wNeedleShadow,
string sCustomNeedle =
"",
bool bVisible =
true)
188 if (!wNeedle || !wNeedleShadow)
193 wNeedle.LoadImageFromSet(0, m_pGaugeData.m_AnalogGauge, sCustomNeedle);
194 wNeedleShadow.LoadImageFromSet(0, m_pGaugeData.m_AnalogGauge, sCustomNeedle);
196 Scale(wNeedle, m_fWidgetScale);
197 Scale(wNeedleShadow, m_fWidgetScale);
199 wNeedle.SetVisible(bVisible);
200 wNeedleShadow.SetVisible(bVisible);
206 protected bool CreateGaugeOverlay(IEntity owner, ImageWidget wOverlay,
string sOverlayTexture,
bool bVisible =
true)
211 if (sOverlayTexture ==
"")
213 wOverlay.SetVisible(
false);
217 wOverlay.LoadImageFromSet(0, m_pGaugeData.m_AnalogGauge, sOverlayTexture);
218 wOverlay.SetVisible(bVisible);
219 Scale(wOverlay, m_fWidgetScale);
225 protected bool CreateGaugeInfoText(IEntity owner, TextWidget wInfo,
string sText, Widget wAnchor,
float fPosX,
float fPosY,
bool bVisible =
true)
227 if (!wInfo || !wAnchor)
232 wInfo.SetVisible(
false);
236 wInfo.SetVisible(bVisible);
237 wInfo.SetText(sText);
238 Scale(wInfo, m_fWidgetScale);
239 MovePerc(wAnchor, fPosX, fPosY);
245 protected void UpdateGauge(IEntity owner,
float timeSlice,
float value)
248 float fValuePerc = GetValuePerc(value);
250 UpdateGaugeNeedle(owner, timeSlice, m_wNeedle, m_wNeedleShadow, fValuePerc);
255 protected void UpdateGaugeNeedle(IEntity owner,
float timeSlice, ImageWidget wNeedle, ImageWidget wNeedleShadow,
float fValuePerc,
float fScaleValue = 1.00,
bool bClamp =
true)
261 fValuePerc = fValuePerc * fScaleValue;
266 fValuePerc = Math.Clamp(fValuePerc, 0, 1);
270 fValuePerc = fValuePerc - Math.Floor(fValuePerc);
273 fValuePerc = 1 + fValuePerc;
277 float fAngle = m_fZeroValueRotation + (fValuePerc * m_fWidgetRange);
279 wNeedle.SetRotation(fAngle);
282 wNeedleShadow.SetRotation(fAngle);
286 protected void DestroyGauge()
300 override event void DisplayUpdate(IEntity owner,
float timeSlice)
306 float value = GetValue();
308 UpdateGauge(owner, timeSlice, value);
312 override bool DisplayStartDrawInit(IEntity owner)
319 m_pGaugeData = GetGaugeData();
325 if (m_LayoutPath ==
"")
326 m_LayoutPath = m_pGaugeData.m_sDefaultLayout;
332 override void DisplayStartDraw(IEntity owner)
341 bool bSuccess =
true;
342 InitGauge(owner, bSuccess);
348 CreateGauge(owner, bSuccess);
355 override void DisplayStopDraw(IEntity owner)
361 override void DisplayInit(IEntity owner)
368 private void MovePerc(Widget widget,
float x,
float y)
370 if (!widget || !m_wRing)
377 OverlaySlot.SetPadding(widget, x * m_fGaugeSizeX, y * m_fGaugeSizeY, 0, 0);
381 private void Scale(ImageWidget widget,
float scale)
388 int image = widget.GetImage();
390 widget.GetImageSize(image, imageWidth, imageHeight);
391 widget.SetSize((
float)imageWidth * scale, (
float)imageHeight * scale);
395 private void Scale(TextWidget widget,
float scale)
400 float sizeY = FrameSlot.GetSizeY(widget);
401 FrameSlot.SetSizeY(widget, sizeY * scale);
405 protected void CreateRingLabel(WorkspaceWidget workspace,
float angle,
float value,
bool absValues =
true,
float labelValueMultiplier = 1,
int labelValuePrecision = 0)
407 value = value * labelValueMultiplier;
409 if (labelValuePrecision == 0)
411 value = Math.Round(value);
415 float decimals = labelValuePrecision * 10;
418 decimals = -1 / decimals;
420 value = Math.Round(value * decimals);
421 value = value / decimals;
424 if (value == 0 && !m_bShowLabel0)
428 value = Math.AbsFloat(value);
430 float rads = angle / Math.RAD2DEG;
432 float xcoef = - Math.Sin(rads);
433 float ycoef = Math.Cos(rads);
435 float x = 0.5 * m_fGaugeSizeX * xcoef * m_pGaugeData.m_fRingLabelOffset;
436 float y = 0.5 * m_fGaugeSizeY * ycoef * m_pGaugeData.m_fRingLabelOffset;
438 Widget w = workspace.CreateWidget(WidgetType.TextWidgetTypeID, WidgetFlags.INHERIT_CLIPPING | WidgetFlags.VISIBLE | WidgetFlags.ADDITIVE | WidgetFlags.STRETCH,
null, 0, m_wRingLabels);
439 TextWidget wText = TextWidget.Cast(w);
441 wText.SetText(value.ToString());
442 wText.SetFont(
"{EABA4FE9D014CCEF}UI/Fonts/RobotoCondensed/RobotoCondensed_Bold.fnt");
443 wText.SetExactFontSize(m_pGaugeData.m_fRingLabelFontSize * m_fWidgetScale);
445 float alignx = xcoef / 2 + 0.5;
446 float aligny = ycoef / 2 + 0.5;
448 FrameSlot.SetAlignment(wText, alignx, aligny);
449 FrameSlot.SetAnchorMin(wText, 0.5, 0.5);
450 FrameSlot.SetAnchorMax(wText, 0.5, 0.5);
451 FrameSlot.SetSizeToContent(wText,
true);
452 FrameSlot.SetPos(wText, x, y);
456 protected void CreateRingMark(WorkspaceWidget workspace,
float angle,
string texture)
458 Widget w = workspace.CreateWidget(WidgetType.ImageWidgetTypeID, WidgetFlags.INHERIT_CLIPPING | WidgetFlags.VISIBLE | WidgetFlags.ADDITIVE | WidgetFlags.STRETCH,
null, 0, m_wRingMarks);
459 ImageWidget wImage = ImageWidget.Cast(w);
461 wImage.LoadImageFromSet(0, m_pGaugeData.m_AnalogGauge, texture);
462 FrameSlot.SetAlignment(wImage, 0.5, 0);
463 FrameSlot.SetAnchorMin(wImage, 0.5, 0.5);
464 FrameSlot.SetAnchorMax(wImage, 0.5, 0.5);
465 FrameSlot.SetSizeToContent(wImage,
true);
466 FrameSlot.SetPos(wImage, 0, 0);
468 Scale(wImage, m_fWidgetScale);
470 wImage.SetPivot(0.5, 0);
471 wImage.SetRotation(angle);