Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
debugmonitor.c
Go to the documentation of this file.
2{
3 protected bool m_IsUsingKBM;
4
5 private Widget m_WidgetRoot;
6 private TextWidget m_WindowLabelText;
7
8 private TextWidget m_VersionValue;
9 private TextWidget m_HealthValue;
10 private TextWidget m_BloodValue;
11 private TextWidget m_DmgSourceValue;
12 private TextWidget m_MapTileValue;
13 private TextWidget m_PositionValue;
14 private TextWidget m_CopyPositionInfo;
15
16 private TextWidget m_FPSValue;
17 private TextWidget m_FPSMinValue;
18 private TextWidget m_FPSMaxValue;
19 private TextWidget m_FPSAvgValue;
20
21 private int m_FPSTextDefaultColor;
22
23 void DebugMonitor()
24 {
25 m_WidgetRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/debug/day_z_debug_monitor.layout");
26 m_WidgetRoot.Show(false);
27
28 m_VersionValue = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("VersionValue"));
29 m_HealthValue = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("HealthValue"));
30 m_BloodValue = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("BloodValue"));
31 m_DmgSourceValue = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("DmgSourceValue"));
32 m_MapTileValue = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("MapTileValue"));
33 m_PositionValue = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("PositionValue"));
34 m_CopyPositionInfo = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("CopyPositionInfo"));
35
36 m_FPSValue = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("FPSCurrentValue"));
37 m_FPSMinValue = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("FPSMinValue"));
38 m_FPSMaxValue = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("FPSMaxValue"));
39 m_FPSAvgValue = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("FPSAvgValue"));
40
41 m_FPSTextDefaultColor = m_FPSValue.GetColor();
42 }
43
44 void Init()
45 {
46 string version;
47 g_Game.GetVersion(version);
48 m_VersionValue.SetText(" " + version);
49
50 GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
51 if (GetGame().GetInput().IsKeyboardConnected())
52 m_IsUsingKBM = true;
53
54 m_WidgetRoot.Show(true);
55 }
56
57 void SetHealth(float value)
58 {
59 string health = string.Format(" %1", value.ToString());
60 m_HealthValue.SetText(health);
61 }
62
63 void SetBlood(float value)
64 {
65 string blood = string.Format(" %1", value.ToString());
66 m_BloodValue.SetText(blood);
67 }
68
69 void SetLastDamage(string value)
70 {
71 if (value != "")
72 m_DmgSourceValue.SetText(" " + value);
73 else
74 m_DmgSourceValue.SetText(" -");
75 }
76
80 void SetFramerate(float current, float min, float max, float avg)
81 {
82 SetFramerateText(m_FPSValue, current);
83 SetFramerateText(m_FPSMinValue, min);
84 SetFramerateText(m_FPSMaxValue, max);
85 SetFramerateText(m_FPSAvgValue, avg);
86 }
87
92 protected void SetFramerateText(TextWidget widget, float value)
93 {
94 // Ideally we would poll the refresh rate and base the values as
95 // percentage thereof, but there is no such API in scripts.
96
97 #ifdef PLATFORM_CONSOLE
98 // default [30, inf] ; orange [20, 29] ; red [0, 19]
99 if (value > 29)
100 widget.SetColor(m_FPSTextDefaultColor);
101 else if (value > 19)
102 widget.SetColor(0xFFFF8000); // COLOR_ORANGE
103 else
104 widget.SetColor(COLOR_RED);
105 #else
106 // default [60, inf] ; yellow [40, 59] ; orange [30, 39] ; red [0, 29]
107 if (value > 59)
108 widget.SetColor(m_FPSTextDefaultColor);
109 else if (value > 39)
110 widget.SetColor(COLOR_YELLOW);
111 else if (value > 29)
112 widget.SetColor(0xFFFF8000); // COLOR_ORANGE
113 else
114 widget.SetColor(COLOR_RED);
115 #endif
116
117 widget.SetTextFormat("%1", Math.Round(value));
118 }
119
120 void SetPosition(vector value)
121 {
122 m_MapTileValue.SetText(" " + CalculateMapTile(value));
123 string position = string.Format(" %1 %2 %3", value[0].ToString(), value[1].ToString(), value[2].ToString());
124 m_PositionValue.SetText(position);
125
126 if (GetUApi().GetInputByID(UAUICopyDebugMonitorPos).LocalPress())
127 {
128 string adjusted = (value[0] + 200000).ToString() + " " + value[2].ToString();
129 GetGame().CopyToClipboard(adjusted);
130 }
131
132 if (m_IsUsingKBM)
133 m_CopyPositionInfo.SetText(" (P to clipboard)");
134 else
135 m_CopyPositionInfo.SetText("");
136 }
137
138 void Show()
139 {
140 m_WidgetRoot.Show(true);
141 }
142
143 void Hide()
144 {
145 m_WidgetRoot.Show(false);
146 }
147
149 {
150 string tile;
151 float worldSize = GetGame().GetWorld().GetWorldSize();
152
153 float tileX = Math.InverseLerp(0, worldSize, pos[0]);
154 float tileY = Math.InverseLerp(0, worldSize, pos[2]);
155
156 tile = GetTileFomFraction(tileX).ToString() + GetTileFomFraction(tileY).ToString();
157
158 return tile;
159 }
160
161 int GetTileFomFraction(float fraction)
162 {
163 if (fraction < 0.25)
164 return 0;
165 else if (fraction < 0.5)
166 return 1;
167 else if (fraction < 0.75)
168 return 2;
169 else
170 return 3;
171
172 }
173
175 {
176 if (pInputDeviceType == EInputDeviceType.MOUSE_AND_KEYBOARD)
177 m_IsUsingKBM = true;
178 else
179 m_IsUsingKBM = false;
180 }
181
183 {
184 return m_WidgetRoot.IsVisible();
185 }
186};
187
bool m_IsUsingKBM
Definition debugmonitor.c:3
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
int GetTileFomFraction(float fraction)
void SetPosition(vector value)
string CalculateMapTile(vector pos)
void SetFramerateText(TextWidget widget, float value)
Definition enmath.c:7
DayZGame g_Game
Definition dayzgame.c:3868
class DayZProfilesOptions m_WidgetRoot
proto string ToString()
proto native CGame GetGame()
const int COLOR_RED
Definition constants.c:64
const int COLOR_YELLOW
Definition constants.c:67
EInputDeviceType
Definition input.c:3
proto native UAInputAPI GetUApi()