Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
debugmonitor.c
Go to the documentation of this file.
2{
3 protected bool m_IsUsingKBM;
4
7
15
20
22
24 {
25 m_WidgetRoot = g_Game.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
42 }
43
44 void Init()
45 {
46 string version;
47 g_Game.GetVersion(version);
48 m_VersionValue.SetText(" " + version);
49
50 g_Game.GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
51 if (g_Game.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 {
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 g_Game.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 = g_Game.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
TextWidget m_PositionValue
TextWidget m_MapTileValue
int m_FPSTextDefaultColor
TextWidget m_CopyPositionInfo
TextWidget m_FPSValue
TextWidget m_BloodValue
TextWidget m_VersionValue
Definition debugmonitor.c:8
TextWidget m_DmgSourceValue
TextWidget m_FPSMaxValue
TextWidget m_FPSMinValue
void DebugMonitor()
void SetLastDamage(string value)
void SetPosition(vector value)
int GetTileFomFraction(float fraction)
Widget m_WidgetRoot
Definition debugmonitor.c:5
void SetFramerate(float current, float min, float max, float avg)
Update the framerate values displayed within the debug monitor with new ones.
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
void SetBlood(float value)
string CalculateMapTile(vector pos)
TextWidget m_WindowLabelText
Definition debugmonitor.c:6
TextWidget m_HealthValue
Definition debugmonitor.c:9
TextWidget m_FPSAvgValue
void SetHealth(float value)
void SetFramerateText(TextWidget widget, float value)
Sets the provided text widget to display framerate value.
bool m_IsUsingKBM
Definition debugmonitor.c:3
Definition enmath.c:7
proto string ToString(bool simple=true)
proto string ToString(bool beautify=true)
Vector to string.
DayZGame g_Game
Definition dayzgame.c:3942
proto string ToString()
const int COLOR_RED
Definition constants.c:64
const int COLOR_YELLOW
Definition constants.c:67
static proto float Round(float f)
Returns mathematical round of value.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
EInputDeviceType
Definition input.c:3
proto native UAInputAPI GetUApi()