Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
huddebugwincharmodifiers.c
Go to the documentation of this file.
2 {
3  string m_Name;
4  int m_ID;
5 
6  void DebugModifierData( string name, int id )
7  {
8  m_Name = name;
9  m_ID = id;
10  }
11 
12  string GetName()
13  {
14  return m_Name;
15  }
16 
17  int GetID()
18  {
19  return m_ID;
20  }
21 }
22 
24 {
25  protected Widget m_WgtModifiersContent;
28  protected PluginDeveloperSync m_PluginDeveloperSync;
31  protected int m_DetailedInfoIndex;
32 
33 //m_RPCSent
34 
35  //============================================
36  // HudDebugWinCharModifiers
37  //============================================
38  void HudDebugWinCharModifiers( Widget widget_root )
39  {
40  m_WgtRoot = widget_root;
41  m_WgtModifiersContent = Widget.Cast( m_WgtRoot.FindAnyWidget( "pnl_CharModifiers_Values" ) );
44  m_PluginDeveloperSync = PluginDeveloperSync.Cast( GetPlugin( PluginDeveloperSync ) );
45  }
46 
48  {
49  SetUpdate( false );
50  }
51 
52  //============================================
53  // GetWinType
54  //============================================
55  override int GetType()
56  {
57  return HudDebug.HUD_WIN_CHAR_MODIFIERS;
58  }
59 
60  //============================================
61  // Update
62  //============================================
63  override void SetUpdate( bool state )
64  {
65  //Disable update on server (PluginDeveloperSync)
66  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
67 
68  //if client, send RPC
69  if ( GetGame().IsClient() )
70  {
71  ref Param1<bool> params = new Param1<bool>( state );
72  if ( player )
73  {
74  player.RPCSingleParam( ERPCs.DEV_MODS_UPDATE, params, true );
75  SetRPCSent();
76  }
77  }
78  //else set directly
79  else
80  {
82  {
83  m_PluginDeveloperSync.EnableUpdate( state, ERPCs.DEV_MODS_UPDATE, player );
84  }
85  }
86  }
87 
88  override void Update()
89  {
90  super.Update();
91 
92  Refresh();
93  }
94 
95  //============================================
96  // Show / Hide
97  //============================================
98  override void Show()
99  {
100  super.Show();
101 
102  //Print("Show()");
103 
104  SetUpdate( true );
105  }
106 
107  override void Hide()
108  {
109  super.Hide();
110 
111  //Print("Hide()");
112 
113  SetUpdate( false );
114  }
115 
116  void Refresh()
117  {
118  SetModifiers();
119  if(m_WgtDetailedInfo && m_WgtDetailedInfo.IsVisible())
120  {
122  m_WgtDetailedInfoText = TextWidget.Cast(m_WgtDetailedInfo.FindAnyWidget( "TextWidget" ));
123  m_WgtDetailedInfoText.SetText(m_PluginDeveloperSync.m_PlayerModsDetailedSynced);
124  }
125  }
126 
127  //============================================
128  // FitWindow
129  //============================================
130  void FitWindow()
131  {
132  float title_size = 20;
133  float spacing = 20;
134 
135  //get wgt content size values
136  float wgt_content_size_x;
137  float wgt_content_size_y;
138  m_WgtModifiersContent.GetSize( wgt_content_size_x, wgt_content_size_y );
139 
140  //get wgt root size values
141  float wgt_root_size_x;
142  float wgt_root_size_y;
143  m_WgtRoot.GetSize( wgt_root_size_x, wgt_root_size_y );
144 
145  //calculate new Y size
146  float new_size_y = title_size + wgt_content_size_y + spacing;
147 
148  //set size
149  m_WgtRoot.SetSize( wgt_root_size_x, new_size_y );
150  }
151 
152  //============================================
153  // Display Modifiers
154  //============================================
156  {
157  //clear window
158  ClearModifiers();
159 
160  if ( m_PluginDeveloperSync.m_PlayerModsSynced.Count() > 0 )
161  {
162  //set active mods
163  for ( int i = 0; i < m_PluginDeveloperSync.m_PlayerModsSynced.Count(); ++i )
164  {
165  SyncedValueModifier synced_value = m_PluginDeveloperSync.m_PlayerModsSynced.Get( i );
166  AddModifier( synced_value.GetName(), synced_value.GetID(), synced_value.GetActive(),synced_value.GetLocked() );
167  }
168  }
169 
170  FitWindow();
171  }
172 
173  void AddModifier( string name, int id, bool active, bool locked )
174  {
175  //create widget
176  Widget widget = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/debug/day_z_hud_debug_modifier.layout", m_WgtModifiersContent );
177 
178  //add to widget array (for clearing purposes)
179  m_ModifierWidgets.Insert( widget );
180 
181  //set widget name
182  ButtonWidget mod_name_text = ButtonWidget.Cast( widget.FindAnyWidget( "TextModifierName" ) );
183  mod_name_text.SetText( name );
184  if ( active )
185  {
186  mod_name_text.SetTextColor( ARGB( 255, 0, 255, 0 ) );
187  }
188  else
189  {
190  mod_name_text.SetTextColor( ARGB( 255, 255, 0, 0 ) );
191  }
192 
193  //set set data for interactive parts (modifier ID should be enough)
194  DebugModifierData data = new DebugModifierData( name, id );
195 
196  Widget modifier_button = widget.FindAnyWidget( "TextModifierName" );
197  m_ModifierWidgetData.Insert( modifier_button, data );
198  //Activate button
199  Widget activate_button = widget.FindAnyWidget( "ButtonModifierActivate" );
200  m_ModifierWidgetData.Insert( activate_button, data );
201 
202  //Deactivate button
203  Widget deactivate_button = widget.FindAnyWidget( "ButtonModifierDeactivate" );
204  m_ModifierWidgetData.Insert( deactivate_button, data );
205 
206  //Lock checkbox
207  Widget checkbox_widget = widget.FindAnyWidget( "CheckBoxLock" );
208  m_ModifierWidgetData.Insert( checkbox_widget, data );
209  //set lock based on checkbox value
210  CheckBoxWidget checkbox = CheckBoxWidget.Cast( checkbox_widget );
211  checkbox.SetChecked( locked );
212 
213  AutoHeightSpacer WgtModifiersContent_panel_script;
214  m_WgtModifiersContent.GetScript( WgtModifiersContent_panel_script );
215  WgtModifiersContent_panel_script.Update();
216  }
217 
219  {
220  //clear widget data
221  m_ModifierWidgetData.Clear();
222 
223  //destroy all modifier widgets
224  for ( int i = 0; i < m_ModifierWidgets.Count(); ++i )
225  {
226  delete m_ModifierWidgets.Get( i );
227  }
228  m_ModifierWidgets.Clear();
229  }
230 
231  //============================================
232  // OnClick
233  //============================================
234  bool OnClick( Widget w, int x, int y, int button )
235  {
236  if ( w )
237  {
238  if ( w.GetName() == "TextModifierName" )
239  {
240  //Print("clicked");
241  DebugModifierData bc_data = m_ModifierWidgetData.Get( w );
242 
243  //Print( bc_data.GetID() );
244 
245  if(bc_data.GetID() == m_DetailedInfoIndex)//repeated request --> hide
246  {
247  if(m_WgtDetailedInfo && m_WgtDetailedInfo.IsVisible())
248  {
249  m_WgtDetailedInfo.Show(false);
250  }
252  }
253  else
254  {
255  if(!m_WgtDetailedInfo)
256  m_WgtDetailedInfo = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/debug/day_z_hud_debug_modifier_detailed.layout");
257  if(!m_WgtDetailedInfo.IsVisible())
258  {
259  m_WgtDetailedInfo.Show(true);
260  }
261  m_DetailedInfoIndex = bc_data.GetID();
262  }
264  m_WgtDetailedInfoText.SetText("");
265  m_PluginDeveloperSync.m_PlayerModsDetailedSynced = "";
266  RequestDetailedInfo( bc_data.GetID());
267  return true;
268  }
269  //Button activate
270  if ( w.GetName() == "ButtonModifierActivate" )
271  {
272  DebugModifierData ba_data = m_ModifierWidgetData.Get( w );
273 
274  //activate
275  ActivateModifier( ba_data.GetID() );
276 
277  //force update
278  m_PluginDeveloperSync.Update();
279 
280  return true;
281  }
282  //Button deactivate
283  else if ( w.GetName() == "ButtonModifierDeactivate" )
284  {
285  DebugModifierData bd_data = m_ModifierWidgetData.Get( w );
286 
287  //deactivate
288  DeactivateModifier( bd_data.GetID() );
289 
290  //force update
291  m_PluginDeveloperSync.Update();
292 
293  return true;
294  }
295  //Lock checkbox
296  else if ( w.GetName() == "CheckBoxLock" )
297  {
298  DebugModifierData lcb_data = m_ModifierWidgetData.Get( w );
299  CheckBoxWidget checkbox = CheckBoxWidget.Cast( w );
300 
301  //set lock
302  LockModifier( lcb_data.GetID(), checkbox.IsChecked() );
303 
304  //force update
305  m_PluginDeveloperSync.Update();
306 
307  return true;
308  }
309  else if ( w.GetName() == "ResetModifiers" )
310  {
311 
312  ResetModifiers();
313  return true;
314  }
315  }
316 
317  return false;
318  }
319 
320  //============================================
321  // Actions
322  //============================================
323 
325  {
326  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
327 
328  //if client, send RPC
329 
330  ref Param1<bool> params = new Param1<bool>( false );
331  if ( player )
332  {
333  player.RPCSingleParam( ERPCs.DEV_RPC_MODS_RESET, params, true );
334  }
335 
336 
337  }
338 
339 
340  void RequestDetailedInfo( int id )
341  {
342  //Disable update on server (PluginDeveloperSync)
343  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
344 
345  //if client, send RPC
346  if ( GetGame().IsClient() )
347  {
348  ref Param1<int> params = new Param1<int>( id );
349  if ( player )
350  {
351  player.RPCSingleParam( ERPCs.DEV_RPC_MODS_DETAILED, params, true );
352  }
353  }
354  //else set directly
355  else
356  {
357  m_PluginDeveloperSync.RequestDetailedInfo( id , player);
358  }
359  }
360 
361  void ActivateModifier( int id )
362  {
363  //Disable update on server (PluginDeveloperSync)
364  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
365 
366  //if client, send RPC
367  if ( GetGame().IsClient() )
368  {
369  ref Param1<int> params = new Param1<int>( id );
370  if ( player )
371  {
372  player.RPCSingleParam( ERPCs.DEV_RPC_MODS_ACTIVATE, params, true );
373  }
374  }
375  //else set directly
376  else
377  {
378  m_PluginDeveloperSync.ActivateModifier( id );
379  }
380  }
381 
382  void DeactivateModifier( int id )
383  {
384  //Disable update on server (PluginDeveloperSync)
385  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
386 
387  //if client, send RPC
388  if ( GetGame().IsClient() )
389  {
390  ref Param1<int> params = new Param1<int>( id );
391  if ( player )
392  {
393  player.RPCSingleParam( ERPCs.DEV_RPC_MODS_DEACTIVATE, params, true );
394  }
395  }
396  //else set directly
397  else
398  {
399  m_PluginDeveloperSync.DeactivateModifier( id );
400  }
401  }
402 
403  void LockModifier( int id, bool state )
404  {
405  //Disable update on server (PluginDeveloperSync)
406  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
407 
408  //if client, send RPC
409  if ( GetGame().IsClient() )
410  {
411  ref Param2<int, bool> params = new Param2<int, bool>( id, state );
412  if ( player )
413  {
414  player.RPCSingleParam( ERPCs.DEV_RPC_MODS_LOCK, params, true );
415  }
416  }
417  //else set directly
418  else
419  {
420  m_PluginDeveloperSync.LockModifier( id, state );
421  }
422  }
423 }
Param2
Definition: ppeconstants.c:66
GetGame
proto native CGame GetGame()
m_WgtRoot
Widget m_WgtRoot
Definition: huddebug.c:92
OnClick
bool OnClick(Widget w, int x, int y, int button)
Definition: huddebugwincharmodifiers.c:234
AutoHeightSpacer
Definition: autoheightspacer.c:2
SetModifiers
void SetModifiers()
Definition: huddebugwincharmodifiers.c:155
m_Name
string m_Name
Definition: bioslobbyservice.c:35
y
Icon y
ClearModifiers
void ClearModifiers()
Definition: huddebugwincharmodifiers.c:218
HudDebugWinBase
Definition: huddebugwinbase.c:1
Hide
override void Hide()
Definition: huddebugwincharmodifiers.c:107
SetUpdate
override void SetUpdate(bool state)
Definition: huddebugwincharmodifiers.c:63
m_ModifierWidgetData
protected ref map< Widget, ref DebugModifierData > m_ModifierWidgetData
Definition: huddebugwincharmodifiers.c:27
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
FitWindow
void FitWindow()
Definition: huddebugwincharmodifiers.c:130
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
m_ModifierWidgets
protected ref array< ref Widget > m_ModifierWidgets
Definition: huddebugwincharmodifiers.c:26
TextWidget
Definition: enwidgets.c:219
m_PluginDeveloperSync
protected PluginDeveloperSync m_PluginDeveloperSync
Definition: huddebugwincharmodifiers.c:28
m_WgtDetailedInfo
protected Widget m_WgtDetailedInfo
Definition: huddebugwincharmodifiers.c:29
Refresh
void Refresh()
Definition: huddebugwincharmodifiers.c:116
AddModifier
void AddModifier(string name, int id, bool active, bool locked)
Definition: huddebugwincharmodifiers.c:173
ResetModifiers
void ResetModifiers()
Definition: huddebugwincharmodifiers.c:324
GetType
override int GetType()
Definition: huddebugwincharmodifiers.c:55
DebugModifierData
Definition: huddebugwincharmodifiers.c:1
m_DetailedInfoIndex
protected int m_DetailedInfoIndex
Definition: huddebugwincharmodifiers.c:31
array< ref Widget >
Update
override void Update()
Definition: huddebugwincharmodifiers.c:88
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
~HudDebugWinCharModifiers
void ~HudDebugWinCharModifiers()
Definition: huddebugwincharmodifiers.c:47
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
RequestDetailedInfo
void RequestDetailedInfo(int id)
Definition: huddebugwincharmodifiers.c:340
HudDebug
void HudDebug()
Definition: huddebug.c:104
LockModifier
void LockModifier(int id, bool state)
Definition: huddebugwincharmodifiers.c:403
ERPCs
ERPCs
Definition: erpcs.c:1
Widget
Definition: enwidgets.c:189
Show
override void Show()
Definition: huddebugwincharmodifiers.c:98
ActivateModifier
void ActivateModifier(int id)
Definition: huddebugwincharmodifiers.c:361
m_WgtDetailedInfoText
protected TextWidget m_WgtDetailedInfoText
Definition: huddebugwincharmodifiers.c:30
SyncedValueModifier
Definition: syncedvalue.c:67
DeactivateModifier
void DeactivateModifier(int id)
Definition: huddebugwincharmodifiers.c:382
m_ID
protected int m_ID
ID of effect, given by SEffectManager when registered (automatically done when playing through it)
Definition: effect.c:49
ARGB
int ARGB(int a, int r, int g, int b)
Definition: proto.c:322
m_WgtModifiersContent
class DebugModifierData m_WgtModifiersContent
HudDebugWinCharModifiers
void HudDebugWinCharModifiers(Widget widget_root)
Definition: huddebugwincharmodifiers.c:38