Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AnalogGauge.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", UIWidgets.SpinBox, "Min. value (usually 0, but can be any value, even negative)")]
6  protected float m_fValueMin;
7 
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;
10 
11  // Attributes: labels
12  [Attribute("10", UIWidgets.SpinBox, "Section mark on gauge ring every N-units")]
13  protected float m_fSectionEveryNthValue;
14 
15  [Attribute("2", UIWidgets.SpinBox, "Section subdivisions on gauge ring", "1 10 1")]
16  protected int m_iSectionSubdivisions;
17 
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;
20 
21 
22  // Attributes: signal
23  [Attribute("speed", UIWidgets.EditBox, "Name of the signal to listen to.")]
24  protected string m_sSignalName;
25 
26 
27  // Attributes: custom data
28  [Attribute("", UIWidgets.EditBox, "Gauge overlay texture.")]
29  protected string m_sOverlay;
30 
31  [Attribute("", UIWidgets.EditBox, "Gauge custom needle texture. If not selected, default is used.")]
32  protected string m_sCustomNeedle;
33 
34 
35  protected SignalsManagerComponent m_SignalsManagerComponent;
36  protected int m_iSignalIndex = -1;
37 
38  protected float m_fValueRange;
39 
40 
41  //------------------------------------------------------------------------------------------------
42  override SCR_BaseAnalogGaugeData GetGaugeData()
43  {
45 
46  // Custom attributes
47  data.m_sOverlay = m_sOverlay;
48  data.m_sCustomNeedle = m_sCustomNeedle;
49 
50  return data;
51  }
52 
53  //------------------------------------------------------------------------------------------------
54  override void InitGauge(IEntity owner, out bool bSuccess)
55  {
56  // Verify markings & label settings
57  if (m_fSectionEveryNthValue <= 0)
58  m_fSectionEveryNthValue = 10;
59 
60  if (m_iLabelEveryNthSection < 1)
61  m_iLabelEveryNthSection = 1;
62 
63  if (m_iSectionSubdivisions < 1)
64  m_iSectionSubdivisions = 1;
65 
66  // Force min & max values to be always labeled
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;
69 
70  // Get gauge value range
71  m_fValueRange = m_fValueMax - m_fValueMin;
72 
73  if (m_fValueRange <= 0)
74  bSuccess = false;
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  override bool CreateGaugeRing(IEntity owner)
79  {
80  bool bSuccess = super.CreateGaugeRing(owner);
81 
82  if (!bSuccess)
83  return false;
84 
85  int sections = (m_fValueRange / m_fSectionEveryNthValue);
86 
87  WorkspaceWidget workspace = GetGame().GetWorkspace();
88 
89  int steps = sections * m_iSectionSubdivisions;
90  float markAngle = m_fWidgetRange / steps;
91  float angle, value;
92 
93  string texture;
94 
95  for (int i = 0; i <= steps; i++)
96  {
97  angle = m_fZeroValueRotation + (i * markAngle);
98 
99  // Add marks on the gauge ring
100  if (i % m_iSectionSubdivisions == 0)
101  texture = m_pGaugeData.m_sRingMarkSection;
102  else
103  texture = m_pGaugeData.m_sRingMarkSubsection;
104 
105  CreateRingMark(workspace, angle, texture);
106 
107  if (i == 0 && !m_bShowLabelMin)
108  continue;
109 
110  if (i == steps && !m_bShowLabelMax)
111  continue;
112 
113  // Add labels to section marks
114  if (i % (m_iSectionSubdivisions * m_iLabelEveryNthSection) == 0)
115  {
116  value = m_fValueMin + (i / m_iSectionSubdivisions * m_fSectionEveryNthValue);
117  CreateRingLabel(workspace, angle, value, m_bAbsLabelValues, m_fLabelValueMultiplier, m_iLabelValuePrecision);
118  }
119  }
120 
121  return true;
122  }
123 
124  //------------------------------------------------------------------------------------------------
125  override float GetValue()
126  {
128  return 0;
129 
130  if (m_iSignalIndex == -1)
131  return 0;
132 
133  float value = m_SignalsManagerComponent.GetSignalValue(m_iSignalIndex);
134 
135  return value;
136  }
137 
138  //------------------------------------------------------------------------------------------------
139  override float GetValuePerc(float value)
140  {
141  if (m_fValueRange == 0)
142  return 0;
143 
144  float fValuePerc = (value - m_fValueMin) / m_fValueRange;
145 
146  return fValuePerc;
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  override event void DisplayStartDraw(IEntity owner)
151  {
153  return;
154 
155  m_iSignalIndex = m_SignalsManagerComponent.FindSignal(m_sSignalName);
156 
157  super.DisplayStartDraw(owner);
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  override event void DisplayInit(IEntity owner)
162  {
163  super.DisplayInit(owner);
164 
165  GenericEntity genericEntity = GenericEntity.Cast(owner);
166 
167  if (!genericEntity)
168  return;
169 
170  m_SignalsManagerComponent = SignalsManagerComponent.Cast(genericEntity.FindComponent(SignalsManagerComponent));
171  }
172 };
173 
SCR_AnalogGauge
Definition: SCR_AnalogGauge.c:2
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
m_SignalsManagerComponent
protected SignalsManagerComponent m_SignalsManagerComponent
Definition: SCR_SignalsDebugComponent.c:22
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305