Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
huddebugwincharstats.c
Go to the documentation of this file.
1class HudDebugWinCharStats extends HudDebugWinBase
2{
3 TextListboxWidget m_WgtValues;
4 Widget m_WgtPanel;
5 ref array<ref Widget> m_StatWidgets = new array<ref Widget>;
7 ref array<ref TextWidget> m_StatValues = new array<ref TextWidget>;
9 bool m_Populated;
10 bool m_ChangingSlider;
11
12 //============================================
13 // Constructor
14 //============================================
15 void HudDebugWinCharStats(Widget widget_root)
16 {
17 m_WgtRoot = widget_root;
18 m_WgtPanel = Widget.Cast(m_WgtRoot.FindAnyWidget("Stats") );
19 //FitWindow();
20 }
21
22 //============================================
23 // Destructor
24 //============================================
25 void ~HudDebugWinCharStats()
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)
69 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
70
71 PluginDeveloperSync developer_sync = PluginDeveloperSync.Cast( GetPlugin( PluginDeveloperSync ) );
72
73 //if client, send RPC
74 if ( GetGame().IsClient() )
75 {
76 ref Param1<bool> params = new Param1<bool>( state );
77 if ( player )
78 {
79 player.RPCSingleParam( ERPCs.DEV_STATS_UPDATE, params, true );
80 SetRPCSent();
81 }
82 }
83 //else set directly
84 else
85 {
86 if ( developer_sync )
87 {
88 developer_sync.EnableUpdate( state, ERPCs.DEV_STATS_UPDATE, player );
89 }
90 }
91 }
92
93
94 override void Update()
95 {
96 super.Update();
97
98 if (!m_Populated)
99 SetupValues();
100
101 UpdateValues();
102 }
103
104 void SetupValues()
105 {
106 PluginDeveloperSync developerSync = PluginDeveloperSync.Cast(GetPlugin(PluginDeveloperSync));
107
108 //clear window
109 //ClearValues();
110
111 if ( developerSync.m_PlayerStatsSynced.Count() > 0 )
112 {
113 foreach (SyncedValue syncedValue : developerSync.m_PlayerStatsSynced)
114 {
115 string name = syncedValue.GetName();
116 string value = syncedValue.GetValue().ToString();
117
118 AddValue(name, value);
119 }
120
121 FitWindow();
122 m_Populated = true;
123 }
124 }
125
126
127 void UpdateValues()
128 {
129 PluginDeveloperSync developerSync = PluginDeveloperSync.Cast( GetPlugin( PluginDeveloperSync ) );
130 if ( developerSync.m_PlayerStatsSynced.Count() > 0 )
131 {
132 foreach (int i, SyncedValue syncedValue : developerSync.m_PlayerStatsSynced)
133 {
134 string statName = syncedValue.GetName();
135 float valueNormalized = syncedValue.GetValueNorm();
136 float value = syncedValue.GetValue();
137
138 if ( statName == "BloodType" )
139 {
140 string type, name;
141 bool positive;
142
143 name = value.ToString();
144 name += "("+BloodTypes.GetBloodTypeName(Math.Round(value), type, positive)+")";
145 m_StatValues.Get(i).SetText(name);
146 }
147 else
148 {
149 if (statName == "HeatBuffer")
150 {
151 float heatBufferNormalized = Math.Round(Math.Lerp(-1, 1, valueNormalized) * 1000) * 0.001;
152 m_StatValues.Get(i).SetText(string.Format("%1 (%2)", heatBufferNormalized.ToString(), value.ToString()));
153 }
154 else
155 m_StatValues.Get(i).SetText(value.ToString());
156
157 }
158
159 if (!m_ChangingSlider)
160 m_SliderWidgets.GetKeyByValue(statName).SetCurrent(valueNormalized * 100);
161 }
162 }
163
164 }
165
166 void AddValue(string title, string value)
167 {
168 Widget widget = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/debug/day_z_hud_debug_stat.layout", m_WgtPanel );
169
170 TextWidget tw = TextWidget.Cast(widget.FindAnyWidget("StatName"));
171 tw.SetText(title);
172 m_StatWidgets.Insert(widget);
173
174 TextWidget tw_output = TextWidget.Cast(widget.FindAnyWidget("OutputValue"));
175 m_StatValues.Insert(tw_output);
176
177 EditBoxWidget ebw_input = EditBoxWidget.Cast(widget.FindAnyWidget("InputValue"));
178 m_StatValuesInput.Insert(ebw_input, title );
179
180 SliderWidget sw = SliderWidget.Cast(widget.FindAnyWidget("StatSlider"));
181 m_SliderWidgets.Insert(sw,title );
182
183 AutoHeightSpacer WgtModifiersContent_panel_script;
184 m_WgtPanel.GetScript( WgtModifiersContent_panel_script );
185 WgtModifiersContent_panel_script.Update();
186 }
187
188 void ClearValues()
189 {
190 m_StatWidgets.Clear();
191 }
192
193 void FitWindow()
194 {
195 TextListboxWidget wgt = TextListboxWidget.Cast(m_WgtPanel);
196 if(wgt)
197 FitWindowByContent( wgt );
198 }
199
200 bool OnClick( Widget w, int x, int y, int button )
201 {
202 if ( w.GetName() == "ResetStats" )
203 {
204 ResetStats();
205 return true;
206 }
207
208 return false;
209 }
210
211 bool OnChange(Widget w, int x, int y, bool finished)
212 {
213 if ( m_StatValuesInput.Contains(EditBoxWidget.Cast(w)) && finished )
214 {
215 EditBoxWidget ebw = EditBoxWidget.Cast(w);
216 RPCChangeStat(m_StatValuesInput.Get(EditBoxWidget.Cast(w)), ebw.GetText().ToFloat());
217 return true;
218 }
219 if (m_SliderWidgets.Contains(SliderWidget.Cast(w)))
220 {
221 m_ChangingSlider = true;
222 string stat_name = m_SliderWidgets.Get(SliderWidget.Cast(w));
223 SliderWidget sw = SliderWidget.Cast(w);
224 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
225 for ( int i = 0; i < player.m_PlayerStats.GetPCO().Get().Count(); i++ )
226 {
227 string label = player.m_PlayerStats.GetPCO().Get().Get( i ).GetLabel();
228 if(label == stat_name)
229 {
230 float stat_min = player.m_PlayerStats.GetPCO().Get().Get( i ).GetMin();
231 float stat_max = player.m_PlayerStats.GetPCO().Get().Get( i ).GetMax();
232 float current_value_norm = sw.GetCurrent() / 100;
233 float current_value_abs = stat_min + (stat_max - stat_min) * current_value_norm;
234
235 RPCChangeStat(label, current_value_abs);
236 }
237 }
238 //Print("OnChange " + finished);
239 if(finished)
240 m_ChangingSlider = false;
241 }
242
243 return false;
244 }
245
246
247 void ResetStats()
248 {
249 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
250
251 //if client, send RPC
252
253 ref Param1<bool> params = new Param1<bool>( false );
254 if ( player )
255 {
256 player.RPCSingleParam( ERPCs.DEV_RPC_STATS_RESET, params, true );
257 }
258 }
259
260 void RPCChangeStat(string stat, float value)
261 {
262 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
263
264 //if client, send RPC
265
266 ref Param2<string, float> params = new Param2<string, float>( stat, value );
267 if ( player )
268 {
269 player.RPCSingleParam( ERPCs.DEV_RPC_STAT_SET, params, true );
270 }
271 }
272
273
274}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
void FitWindowByContent(TextListboxWidget wgt)
void SetUpdate(bool state)
Definition enmath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition dayzgame.c:151
ERPCs
Definition erpcs.c:2
proto native CGame GetGame()
void HudDebug()
Definition huddebug.c:108
Widget m_WgtRoot
Definition huddebug.c:94
Widget m_WgtPanel
Icon x
Icon y
PlayerBase GetPlayer()
override float Get()
override bool OnChange(Widget w, int x, int y, bool finished)
PluginBase GetPlugin(typename plugin_type)