Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_StatsPanelBase.c
Go to the documentation of this file.
1//#define DEBUG_STATS_PANELS
2
10
17
18class SCR_StatsPanelBase : SCR_InfoDisplayExtended
19{
20 [Attribute("#AR-ValueUnit_Milliseconds", UIWidgets.EditBox, "Pattern defining how the value and units are displayed (e.g. '%1 ms'.")]
21 protected string m_sFormattingPattern;
22
23 [Attribute("50", UIWidgets.SpinBox, "Threshold value for 'warning visual' style. Set it to same or higher value than 'm_iValueError' to disable 'warning visual' style.")]
24 protected int m_iValueWarning;
25
26 [Attribute("100", UIWidgets.SpinBox, "Threshold value for 'error visual' style.")]
27 protected int m_iValueError;
28
29 [Attribute("999", UIWidgets.SpinBox, "Max. value that can be displayed in the widget. Used to cap the value and also to reserve the space for the value text, to prevent visual glitches.")]
30 protected int m_iValueMax;
31
32 [Attribute("ping-high", UIWidgets.EditBox, "OK icon, used when value is bellow 'm_iValueWarning' threshold.")]
33 protected string m_sIconOK;
34
35 [Attribute("ping-high", UIWidgets.EditBox, "Warning icon, used when value is above 'm_iValueWarning', but under 'm_iValueError' threshold.")]
36 protected string m_sIconWarning;
37
38 [Attribute("ping-high", UIWidgets.EditBox, "Error icon, used when value is above 'm_iValueError' threshold.")]
39 protected string m_sIconError;
40
41 [Attribute("", UIWidgets.EditBox, "Label displayed next to the icon (optional).")]
42 protected string m_sLabel;
43
44 [Attribute("1", UIWidgets.SpinBox, "How often the display is updated (in seconds).", "1 10")]
45 protected int m_iUpdateInterval;
46
47 [Attribute(SCR_Enum.GetDefault(EStatsPanelEval.SHOW_AVERAGE), UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EStatsPanelEval))]
49
50 [Attribute("0", UIWidgets.CheckBox, "Should the indicator be shown in single player game?")]
51 protected bool m_bShowInSinglePlayer;
52
53 [Attribute("1", UIWidgets.CheckBox, "Should the indicator be shown on server?")]
54 protected bool m_bShowOnServer;
55
59
60 protected bool m_bShowInDefaultState; // Based on SCR_InfoDisplay 'm_bShowWhenCreated' flag
61
62 protected float m_fTimeElapsed;
63 protected int m_iRecords;
64
65 protected float m_fValueToShow;
66 protected float m_fValueRecorded;
67
68 //------------------------------------------------------------------------------------------------
69 override bool DisplayStartDrawInit(IEntity owner)
70 {
71 if (m_iUpdateInterval <= 0)
72 return false;
73
74 if (!Replication.IsRunning() && !m_bShowInSinglePlayer)
75 return false;
76
77 if (Replication.IsRunning() && Replication.IsServer() && !m_bShowOnServer)
78 return false;
79
80 m_RplIdentity = RplIdentity.Local();
81
82 return true;
83 }
84
85 //------------------------------------------------------------------------------------------------
86 override void DisplayStartDraw(IEntity owner)
87 {
88 if (!m_wRoot)
89 return;
90
92 m_Widgets.Init(m_wRoot);
93
94 m_Widgets.m_wLabel.SetText(m_sLabel);
95
96 // Fill-in the max value to reserve space in the stats bar
97 string text = WidgetManager.Translate(m_sFormattingPattern, m_iValueMax);
98 m_Widgets.m_wTextPlaceholder.SetText(text);
99
101
102 float value = GetValue();
103 Update(value);
104 }
105
106 //------------------------------------------------------------------------------------------------
107 override void DisplayUpdate(IEntity owner, float timeSlice)
108 {
109 if (!m_wRoot)
110 return;
111
112 m_fTimeElapsed += timeSlice;
113
114 float value = GetValue();
115
116 // Increment records counter
117 m_iRecords++;
118
119 if (m_eValueCalc == EStatsPanelEval.SHOW_AVERAGE)
120 {
122 }
123 else
124 {
125 if (m_eValueCalc == EStatsPanelEval.SHOW_HIGHEST && value > m_fValueRecorded) m_fValueRecorded = value;
126 else if (m_eValueCalc == EStatsPanelEval.SHOW_LOWEST && value < m_fValueRecorded) m_fValueRecorded = value;
127 }
128
130 return;
131
132 // Calculate avg stat value
133 if (m_iRecords > 0)
134 {
135 if (m_eValueCalc == EStatsPanelEval.SHOW_AVERAGE)
137 else
139
141 }
142
143 // Reset after update
144 m_iRecords = 0;
147 }
148
149 //------------------------------------------------------------------------------------------------
150 protected float GetValue()
151 {
152 return 0;
153 }
154
155 //------------------------------------------------------------------------------------------------
156 protected void Update(float value)
157 {
158 value = Math.Clamp(Math.Round(value), 0, m_iValueMax);
159
160 /*
161 if (this.Type() == SCR_StatsPanel_PacketLoss)
162 {
163 PrintFormat("Packet loss: %1\%", value)
164 }
165 */
166
167 // Update text
168 string text = WidgetManager.Translate(m_sFormattingPattern, value);
169 m_Widgets.m_wText.SetText(text);
170
171 // Evaluate the state based on current value
172 EStatsPanelState state = EStatsPanelState.DEFAULT;
173
174 // Determine state for case where lower is better (like latency or packet loss)
176 {
177 if (value > m_iValueError)
178 state = EStatsPanelState.ERROR;
179 else if (value > m_iValueWarning)
180 state = EStatsPanelState.WARNING;
181 }
182 // Determine state for case where higher is better (like FPS)
183 else
184 {
185 if (value < m_iValueError)
186 state = EStatsPanelState.ERROR;
187 else if (value < m_iValueWarning)
188 state = EStatsPanelState.WARNING;
189 }
190
191 // State didn't change, no need to update visuals (text already updated)
192 if (m_eState == state)
193 return;
194
195 m_eState = state;
196
197 // Get visialization attributes based on the new state
198 float opacity;
199 Color color;
200 Color colorGlow;
201 string icon;
202
203 switch (state)
204 {
205 case EStatsPanelState.WARNING:
206 opacity = 1;
207 color = GUIColors.ORANGE_BRIGHT2;
208 //colorGlow = GUIColors.ORANGE;
209 colorGlow = GUIColors.DEFAULT_GLOW;
210 icon = m_sIconWarning;
211 break;
212
213 case EStatsPanelState.ERROR:
214 opacity = 1;
215 color = GUIColors.RED_BRIGHT2;
216 //colorGlow = GUIColors.RED;
217 colorGlow = GUIColors.DEFAULT_GLOW;
218 icon = m_sIconError;
219 break;
220
221 default:
222 opacity = 0.5;
223 color = GUIColors.DEFAULT;
224 colorGlow = GUIColors.DEFAULT_GLOW;
225 icon = m_sIconOK;
226 break;
227 }
228
229 // Set global color & opacity
230 m_Widgets.m_wColorOpacity.SetOpacity(opacity);
231 m_Widgets.m_wColorOpacity.SetColor(color);
232
233 // Set icon & glow
234 m_Widgets.m_wIcon.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, icon);
235 m_Widgets.m_wIconGlow.LoadImageFromSet(0, UIConstants.ICONS_GLOW_IMAGE_SET, icon);
236 m_Widgets.m_wIconGlow.SetColor(colorGlow);
237
238 // Update text shadow
239 m_Widgets.m_wText.SetShadow(20, colorGlow.PackToInt(), 0.35);
240
241 // Set visibility
242 Show((state == EStatsPanelState.DEFAULT && m_bShowInDefaultState) || state != EStatsPanelState.DEFAULT);
243 }
244}
Widget m_wRoot
bool m_bShown
EStatsPanelState
EStatsPanelEval
@ SHOW_LOWEST
@ SHOW_AVERAGE
@ SHOW_HIGHEST
Definition Color.c:13
Definition Math.c:13
Main replication API.
Definition Replication.c:14
Replication connection identity.
Definition RplIdentity.c:14
void Update(float value)
override void DisplayStartDraw(IEntity owner)
EStatsPanelEval m_eValueCalc
override bool DisplayStartDrawInit(IEntity owner)
EStatsPanelState m_eState
ref SCR_StatsPanelWidgets m_Widgets
override void DisplayUpdate(IEntity owner, float timeSlice)
override void Show()
Definition gameLib.c:262
@ DEFAULT
Use currently set main RT format (based on game options).
@ WARNING
Definition LogLevel.c:19
@ ERROR
Same as DELETE, but global error count for OnAfterLoad is affected.
Definition LogLevel.c:20
SCR_FieldOfViewSettings Attribute
@ INIT
Workshop is initializing data and any systems or UI elements should wait until ready.
Definition EntityEvent.c:16