/* ============== idSessionLocal::HandleIntroMenuCommands Executes any commands returned by the gui ============== */ void idSessionLocal::HandleIntroMenuCommands( const char *menuCommand ) { // execute the command from the menu int i; idCmdArgs args; args.TokenizeString( menuCommand, false ); for( i = 0; i < args.Argc(); ) { const char *cmd = args.Argv( i++ ); if ( !idStr::Icmp( cmd, "startGame" ) ) { menuSoundWorld->ClearAllSoundEmitters(); ExitMenu(); continue; } if ( !idStr::Icmp( cmd, "play" ) ) { if ( args.Argc() - i >= 1 ) { idStr snd = args.Argv(i++); menuSoundWorld->PlayShaderDirectly(snd); } continue; } } }
/* ============== idSessionLocal::HandleRestartMenuCommands Executes any commands returned by the gui ============== */ void idSessionLocal::HandleRestartMenuCommands(const char *menuCommand) { // execute the command from the menu int icmd; idCmdArgs args; args.TokenizeString(menuCommand, false); for (icmd = 0; icmd < args.Argc();) { const char *cmd = args.Argv(icmd++); if (HandleSaveGameMenuCommand(args, icmd)) { continue; } if (!idStr::Icmp(cmd, "restart")) { if (!LoadGame(GetAutoSaveName(mapSpawnData.serverInfo.GetString("si_map")))) { // If we can't load the autosave then just restart the map MoveToNewMap(mapSpawnData.serverInfo.GetString("si_map")); } continue; } if (!idStr::Icmp(cmd, "quit")) { ExitMenu(); common->Quit(); return; } if (!idStr::Icmp(cmd, "exec")) { cmdSystem->BufferCommandText(CMD_EXEC_APPEND, args.Argv(icmd++)); continue; } if (!idStr::Icmp(cmd, "play")) { if (args.Argc() - icmd >= 1) { idStr snd = args.Argv(icmd++); sw->PlayShaderDirectly(snd); } continue; } } }
/* ============== idSessionLocal::HandleMainMenuCommands Executes any commands returned by the gui ============== */ void idSessionLocal::HandleMainMenuCommands( const char *menuCommand ) { // execute the command from the menu int icmd; idCmdArgs args; args.TokenizeString( menuCommand, false ); for( icmd = 0; icmd < args.Argc(); ) { const char *cmd = args.Argv( icmd++ ); if ( HandleSaveGameMenuCommand( args, icmd ) ) { continue; } // always let the game know the command is being run if ( game ) { game->HandleMainMenuCommands( cmd, guiActive ); } if ( !idStr::Icmp( cmd, "startGame" ) ) { cvarSystem->SetCVarInteger( "g_skill", guiMainMenu->State().GetInt( "skill" ) ); if ( icmd < args.Argc() ) { StartNewGame( args.Argv( icmd++ ) ); } else { #ifndef ID_DEMO_BUILD StartNewGame( "game/mars_city1" ); #else StartNewGame( "game/demo_mars_city1" ); #endif } // need to do this here to make sure com_frameTime is correct or the gui activates with a time that // is "however long map load took" time in the past common->GUIFrame( false, false ); SetGUI( guiIntro, NULL ); guiIntro->StateChanged( com_frameTime, true ); // stop playing the game sounds soundSystem->SetPlayingSoundWorld( menuSoundWorld ); continue; } if ( !idStr::Icmp( cmd, "quit" ) ) { ExitMenu(); common->Quit(); return; } if ( !idStr::Icmp( cmd, "loadMod" ) ) { int choice = guiActive->State().GetInt( "modsList_sel_0" ); if ( choice >= 0 && choice < modsList.Num() ) { cvarSystem->SetCVarString( "fs_game", modsList[ choice ] ); cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "reloadEngine menu\n" ); } } if ( !idStr::Icmp( cmd, "UpdateServers" ) ) { if ( guiActive->State().GetBool( "lanSet" ) ) { cmdSystem->BufferCommandText( CMD_EXEC_NOW, "LANScan" ); } else { idAsyncNetwork::GetNETServers(); } continue; } if ( !idStr::Icmp( cmd, "RefreshServers" ) ) { if ( guiActive->State().GetBool( "lanSet" ) ) { cmdSystem->BufferCommandText( CMD_EXEC_NOW, "LANScan" ); } else { idAsyncNetwork::client.serverList.NetScan( ); } continue; } if ( !idStr::Icmp( cmd, "FilterServers" ) ) { idAsyncNetwork::client.serverList.ApplyFilter( ); continue; } if ( !idStr::Icmp( cmd, "sortServerName" ) ) { idAsyncNetwork::client.serverList.SetSorting( SORT_SERVERNAME ); continue; } if ( !idStr::Icmp( cmd, "sortGame" ) ) { idAsyncNetwork::client.serverList.SetSorting( SORT_GAME ); continue; } if ( !idStr::Icmp( cmd, "sortPlayers" ) ) { idAsyncNetwork::client.serverList.SetSorting( SORT_PLAYERS ); continue; } if ( !idStr::Icmp( cmd, "sortPing" ) ) { idAsyncNetwork::client.serverList.SetSorting( SORT_PING ); continue; } if ( !idStr::Icmp( cmd, "sortGameType" ) ) { idAsyncNetwork::client.serverList.SetSorting( SORT_GAMETYPE ); continue; } if ( !idStr::Icmp( cmd, "sortMap" ) ) { idAsyncNetwork::client.serverList.SetSorting( SORT_MAP ); continue; } if ( !idStr::Icmp( cmd, "serverList" ) ) { idAsyncNetwork::client.serverList.GUIUpdateSelected(); continue; } if ( !idStr::Icmp( cmd, "LANConnect" ) ) { int sel = guiActive->State().GetInt( "serverList_selid_0" ); cmdSystem->BufferCommandText( CMD_EXEC_NOW, va( "Connect %d\n", sel ) ); return; } if ( !idStr::Icmp( cmd, "MAPScan" ) ) { const char *gametype = cvarSystem->GetCVarString( "si_gameType" ); if ( gametype == NULL || *gametype == 0 || idStr::Icmp( gametype, "singleplayer" ) == 0 ) { gametype = "Deathmatch"; } int i, num; idStr si_map = cvarSystem->GetCVarString("si_map"); const idDict *dict; guiMainMenu_MapList->Clear(); guiMainMenu_MapList->SetSelection( 0 ); num = fileSystem->GetNumMaps(); for ( i = 0; i < num; i++ ) { dict = fileSystem->GetMapDecl( i ); if ( dict && dict->GetBool( gametype ) ) { const char *mapName = dict->GetString( "name" ); if ( mapName[ 0 ] == '\0' ) { mapName = dict->GetString( "path" ); } mapName = common->GetLanguageDict()->GetString( mapName ); guiMainMenu_MapList->Add( i, mapName ); if ( !si_map.Icmp( dict->GetString( "path" ) ) ) { guiMainMenu_MapList->SetSelection( guiMainMenu_MapList->Num() - 1 ); } } } i = guiMainMenu_MapList->GetSelection( NULL, 0 ); if ( i >= 0 ) { dict = fileSystem->GetMapDecl( i); } else { dict = NULL; } cvarSystem->SetCVarString( "si_map", ( dict ? dict->GetString( "path" ) : "" ) ); // set the current level shot UpdateMPLevelShot(); continue; } if ( !idStr::Icmp( cmd, "click_mapList" ) ) { int mapNum = guiMainMenu_MapList->GetSelection( NULL, 0 ); const idDict *dict = fileSystem->GetMapDecl( mapNum ); if ( dict ) { cvarSystem->SetCVarString( "si_map", dict->GetString( "path" ) ); } UpdateMPLevelShot(); continue; } if ( !idStr::Icmp( cmd, "inetConnect" ) ) { const char *s = guiMainMenu->State().GetString( "inetGame" ); if ( !s || s[0] == 0 ) { // don't put the menu away if there isn't a valid selection continue; } cmdSystem->BufferCommandText( CMD_EXEC_NOW, va( "connect %s", s ) ); return; } if ( !idStr::Icmp( cmd, "startMultiplayer" ) ) { int dedicated = guiActive->State().GetInt( "dedicated" ); cvarSystem->SetCVarBool( "net_LANServer", guiActive->State().GetBool( "server_type" ) ); if ( gui_configServerRate.GetInteger() > 0 ) { // guess the best rate for upstream, number of internet clients if ( gui_configServerRate.GetInteger() == 5 || cvarSystem->GetCVarBool( "net_LANServer" ) ) { cvarSystem->SetCVarInteger( "net_serverMaxClientRate", 25600 ); } else { // internet players int n_clients = cvarSystem->GetCVarInteger( "si_maxPlayers" ); if ( !dedicated ) { n_clients--; } int maxclients = 0; switch ( gui_configServerRate.GetInteger() ) { case 1: // 128 kbits cvarSystem->SetCVarInteger( "net_serverMaxClientRate", 8000 ); maxclients = 2; break; case 2: // 256 kbits cvarSystem->SetCVarInteger( "net_serverMaxClientRate", 9500 ); maxclients = 3; break; case 3: // 384 kbits cvarSystem->SetCVarInteger( "net_serverMaxClientRate", 10500 ); maxclients = 4; break; case 4: // 512 and above.. cvarSystem->SetCVarInteger( "net_serverMaxClientRate", 14000 ); maxclients = 4; break; } if ( n_clients > maxclients ) { if ( MessageBox( MSG_OKCANCEL, va( common->GetLanguageDict()->GetString( "#str_04315" ), dedicated ? maxclients : Min( 8, maxclients + 1 ) ), common->GetLanguageDict()->GetString( "#str_04316" ), true, "OK" )[ 0 ] == '\0' ) { continue; } cvarSystem->SetCVarInteger( "si_maxPlayers", dedicated ? maxclients : Min( 8, maxclients + 1 ) ); } } } if ( !dedicated && !cvarSystem->GetCVarBool( "net_LANServer" ) && cvarSystem->GetCVarInteger("si_maxPlayers") > 4 ) { // "Dedicated server mode is recommended for internet servers with more than 4 players. Continue in listen mode?" if ( !MessageBox( MSG_YESNO, common->GetLanguageDict()->GetString ( "#str_00100625" ), common->GetLanguageDict()->GetString ( "#str_00100626" ), true, "yes" )[ 0 ] ) { continue; } } if ( dedicated ) { cvarSystem->SetCVarInteger( "net_serverDedicated", 1 ); } else { cvarSystem->SetCVarInteger( "net_serverDedicated", 0 ); } ExitMenu(); // may trigger a reloadEngine - APPEND cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "SpawnServer\n" ); return; } if ( !idStr::Icmp( cmd, "mpSkin")) { idStr skin; if ( args.Argc() - icmd >= 1 ) { skin = args.Argv( icmd++ ); cvarSystem->SetCVarString( "ui_skin", skin ); SetMainMenuSkin(); } continue; } if ( !idStr::Icmp( cmd, "close" ) ) { // if we aren't in a game, the menu can't be closed if ( mapSpawned ) { ExitMenu(); } continue; } if ( !idStr::Icmp( cmd, "resetdefaults" ) ) { cmdSystem->BufferCommandText( CMD_EXEC_NOW, "exec default.cfg" ); guiMainMenu->SetKeyBindingNames(); continue; } if ( !idStr::Icmp( cmd, "bind" ) ) { if ( args.Argc() - icmd >= 2 ) { int key = atoi( args.Argv( icmd++ ) ); idStr bind = args.Argv( icmd++ ); if ( idKeyInput::NumBinds( bind ) >= 2 && !idKeyInput::KeyIsBoundTo( key, bind ) ) { idKeyInput::UnbindBinding( bind ); } idKeyInput::SetBinding( key, bind ); guiMainMenu->SetKeyBindingNames(); } continue; } if ( !idStr::Icmp( cmd, "play" ) ) { if ( args.Argc() - icmd >= 1 ) { idStr snd = args.Argv( icmd++ ); int channel = 1; if ( snd.Length() == 1 ) { channel = atoi( snd ); snd = args.Argv( icmd++ ); } menuSoundWorld->PlayShaderDirectly( snd, channel ); } continue; } if ( !idStr::Icmp( cmd, "music" ) ) { if ( args.Argc() - icmd >= 1 ) { idStr snd = args.Argv( icmd++ ); menuSoundWorld->PlayShaderDirectly( snd, 2 ); } continue; } // triggered from mainmenu or mpmain if ( !idStr::Icmp( cmd, "sound" ) ) { idStr vcmd; if ( args.Argc() - icmd >= 1 ) { vcmd = args.Argv( icmd++ ); } if ( !vcmd.Length() || !vcmd.Icmp( "speakers" ) ) { int old = cvarSystem->GetCVarInteger( "s_numberOfSpeakers" ); cmdSystem->BufferCommandText( CMD_EXEC_NOW, "s_restart\n" ); if ( old != cvarSystem->GetCVarInteger( "s_numberOfSpeakers" ) ) { #ifdef _WIN32 MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_04142" ), common->GetLanguageDict()->GetString( "#str_04141" ), true ); #else // a message that doesn't mention the windows control panel MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_07230" ), common->GetLanguageDict()->GetString( "#str_04141" ), true ); #endif } } if ( !vcmd.Icmp( "eax" ) ) { if ( cvarSystem->GetCVarBool( "s_useEAXReverb" ) ) { int efx = soundSystem->IsEFXAvailable(); switch ( efx ) { case 1: // when you restart MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_04137" ), common->GetLanguageDict()->GetString( "#str_07231" ), true ); break; case -1: cvarSystem->SetCVarBool( "s_useEAXReverb", false ); // disabled MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_07233" ), common->GetLanguageDict()->GetString( "#str_07231" ), true ); break; case 0: cvarSystem->SetCVarBool( "s_useEAXReverb", false ); // not available MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_07232" ), common->GetLanguageDict()->GetString( "#str_07231" ), true ); break; } } else { // when you restart MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_04137" ), common->GetLanguageDict()->GetString( "#str_07231" ), true ); } } if ( !vcmd.Icmp( "drivar" ) ) { cmdSystem->BufferCommandText( CMD_EXEC_NOW, "s_restart\n" ); } continue; } if ( !idStr::Icmp( cmd, "video" ) ) { idStr vcmd; if ( args.Argc() - icmd >= 1 ) { vcmd = args.Argv( icmd++ ); } int oldSpec = com_machineSpec.GetInteger(); if ( idStr::Icmp( vcmd, "low" ) == 0 ) { com_machineSpec.SetInteger( 0 ); } else if ( idStr::Icmp( vcmd, "medium" ) == 0 ) { com_machineSpec.SetInteger( 1 ); } else if ( idStr::Icmp( vcmd, "high" ) == 0 ) { com_machineSpec.SetInteger( 2 ); } else if ( idStr::Icmp( vcmd, "ultra" ) == 0 ) { com_machineSpec.SetInteger( 3 ); } else if ( idStr::Icmp( vcmd, "recommended" ) == 0 ) { cmdSystem->BufferCommandText( CMD_EXEC_NOW, "setMachineSpec\n" ); } if ( oldSpec != com_machineSpec.GetInteger() ) { guiActive->SetStateInt( "com_machineSpec", com_machineSpec.GetInteger() ); guiActive->StateChanged( com_frameTime ); cmdSystem->BufferCommandText( CMD_EXEC_NOW, "execMachineSpec\n" ); } if ( idStr::Icmp( vcmd, "restart" ) == 0) { guiActive->HandleNamedEvent( "cvar write render" ); cmdSystem->BufferCommandText( CMD_EXEC_NOW, "vid_restart\n" ); } continue; } if ( !idStr::Icmp( cmd, "clearBind" ) ) { if ( args.Argc() - icmd >= 1 ) { idKeyInput::UnbindBinding( args.Argv( icmd++ ) ); guiMainMenu->SetKeyBindingNames(); } continue; } // FIXME: obsolete if ( !idStr::Icmp( cmd, "chatdone" ) ) { idStr temp = guiActive->State().GetString( "chattext" ); temp += "\r"; guiActive->SetStateString( "chattext", "" ); continue; } if ( !idStr::Icmp ( cmd, "exec" ) ) { //Backup the language so we can restore it after defaults. idStr lang = cvarSystem->GetCVarString("sys_lang"); cmdSystem->BufferCommandText( CMD_EXEC_NOW, args.Argv( icmd++ ) ); if ( idStr::Icmp( "cvar_restart", args.Argv( icmd - 1 ) ) == 0 ) { cmdSystem->BufferCommandText( CMD_EXEC_NOW, "exec default.cfg" ); cmdSystem->BufferCommandText( CMD_EXEC_NOW, "setMachineSpec\n" ); //Make sure that any r_brightness changes take effect float bright = cvarSystem->GetCVarFloat("r_brightness"); cvarSystem->SetCVarFloat("r_brightness", 0.0f); cvarSystem->SetCVarFloat("r_brightness", bright); //Force user info modified after a reset to defaults cvarSystem->SetModifiedFlags(CVAR_USERINFO); guiActive->SetStateInt( "com_machineSpec", com_machineSpec.GetInteger() ); //Restore the language cvarSystem->SetCVarString("sys_lang", lang); } continue; } if ( !idStr::Icmp ( cmd, "loadBinds" ) ) { guiMainMenu->SetKeyBindingNames(); continue; } if ( !idStr::Icmp( cmd, "systemCvars" ) ) { guiActive->HandleNamedEvent( "cvar read render" ); guiActive->HandleNamedEvent( "cvar read sound" ); continue; } if ( !idStr::Icmp( cmd, "SetCDKey" ) ) { // we can't do this from inside the HandleMainMenuCommands code, otherwise the message box stuff gets confused cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "promptKey\n" ); continue; } if ( !idStr::Icmp( cmd, "CheckUpdate" ) ) { idAsyncNetwork::client.SendVersionCheck(); continue; } if ( !idStr::Icmp( cmd, "CheckUpdate2" ) ) { idAsyncNetwork::client.SendVersionCheck( true ); continue; } if ( !idStr::Icmp( cmd, "checkKeys" ) ) { #if ID_ENFORCE_KEY // not a strict check so you silently auth in the background without bugging the user if ( !session->CDKeysAreValid( false ) ) { cmdSystem->BufferCommandText( CMD_EXEC_NOW, "promptKey force" ); cmdSystem->ExecuteCommandBuffer(); } #endif continue; } // triggered from mainmenu or mpmain if ( !idStr::Icmp( cmd, "punkbuster" ) ) { idStr vcmd; if ( args.Argc() - icmd >= 1 ) { vcmd = args.Argv( icmd++ ); } // filtering PB based on enabled/disabled idAsyncNetwork::client.serverList.ApplyFilter( ); SetPbMenuGuiVars(); continue; } } }