Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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")]
11  protected int m_iSectionSubdivisions;
12 
13  [Attribute("1", UIWidgets.SpinBox, "Label on gauge ring every N-sections (e.g. if 1 every section is labeled)", "1 10 1")]
14  protected int m_iLabelEveryNthSection;
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 
29  protected SignalsManagerComponent m_SignalsManagerComponent;
30  protected int m_iSignalIndex = -1;
31 
32  protected float m_fValueMin, m_fValueMax, m_fValueRange;
33  protected ref array<float> m_aValues = new array<float>();
34 
35  //------------------------------------------------------------------------------------------------
36  override SCR_BaseAnalogGaugeData GetGaugeData()
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
81  m_fValueRange = m_fValueMax - m_fValueMin;
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
136  if (i % (m_iSectionSubdivisions * m_iLabelEveryNthSection) == 0)
137  {
138  index = i / m_iSectionSubdivisions;
139  value = m_aValues[index];
140 
141  CreateRingLabel(workspace, angle, value, m_bAbsLabelValues, m_fLabelValueMultiplier, m_iLabelValuePrecision);
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  for (int i = 0; i < iSegments; i++)
179  {
180  if (fValuePerc > -1)
181  continue;
182 
183  fMin = m_aValues[i];
184  fMax = m_aValues[i + 1];
185 
186  if (value < fMax)
187  {
188  fValuePerc = i * fSegmentSize; // percentage based on segment
189  fValuePerc += fSegmentSize * (value - fMin) / (fMax - fMin); // percentage based on progress within segment
190  }
191  }
192 
193  return fValuePerc;
194  }
195 
196  //------------------------------------------------------------------------------------------------
197  override event void DisplayStartDraw(IEntity owner)
198  {
200  return;
201 
202  m_iSignalIndex = m_SignalsManagerComponent.FindSignal(m_sSignalName);
203 
204  super.DisplayStartDraw(owner);
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  override event void DisplayInit(IEntity owner)
209  {
210  super.DisplayInit(owner);
211 
212  GenericEntity genericEntity = GenericEntity.Cast(owner);
213 
214  if (!genericEntity)
215  return;
216 
217  m_SignalsManagerComponent = SignalsManagerComponent.Cast(genericEntity.FindComponent(SignalsManagerComponent));
218  }
219 };
220 
m_aValues
SCR_BaseEditorAttributeEntryTimeSlider m_aValues
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_BaseAnalogGauge
Definition: SCR_BaseAnalogGauge.c:16
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_BaseAnalogGaugeData
Definition: SCR_BaseAnalogGauge.c:1
SCR_AnalogGaugeNonLinear
Definition: SCR_AnalogGaugeNonLinear.c:2
m_SignalsManagerComponent
protected SignalsManagerComponent m_SignalsManagerComponent
Definition: SCR_SignalsDebugComponent.c:22
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305