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.

129 lines
3.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "BuyMenu.h"
  9. #include "BuySubMenu.h"
  10. using namespace vgui;
  11. #include "mouseoverpanelbutton.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Constructor
  16. //-----------------------------------------------------------------------------
  17. CBuyMenu::CBuyMenu(IViewPort *pViewPort) : WizardPanel( NULL, PANEL_BUY )
  18. {
  19. SetScheme("ClientScheme");
  20. SetTitle( "#Cstrike_Buy_Menu", true);
  21. SetMoveable(false);
  22. SetSizeable(false);
  23. SetProportional(true);
  24. // hide the system buttons
  25. SetTitleBarVisible( false );
  26. SetAutoDelete( false ); // we reuse this panel, don't let WizardPanel delete us
  27. LoadControlSettings( "Resource/UI/BuyMenu.res" );
  28. ShowButtons( false );
  29. m_pViewPort = pViewPort;
  30. m_pMainMenu = new CBuySubMenu( this, "mainmenu" );
  31. m_pMainMenu->LoadControlSettings( "Resource/UI/MainBuyMenu.res" );
  32. m_pMainMenu->SetVisible( false );
  33. int w, h;
  34. // Demo kludge to ensure widescreen buy menu does not get clipped
  35. engine->GetScreenSize( w, h );
  36. float aspectRatio = (float)w/(float)h;
  37. bool bIsWidescreen = ( aspectRatio >= 1.7f ) || ( aspectRatio <= 1.6f );
  38. if ( bIsWidescreen )
  39. {
  40. SetMinimumSize( w, 480 );
  41. SetWide(w);
  42. }
  43. }
  44. //-----------------------------------------------------------------------------
  45. // Purpose: Destructor
  46. //-----------------------------------------------------------------------------
  47. CBuyMenu::~CBuyMenu()
  48. {
  49. if ( m_pMainMenu )
  50. m_pMainMenu->DeleteSubPanels(); //?
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose: shows/hides the buy menu
  54. //-----------------------------------------------------------------------------
  55. void CBuyMenu::ShowPanel(bool bShow)
  56. {
  57. if ( BaseClass::IsVisible() == bShow )
  58. return;
  59. if ( bShow )
  60. {
  61. Update();
  62. Run( m_pMainMenu );
  63. SetMouseInputEnabled( true );
  64. // Prevent the system menu from appearing - we close the buy menu
  65. // when Esc is pressed
  66. engine->ClientCmd_Unrestricted( "gameui_preventescapetoshow\n" );
  67. }
  68. else
  69. {
  70. // Re-enable default system menu behavior
  71. engine->ClientCmd_Unrestricted( "gameui_allowescapetoshow\n" );
  72. SetVisible( false );
  73. SetMouseInputEnabled( false );
  74. }
  75. m_pViewPort->ShowBackGround( bShow );
  76. }
  77. void CBuyMenu::Update()
  78. {
  79. //Don't need to do anything, but do need to implement this function as base is pure virtual
  80. NULL;
  81. }
  82. void CBuyMenu::OnClose()
  83. {
  84. // This can get called bypassing ShowPanel(false), so make sure the
  85. // system menu works properly
  86. engine->ClientCmd_Unrestricted( "gameui_allowescapetoshow\n" );
  87. BaseClass::OnClose();
  88. ResetHistory();
  89. }
  90. void CBuyMenu::OnKeyCodeTyped( KeyCode code )
  91. {
  92. // Close the buy menu when the Esc key is pressed.
  93. if ( code == KEY_ESCAPE )
  94. {
  95. OnClose();
  96. }
  97. else
  98. {
  99. BaseClass::OnKeyCodeTyped( code );
  100. }
  101. }