DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
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{
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 //============================================
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
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 {
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
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}
ERPCs
Definition ERPCs.c:2
void HudDebug()
Definition HudDebug.c:104
Widget m_WgtRoot
Definition HudDebug.c:92
void HudDebugWinCharModifiers(Widget widget_root)
protected ref map< Widget, ref DebugModifierData > m_ModifierWidgetData
void ClearModifiers()
protected PluginDeveloperSync m_PluginDeveloperSync
protected ref array< ref Widget > m_ModifierWidgets
protected TextWidget m_WgtDetailedInfoText
void ResetModifiers()
class DebugModifierData m_WgtModifiersContent
void ~HudDebugWinCharModifiers()
void RequestDetailedInfo(int id)
void SetModifiers()
protected int m_DetailedInfoIndex
protected Widget m_WgtDetailedInfo
void LockModifier(int id, bool state)
Icon x
Icon y
PlayerBase GetPlayer()
void DeactivateModifier(int modifier_id, bool triggerEvent=true)
void ActivateModifier(int modifier_id, bool triggerEvent=EActivationType.TRIGGER_EVENT_ON_ACTIVATION)
void AddModifier(ModifierBase modifier)
string name
PluginBase GetPlugin(typename plugin_type)
void Refresh()
proto native WorkspaceWidget GetWorkspace()
void DebugModifierData(string name, int id)
protected PluginDeveloperSync m_PluginDeveloperSync
void SetUpdate(bool state)
bool OnClick(Widget w, int x, int y, int button)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.
int ARGB(int a, int r, int g, int b)
Definition proto.c:322