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.

87 lines
2.7 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. // HACK: Copy/paste from ugc_utils... not worth adding to project just for this
  10. uint64 GetMapIDFromMapPath( const char *pMapPath )
  11. {
  12. char tmp[ MAX_PATH ];
  13. V_strcpy_safe( tmp, pMapPath );
  14. V_FixSlashes( tmp, '/' ); // internal path strings use forward slashes, make sure we compare like that.
  15. if ( V_strstr( tmp, "workshop/" ) )
  16. {
  17. V_StripFilename( tmp );
  18. V_StripTrailingSlash( tmp );
  19. const char* szDirName = V_GetFileName( tmp );
  20. return V_atoui64( szDirName );
  21. }
  22. return 0;
  23. }
  24. //-----------------------------------------------------------------------------
  25. // Purpose: Constructor
  26. //-----------------------------------------------------------------------------
  27. CServerContextMenu::CServerContextMenu(Panel *parent) : Menu(parent, "ServerContextMenu")
  28. {
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Purpose: Destructor
  32. //-----------------------------------------------------------------------------
  33. CServerContextMenu::~CServerContextMenu()
  34. {
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Activates the menu
  38. //-----------------------------------------------------------------------------
  39. void CServerContextMenu::ShowMenu(
  40. Panel *target,
  41. unsigned int serverID,
  42. bool showConnect,
  43. bool showViewGameInfo,
  44. bool showRefresh,
  45. bool showAddToFavorites )
  46. {
  47. if (showConnect)
  48. {
  49. AddMenuItem("ConnectToServer", "#ServerBrowser_ConnectToServer", new KeyValues("ConnectToServer", "serverID", serverID), target);
  50. }
  51. if (showViewGameInfo)
  52. {
  53. AddMenuItem("ViewGameInfo", "#ServerBrowser_ViewServerInfo", new KeyValues("ViewGameInfo", "serverID", serverID), target);
  54. }
  55. if (showRefresh)
  56. {
  57. AddMenuItem("RefreshServer", "#ServerBrowser_RefreshServer", new KeyValues("RefreshServer", "serverID", serverID), target);
  58. }
  59. if (showAddToFavorites)
  60. {
  61. AddMenuItem("AddToFavorites", "#ServerBrowser_AddServerToFavorites", new KeyValues("AddToFavorites", "serverID", serverID), target);
  62. AddMenuItem("AddToBlacklist", "#ServerBrowser_AddServerToBlacklist", new KeyValues("AddToBlacklist", "serverID", serverID), target);
  63. }
  64. gameserveritem_t *pServer = ServerBrowserDialog().GetServer( serverID );
  65. if ( pServer && GetMapIDFromMapPath( pServer->m_szMap ) != 0 )
  66. {
  67. AddMenuItem( "ViewWorkshop", "#ServerBrowser_ViewInWorkshop", new KeyValues( "ViewInWorkshop", "serverID", serverID ), target );
  68. }
  69. int x, y, gx, gy;
  70. input()->GetCursorPos(x, y);
  71. ipanel()->GetPos(surface()->GetEmbeddedPanel(), gx, gy);
  72. SetPos(x - gx, y - gy);
  73. SetVisible(true);
  74. }