Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AnalogGaugeNonLinear.c
Go to the documentation of this file.
1// Default signal based analog gauge, needle movement clamped by Min and Max values, supports 1 needle - standard size
3{
4 // Attributes: values definition
5 [Attribute("0 10 30 60 120", UIWidgets.EditBox, "Direct definition of values to be displayed on the gauge; float values separated by space")]
6 protected string m_sValues;
7
8
9 // Attributes: labels
10 [Attribute("2", UIWidgets.SpinBox, "Section subdivisions on gauge ring", "1 10 1")]
12
13 [Attribute("1", UIWidgets.SpinBox, "Label on gauge ring every N-sections (e.g. if 1 every section is labeled)", "1 10 1")]
15
16
17 // Attributes: signal
18 [Attribute("speed", UIWidgets.EditBox, "Name of the signal to listen to.")]
19 protected string m_sSignalName;
20
21
22 // Attributes: custom data
23 [Attribute("", UIWidgets.EditBox, "Gauge overlay texture.")]
24 protected string m_sOverlay;
25
26 [Attribute("", UIWidgets.EditBox, "Gauge custom needle texture. If not selected, default is used.")]
27 protected string m_sCustomNeedle;
28
30 protected int m_iSignalIndex = -1;
31
33 protected ref array<float> m_aValues = new array<float>();
34
35 //------------------------------------------------------------------------------------------------
37 {
39
40 // Custom attributes
41 data.m_sOverlay = m_sOverlay;
42 data.m_sCustomNeedle = m_sCustomNeedle;
43
44 return data;
45 }
46
47 //------------------------------------------------------------------------------------------------
48 override void InitGauge(IEntity owner, out bool bSuccess)
49 {
50 // Parse and validate value data from the editbox input
51 array<string> aValueStrings = new array<string>();
52 m_sValues.Split(" ", aValueStrings, true);
53
54 float fValue;
55 int iValues = 0;
56
57 foreach (string sValue : aValueStrings)
58 {
59 fValue = sValue.ToFloat();
60
61 if (iValues == 0 || fValue > m_fValueMax)
62 {
63 if (iValues == 0)
64 m_fValueMin = fValue;
65
66 iValues++;
67
68 m_aValues.Insert(fValue);
69 m_fValueMax = fValue;
70 }
71 }
72
73 // Need at least 2 values (min & max)
74 if (iValues < 2)
75 {
76 bSuccess = false;
77 return;
78 }
79
80 // Get gauge value range
82
83 if (m_fValueRange <= 0)
84 {
85 bSuccess = false;
86 return;
87 }
88 }
89
90 //------------------------------------------------------------------------------------------------
91 override void DestroyGauge()
92 {
93 m_aValues.Clear();
94
95 super.DestroyGauge();
96 }
97
98 //------------------------------------------------------------------------------------------------
99 override bool CreateGaugeRing(IEntity owner)
100 {
101 bool bSuccess = super.CreateGaugeRing(owner);
102
103 if (!bSuccess)
104 return false;
105
106 int sections = m_aValues.Count() - 1;
107
108 WorkspaceWidget workspace = GetGame().GetWorkspace();
109
110 int steps = sections * m_iSectionSubdivisions;
111 float markAngle = m_fWidgetRange / steps;
112 float angle, value;
113 int index;
114
115 string texture;
116
117 for (int i = 0; i <= steps; i++)
118 {
119 angle = m_fZeroValueRotation + (i * markAngle);
120
121 // Add marks on the gauge ring
122 if (i % m_iSectionSubdivisions == 0)
123 texture = m_pGaugeData.m_sRingMarkSection;
124 else
125 texture = m_pGaugeData.m_sRingMarkSubsection;
126
127 CreateRingMark(workspace, angle, texture);
128
129 if (i == 0 && !m_bShowLabelMin)
130 continue;
131
132 if (i == steps && !m_bShowLabelMax)
133 continue;
134
135 // Add labels to section marks
137 {
139 value = m_aValues[index];
140
142 }
143 }
144
145 return true;
146 }
147
148 //------------------------------------------------------------------------------------------------
149 override float GetValue()
150 {
152 return 0;
153
154 if (m_iSignalIndex == -1)
155 return 0;
156
157 float value = m_SignalsManagerComponent.GetSignalValue(m_iSignalIndex);
158
159 return value;
160 }
161
162 //------------------------------------------------------------------------------------------------
163 override float GetValuePerc(float value)
164 {
165 if (m_fValueRange == 0)
166 return 0;
167
168 // Get segment value is in
169 float fMin, fMax;
170 int iSegments = m_aValues.Count() - 1;
171
172 if (iSegments <= 0)
173 return 0;
174
175 float fValuePerc = -1;
176 float fSegmentSize = 1 / iSegments;
177
178 // Clamp progress to 100% if out of bounds
179 if (value > m_aValues[iSegments])
180 return 1;
181
182 for (int i = 0; i < iSegments; i++)
183 {
184 if (fValuePerc > -1)
185 continue;
186
187 fMin = m_aValues[i];
188 fMax = m_aValues[i + 1];
189
190 if (value < fMax)
191 {
192 fValuePerc = i * fSegmentSize; // percentage based on segment
193 fValuePerc += fSegmentSize * (value - fMin) / (fMax - fMin); // percentage based on progress within segment
194 }
195 }
196
197 return fValuePerc;
198 }
199
200 //------------------------------------------------------------------------------------------------
201 override event void DisplayStartDraw(IEntity owner)
202 {
204 return;
205
207
208 super.DisplayStartDraw(owner);
209 }
210
211 //------------------------------------------------------------------------------------------------
212 override event void DisplayInit(IEntity owner)
213 {
214 super.DisplayInit(owner);
215
216 GenericEntity genericEntity = GenericEntity.Cast(owner);
217
218 if (!genericEntity)
219 return;
220
222 }
223};
224
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Get all prefabs that have the spawner data
proto external Managed FindComponent(typename typeName)
override void InitGauge(IEntity owner, out bool bSuccess)
override float GetValuePerc(float value)
override event void DisplayInit(IEntity owner)
SignalsManagerComponent m_SignalsManagerComponent
override SCR_BaseAnalogGaugeData GetGaugeData()
override event void DisplayStartDraw(IEntity owner)
override bool CreateGaugeRing(IEntity owner)
ref SCR_BaseAnalogGaugeData m_pGaugeData
void CreateRingMark(WorkspaceWidget workspace, float angle, string texture)
void CreateRingLabel(WorkspaceWidget workspace, float angle, float value, bool absValues=true, float labelValueMultiplier=1, int labelValuePrecision=0)
SCR_FieldOfViewSettings Attribute