5 [
Attribute(
"0", UIWidgets.SpinBox,
"Min. value (usually 0, but can be any value, even negative)")]
6 protected float m_fValueMin;
8 [
Attribute(
"120", UIWidgets.SpinBox,
"Max. value (in the units provided, e.g. km/h)",
"0.1 1000000000 0.1")]
9 protected float m_fValueMax;
12 [
Attribute(
"10", UIWidgets.SpinBox,
"Section mark on gauge ring every N-units")]
13 protected float m_fSectionEveryNthValue;
15 [
Attribute(
"2", UIWidgets.SpinBox,
"Section subdivisions on gauge ring",
"1 10 1")]
16 protected int m_iSectionSubdivisions;
18 [
Attribute(
"2", UIWidgets.SpinBox,
"Label on gauge ring every N-sections (e.g. if 1 every section is labeled)",
"1 10 1")]
19 protected int m_iLabelEveryNthSection;
23 [
Attribute(
"speed", UIWidgets.EditBox,
"Name of the signal to listen to.")]
24 protected string m_sSignalName;
28 [
Attribute(
"", UIWidgets.EditBox,
"Gauge overlay texture.")]
29 protected string m_sOverlay;
31 [
Attribute(
"", UIWidgets.EditBox,
"Gauge custom needle texture. If not selected, default is used.")]
32 protected string m_sCustomNeedle;
35 protected SignalsManagerComponent m_SignalsManagerComponent;
36 protected int m_iSignalIndex = -1;
38 protected float m_fValueRange;
47 data.m_sOverlay = m_sOverlay;
48 data.m_sCustomNeedle = m_sCustomNeedle;
54 override void InitGauge(IEntity owner, out
bool bSuccess)
57 if (m_fSectionEveryNthValue <= 0)
58 m_fSectionEveryNthValue = 10;
60 if (m_iLabelEveryNthSection < 1)
61 m_iLabelEveryNthSection = 1;
63 if (m_iSectionSubdivisions < 1)
64 m_iSectionSubdivisions = 1;
67 m_fValueMax = (Math.Ceil(m_fValueMax / (m_fSectionEveryNthValue * m_iLabelEveryNthSection))) * m_fSectionEveryNthValue * m_iLabelEveryNthSection;
68 m_fValueMin = (Math.Floor(m_fValueMin / (m_fSectionEveryNthValue * m_iLabelEveryNthSection))) * m_fSectionEveryNthValue * m_iLabelEveryNthSection;
71 m_fValueRange = m_fValueMax - m_fValueMin;
73 if (m_fValueRange <= 0)
78 override bool CreateGaugeRing(IEntity owner)
80 bool bSuccess = super.CreateGaugeRing(owner);
85 int sections = (m_fValueRange / m_fSectionEveryNthValue);
87 WorkspaceWidget workspace =
GetGame().GetWorkspace();
89 int steps = sections * m_iSectionSubdivisions;
90 float markAngle = m_fWidgetRange / steps;
95 for (
int i = 0; i <= steps; i++)
97 angle = m_fZeroValueRotation + (i * markAngle);
100 if (i % m_iSectionSubdivisions == 0)
101 texture = m_pGaugeData.m_sRingMarkSection;
103 texture = m_pGaugeData.m_sRingMarkSubsection;
105 CreateRingMark(workspace, angle, texture);
107 if (i == 0 && !m_bShowLabelMin)
110 if (i == steps && !m_bShowLabelMax)
114 if (i % (m_iSectionSubdivisions * m_iLabelEveryNthSection) == 0)
116 value = m_fValueMin + (i / m_iSectionSubdivisions * m_fSectionEveryNthValue);
117 CreateRingLabel(workspace, angle, value, m_bAbsLabelValues, m_fLabelValueMultiplier, m_iLabelValuePrecision);
125 override float GetValue()
130 if (m_iSignalIndex == -1)
139 override float GetValuePerc(
float value)
141 if (m_fValueRange == 0)
144 float fValuePerc = (value - m_fValueMin) / m_fValueRange;
150 override event void DisplayStartDraw(IEntity owner)
157 super.DisplayStartDraw(owner);
161 override event void DisplayInit(IEntity owner)
163 super.DisplayInit(owner);