Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
huddebugwincharstats.c
Go to the documentation of this file.
1 class 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  //Print("panel:" + m_WgtPanel);
98  //Print("Update()");
99 
100  //refresh notifiers
101 
102 
103  if(!m_Populated)
104  SetupValues();
105 
106  UpdateValues();
107  }
108 
109  void SetupValues()
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 
130  void UpdateValues()
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 
202  void ClearValues()
203  {
204  m_StatWidgets.Clear();
205  //m_WgtValues.ClearItems();
206  }
207 
208  void FitWindow()
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 
261  void ResetStats()
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 }
Param2< string, float >
GetGame
proto native CGame GetGame()
m_WgtRoot
Widget m_WgtRoot
Definition: huddebug.c:92
AutoHeightSpacer
Definition: autoheightspacer.c:2
FitWindow
void FitWindow()
Definition: huddebugwincharagents.c:228
Show
proto native void Show(bool show, bool immedUpdate=true)
SetUpdate
override void SetUpdate(bool state)
Definition: huddebugwincharagents.c:57
EditBoxWidget
Definition: enwidgets.c:353
y
Icon y
HudDebugWinBase
Definition: huddebugwinbase.c:1
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
TextWidget
Definition: enwidgets.c:219
BloodTypes
Definition: bloodtype.c:1
Get
array< ref PlayerStatBase > Get()
Definition: playerstatspco.c:103
array< ref Widget >
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
HudDebug
void HudDebug()
Definition: huddebug.c:104
ERPCs
ERPCs
Definition: erpcs.c:1
OnChange
bool OnChange(Widget w, int x, int y, bool finished)
Definition: huddebug.c:336
Widget
Definition: enwidgets.c:189
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
Math
Definition: enmath.c:6
Hide
void Hide()
Definition: dayzgame.c:165
GetType
override int GetType()
Definition: huddebugwincharagents.c:49
Count
@ Count
Definition: randomgeneratorsyncmanager.c:7