DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
HudDebugWinCharAgents.c
Go to the documentation of this file.
2{
3 string m_Name;
4 int m_ID;
5
6 void DebugAgentData( 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
23
25{
29 //============================================
30 // HudDebugWinCharAgents
31 //============================================
32 void HudDebugWinCharAgents( Widget widget_root )
33 {
34 m_WgtRoot = widget_root;
35 //m_WgtAgents = TextListboxWidget.Cast( m_WgtRoot.FindAnyWidget( "txl_CharAgents_Values" ) );
36 m_WgtAgents = m_WgtRoot.FindAnyWidget( "AgentList" );
37
38 //FitWindowByContent( m_WgtAgents );
39 }
40
42 {
43 SetUpdate( false );
44 }
45
46 //============================================
47 // GetWinType
48 //============================================
49 override int GetType()
50 {
51 return HudDebug.HUD_WIN_CHAR_AGENTS;
52 }
53
54 //============================================
55 // Update
56 //============================================
57 override void SetUpdate( bool state )
58 {
59 //Disable update on server (PluginDeveloperSync)
60 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
61 PluginDeveloperSync developer_sync = PluginDeveloperSync.Cast( GetPlugin( PluginDeveloperSync ) );
62
63 //if client, send RPC
64 if ( GetGame().IsClient() )
65 {
66 ref Param1<bool> params = new Param1<bool>( state );
67 if ( player )
68 {
69 player.RPCSingleParam( ERPCs.DEV_AGENTS_UPDATE, params, true );
70 SetRPCSent();
71 }
72 }
73 //else set directly
74 else
75 {
76 if ( developer_sync )
77 {
78 developer_sync.EnableUpdate( state, ERPCs.DEV_AGENTS_UPDATE, player );
79 }
80 }
81 }
82
83 override void Update()
84 {
85 super.Update();
86
87 //Print("Update()");
88
89 //refresh notifiers
90 SetAgents();
91 }
92
93 //============================================
94 // Show / Hide
95 //============================================
96 override void Show()
97 {
98 super.Show();
99
100 //Print("Show()");
101
102 SetUpdate( true );
103 }
104
105 override void Hide()
106 {
107 super.Hide();
108
109 //Print("Hide()");
110
111 SetUpdate( false );
112 }
113
115 {
116 PluginDeveloperSync developer_sync = PluginDeveloperSync.Cast( GetPlugin( PluginDeveloperSync ) );
117
118 //clear window
119 ClearAgents();
120
121 //set agents
122 if ( developer_sync.m_PlayerAgentsSynced.Count() > 0 )
123 {
124 for ( int i = 0; i < developer_sync.m_PlayerAgentsSynced.Count(); i++ )
125 {
126 AddAgent( developer_sync.m_PlayerAgentsSynced.Get( i ).GetName(), developer_sync.m_PlayerAgentsSynced.Get( i ).GetValue(), developer_sync.m_PlayerAgentsSynced.Get( i ).GetID() );
127 }
128 }
129
130 //fit to screen
131 //FitWindow();
132 }
133
134 /*
135 void AddAgent( string title, string value )
136 {
137 int index = m_WgtAgents.AddItem( title, NULL, 0 );
138 m_WgtAgents.SetItem( index, value, NULL, 1 );
139 }
140 */
141 bool OnClick( Widget w, int x, int y, int button )
142 {
143 //Button activate
144 DebugAgentData data;
145 if ( w.GetName() == "ButtonAgentActivate" )
146 {
147 data = m_AgentWidgetData.Get( w );
148 DebugGrowAgentsRequest(data.GetID(), true);
149 //Print("activate" + data.GetID().ToString());
150 return true;
151 }
152 //Button deactivate
153 else if ( w.GetName() == "ButtonAgentDeactivate" )
154 {
155 data = m_AgentWidgetData.Get( w );
156 DebugGrowAgentsRequest(data.GetID(), false);
157 //Print("deactivate" + data.GetID().ToString());
158 return true;
159 }
160 else if ( w.GetName() == "ResetAgents" )
161 {
163 return true;
164 }
165
166
167 return false;
168 }
169
170 void DebugGrowAgentsRequest(int agent_id, bool should_grow)
171 {
172 if(!should_grow)//id is minus value to mark killing instead of growing
173 {
174 agent_id *= -1;
175 }
176
177 ref Param1<int> p1 = new Param1<int>( agent_id );
178 Man man = GetGame().GetPlayer();
179 man.RPCSingleParam(ERPCs.DEV_AGENT_GROW, p1, true, man.GetIdentity());
180 }
181
183 {
184 ref Param1<bool> p1 = new Param1<bool>( false );
185 Man man = GetGame().GetPlayer();
186 man.RPCSingleParam(ERPCs.DEV_RPC_AGENT_RESET, p1, true, man.GetIdentity());
187 }
188
189 void AddAgent( string title, string value, int id )
190 {
191 Widget widget = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/debug/day_z_hud_debug_agent.layout", m_WgtAgents );
192 ButtonWidget btn = ButtonWidget.Cast( widget.FindAnyWidget( "TextAgentName" ) );
193
194
195 DebugAgentData data = new DebugAgentData( "", id );
196 m_AgentWidgetData.Insert(btn, data);
197
198 Widget activate_button = widget.FindAnyWidget( "ButtonAgentActivate" );
199 m_AgentWidgetData.Insert( activate_button, data );
200
201 TextWidget count_widget = TextWidget.Cast(widget.FindAnyWidget( "TextWidgetAgentCount" ));
202 m_AgentWidgetData.Insert( count_widget, data );
203 count_widget.SetText(value);
204
205 //Deactivate button
206 Widget deactivate_button = widget.FindAnyWidget( "ButtonAgentDeactivate" );
207 m_AgentWidgetData.Insert( deactivate_button, data );
208
209 btn.SetText(title);
210 m_AgentWidgets.Insert(widget);
211
212 AutoHeightSpacer WgtModifiersContent_panel_script;
213 m_WgtAgents.GetScript( WgtModifiersContent_panel_script );
214 WgtModifiersContent_panel_script.Update();
215 }
216
218 {
219 m_AgentWidgetData.Clear();
220 for ( int i = 0; i < m_AgentWidgets.Count(); i++ )
221 {
222 delete m_AgentWidgets.Get( i );
223 }
224
225 m_AgentWidgets.Clear();
226 }
227
229 {
230 FitWindowByContent( TextListboxWidget.Cast(m_WgtAgents) );
231 }
232}
ERPCs
Definition ERPCs.c:2
void HudDebug()
Definition HudDebug.c:104
Widget m_WgtRoot
Definition HudDebug.c:92
void HudDebugWinCharAgents(Widget widget_root)
protected ref array< ref Widget > m_AgentWidgets
void ClearAgents()
void ~HudDebugWinCharAgents()
protected ref map< Widget, ref DebugAgentData > m_AgentWidgetData
void SetAgents()
void AddAgent(string title, string value, int id)
void DebugGrowAgentsRequest(int agent_id, bool should_grow)
class DebugAgentData m_WgtAgents
void DebugRemoveAgentsRequest()
Icon x
Icon y
PlayerBase GetPlayer()
string name
PluginBase GetPlugin(typename plugin_type)
proto native DayZPlayer GetPlayer()
proto native WorkspaceWidget GetWorkspace()
void DebugAgentData(string name, int id)
void SetUpdate(bool state)
bool OnClick(Widget w, int x, int y, int button)
void FitWindowByContent(TextListboxWidget wgt)
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.