Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef HUD_VOTE_H
  8. #define HUD_VOTE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "hudelement.h"
  13. #include <vgui_controls/EditablePanel.h>
  14. #include <vgui_controls/SectionedListPanel.h>
  15. #include <vgui_controls/Frame.h>
  16. #include <vgui_controls/Button.h>
  17. #include <networkstringtabledefs.h>
  18. #include "vgui_avatarimage.h"
  19. extern INetworkStringTable *g_pStringTableServerMapCycle;
  20. #ifdef TF_CLIENT_DLL
  21. extern INetworkStringTable *g_pStringTableServerPopFiles;
  22. extern INetworkStringTable *g_pStringTableServerMapCycleMvM;
  23. #endif
  24. static const int k_MAX_VOTE_NAME_LENGTH = 256;
  25. namespace vgui
  26. {
  27. class SectionedListPanel;
  28. class ComboBox;
  29. class ImageList;
  30. };
  31. struct VoteIssue_t
  32. {
  33. char szName[k_MAX_VOTE_NAME_LENGTH];
  34. char szNameString[k_MAX_VOTE_NAME_LENGTH];
  35. bool bIsActive;
  36. };
  37. class VoteBarPanel : public vgui::Panel, public CGameEventListener
  38. {
  39. DECLARE_CLASS_SIMPLE( VoteBarPanel, vgui::Panel );
  40. VoteBarPanel( vgui::Panel *parent, const char *panelName );
  41. virtual void Paint( void );
  42. virtual void FireGameEvent( IGameEvent *event );
  43. private:
  44. int m_nVoteOptionCount[MAX_VOTE_OPTIONS]; // Vote options counter
  45. int m_nPotentialVotes; // If set, draw a line at this point to show the required bar length
  46. CPanelAnimationVarAliasType( int, m_iBoxSize, "box_size", "16", "proportional_int" );
  47. CPanelAnimationVarAliasType( int, m_iSpacer, "spacer", "4", "proportional_int" );
  48. CPanelAnimationVarAliasType( int, m_iBoxInset, "box_inset", "1", "proportional_int" );
  49. CPanelAnimationVarAliasType( int, m_nYesTextureId, "yes_texture", "vgui/hud/vote_yes", "textureid" );
  50. CPanelAnimationVarAliasType( int, m_nNoTextureId, "no_texture", "vgui/hud/vote_no", "textureid" );
  51. };
  52. //-----------------------------------------------------------------------------
  53. // Purpose: A selection UI for votes that require additional parameters - such as players, maps
  54. //-----------------------------------------------------------------------------
  55. class CVoteSetupDialog : public vgui::Frame
  56. {
  57. DECLARE_CLASS_SIMPLE( CVoteSetupDialog, vgui::Frame );
  58. public:
  59. CVoteSetupDialog( vgui::Panel *parent );
  60. ~CVoteSetupDialog();
  61. virtual void Activate();
  62. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  63. virtual void PostApplySchemeSettings( vgui::IScheme *pScheme );
  64. virtual void ApplySettings(KeyValues *inResourceData);
  65. void InitializeIssueList( void );
  66. void UpdateCurrentMap( void );
  67. void AddVoteIssues( CUtlVector< VoteIssue_t > &m_VoteSetupIssues );
  68. void AddVoteIssueParams_MapCycle( CUtlStringList &m_VoteSetupMapCycle );
  69. #ifdef TF_CLIENT_DLL
  70. void AddVoteIssueParams_PopFiles( CUtlStringList &m_VoteSetupPopFiles );
  71. #endif
  72. private:
  73. //MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
  74. MESSAGE_FUNC_PTR( OnItemSelected, "ItemSelected", panel );
  75. virtual void OnCommand( const char *command );
  76. virtual void OnClose( void );
  77. void RefreshIssueParameters( void );
  78. void ResetData( void );
  79. vgui::ComboBox *m_pComboBox;
  80. vgui::SectionedListPanel *m_pVoteSetupList;
  81. vgui::SectionedListPanel *m_pVoteParameterList;
  82. vgui::Button *m_pCallVoteButton;
  83. vgui::ImageList *m_pImageList;
  84. CUtlVector< VoteIssue_t > m_VoteIssues;
  85. CUtlVector<const char*> m_VoteIssuesMapCycle;
  86. #ifdef TF_CLIENT_DLL
  87. CUtlVector<const char*> m_VoteIssuesPopFiles;
  88. #endif
  89. CPanelAnimationVarAliasType( int, m_iIssueWidth, "issue_width", "100", "proportional_int" );
  90. CPanelAnimationVarAliasType( int, m_iParameterWidth, "parameter_width", "150", "proportional_int" );
  91. bool m_bVoteButtonEnabled;
  92. char m_szCurrentMap[MAX_MAP_NAME];
  93. vgui::HFont m_hHeaderFont;
  94. Color m_HeaderFGColor;
  95. vgui::HFont m_hIssueFont;
  96. Color m_IssueFGColor;
  97. Color m_IssueFGColorDisabled;
  98. };
  99. class CHudVote : public vgui::EditablePanel, public CHudElement
  100. {
  101. DECLARE_CLASS_SIMPLE( CHudVote, vgui::EditablePanel );
  102. CHudVote( const char *pElementName );
  103. virtual void LevelInit( void );
  104. virtual void Init( void );
  105. virtual bool ShouldDraw( void );
  106. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  107. virtual void FireGameEvent( IGameEvent *event );
  108. virtual void OnThink();
  109. virtual int KeyInput( int down, ButtonCode_t keynum, const char *pszCurrentBinding );
  110. // NOTE: Any MsgFunc_*() methods added here need to check IsPlayingDemo().
  111. void MsgFunc_CallVoteFailed( bf_read &msg );
  112. void MsgFunc_VoteStart( bf_read &msg );
  113. void MsgFunc_VotePass( bf_read &msg );
  114. void MsgFunc_VoteFailed( bf_read &msg );
  115. void MsgFunc_VoteSetup( bf_read &msg );
  116. void PropagateOptionParameters( void );
  117. void ShowVoteUI( bool bShow ) { m_bShowVoteActivePanel = bShow; }
  118. bool IsVoteUIActive( void );
  119. bool IsVoteSystemActive( void ) { return m_bVoteSystemActive; }
  120. bool IsShowingVoteSetupDialog();
  121. bool IsShowingVotingUI();
  122. virtual GameActionSet_t GetPreferredActionSet() { return IsShowingVoteSetupDialog() ? GAME_ACTION_SET_MENUCONTROLS : CHudElement::GetPreferredActionSet(); }
  123. private:
  124. bool IsPlayingDemo() const;
  125. EditablePanel *m_pVoteActive;
  126. vgui::Label *m_pVoteActiveIssueLabel;
  127. CAvatarImagePanel *m_pVoteActiveTargetAvatar;
  128. VoteBarPanel *m_voteBar;
  129. EditablePanel *m_pVoteFailed;
  130. EditablePanel *m_pVotePassed;
  131. EditablePanel *m_pCallVoteFailed;
  132. CVoteSetupDialog *m_pVoteSetupDialog;
  133. CUtlVector< VoteIssue_t > m_VoteSetupIssues;
  134. CUtlStringList m_VoteSetupMapCycle;
  135. int m_nVoteActiveIssueLabelX;
  136. int m_nVoteActiveIssueLabelY;
  137. #ifdef TF_CLIENT_DLL
  138. CUtlStringList m_VoteSetupPopFiles;
  139. #endif
  140. CUtlStringList m_VoteSetupChoices;
  141. bool m_bVotingActive;
  142. bool m_bVoteSystemActive;
  143. float m_flVoteResultCycleTime; // what time will we cycle to the result
  144. float m_flHideTime; // what time will we hide
  145. bool m_bVotePassed; // what mode are we going to cycle to
  146. int m_nVoteOptionCount[MAX_VOTE_OPTIONS]; // Vote options counter
  147. int m_nPotentialVotes; // If set, draw a line at this point to show the required bar length
  148. bool m_bIsYesNoVote;
  149. int m_nVoteChoicesCount;
  150. bool m_bPlayerVoted;
  151. float m_flPostVotedHideTime;
  152. bool m_bShowVoteActivePanel;
  153. int m_iVoteCallerIdx;
  154. int m_nVoteTeamIndex; // If defined, only players on this team will see/vote on the issue
  155. };
  156. #endif // HUD_VOTE_H