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.

136 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "pch_serverbrowser.h"
  7. using namespace vgui;
  8. //-----------------------------------------------------------------------------
  9. // Purpose: Constructor
  10. //-----------------------------------------------------------------------------
  11. CHistoryGames::CHistoryGames(vgui::Panel *parent) :
  12. CBaseGamesPage(parent, "HistoryGames", eHistoryServer )
  13. {
  14. m_bRefreshOnListReload = false;
  15. m_pGameList->AddColumnHeader(10, "LastPlayed", "#ServerBrowser_LastPlayed", 100);
  16. m_pGameList->SetSortFunc(10, LastPlayedCompare);
  17. m_pGameList->SetSortColumn(10);
  18. if ( !IsSteamGameServerBrowsingEnabled() )
  19. {
  20. m_pGameList->SetEmptyListText("#ServerBrowser_OfflineMode");
  21. m_pConnect->SetEnabled( false );
  22. m_pRefreshAll->SetEnabled( false );
  23. m_pRefreshQuick->SetEnabled( false );
  24. m_pAddServer->SetEnabled( false );
  25. m_pFilter->SetEnabled( false );
  26. }
  27. }
  28. //-----------------------------------------------------------------------------
  29. // Purpose: Destructor
  30. //-----------------------------------------------------------------------------
  31. CHistoryGames::~CHistoryGames()
  32. {
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose: loads favorites list from disk
  36. //-----------------------------------------------------------------------------
  37. void CHistoryGames::LoadHistoryList()
  38. {
  39. if ( IsSteamGameServerBrowsingEnabled() )
  40. {
  41. // set empty message
  42. m_pGameList->SetEmptyListText("#ServerBrowser_NoServersPlayed");
  43. }
  44. if ( m_bRefreshOnListReload )
  45. {
  46. m_bRefreshOnListReload = false;
  47. StartRefresh();
  48. }
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose: returns true if the game list supports the specified ui elements
  52. //-----------------------------------------------------------------------------
  53. bool CHistoryGames::SupportsItem(InterfaceItem_e item)
  54. {
  55. switch (item)
  56. {
  57. case FILTERS:
  58. return true;
  59. case ADDSERVER:
  60. case GETNEWLIST:
  61. default:
  62. return false;
  63. }
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose: called when the current refresh list is complete
  67. //-----------------------------------------------------------------------------
  68. void CHistoryGames::RefreshComplete( HServerListRequest hReq, EMatchMakingServerResponse response )
  69. {
  70. SetRefreshing(false);
  71. m_pGameList->SetEmptyListText("#ServerBrowser_NoServersPlayed");
  72. m_pGameList->SortList();
  73. BaseClass::RefreshComplete( hReq, response );
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Purpose: opens context menu (user right clicked on a server)
  77. //-----------------------------------------------------------------------------
  78. void CHistoryGames::OnOpenContextMenu(int itemID)
  79. {
  80. CServerContextMenu *menu = ServerBrowserDialog().GetContextMenu(GetActiveList());
  81. // get the server
  82. int serverID = GetSelectedServerID();
  83. if( serverID != -1 )
  84. {
  85. // Activate context menu
  86. menu->ShowMenu(this, serverID, true, true, true, true);
  87. menu->AddMenuItem("RemoveServer", "#ServerBrowser_RemoveServerFromHistory", new KeyValues("RemoveFromHistory"), this);
  88. }
  89. else
  90. {
  91. // no selected rows, so don't display default stuff in menu
  92. menu->ShowMenu(this, (uint32)-1, false, false, false, false);
  93. }
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose: removes a server from the favorites
  97. //-----------------------------------------------------------------------------
  98. void CHistoryGames::OnRemoveFromHistory()
  99. {
  100. if ( !steamapicontext->SteamMatchmakingServers() || !steamapicontext->SteamMatchmaking() )
  101. return;
  102. // iterate the selection
  103. for ( int i = m_pGameList->GetSelectedItemsCount() - 1; i >= 0; i-- )
  104. {
  105. int itemID = m_pGameList->GetSelectedItem( i );
  106. int serverID = m_pGameList->GetItemData(itemID)->userData;
  107. gameserveritem_t *pServer = steamapicontext->SteamMatchmakingServers()->GetServerDetails( m_hRequest, serverID );
  108. if ( pServer )
  109. steamapicontext->SteamMatchmaking()->RemoveFavoriteGame( pServer->m_nAppID, pServer->m_NetAdr.GetIP(), pServer->m_NetAdr.GetConnectionPort(), pServer->m_NetAdr.GetQueryPort(), k_unFavoriteFlagHistory );
  110. }
  111. UpdateStatus();
  112. InvalidateLayout();
  113. Repaint();
  114. }