Counter Strike : Global Offensive Source Code
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.

287 lines
8.2 KiB

  1. //========= Copyright � 1996-2002, Valve LLC, 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 OnKeyCodeTyped(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. struct servermaps_t
  44. {
  45. const char *pOriginalName;
  46. const char *pFriendlyName;
  47. int iPanelIndex;
  48. bool bOnDisk;
  49. };
  50. struct gametypes_t
  51. {
  52. ~gametypes_t()
  53. {
  54. delete[] m_szPrefix;
  55. delete[] m_szGametypeName;
  56. delete[] m_szGametypeIcon;
  57. }
  58. const char *m_szPrefix;
  59. const char *m_szGametypeName;
  60. const char *m_szGametypeIcon;
  61. int m_iIconImageIndex;
  62. };
  63. //-----------------------------------------------------------------------------
  64. // Purpose: Base property page for all the games lists (internet/favorites/lan/etc.)
  65. //-----------------------------------------------------------------------------
  66. class CBaseGamesPage : public vgui::PropertyPage, public IGameList, public ISteamMatchmakingServerListResponse, public ISteamMatchmakingPingResponse
  67. {
  68. DECLARE_CLASS_SIMPLE( CBaseGamesPage, vgui::PropertyPage );
  69. public:
  70. enum EPageType
  71. {
  72. eInternetServer,
  73. eLANServer,
  74. eFriendsServer,
  75. eFavoritesServer,
  76. eHistoryServer,
  77. eSpectatorServer
  78. };
  79. const char* PageTypeToString( EPageType eType ) const;
  80. public:
  81. CBaseGamesPage( vgui::Panel *parent, const char *name, EPageType eType, const char *pCustomResFilename=NULL);
  82. ~CBaseGamesPage();
  83. virtual void PerformLayout();
  84. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  85. // gets information about specified server
  86. virtual gameserveritem_t *GetServer(unsigned int serverID);
  87. uint32 GetServerFilters( MatchMakingKeyValuePair_t **pFilters );
  88. virtual void SetRefreshing(bool state);
  89. // loads filter settings from disk
  90. virtual void LoadFilterSettings();
  91. // Called by CGameList when the enter key is pressed.
  92. // This is overridden in the add server dialog - since there is no Connect button, the message
  93. // never gets handled, but we want to add a server when they dbl-click or press enter.
  94. virtual bool OnGameListEnterPressed();
  95. int GetSelectedItemsCount();
  96. // adds a server to the favorites
  97. MESSAGE_FUNC( OnAddToFavorites, "AddToFavorites" );
  98. MESSAGE_FUNC( OnAddToBlacklist, "AddToBlacklist" );
  99. virtual void StartRefresh();
  100. virtual void UpdateDerivedLayouts( void );
  101. void PrepareQuickListMap( const char *pMapName, int iListID );
  102. void SelectQuickListServers( void );
  103. vgui::Panel *GetActiveList( void );
  104. virtual bool IsQuickListButtonChecked()
  105. {
  106. return false; // m_pQuickListCheckButton ? m_pQuickListCheckButton->IsSelected() : false;
  107. }
  108. STEAM_CALLBACK( CBaseGamesPage, OnFavoritesMsg, FavoritesListChanged_t, m_CallbackFavoritesMsg );
  109. // applies games filters to current list
  110. void ApplyGameFilters();
  111. protected:
  112. #if !defined(NO_STEAM)
  113. bool ViewCommunityMapsInWorkshop( uint64 workshopID = 0 );
  114. #endif
  115. virtual void OnCommand(const char *command);
  116. virtual void OnKeyCodePressed(vgui::KeyCode code);
  117. virtual int GetRegionCodeToFilter() { return -1; }
  118. MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
  119. // updates server count UI
  120. void UpdateStatus();
  121. // ISteamMatchmakingServerListResponse callbacks
  122. virtual void ServerResponded( HServerListRequest hReq, int iServer );
  123. virtual void ServerResponded( int iServer, gameserveritem_t *pServerItem );
  124. virtual void ServerFailedToRespond( HServerListRequest hReq, int iServer );
  125. virtual void RefreshComplete( HServerListRequest hReq, EMatchMakingServerResponse response ) = 0;
  126. // ISteamMatchmakingPingResponse callbacks
  127. virtual void ServerResponded( gameserveritem_t &server );
  128. virtual void ServerFailedToRespond() {}
  129. // Removes server from list
  130. void RemoveServer( serverdisplay_t &server );
  131. virtual bool BShowServer( serverdisplay_t &server ) { return server.m_bDoNotRefresh; }
  132. void ClearServerList();
  133. // filtering methods
  134. // returns true if filters passed; false if failed
  135. virtual bool CheckPrimaryFilters( gameserveritem_t &server);
  136. virtual bool CheckSecondaryFilters( gameserveritem_t &server );
  137. virtual bool CheckTagFilter( gameserveritem_t &server ) { return true; }
  138. virtual int GetInvalidServerListID();
  139. virtual void OnSaveFilter(KeyValues *filter);
  140. virtual void OnLoadFilter(KeyValues *filter);
  141. virtual void UpdateFilterSettings();
  142. // whether filter settings limit which master server to query
  143. CGameID &GetFilterAppID() { return m_iLimitToAppID; }
  144. virtual void GetNewServerList();
  145. virtual void StopRefresh();
  146. virtual bool IsRefreshing();
  147. virtual void OnPageShow();
  148. virtual void OnPageHide();
  149. // called when Connect button is pressed
  150. MESSAGE_FUNC( OnBeginConnect, "ConnectToServer" );
  151. // called to look at game info
  152. MESSAGE_FUNC( OnViewGameInfo, "ViewGameInfo" );
  153. // refreshes a single server
  154. MESSAGE_FUNC_INT( OnRefreshServer, "RefreshServer", serverID );
  155. // View workshop page for a map
  156. MESSAGE_FUNC_INT( OnViewWorkshop, "ViewInWorkshop", serverID );
  157. // If true, then we automatically select the first item that comes into the games list.
  158. bool m_bAutoSelectFirstItemInGameList;
  159. CGameListPanel *m_pGameList;
  160. vgui::PanelListPanel *m_pQuickList;
  161. vgui::ComboBox *m_pLocationFilter;
  162. // command buttons
  163. vgui::Button *m_pConnect;
  164. vgui::Button *m_pRefreshAll;
  165. vgui::Button *m_pRefreshQuick;
  166. vgui::Button *m_pAddServer;
  167. vgui::Button *m_pAddCurrentServer;
  168. vgui::Button *m_pAddToFavoritesButton;
  169. vgui::ToggleButton *m_pFilter;
  170. CUtlMap<uint64, int> m_mapGamesFilterItem;
  171. CUtlMap<int, serverdisplay_t> m_mapServers;
  172. CUtlMap<netadr_t, int> m_mapServerIP;
  173. CUtlVector<MatchMakingKeyValuePair_t> m_vecServerFilters;
  174. CUtlDict< CQuickListMapServerList, int > m_quicklistserverlist;
  175. int m_iServerRefreshCount;
  176. CUtlVector< servermaps_t > m_vecMapNamesFound;
  177. EPageType m_eMatchMakingType;
  178. HServerListRequest m_hRequest;
  179. int GetSelectedServerID( void );
  180. void ClearQuickList( void );
  181. bool TagsExclude( void );
  182. protected:
  183. virtual void CreateFilters();
  184. virtual void UpdateGameFilter();
  185. MESSAGE_FUNC_PTR_CHARPTR( OnTextChanged, "TextChanged", panel, text );
  186. MESSAGE_FUNC_PTR_INT( OnButtonToggled, "ButtonToggled", panel, state );
  187. void UpdateFilterAndQuickListVisibility();
  188. private:
  189. void RequestServersResponse( int iServer, EMatchMakingServerResponse response, bool bLastServer ); // callback for matchmaking interface
  190. void RecalculateFilterString();
  191. // If set, it uses the specified resfile name instead of its default one.
  192. const char *m_pCustomResFilename;
  193. // filter controls
  194. vgui::ComboBox *m_pGameFilter;
  195. vgui::TextEntry *m_pMapFilter;
  196. vgui::ComboBox *m_pWorkshopFilter;
  197. vgui::ComboBox *m_pPingFilter;
  198. vgui::ComboBox *m_pSecureFilter;
  199. vgui::ComboBox *m_pTagsIncludeFilter;
  200. vgui::CheckButton *m_pNoFullServersFilterCheck;
  201. vgui::CheckButton *m_pNoEmptyServersFilterCheck;
  202. vgui::CheckButton *m_pNoPasswordFilterCheck;
  203. // vgui::CheckButton *m_pQuickListCheckButton;
  204. vgui::Label *m_pFilterString;
  205. char m_szComboAllText[64];
  206. KeyValues *m_pFilters; // base filter data
  207. bool m_bFiltersVisible; // true if filter section is currently visible
  208. vgui::HFont m_hFont;
  209. // filter data
  210. char m_szGameFilter[32];
  211. char m_szMapFilter[32];
  212. int m_iWorkshopFilter;
  213. int m_iPingFilter;
  214. bool m_bFilterNoFullServers;
  215. bool m_bFilterNoEmptyServers;
  216. bool m_bFilterNoPasswordedServers;
  217. int m_iSecureFilter;
  218. int m_iServersBlacklisted;
  219. int m_iWorkshopIconIndex;
  220. CGameID m_iLimitToAppID;
  221. };
  222. #endif // BASEGAMESPAGE_H