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.

325 lines
9.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef BASEGAMESPAGE_H
  8. #define BASEGAMESPAGE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tier1/utldict.h"
  13. class CBaseGamesPage;
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Acts like a regular ListPanel but forwards enter key presses
  16. // to its outer control.
  17. //-----------------------------------------------------------------------------
  18. class CGameListPanel : public vgui::ListPanel
  19. {
  20. public:
  21. DECLARE_CLASS_SIMPLE( CGameListPanel, vgui::ListPanel );
  22. CGameListPanel( CBaseGamesPage *pOuter, const char *pName );
  23. virtual void OnKeyCodePressed(vgui::KeyCode code);
  24. private:
  25. CBaseGamesPage *m_pOuter;
  26. };
  27. class CQuickListMapServerList : public CUtlVector< int >
  28. {
  29. public:
  30. CQuickListMapServerList() : CUtlVector< int >( 1, 0 )
  31. {
  32. }
  33. CQuickListMapServerList( const CQuickListMapServerList& src )
  34. {
  35. CopyArray( src.Base(), src.Count() );
  36. }
  37. CQuickListMapServerList &operator=( const CQuickListMapServerList &src )
  38. {
  39. CopyArray( src.Base(), src.Count() );
  40. return *this;
  41. }
  42. };
  43. class CCheckBoxWithStatus : public vgui::CheckButton
  44. {
  45. public:
  46. DECLARE_CLASS_SIMPLE( CCheckBoxWithStatus, vgui::CheckButton );
  47. CCheckBoxWithStatus(Panel *parent, const char *panelName, const char *text) : vgui::CheckButton( parent, panelName, text )
  48. {
  49. }
  50. virtual void OnCursorEntered();
  51. virtual void OnCursorExited();
  52. };
  53. struct servermaps_t
  54. {
  55. const char *pOriginalName;
  56. const char *pFriendlyName;
  57. int iPanelIndex;
  58. bool bOnDisk;
  59. };
  60. struct gametypes_t
  61. {
  62. const char *pPrefix;
  63. const char *pGametypeName;
  64. };
  65. //-----------------------------------------------------------------------------
  66. // Purpose: Base property page for all the games lists (internet/favorites/lan/etc.)
  67. //-----------------------------------------------------------------------------
  68. class CBaseGamesPage : public vgui::PropertyPage, public IGameList, public ISteamMatchmakingServerListResponse, public ISteamMatchmakingPingResponse
  69. {
  70. DECLARE_CLASS_SIMPLE( CBaseGamesPage, vgui::PropertyPage );
  71. public:
  72. enum EPageType
  73. {
  74. eInternetServer,
  75. eLANServer,
  76. eFriendsServer,
  77. eFavoritesServer,
  78. eHistoryServer,
  79. eSpectatorServer
  80. };
  81. // Column indices
  82. enum
  83. {
  84. k_nColumn_Password = 0,
  85. k_nColumn_Secure = 1,
  86. k_nColumn_Replay = 2,
  87. k_nColumn_Name = 3,
  88. k_nColumn_IPAddr = 4,
  89. k_nColumn_GameDesc = 5,
  90. k_nColumn_Players = 6,
  91. k_nColumn_Bots = 7,
  92. k_nColumn_Map = 8,
  93. k_nColumn_Ping = 9,
  94. };
  95. CBaseGamesPage( vgui::Panel *parent, const char *name, EPageType eType, const char *pCustomResFilename=NULL);
  96. ~CBaseGamesPage();
  97. virtual void PerformLayout();
  98. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  99. // gets information about specified server
  100. virtual gameserveritem_t *GetServer(unsigned int serverID);
  101. virtual const char *GetConnectCode();
  102. uint32 GetServerFilters( MatchMakingKeyValuePair_t **pFilters );
  103. virtual void SetRefreshing(bool state);
  104. // loads filter settings from disk
  105. virtual void LoadFilterSettings();
  106. // Called by CGameList when the enter key is pressed.
  107. // This is overridden in the add server dialog - since there is no Connect button, the message
  108. // never gets handled, but we want to add a server when they dbl-click or press enter.
  109. virtual bool OnGameListEnterPressed();
  110. int GetSelectedItemsCount();
  111. // adds a server to the favorites
  112. MESSAGE_FUNC( OnAddToFavorites, "AddToFavorites" );
  113. MESSAGE_FUNC( OnAddToBlacklist, "AddToBlacklist" );
  114. virtual void StartRefresh();
  115. virtual void UpdateDerivedLayouts( void );
  116. void PrepareQuickListMap( const char *pMapName, int iListID );
  117. void SelectQuickListServers( void );
  118. vgui::Panel *GetActiveList( void );
  119. virtual bool IsQuickListButtonChecked()
  120. {
  121. return m_pQuickListCheckButton ? m_pQuickListCheckButton->IsSelected() : false;
  122. }
  123. STEAM_CALLBACK( CBaseGamesPage, OnFavoritesMsg, FavoritesListChanged_t, m_CallbackFavoritesMsg );
  124. // applies games filters to current list
  125. void ApplyGameFilters();
  126. void OnLoadingStarted()
  127. {
  128. StopRefresh();
  129. }
  130. protected:
  131. virtual void OnCommand(const char *command);
  132. virtual void OnKeyCodePressed(vgui::KeyCode code);
  133. virtual int GetRegionCodeToFilter() { return 255; }
  134. MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
  135. // updates server count UI
  136. void UpdateStatus();
  137. // ISteamMatchmakingServerListResponse callbacks
  138. virtual void ServerResponded( HServerListRequest hReq, int iServer );
  139. virtual void ServerResponded( int iServer, gameserveritem_t *pServerItem );
  140. virtual void ServerFailedToRespond( HServerListRequest hReq, int iServer );
  141. virtual void RefreshComplete( HServerListRequest hReq, EMatchMakingServerResponse response ) = 0;
  142. // ISteamMatchmakingPingResponse callbacks
  143. virtual void ServerResponded( gameserveritem_t &server );
  144. virtual void ServerFailedToRespond() {}
  145. // Removes server from list
  146. void RemoveServer( serverdisplay_t &server );
  147. virtual bool BShowServer( serverdisplay_t &server ) { return server.m_bDoNotRefresh; }
  148. void ClearServerList();
  149. // filtering methods
  150. // returns true if filters passed; false if failed
  151. virtual bool CheckPrimaryFilters( gameserveritem_t &server);
  152. virtual bool CheckSecondaryFilters( gameserveritem_t &server );
  153. virtual bool CheckTagFilter( gameserveritem_t &server ) { return true; }
  154. virtual bool CheckWorkshopFilter( gameserveritem_t &server ) { return true; }
  155. virtual int GetInvalidServerListID();
  156. virtual void OnSaveFilter(KeyValues *filter);
  157. virtual void OnLoadFilter(KeyValues *filter);
  158. virtual void UpdateFilterSettings();
  159. // whether filter settings limit which master server to query
  160. CGameID &GetFilterAppID() { return m_iLimitToAppID; }
  161. virtual void GetNewServerList();
  162. virtual void StopRefresh();
  163. virtual bool IsRefreshing();
  164. virtual void OnPageShow();
  165. virtual void OnPageHide();
  166. // called when Connect button is pressed
  167. MESSAGE_FUNC( OnBeginConnect, "ConnectToServer" );
  168. // called to look at game info
  169. MESSAGE_FUNC( OnViewGameInfo, "ViewGameInfo" );
  170. // refreshes a single server
  171. MESSAGE_FUNC_INT( OnRefreshServer, "RefreshServer", serverID );
  172. // If true, then we automatically select the first item that comes into the games list.
  173. bool m_bAutoSelectFirstItemInGameList;
  174. CGameListPanel *m_pGameList;
  175. vgui::PanelListPanel *m_pQuickList;
  176. vgui::ComboBox *m_pLocationFilter;
  177. // command buttons
  178. vgui::Button *m_pConnect;
  179. vgui::Button *m_pRefreshAll;
  180. vgui::Button *m_pRefreshQuick;
  181. vgui::Button *m_pAddServer;
  182. vgui::Button *m_pAddCurrentServer;
  183. vgui::Button *m_pAddToFavoritesButton;
  184. vgui::ToggleButton *m_pFilter;
  185. CUtlMap<uint64, int> m_mapGamesFilterItem;
  186. CUtlMap<int, serverdisplay_t> m_mapServers;
  187. CUtlMap<netadr_t, int> m_mapServerIP;
  188. CUtlVector<MatchMakingKeyValuePair_t> m_vecServerFilters;
  189. CUtlDict< CQuickListMapServerList, int > m_quicklistserverlist;
  190. int m_iServerRefreshCount;
  191. CUtlVector< servermaps_t > m_vecMapNamesFound;
  192. EPageType m_eMatchMakingType;
  193. HServerListRequest m_hRequest;
  194. int GetSelectedServerID( KeyValues **pKV = NULL );
  195. void ClearQuickList( void );
  196. bool TagsExclude( void );
  197. enum eWorkshopMode {
  198. // These correspond to the dropdown indices
  199. eWorkshop_None = 0,
  200. eWorkshop_WorkshopOnly = 1,
  201. eWorkshop_SubscribedOnly = 2
  202. };
  203. eWorkshopMode WorkshopMode();
  204. void HideReplayFilter( void );
  205. protected:
  206. virtual void CreateFilters();
  207. virtual void UpdateGameFilter();
  208. MESSAGE_FUNC_PTR_CHARPTR( OnTextChanged, "TextChanged", panel, text );
  209. MESSAGE_FUNC_PTR_INT( OnButtonToggled, "ButtonToggled", panel, state );
  210. void UpdateFilterAndQuickListVisibility();
  211. bool BFiltersVisible() { return m_bFiltersVisible; }
  212. private:
  213. void RequestServersResponse( int iServer, EMatchMakingServerResponse response, bool bLastServer ); // callback for matchmaking interface
  214. void RecalculateFilterString();
  215. void SetQuickListEnabled( bool bEnabled );
  216. void SetFiltersVisible( bool bVisible );
  217. // If set, it uses the specified resfile name instead of its default one.
  218. const char *m_pCustomResFilename;
  219. // filter controls
  220. vgui::ComboBox *m_pGameFilter;
  221. vgui::TextEntry *m_pMapFilter;
  222. vgui::TextEntry *m_pMaxPlayerFilter;
  223. vgui::ComboBox *m_pPingFilter;
  224. vgui::ComboBox *m_pSecureFilter;
  225. vgui::ComboBox *m_pTagsIncludeFilter;
  226. vgui::ComboBox *m_pWorkshopFilter;
  227. vgui::CheckButton *m_pNoFullServersFilterCheck;
  228. vgui::CheckButton *m_pNoEmptyServersFilterCheck;
  229. vgui::CheckButton *m_pNoPasswordFilterCheck;
  230. CCheckBoxWithStatus *m_pQuickListCheckButton;
  231. vgui::Label *m_pFilterString;
  232. char m_szComboAllText[64];
  233. vgui::CheckButton *m_pReplayFilterCheck;
  234. KeyValues *m_pFilters; // base filter data
  235. bool m_bFiltersVisible; // true if filter section is currently visible
  236. vgui::HFont m_hFont;
  237. int m_nImageIndexPassword;
  238. int m_nImageIndexSecure;
  239. int m_nImageIndexSecureVacBanned;
  240. int m_nImageIndexReplay;
  241. // filter data
  242. char m_szGameFilter[32];
  243. char m_szMapFilter[32];
  244. int m_iMaxPlayerFilter;
  245. int m_iPingFilter;
  246. bool m_bFilterNoFullServers;
  247. bool m_bFilterNoEmptyServers;
  248. bool m_bFilterNoPasswordedServers;
  249. int m_iSecureFilter;
  250. int m_iServersBlacklisted;
  251. bool m_bFilterReplayServers;
  252. CGameID m_iLimitToAppID;
  253. };
  254. #endif // BASEGAMESPAGE_H