File size: 4,026 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
class HudDebugWinCharStomach extends HudDebugWinBase
{
	TextListboxWidget				m_WgtValues;
	TextWidget						m_WgtOverall;
	
	//============================================
	// Constructor
	//============================================
	void HudDebugWinCharStomach(Widget widget_root)
	{	
		m_WgtValues = TextListboxWidget.Cast( widget_root.FindAnyWidget("txl_StomachContents") );
		m_WgtOverall = TextWidget.Cast( widget_root.FindAnyWidget("InfoOverall") );
		//FitWindow();
	}

	//============================================
	// Destructor
	//============================================
	void ~HudDebugWinCharStomach()
	{	
		SetUpdate( false );
	}


	//============================================
	// GetWinType
	//============================================
	override int GetType()
	{
		return HudDebug.HUD_WIN_CHAR_STOMACH;
	}
	
	//============================================
	// Show 
	//============================================
	override void Show()
	{
		super.Show();
		
		//Print("Show()");
		
		SetUpdate( true );
	}

	//============================================
	// Hide 
	//============================================
	override void Hide()
	{
		super.Hide();
		
		//Print("Hide()");
		
		SetUpdate( false );
	}

	//============================================
	// SetUpdate
	//============================================
	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_STOMACH_UPDATE, params, true );
				SetRPCSent();
			}
		}
		//else set directly
		else
		{
			if ( developer_sync )
			{
				developer_sync.EnableUpdate( state, ERPCs.DEV_STOMACH_UPDATE, player );	
			}
		}
	}


	override void Update()
	{
		super.Update();
		
		//Print("Update()");
		
		//refresh notifiers
		SetContentValues();
	}
	
	
	void SetContentValues()
	{
		PluginDeveloperSync developer_sync = PluginDeveloperSync.Cast( GetPlugin( PluginDeveloperSync ) );
		
		//clear window
		ClearValues();
			
		for ( int i = 0; i < developer_sync.m_PlayerStomachSynced.Count() - 1; i++ )
		{
			//new Param4<int,int,int,float>(id, food_stage, agents, amount);
			Param4<int,int,int,float> p4 = Param4<int,int,int,float>.Cast(developer_sync.m_PlayerStomachSynced.Get(i));
			AddValue( PlayerStomach.GetClassnameFromID(p4.param1), p4.param2, p4.param3, p4.param4);
		}
		
		if( developer_sync.m_PlayerStomachSynced.Count() )
		{
			int last_index = developer_sync.m_PlayerStomachSynced.Count() - 1;
			Param1<float> p1 = Param1<float>.Cast(developer_sync.m_PlayerStomachSynced.Get(last_index));
			m_WgtOverall.SetText("Overall volume:" + p1.param1.ToString());
		}
		else
		{
			m_WgtOverall.SetText("");
		}
		
		
		
		//fit to screen
		//FitWindow();
	}

	void AddValue( string classname, int food_stage, int agents, float amount)
	{
		int index = m_WgtValues.AddItem( classname, NULL, 0 );
		string stage = typename.EnumToString(FoodStageType, food_stage) + "(" + food_stage.ToString()+")";;
		m_WgtValues.SetItem( index, amount.ToString(), NULL, 1 );
		m_WgtValues.SetItem( index,stage , NULL, 2 );
		array<string> agent_list = GetAgentsArray(agents);
		string agent_line = "("+agents.ToString()+") ";
		
		for(int i = 0; i < agent_list.Count();i++)
		{
			agent_line +=  "," +agent_list.Get(i);
		}
		
		m_WgtValues.SetItem( index, agent_line , NULL, 3);
	}
	
	array<string> GetAgentsArray(int agents)
	{
		array<string> list = new array<string>;
		for(int i = 0; i < 32; i++)
		{
			int agent = agents & (1 << i);
			if(agent)
			{
				list.Insert(PluginTransmissionAgents.GetNameByID(agent));
			}
		}
		return list;
	}

	void ClearValues()
	{
		m_WgtValues.ClearItems();
	}

	void FitWindow()
	{
		FitWindowByContent( m_WgtValues );
	}
}