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