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.

151 lines
3.2 KiB

  1. //========= Copyright 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. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Destructor
  36. //-----------------------------------------------------------------------------
  37. CBuyMenu::~CBuyMenu()
  38. {
  39. if ( m_pMainMenu )
  40. m_pMainMenu->DeleteSubPanels(); //?
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose: shows/hides the buy menu
  44. //-----------------------------------------------------------------------------
  45. void CBuyMenu::ShowPanel(bool bShow)
  46. {
  47. if ( BaseClass::IsVisible() == bShow )
  48. return;
  49. if ( bShow )
  50. {
  51. Update();
  52. Run( m_pMainMenu );
  53. SetMouseInputEnabled( true );
  54. engine->ClientCmd_Unrestricted( "gameui_preventescapetoshow\n" );
  55. }
  56. else
  57. {
  58. engine->ClientCmd_Unrestricted( "gameui_allowescapetoshow\n" );
  59. SetVisible( false );
  60. SetMouseInputEnabled( false );
  61. }
  62. m_pViewPort->ShowBackGround( bShow );
  63. }
  64. void CBuyMenu::Update()
  65. {
  66. //Don't need to do anything, but do need to implement this function as base is pure virtual
  67. }
  68. void CBuyMenu::OnClose()
  69. {
  70. engine->ClientCmd_Unrestricted( "gameui_allowescapetoshow\n" );
  71. BaseClass::OnClose();
  72. ResetHistory();
  73. }
  74. void CBuyMenu::OnKeyCodePressed( vgui::KeyCode code )
  75. {
  76. int nDir = 0;
  77. switch ( code )
  78. {
  79. case KEY_XBUTTON_UP:
  80. case KEY_XSTICK1_UP:
  81. case KEY_XSTICK2_UP:
  82. case KEY_UP:
  83. case STEAMCONTROLLER_DPAD_UP:
  84. nDir = -1;
  85. break;
  86. case KEY_XBUTTON_DOWN:
  87. case KEY_XSTICK1_DOWN:
  88. case KEY_XSTICK2_DOWN:
  89. case KEY_DOWN:
  90. case STEAMCONTROLLER_DPAD_DOWN:
  91. nDir = 1;
  92. break;
  93. }
  94. if ( nDir != 0 )
  95. {
  96. Panel *pSubPanel = ( GetCurrentSubPanel() ? GetCurrentSubPanel() : m_pMainMenu );
  97. CUtlSortVector< SortedPanel_t, CSortedPanelYLess > vecSortedButtons;
  98. VguiPanelGetSortedChildButtonList( pSubPanel, (void*)&vecSortedButtons, "&", 0 );
  99. if ( VguiPanelNavigateSortedChildButtonList( (void*)&vecSortedButtons, nDir ) != -1 )
  100. {
  101. // Handled!
  102. return;
  103. }
  104. }
  105. else
  106. {
  107. BaseClass::OnKeyCodePressed( code );
  108. }
  109. }
  110. void CBuyMenu::OnKeyCodeTyped( KeyCode code )
  111. {
  112. if ( code == KEY_ESCAPE )
  113. {
  114. OnClose();
  115. }
  116. else
  117. {
  118. BaseClass::OnKeyCodeTyped( code );
  119. }
  120. }