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.

160 lines
4.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "pch_serverbrowser.h"
  8. using namespace vgui;
  9. const float BROADCAST_LIST_TIMEOUT = 0.4f;
  10. //-----------------------------------------------------------------------------
  11. // Purpose: Constructor
  12. //-----------------------------------------------------------------------------
  13. CLanGames::CLanGames(vgui::Panel *parent, bool bAutoRefresh, const char *pCustomResFilename ) :
  14. CBaseGamesPage(parent, "LanGames", eLANServer, pCustomResFilename)
  15. {
  16. m_iServerRefreshCount = 0;
  17. m_bRequesting = false;
  18. m_bAutoRefresh = bAutoRefresh;
  19. }
  20. //-----------------------------------------------------------------------------
  21. // Purpose: Destructor
  22. //-----------------------------------------------------------------------------
  23. CLanGames::~CLanGames()
  24. {
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Activates the page, starts refresh
  28. //-----------------------------------------------------------------------------
  29. void CLanGames::OnPageShow()
  30. {
  31. if ( m_bAutoRefresh )
  32. StartRefresh();
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Called every frame
  36. //-----------------------------------------------------------------------------
  37. void CLanGames::OnTick()
  38. {
  39. BaseClass::OnTick();
  40. CheckRetryRequest();
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose: returns true if the game list supports the specified ui elements
  44. //-----------------------------------------------------------------------------
  45. bool CLanGames::SupportsItem(InterfaceItem_e item)
  46. {
  47. switch (item)
  48. {
  49. case FILTERS:
  50. return true;
  51. case GETNEWLIST:
  52. default:
  53. return false;
  54. }
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Purpose: starts the servers refreshing
  58. //-----------------------------------------------------------------------------
  59. void CLanGames::StartRefresh()
  60. {
  61. BaseClass::StartRefresh();
  62. m_fRequestTime = Plat_FloatTime();
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Purpose: Control which button are visible.
  66. //-----------------------------------------------------------------------------
  67. void CLanGames::ManualShowButtons( bool bShowConnect, bool bShowRefreshAll, bool bShowFilter )
  68. {
  69. m_pConnect->SetVisible( bShowConnect );
  70. m_pRefreshAll->SetVisible( bShowRefreshAll );
  71. m_pFilter->SetVisible( bShowFilter );
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Purpose: stops current refresh/GetNewServerList()
  75. //-----------------------------------------------------------------------------
  76. void CLanGames::StopRefresh()
  77. {
  78. BaseClass::StopRefresh();
  79. // clear update states
  80. m_bRequesting = false;
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose: Check to see if we've finished looking for local servers
  84. //-----------------------------------------------------------------------------
  85. void CLanGames::CheckRetryRequest()
  86. {
  87. if (!m_bRequesting)
  88. return;
  89. double curtime = Plat_FloatTime();
  90. if (curtime - m_fRequestTime <= BROADCAST_LIST_TIMEOUT)
  91. {
  92. return;
  93. }
  94. // time has elapsed, finish up
  95. m_bRequesting = false;
  96. }
  97. //-----------------------------------------------------------------------------
  98. // Purpose: called when a server response has timed out, remove it
  99. //-----------------------------------------------------------------------------
  100. void CLanGames::ServerFailedToRespond( HServerListRequest hReq, int iServer )
  101. {
  102. int iServerMap = m_mapServers.Find( iServer );
  103. if ( iServerMap != m_mapServers.InvalidIndex() )
  104. RemoveServer( m_mapServers[ iServerMap ] );
  105. }
  106. //-----------------------------------------------------------------------------
  107. // Purpose: called when the current refresh list is complete
  108. //-----------------------------------------------------------------------------
  109. void CLanGames::RefreshComplete( HServerListRequest hReq, EMatchMakingServerResponse response )
  110. {
  111. SetRefreshing( false );
  112. m_pGameList->SortList();
  113. m_iServerRefreshCount = 0;
  114. m_pGameList->SetEmptyListText("#ServerBrowser_NoLanServers");
  115. SetEmptyListText();
  116. BaseClass::RefreshComplete( hReq, response );
  117. }
  118. void CLanGames::SetEmptyListText()
  119. {
  120. m_pGameList->SetEmptyListText("#ServerBrowser_NoLanServers");
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose: opens context menu (user right clicked on a server)
  124. //-----------------------------------------------------------------------------
  125. void CLanGames::OnOpenContextMenu(int row)
  126. {
  127. int serverID = GetSelectedServerID();
  128. if ( serverID == -1 )
  129. return;
  130. // Activate context menu
  131. CServerContextMenu *menu = ServerBrowserDialog().GetContextMenu(GetActiveList());
  132. menu->ShowMenu(this, serverID, true, true, true, false);
  133. }