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.

164 lines
5.0 KiB

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