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.

95 lines
2.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Base class menus should all inherit from
  4. //
  5. // $Revision: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "basemenu.h"
  9. #include "menumanager.h"
  10. #include <ctype.h>
  11. #include "vgui/iinput.h"
  12. //-----------------------------------------------------------------------------
  13. // Constructor, destructor
  14. //-----------------------------------------------------------------------------
  15. CBaseMenu::CBaseMenu( vgui::Panel *pParent, const char *pPanelName ) :
  16. BaseClass( pParent, pPanelName )
  17. {
  18. SetKeyBoardInputEnabled( true );
  19. SetMouseInputEnabled( true );
  20. SetSizeable( false );
  21. SetMoveable( false );
  22. }
  23. CBaseMenu::~CBaseMenu()
  24. {
  25. }
  26. void CBaseMenu::OnKeyCodeTyped( vgui::KeyCode code )
  27. {
  28. BaseClass::OnKeyCodeTyped( code );
  29. bool shift = (vgui::input()->IsKeyDown(vgui::KEY_LSHIFT) || vgui::input()->IsKeyDown(vgui::KEY_RSHIFT));
  30. bool ctrl = (vgui::input()->IsKeyDown(vgui::KEY_LCONTROL) || vgui::input()->IsKeyDown(vgui::KEY_RCONTROL));
  31. bool alt = (vgui::input()->IsKeyDown(vgui::KEY_LALT) || vgui::input()->IsKeyDown(vgui::KEY_RALT));
  32. if ( ctrl && shift && alt && code == vgui::KEY_B)
  33. {
  34. // enable build mode
  35. ActivateBuildMode();
  36. }
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Commands
  40. //-----------------------------------------------------------------------------
  41. void CBaseMenu::OnCommand( const char *pCommand )
  42. {
  43. if ( !Q_stricmp( pCommand, "quit" ) )
  44. {
  45. IGameManager::Stop();
  46. return;
  47. }
  48. if ( !Q_stricmp( pCommand, "popmenu" ) )
  49. {
  50. g_pMenuManager->PopMenu();
  51. return;
  52. }
  53. if ( !Q_stricmp( pCommand, "popallmenus" ) )
  54. {
  55. g_pMenuManager->PopAllMenus();
  56. return;
  57. }
  58. if ( !Q_strnicmp( pCommand, "pushmenu ", 9 ) )
  59. {
  60. const char *pMenuName = pCommand + 9;
  61. while( isspace(*pMenuName) )
  62. {
  63. ++pMenuName;
  64. }
  65. g_pMenuManager->PushMenu( pMenuName );
  66. return;
  67. }
  68. if ( !Q_strnicmp( pCommand, "switchmenu ", 11 ) )
  69. {
  70. const char *pMenuName = pCommand + 11;
  71. while( isspace(*pMenuName) )
  72. {
  73. ++pMenuName;
  74. }
  75. g_pMenuManager->SwitchToMenu( pMenuName );
  76. return;
  77. }
  78. BaseClass::OnCommand( pCommand );
  79. }