DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
HudDebugWinCharStats.c
Go to the documentation of this file.
1class HudDebugWinCharStats extends HudDebugWinBase
2{
3 TextListboxWidget m_WgtValues;
5 ref array<ref Widget> m_StatWidgets = new array<ref Widget>;
6 ref map <ref SliderWidget, string> m_SliderWidgets = new map<ref SliderWidget, string>;
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 //============================================
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 //Print("panel:" + m_WgtPanel);
98 //Print("Update()");
99
100 //refresh notifiers
101
102
103 if(!m_Populated)
104 SetupValues();
105
106 UpdateValues();
107 }
108
110 {
111 PluginDeveloperSync developer_sync = PluginDeveloperSync.Cast( GetPlugin( PluginDeveloperSync ) );
112
113 //clear window
114 //ClearValues();
115
116 if ( developer_sync.m_PlayerStatsSynced.Count() > 0 )
117 {
118 //set
119 for ( int i = 0; i < developer_sync.m_PlayerStatsSynced.Count(); i++ )
120 {
121 AddValue( developer_sync.m_PlayerStatsSynced.Get( i ).GetName(), developer_sync.m_PlayerStatsSynced.Get( i ).GetValue().ToString() );
122 }
123 //fit to screen
124 FitWindow();
125 m_Populated = true;
126 }
127 }
128
129
131 {
132 PluginDeveloperSync developer_sync = PluginDeveloperSync.Cast( GetPlugin( PluginDeveloperSync ) );
133 if ( developer_sync.m_PlayerStatsSynced.Count() > 0 )
134 {
135 for ( int i = 0; i < developer_sync.m_PlayerStatsSynced.Count(); i++ )
136 {
137 string stat_name = developer_sync.m_PlayerStatsSynced.Get( i ).GetName();
138 float val_norm = developer_sync.m_PlayerStatsSynced.Get( i ).GetValueNorm();
139 float value = developer_sync.m_PlayerStatsSynced.Get( i ).GetValue();
140
141 if( stat_name == "BloodType" )
142 {
143 string type, name;
144 bool positive;
145
146 name = value.ToString();
147 name += "("+BloodTypes.GetBloodTypeName( Math.Round(value), type, positive)+")";
148 m_StatValues.Get(i).SetText(name);
149 }
150 else
151 {
152 m_StatValues.Get(i).SetText(value.ToString());
153
154 }
155 if(!m_ChangingSlider)
156 m_SliderWidgets.GetKeyByValue(stat_name).SetCurrent(val_norm * 100);
157 /*
158 EditBoxWidget w;
159 w.
160 AddValue( developer_sync.m_PlayerStatsSynced.Get( i ).GetName(), developer_sync.m_PlayerStatsSynced.Get( i ).GetValue().ToString() );
161 */
162 }
163 }
164
165 }
166
167 /*
168
169 void AddValue( string title, string value )
170 {
171 int index = m_WgtValues.AddItem( title, NULL, 0 );
172 m_WgtValues.SetItem( index, value, NULL, 1 );
173 }
174 */
175
176 void AddValue( string title, string value )
177 {
178 Widget widget = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/debug/day_z_hud_debug_stat.layout", m_WgtPanel );
179
180 TextWidget tw = TextWidget.Cast(widget.FindAnyWidget("StatName"));
181 tw.SetText(title);
182 m_StatWidgets.Insert(widget);
183
184 TextWidget tw_output = TextWidget.Cast(widget.FindAnyWidget("OutputValue"));
185 m_StatValues.Insert(tw_output);
186
187 EditBoxWidget ebw_input = EditBoxWidget.Cast(widget.FindAnyWidget("InputValue"));
188 m_StatValuesInput.Insert(ebw_input, title );
189
190 SliderWidget sw = SliderWidget.Cast(widget.FindAnyWidget("StatSlider"));
191 m_SliderWidgets.Insert(sw,title );
192
193
194 //int index = m_WgtValues.AddItem( title, NULL, 0 );
195 //m_WgtValues.SetItem( index, value, NULL, 1 );
196
197 AutoHeightSpacer WgtModifiersContent_panel_script;
198 m_WgtPanel.GetScript( WgtModifiersContent_panel_script );
199 WgtModifiersContent_panel_script.Update();
200 }
201
203 {
204 m_StatWidgets.Clear();
205 //m_WgtValues.ClearItems();
206 }
207
209 {
210 TextListboxWidget wgt = TextListboxWidget.Cast(m_WgtPanel);
211 if(wgt)
212 FitWindowByContent( wgt );
213 }
214
215 bool OnClick( Widget w, int x, int y, int button )
216 {
217 if ( w.GetName() == "ResetStats" )
218 {
219 ResetStats();
220 return true;
221 }
222 return false;
223 }
224
225 bool OnChange(Widget w, int x, int y, bool finished)
226 {
227 if ( m_StatValuesInput.Contains(EditBoxWidget.Cast(w)) && finished )
228 {
229 EditBoxWidget ebw = EditBoxWidget.Cast(w);
230 RPCChangeStat(m_StatValuesInput.Get(EditBoxWidget.Cast(w)), ebw.GetText().ToFloat());
231 return true;
232 }
233 if (m_SliderWidgets.Contains(SliderWidget.Cast(w)))
234 {
235 m_ChangingSlider = true;
236 string stat_name = m_SliderWidgets.Get(SliderWidget.Cast(w));
237 SliderWidget sw = SliderWidget.Cast(w);
238 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
239 for ( int i = 0; i < player.m_PlayerStats.GetPCO().Get().Count(); i++ )
240 {
241 string label = player.m_PlayerStats.GetPCO().Get().Get( i ).GetLabel();
242 if(label == stat_name)
243 {
244 float stat_min = player.m_PlayerStats.GetPCO().Get().Get( i ).GetMin();
245 float stat_max = player.m_PlayerStats.GetPCO().Get().Get( i ).GetMax();
246 float current_value_norm = sw.GetCurrent() / 100;
247 float current_value_abs = stat_min + (stat_max - stat_min) * current_value_norm;
248
249 RPCChangeStat(label, current_value_abs);
250 }
251 }
252 //Print("OnChange " + finished);
253 if(finished)
254 m_ChangingSlider = false;
255 }
256
257 return false;
258 }
259
260
262 {
263 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
264
265 //if client, send RPC
266
267 ref Param1<bool> params = new Param1<bool>( false );
268 if ( player )
269 {
270 player.RPCSingleParam( ERPCs.DEV_RPC_STATS_RESET, params, true );
271 }
272 }
273
274 void RPCChangeStat(string stat, float value)
275 {
276 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
277
278 //if client, send RPC
279
280 ref Param2<string, float> params = new Param2<string, float>( stat, value );
281 if ( player )
282 {
283 player.RPCSingleParam( ERPCs.DEV_RPC_STAT_SET, params, true );
284 }
285 }
286
287
288}
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()
string name
PluginBase GetPlugin(typename plugin_type)
static string GetBloodTypeName(int bloodtype, out string type, out bool positive)
Definition BloodType.c:89
proto native WorkspaceWidget GetWorkspace()
override void Hide()
override void SetUpdate(bool state)
void HudDebugWinCharStats(Widget widget_root)
TextListboxWidget m_WgtValues
void AddValue(string title, string value)
void AddValue(string title, string value, string value2)
override void Update()
override int GetType()
void SetUpdate(bool state)
bool OnClick(Widget w, int x, int y, int button)
override void Show()
void RPCChangeStat(string stat, float value)
bool OnChange(Widget w, int x, int y, bool finished)
void FitWindowByContent(TextListboxWidget wgt)
Definition EnMath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto string ToString()
proto native CGame GetGame()
static proto float Round(float f)
Returns mathematical round of value.
string Get(int index)
Gets n-th character from string.
Definition EnString.c:434
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.