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.

122 lines
2.4 KiB

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