aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/client/voice_menu.cpp
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /mp/src/game/client/voice_menu.cpp
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/game/client/voice_menu.cpp')
-rw-r--r--mp/src/game/client/voice_menu.cpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/mp/src/game/client/voice_menu.cpp b/mp/src/game/client/voice_menu.cpp
new file mode 100644
index 00000000..24405b4b
--- /dev/null
+++ b/mp/src/game/client/voice_menu.cpp
@@ -0,0 +1,123 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//=============================================================================//
+
+#include "cbase.h"
+#include "c_baseplayer.h"
+#include "menu.h"
+#include "KeyValues.h"
+#include "multiplay_gamerules.h"
+
+static int g_ActiveVoiceMenu = 0;
+
+void OpenVoiceMenu( int index )
+{
+ // do not show the menu if the player is dead or is an observer
+ C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
+ if ( !pPlayer )
+ return;
+
+ if ( !pPlayer->IsAlive() || pPlayer->IsObserver() )
+ return;
+
+ CHudMenu *pMenu = (CHudMenu *) gHUD.FindElement( "CHudMenu" );
+ if ( !pMenu )
+ return;
+
+ // if they hit the key again, close the menu
+ if ( g_ActiveVoiceMenu == index )
+ {
+ if ( pMenu->IsMenuOpen() )
+ {
+ pMenu->HideMenu();
+ g_ActiveVoiceMenu = 0;
+ return;
+ }
+ }
+
+ if ( index > 0 && index < 9 )
+ {
+ KeyValues *pKV = new KeyValues( "MenuItems" );
+
+ CMultiplayRules *pRules = dynamic_cast< CMultiplayRules * >( GameRules() );
+ if ( pRules )
+ {
+ if ( !pRules->GetVoiceMenuLabels( index-1, pKV ) )
+ {
+ pKV->deleteThis();
+ return;
+ }
+ }
+
+ pMenu->ShowMenu_KeyValueItems( pKV );
+
+ pKV->deleteThis();
+
+ g_ActiveVoiceMenu = index;
+ }
+ else
+ {
+ g_ActiveVoiceMenu = 0;
+ }
+}
+
+static void OpenVoiceMenu_1( void )
+{
+ OpenVoiceMenu( 1 );
+}
+
+static void OpenVoiceMenu_2( void )
+{
+ OpenVoiceMenu( 2 );
+}
+
+static void OpenVoiceMenu_3( void )
+{
+ OpenVoiceMenu( 3 );
+}
+
+ConCommand voice_menu_1( "voice_menu_1", OpenVoiceMenu_1, "Opens voice menu 1" );
+ConCommand voice_menu_2( "voice_menu_2", OpenVoiceMenu_2, "Opens voice menu 2" );
+ConCommand voice_menu_3( "voice_menu_3", OpenVoiceMenu_3, "Opens voice menu 3" );
+
+CON_COMMAND( menuselect, "menuselect" )
+{
+ if ( args.ArgC() < 2 )
+ return;
+
+ if( g_ActiveVoiceMenu == 0 )
+ {
+ // if we didn't have a menu open, maybe a plugin did. send it on to the server.
+ const char *cmd = VarArgs( "menuselect %s", args[1] );
+ engine->ServerCmd( cmd );
+ return;
+ }
+
+ int iSelection = atoi( args[ 1 ] );
+
+ switch( g_ActiveVoiceMenu )
+ {
+ case 1:
+ case 2:
+ case 3:
+ {
+ char cmd[128];
+ Q_snprintf( cmd, sizeof(cmd), "voicemenu %d %d", g_ActiveVoiceMenu - 1, iSelection - 1 );
+ engine->ServerCmd( cmd );
+ }
+ break;
+
+ default:
+ {
+ // if we didn't have a menu open, maybe a plugin did. send it on to the server.
+ const char *cmd = VarArgs( "menuselect %d", iSelection );
+ engine->ServerCmd( cmd );
+ }
+ break;
+ }
+
+ // reset menu
+ g_ActiveVoiceMenu = 0;
+} \ No newline at end of file