aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/client/hud_vote.h
blob: 38956366bb20d5c34353508d2b8e7ffd4357945c (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef HUD_VOTE_H
#define HUD_VOTE_H
#ifdef _WIN32
#pragma once
#endif

#include "hudelement.h"
#include <vgui_controls/EditablePanel.h>
#include <vgui_controls/SectionedListPanel.h>
#include <vgui_controls/Frame.h>
#include <vgui_controls/Button.h>
#include <networkstringtabledefs.h>

extern INetworkStringTable *g_pStringTableServerMapCycle;

#ifdef TF_CLIENT_DLL
extern INetworkStringTable *g_pStringTableServerPopFiles;
extern INetworkStringTable *g_pStringTableServerMapCycleMvM;
#endif

static const int k_MAX_VOTE_NAME_LENGTH = 256;

namespace vgui
{
	class SectionedListPanel;
	class ComboBox;
	class ImageList;
};

struct VoteIssue_t
{
	char szName[k_MAX_VOTE_NAME_LENGTH];
	char szNameString[k_MAX_VOTE_NAME_LENGTH];
	bool bIsActive;
};

class VoteBarPanel : public vgui::Panel, public CGameEventListener
{
	DECLARE_CLASS_SIMPLE( VoteBarPanel, vgui::Panel );

	VoteBarPanel( vgui::Panel *parent, const char *panelName );

	virtual void Paint( void );
	virtual void FireGameEvent( IGameEvent *event );

private:
	int m_nVoteOptionCount[MAX_VOTE_OPTIONS];	// Vote options counter
	int m_nPotentialVotes;						// If set, draw a line at this point to show the required bar length

	CPanelAnimationVarAliasType( int, m_iBoxSize, "box_size", "16", "proportional_int" );
	CPanelAnimationVarAliasType( int, m_iSpacer, "spacer", "4", "proportional_int" );
	CPanelAnimationVarAliasType( int, m_iBoxInset, "box_inset", "1", "proportional_int" );
	CPanelAnimationVarAliasType( int, m_nYesTextureId, "yes_texture", "vgui/hud/vote_yes", "textureid" );
	CPanelAnimationVarAliasType( int, m_nNoTextureId, "no_texture", "vgui/hud/vote_no", "textureid" );
};

//-----------------------------------------------------------------------------
// Purpose: A selection UI for votes that require additional parameters - such as players, maps
//-----------------------------------------------------------------------------

class CVoteSetupDialog : public vgui::Frame
{
	DECLARE_CLASS_SIMPLE( CVoteSetupDialog, vgui::Frame ); 

public:
	CVoteSetupDialog( vgui::Panel *parent );
	~CVoteSetupDialog();

	virtual void	Activate();
	virtual void	ApplySchemeSettings( vgui::IScheme *pScheme );
	virtual void	PostApplySchemeSettings( vgui::IScheme *pScheme );
	virtual void	ApplySettings(KeyValues *inResourceData);

	void			InitializeIssueList( void );
	void			UpdateCurrentMap( void );
	void			AddVoteIssues( CUtlVector< VoteIssue_t > &m_VoteSetupIssues );
	void			AddVoteIssueParams_MapCycle( CUtlStringList &m_VoteSetupMapCycle );

#ifdef TF_CLIENT_DLL
	void			AddVoteIssueParams_PopFiles( CUtlStringList &m_VoteSetupPopFiles );
#endif

private:
	//MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
	MESSAGE_FUNC_PTR( OnItemSelected, "ItemSelected", panel );

	virtual void	OnCommand( const char *command );
	virtual void	OnClose( void );

	void			RefreshIssueParameters( void );
	void			ResetData( void );

	vgui::ComboBox				*m_pComboBox;

	vgui::SectionedListPanel	*m_pVoteSetupList;
	vgui::SectionedListPanel	*m_pVoteParameterList;
	vgui::Button				*m_pCallVoteButton;
	vgui::ImageList				*m_pImageList;

	CUtlVector< VoteIssue_t >	m_VoteIssues;
	CUtlVector<const char*>	m_VoteIssuesMapCycle;

#ifdef TF_CLIENT_DLL
	CUtlVector<const char*>	m_VoteIssuesPopFiles;
#endif

	CPanelAnimationVarAliasType( int, m_iIssueWidth, "issue_width", "100", "proportional_int" );
	CPanelAnimationVarAliasType( int, m_iParameterWidth, "parameter_width", "150", "proportional_int" );

	bool			m_bVoteButtonEnabled;
	char			m_szCurrentMap[MAX_MAP_NAME];

	vgui::HFont		m_hHeaderFont;
	Color			m_HeaderFGColor;
	vgui::HFont		m_hIssueFont;
	Color			m_IssueFGColor;
	Color			m_IssueFGColorDisabled;
};


class CHudVote : public vgui::EditablePanel, public CHudElement
{
	DECLARE_CLASS_SIMPLE( CHudVote, vgui::EditablePanel );

	CHudVote( const char *pElementName );

	virtual void	LevelInit( void );
	virtual void	Init( void );
	virtual bool	ShouldDraw( void );
	virtual void	ApplySchemeSettings( vgui::IScheme *pScheme );
	virtual void	FireGameEvent( IGameEvent *event );
	virtual void	OnThink();
	virtual int		KeyInput( int down, ButtonCode_t keynum, const char *pszCurrentBinding );

	// NOTE: Any MsgFunc_*() methods added here need to check IsPlayingDemo().
	void			MsgFunc_CallVoteFailed( bf_read &msg );
	void			MsgFunc_VoteStart( bf_read &msg );
	void			MsgFunc_VotePass( bf_read &msg );
	void			MsgFunc_VoteFailed( bf_read &msg );
	void			MsgFunc_VoteSetup( bf_read &msg );

	void			PropagateOptionParameters( void );
	void			ShowVoteUI( bool bShow ) { m_bShowVoteActivePanel = bShow; }
	bool			IsVoteUIActive( void );
	bool			IsVoteSystemActive( void ) { return m_bVoteSystemActive; }

private:
	bool			IsPlayingDemo() const;

	EditablePanel		*m_pVoteActive;
	VoteBarPanel		*m_voteBar;
	EditablePanel		*m_pVoteFailed;
	EditablePanel		*m_pVotePassed;
	EditablePanel		*m_pCallVoteFailed;
	CVoteSetupDialog	*m_pVoteSetupDialog;

	CUtlVector< VoteIssue_t > m_VoteSetupIssues;
	CUtlStringList		m_VoteSetupMapCycle;
	
#ifdef TF_CLIENT_DLL
	CUtlStringList		m_VoteSetupPopFiles;
#endif

	CUtlStringList		m_VoteSetupChoices;

	bool				m_bVotingActive;
	bool				m_bVoteSystemActive;
	float				m_flVoteResultCycleTime;	// what time will we cycle to the result
	float				m_flHideTime;				// what time will we hide
	bool				m_bVotePassed;				// what mode are we going to cycle to
	int					m_nVoteOptionCount[MAX_VOTE_OPTIONS];	// Vote options counter
	int					m_nPotentialVotes;						// If set, draw a line at this point to show the required bar length
	bool				m_bIsYesNoVote;
	int					m_nVoteChoicesCount;
	bool				m_bPlayerVoted;
	float				m_flPostVotedHideTime;
	bool				m_bShowVoteActivePanel;
	int					m_iVoteCallerIdx;
	int					m_nVoteTeamIndex;			// If defined, only players on this team will see/vote on the issue
};

#endif // HUD_VOTE_H