Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_StatsPanelBase.c
Go to the documentation of this file.
1 //#define DEBUG_STATS_PANELS
2 
4 {
5  INIT,
9 };
10 
12 {
16 };
17 
18 class 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))]
48  EStatsPanelEval m_eValueCalc;
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 
56  protected string m_Imageset = "{3262679C50EF4F01}UI/Textures/Icons/icons_wrapperUI.imageset";
57  protected string m_ImagesetGlow = "{00FE3DBDFD15227B}UI/Textures/Icons/icons_wrapperUI-glow.imageset";
58 
59  RplIdentity m_RplIdentity;
60  ref SCR_StatsPanelWidgets m_Widgets;
61  protected EStatsPanelState m_eState = EStatsPanelState.INIT;
62 
63  protected bool m_bShowInDefaultState; // Based on SCR_InfoDisplay 'm_bShowWhenCreated' flag
64 
65  protected float m_fTimeElapsed;
66  protected int m_iRecords;
67 
68  protected float m_fValueToShow;
69  protected float m_fValueRecorded;
70 
71  //------------------------------------------------------------------------------------------------
72  override bool DisplayStartDrawInit(IEntity owner)
73  {
74  if (m_iUpdateInterval <= 0)
75  return false;
76 
77  if (!Replication.IsRunning() && !m_bShowInSinglePlayer)
78  return false;
79 
80  if (Replication.IsRunning() && Replication.IsServer() && !m_bShowOnServer)
81  return false;
82 
83  m_RplIdentity = RplIdentity.Local();
84 
85  return true;
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  override void DisplayStartDraw(IEntity owner)
90  {
91  if (!m_wRoot)
92  return;
93 
95  m_Widgets.Init(m_wRoot);
96 
97  m_Widgets.m_wLabel.SetText(m_sLabel);
98 
99  // Fill-in the max value to reserve space in the stats bar
100  string text = WidgetManager.Translate(m_sFormattingPattern, m_iValueMax);
101  m_Widgets.m_wTextPlaceholder.SetText(text);
102 
103  m_bShowInDefaultState = m_bShown;
104 
105  float value = GetValue();
106  Update(value);
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  override void DisplayUpdate(IEntity owner, float timeSlice)
111  {
112  if (!m_wRoot)
113  return;
114 
115  m_fTimeElapsed += timeSlice;
116 
117  float value = GetValue();
118 
119  // Increment records counter
120  m_iRecords++;
121 
122  if (m_eValueCalc == EStatsPanelEval.SHOW_AVERAGE)
123  {
124  m_fValueRecorded = m_fValueRecorded + value;
125  }
126  else
127  {
128  if (m_eValueCalc == EStatsPanelEval.SHOW_HIGHEST && value > m_fValueRecorded) m_fValueRecorded = value;
129  else if (m_eValueCalc == EStatsPanelEval.SHOW_LOWEST && value < m_fValueRecorded) m_fValueRecorded = value;
130  }
131 
132  if (m_fTimeElapsed < m_iUpdateInterval)
133  return;
134 
135  // Calculate avg stat value
136  if (m_iRecords > 0)
137  {
138  if (m_eValueCalc == EStatsPanelEval.SHOW_AVERAGE)
139  m_fValueToShow = m_fValueRecorded/m_iRecords;
140  else
141  m_fValueToShow = m_fValueRecorded;
142 
143  Update(m_fValueToShow);
144  }
145 
146  // Reset after update
147  m_iRecords = 0;
148  m_fValueRecorded = 0;
149  m_fTimeElapsed = m_fTimeElapsed - m_iUpdateInterval;
150  }
151 
152  //------------------------------------------------------------------------------------------------
153  protected float GetValue()
154  {
155  return 0;
156  }
157 
158  //------------------------------------------------------------------------------------------------
159  protected void Update(float value)
160  {
161  value = Math.Clamp(Math.Round(value), 0, m_iValueMax);
162 
163  /*
164  if (this.Type() == SCR_StatsPanel_PacketLoss)
165  {
166  PrintFormat("Packet loss: %1\%", value)
167  }
168  */
169 
170  // Update text
171  string text = WidgetManager.Translate(m_sFormattingPattern, value);
172  m_Widgets.m_wText.SetText(text);
173 
174  // Evaluate the state based on current value
175  EStatsPanelState state = EStatsPanelState.DEFAULT;
176 
177  // Determine state for case where lower is better (like latency or packet loss)
178  if (m_iValueError >= m_iValueWarning)
179  {
180  if (value > m_iValueError)
181  state = EStatsPanelState.ERROR;
182  else if (value > m_iValueWarning)
183  state = EStatsPanelState.WARNING;
184  }
185  // Determine state for case where higher is better (like FPS)
186  else
187  {
188  if (value < m_iValueError)
189  state = EStatsPanelState.ERROR;
190  else if (value < m_iValueWarning)
191  state = EStatsPanelState.WARNING;
192  }
193 
194  // State didn't change, no need to update visuals (text already updated)
195  if (m_eState == state)
196  return;
197 
198  m_eState = state;
199 
200  // Get visialization attributes based on the new state
201  float opacity;
202  Color color;
203  Color colorGlow;
204  string icon;
205 
206  switch (state)
207  {
208  case EStatsPanelState.WARNING:
209  opacity = 1;
210  color = GUIColors.ORANGE_BRIGHT2;
211  //colorGlow = GUIColors.ORANGE;
212  colorGlow = GUIColors.DEFAULT_GLOW;
213  icon = m_sIconWarning;
214  break;
215 
216  case EStatsPanelState.ERROR:
217  opacity = 1;
218  color = GUIColors.RED_BRIGHT2;
219  //colorGlow = GUIColors.RED;
220  colorGlow = GUIColors.DEFAULT_GLOW;
221  icon = m_sIconError;
222  break;
223 
224  default:
225  opacity = 0.5;
226  color = GUIColors.DEFAULT;
227  colorGlow = GUIColors.DEFAULT_GLOW;
228  icon = m_sIconOK;
229  break;
230  }
231 
232  // Set global color & opacity
233  m_Widgets.m_wColorOpacity.SetOpacity(opacity);
234  m_Widgets.m_wColorOpacity.SetColor(color);
235 
236  // Set icon & glow
237  m_Widgets.m_wIcon.LoadImageFromSet(0, m_Imageset, icon);
238  m_Widgets.m_wIconGlow.LoadImageFromSet(0, m_ImagesetGlow, icon);
239  m_Widgets.m_wIconGlow.SetColor(colorGlow);
240 
241  // Update text shadow
242  m_Widgets.m_wText.SetShadow(20, colorGlow.PackToInt(), 0.35);
243 
244  // Set visibility
245  Show((state == EStatsPanelState.DEFAULT && m_bShowInDefaultState) || state != EStatsPanelState.DEFAULT);
246  }
247 }
DEFAULT
@ DEFAULT
Definition: SCR_StatsPanelBase.c:6
m_bShown
protected bool m_bShown
Definition: SCR_InfoDisplay.c:61
SHOW_AVERAGE
@ SHOW_AVERAGE
Definition: SCR_StatsPanelBase.c:13
SCR_Enum
Definition: SCR_Enum.c:1
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
WARNING
@ WARNING
Definition: SCR_StatsPanelBase.c:7
EStatsPanelState
EStatsPanelState
Definition: SCR_StatsPanelBase.c:3
SHOW_LOWEST
@ SHOW_LOWEST
Definition: SCR_StatsPanelBase.c:15
m_Widgets
ref SCR_VoNOverlay_ElementWidgets m_Widgets
Definition: SCR_VonDisplay.c:3
Show
override void Show(WorkspaceWidget pWorkspace, Widget pToolTipWidget, float desiredPosX, float desiredPosY)
Definition: SCR_ScriptedWidgetTooltip.c:55
EStatsPanelEval
EStatsPanelEval
Definition: SCR_StatsPanelBase.c:11
INIT
@ INIT
Definition: SCR_StatsPanelBase.c:5
m_eState
EAITargetClusterState m_eState
Definition: SCR_AITargetClusterState.c:24
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_StatsPanelBase
Definition: SCR_StatsPanelBase.c:18
SHOW_HIGHEST
@ SHOW_HIGHEST
Definition: SCR_StatsPanelBase.c:14
m_fTimeElapsed
float m_fTimeElapsed
Definition: SCR_MineAwarenessComponent.c:9
ERROR
@ ERROR
Definition: SCR_StatsPanelBase.c:8
SCR_StatsPanelWidgets
Definition: SCR_StatsPanelWidgets.c:4