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.

126 lines
2.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "c_baseplayer.h"
  8. #include "menu.h"
  9. #include "keyvalues.h"
  10. #include "multiplay_gamerules.h"
  11. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. static int g_ActiveVoiceMenu = 0;
  14. void OpenVoiceMenu( int index )
  15. {
  16. // do not show the menu if the player is dead or is an observer
  17. C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
  18. if ( !pPlayer )
  19. return;
  20. if ( !pPlayer->IsAlive() || pPlayer->IsObserver() )
  21. return;
  22. CHudMenu *pMenu = (CHudMenu *) GetHud().FindElement( "CHudMenu" );
  23. if ( !pMenu )
  24. return;
  25. // if they hit the key again, close the menu
  26. if ( g_ActiveVoiceMenu == index )
  27. {
  28. if ( pMenu->IsMenuOpen() )
  29. {
  30. pMenu->HideMenu();
  31. g_ActiveVoiceMenu = 0;
  32. return;
  33. }
  34. }
  35. if ( index > 0 && index < 9 )
  36. {
  37. KeyValues *pKV = new KeyValues( "MenuItems" );
  38. CMultiplayRules *pRules = dynamic_cast< CMultiplayRules * >( GameRules() );
  39. if ( pRules )
  40. {
  41. if ( !pRules->GetVoiceMenuLabels( index-1, pKV ) )
  42. {
  43. pKV->deleteThis();
  44. return;
  45. }
  46. }
  47. pMenu->ShowMenu_KeyValueItems( pKV );
  48. pKV->deleteThis();
  49. g_ActiveVoiceMenu = index;
  50. }
  51. else
  52. {
  53. g_ActiveVoiceMenu = 0;
  54. }
  55. }
  56. static void OpenVoiceMenu_1( void )
  57. {
  58. OpenVoiceMenu( 1 );
  59. }
  60. static void OpenVoiceMenu_2( void )
  61. {
  62. OpenVoiceMenu( 2 );
  63. }
  64. static void OpenVoiceMenu_3( void )
  65. {
  66. OpenVoiceMenu( 3 );
  67. }
  68. ConCommand voice_menu_1( "voice_menu_1", OpenVoiceMenu_1, "Opens voice menu 1" );
  69. ConCommand voice_menu_2( "voice_menu_2", OpenVoiceMenu_2, "Opens voice menu 2" );
  70. ConCommand voice_menu_3( "voice_menu_3", OpenVoiceMenu_3, "Opens voice menu 3" );
  71. CON_COMMAND( menuselect, "menuselect" )
  72. {
  73. if ( args.ArgC() < 2 )
  74. return;
  75. if( g_ActiveVoiceMenu == 0 )
  76. {
  77. // if we didn't have a menu open, maybe a plugin did. send it on to the server.
  78. const char *cmd = VarArgs( "menuselect %s", args[1] );
  79. engine->ServerCmd( cmd );
  80. return;
  81. }
  82. int iSelection = atoi( args[ 1 ] );
  83. switch( g_ActiveVoiceMenu )
  84. {
  85. case 1:
  86. case 2:
  87. case 3:
  88. {
  89. char cmd[128];
  90. Q_snprintf( cmd, sizeof(cmd), "voicemenu %d %d", g_ActiveVoiceMenu - 1, iSelection - 1 );
  91. engine->ServerCmd( cmd );
  92. }
  93. break;
  94. default:
  95. {
  96. // if we didn't have a menu open, maybe a plugin did. send it on to the server.
  97. const char *cmd = VarArgs( "menuselect %d", iSelection );
  98. engine->ServerCmd( cmd );
  99. }
  100. break;
  101. }
  102. // reset menu
  103. g_ActiveVoiceMenu = 0;
  104. }