DayZ 1.24
Loading...
Searching...
No Matches
HudDebugWinCharStats.c
Go to the documentation of this file.
1class HudDebugWinCharStats extends HudDebugWinBase
2{
11
12 //============================================
13 // Constructor
14 //============================================
16 {
18 m_WgtPanel = Widget.Cast(m_WgtRoot.FindAnyWidget("Stats"));
19 //FitWindow();
20 }
21
22 //============================================
23 // Destructor
24 //============================================
26 {
27 SetUpdate(false);
28 }
29
30
31 //============================================
32 // GetWinType
33 //============================================
34 override int GetType()
35 {
36 return HudDebug.HUD_WIN_CHAR_STATS;
37 }
38
39 //============================================
40 // Show
41 //============================================
42 override void Show()
43 {
44 super.Show();
45
46 //Print("Show()");
47
48 SetUpdate(true);
49 }
50
51 //============================================
52 // Hide
53 //============================================
54 override void Hide()
55 {
56 super.Hide();
57
58 //Print("Hide()");
59
60 SetUpdate(false);
61 }
62
63 //============================================
64 // SetUpdate
65 //============================================
66 override void SetUpdate(bool state)
67 {
68 //Disable update on server (PluginDeveloperSync)
70
71 PluginDeveloperSync developer_sync = PluginDeveloperSync.Cast(GetPlugin(PluginDeveloperSync));
72
73 //if client, send RPC
74 if (GetGame().IsClient())
75 {
77 if (player)
78 {
79 player.RPCSingleParam(ERPCs.DEV_STATS_UPDATE, params, true);
80 SetRPCSent();
81 }
82 }
83 //else set directly
84 else
85 {
87 developer_sync.EnableUpdate(state, ERPCs.DEV_STATS_UPDATE, player);
88 }
89 }
90
91
92 override void Update()
93 {
94 super.Update();
95 //Print("panel:" + m_WgtPanel);
96 //Print("Update()");
97
98 //refresh notifiers
99
100
101 if (!m_Populated)
102 SetupValues();
103
104 UpdateValues();
105 }
106
108 {
109 PluginDeveloperSync developer_sync = PluginDeveloperSync.Cast(GetPlugin(PluginDeveloperSync));
110
111 //clear window
112 //ClearValues();
113
114 if (developer_sync.m_PlayerStatsSynced.Count() > 0)
115 {
116 //set
117 for (int i = 0; i < developer_sync.m_PlayerStatsSynced.Count(); i++)
118 AddValue(developer_sync.m_PlayerStatsSynced.Get(i).GetName(), developer_sync.m_PlayerStatsSynced.Get(i).GetValue().ToString());
119 //fit to screen
120 FitWindow();
121 m_Populated = true;
122 }
123 }
124
125
127 {
128 PluginDeveloperSync developer_sync = PluginDeveloperSync.Cast(GetPlugin(PluginDeveloperSync));
129 if (developer_sync.m_PlayerStatsSynced.Count() > 0)
130 {
131 for (int i = 0; i < developer_sync.m_PlayerStatsSynced.Count(); i++)
132 {
133 string stat_name = developer_sync.m_PlayerStatsSynced.Get(i).GetName();
134 float val_norm = developer_sync.m_PlayerStatsSynced.Get(i).GetValueNorm();
135 float value = developer_sync.m_PlayerStatsSynced.Get(i).GetValue();
136
137 if (stat_name == "BloodType")
138 {
139 string type, name;
140 bool positive;
141
142 name = value.ToString();
143 name += "(" + BloodTypes.GetBloodTypeName(Math.Round(value), type, positive) + ")";
144 m_StatValues.Get(i).SetText(name);
145 }
146 else
147 m_StatValues.Get(i).SetText(value.ToString());
148
149 if (!m_ChangingSlider)
150 m_SliderWidgets.GetKeyByValue(stat_name).SetCurrent(val_norm * 100);
151 /*
152 EditBoxWidget w;
153 w.
154 AddValue( developer_sync.m_PlayerStatsSynced.Get( i ).GetName(), developer_sync.m_PlayerStatsSynced.Get( i ).GetValue().ToString() );
155 */
156 }
157 }
158
159 }
160
161 /*
162
163 void AddValue( string title, string value )
164 {
165 int index = m_WgtValues.AddItem( title, NULL, 0 );
166 m_WgtValues.SetItem( index, value, NULL, 1 );
167 }
168 */
169
170 void AddValue(string title, string value)
171 {
172 Widget widget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/debug/day_z_hud_debug_stat.layout", m_WgtPanel);
173
174 TextWidget tw = TextWidget.Cast(widget.FindAnyWidget("StatName"));
175 tw.SetText(title);
176 m_StatWidgets.Insert(widget);
177
178 TextWidget tw_output = TextWidget.Cast(widget.FindAnyWidget("OutputValue"));
179 m_StatValues.Insert(tw_output);
180
181 EditBoxWidget ebw_input = EditBoxWidget.Cast(widget.FindAnyWidget("InputValue"));
182 m_StatValuesInput.Insert(ebw_input, title);
183
184 SliderWidget sw = SliderWidget.Cast(widget.FindAnyWidget("StatSlider"));
185 m_SliderWidgets.Insert(sw, title);
186
187
188 //int index = m_WgtValues.AddItem( title, NULL, 0 );
189 //m_WgtValues.SetItem( index, value, NULL, 1 );
190
192 m_WgtPanel.GetScript(WgtModifiersContent_panel_script);
194 }
195
197 {
198 m_StatWidgets.Clear();
199 //m_WgtValues.ClearItems();
200 }
201
203 {
204 TextListboxWidget wgt = TextListboxWidget.Cast(m_WgtPanel);
205 if (wgt)
207 }
208
209 bool OnClick(Widget w, int x, int y, int button)
210 {
211 if (w.GetName() == "ResetStats")
212 {
213 ResetStats();
214 return true;
215 }
216 return false;
217 }
218
219 bool OnChange(Widget w, int x, int y, bool finished)
220 {
221 if (m_StatValuesInput.Contains(EditBoxWidget.Cast(w)) && finished)
222 {
224 RPCChangeStat(m_StatValuesInput.Get(EditBoxWidget.Cast(w)), ebw.GetText().ToFloat());
225 return true;
226 }
227 if (m_SliderWidgets.Contains(SliderWidget.Cast(w)))
228 {
229 m_ChangingSlider = true;
230 string stat_name = m_SliderWidgets.Get(SliderWidget.Cast(w));
233 for (int i = 0; i < player.m_PlayerStats.GetPCO().Get().Count(); i++)
234 {
235 string label = player.m_PlayerStats.GetPCO().Get().Get(i).GetLabel();
236 if (label == stat_name)
237 {
238 float stat_min = player.m_PlayerStats.GetPCO().Get().Get(i).GetMin();
239 float stat_max = player.m_PlayerStats.GetPCO().Get().Get(i).GetMax();
240 float current_value_norm = sw.GetCurrent() / 100;
242
244 }
245 }
246 //Print("OnChange " + finished);
247 if (finished)
248 m_ChangingSlider = false;
249 }
250
251 return false;
252 }
253
254
256 {
258
259 //if client, send RPC
260
261 ref Param1<bool> params = new Param1<bool>(false);
262 if (player)
263 player.RPCSingleParam(ERPCs.DEV_RPC_STATS_RESET, params, true);
264 }
265
266 void RPCChangeStat(string stat, float value)
267 {
269
270 //if client, send RPC
271
273 if (player)
274 player.RPCSingleParam(ERPCs.DEV_RPC_STAT_SET, params, true);
275 }
276
277
278}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
ERPCs
Definition ERPCs.c:2
void HudDebug()
Definition HudDebug.c:104
Widget m_WgtRoot
Definition HudDebug.c:92
Icon x
Icon y
PlayerBase GetPlayer()
array< ref PlayerStatBase > Get()
PluginBase GetPlugin(typename plugin_type)
static string GetBloodTypeName(int bloodtype, out string type, out bool positive)
Definition BloodType.c:82
void RPCChangeStat(string stat, float value)
bool OnChange(Widget w, int x, int y, bool finished)
bool OnClick(Widget w, int x, int y, int button)
override void Show()
override void Hide()
void AddValue(string title, string value, string value2)
override void Update()
void FitWindowByContent(TextListboxWidget wgt)
void SetUpdate(bool state)
override int GetType()
TextListboxWidget m_WgtValues
void AddValue(string title, string value)
override void SetUpdate(bool state)
void HudDebugWinCharStats(Widget widget_root)
Definition EnMath.c:7
proto native CGame GetGame()
static proto float Round(float f)
Returns mathematical round of value.