/* =============== idSessionLocal::SetSaveGameGuiVars =============== */ void idSessionLocal::SetSaveGameGuiVars(void) { int i; idStr name; idStrList fileList; idList<fileTIME_T> fileTimes; loadGameList.Clear(); fileList.Clear(); fileTimes.Clear(); GetSaveGameList(fileList, fileTimes); loadGameList.SetNum(fileList.Num()); for (i = 0; i < fileList.Num(); i++) { loadGameList[i] = fileList[fileTimes[i].index]; idLexer src(LEXFL_NOERRORS|LEXFL_NOSTRINGCONCAT); if (src.LoadFile(va("savegames/%s.txt", loadGameList[i].c_str()))) { idToken tok; src.ReadToken(&tok); name = tok; } else { name = loadGameList[i]; } name += "\t"; idStr date = Sys_TimeStampToStr(fileTimes[i].timeStamp); name += date; guiActive->SetStateString(va("loadgame_item_%i", i), name); } guiActive->DeleteStateVar(va("loadgame_item_%i", fileList.Num())); guiActive->SetStateString("loadgame_sel_0", "-1"); guiActive->SetStateString("loadgame_shot", "guis/assets/blankLevelShot"); }
/* ============== idSessionLocal::HandleSaveGameMenuCommands ============== */ bool idSessionLocal::HandleSaveGameMenuCommand( idCmdArgs &args, int &icmd ) { const char *cmd = args.Argv(icmd-1); if ( !idStr::Icmp( cmd, "loadGame" ) ) { int choice = guiActive->State().GetInt("loadgame_sel_0"); if ( choice >= 0 && choice < loadGameList.Num() ) { sessLocal.LoadGame( loadGameList[choice] ); } return true; } if ( !idStr::Icmp( cmd, "saveGame" ) ) { const char *saveGameName = guiActive->State().GetString("saveGameName"); if ( saveGameName && saveGameName[0] ) { // First see if the file already exists unless they pass '1' to authorize the overwrite if ( icmd == args.Argc() || atoi(args.Argv( icmd++ )) == 0 ) { idStr saveFileName = saveGameName; sessLocal.ScrubSaveGameFileName( saveFileName ); saveFileName = "savegames/" + saveFileName; saveFileName.SetFileExtension(".save"); idStr game = cvarSystem->GetCVarString( "fs_game" ); idFile *file; if(game.Length()) { file = fileSystem->OpenFileRead( saveFileName, true, game ); } else { file = fileSystem->OpenFileRead( saveFileName ); } if ( file != NULL ) { fileSystem->CloseFile( file ); // The file exists, see if it's an autosave saveFileName.SetFileExtension(".txt"); idLexer src(LEXFL_NOERRORS|LEXFL_NOSTRINGCONCAT); if ( src.LoadFile( saveFileName ) ) { idToken tok; src.ReadToken( &tok ); // Name src.ReadToken( &tok ); // Map src.ReadToken( &tok ); // Screenshot if ( !tok.IsEmpty() ) { // NOTE: base/ gui doesn't handle that one guiActive->HandleNamedEvent( "autosaveOverwriteError" ); return true; } } guiActive->HandleNamedEvent( "saveGameOverwrite" ); return true; } } sessLocal.SaveGame( saveGameName ); SetSaveGameGuiVars( ); guiActive->StateChanged( com_frameTime ); } return true; } if ( !idStr::Icmp( cmd, "deleteGame" ) ) { int choice = guiActive->State().GetInt( "loadgame_sel_0" ); if ( choice >= 0 && choice < loadGameList.Num() ) { fileSystem->RemoveFile( va("savegames/%s.save", loadGameList[choice].c_str()) ); fileSystem->RemoveFile( va("savegames/%s.tga", loadGameList[choice].c_str()) ); fileSystem->RemoveFile( va("savegames/%s.txt", loadGameList[choice].c_str()) ); SetSaveGameGuiVars( ); guiActive->StateChanged( com_frameTime ); } return true; } if ( !idStr::Icmp( cmd, "updateSaveGameInfo" ) ) { int choice = guiActive->State().GetInt( "loadgame_sel_0" ); if ( choice >= 0 && choice < loadGameList.Num() ) { const idMaterial *material; idStr saveName, description, screenshot; idLexer src(LEXFL_NOERRORS|LEXFL_NOSTRINGCONCAT); if ( src.LoadFile( va("savegames/%s.txt", loadGameList[choice].c_str()) ) ) { idToken tok; src.ReadToken( &tok ); saveName = tok; src.ReadToken( &tok ); description = tok; src.ReadToken( &tok ); screenshot = tok; } else { saveName = loadGameList[choice]; description = loadGameList[choice]; screenshot = ""; } if ( screenshot.Length() == 0 ) { screenshot = va("savegames/%s.tga", loadGameList[choice].c_str()); } material = declManager->FindMaterial( screenshot ); if ( material ) { material->ReloadImages( false ); } guiActive->SetStateString( "loadgame_shot", screenshot ); saveName.RemoveColors(); guiActive->SetStateString( "saveGameName", saveName ); guiActive->SetStateString( "saveGameDescription", description ); ID_TIME_T timeStamp; fileSystem->ReadFile( va("savegames/%s.save", loadGameList[choice].c_str()), NULL, &timeStamp ); idStr date = Sys_TimeStampToStr(timeStamp); int tab = date.Find( '\t' ); idStr time = date.Right( date.Length() - tab - 1); guiActive->SetStateString( "saveGameDate", date.Left( tab ) ); guiActive->SetStateString( "saveGameTime", time ); } return true; } return false; }
/* ======================== idMenuWidget_Shell_SaveInfo::Update ======================== */ void idMenuWidget_Shell_SaveInfo::Update() { if( GetSWFObject() == NULL ) { return; } idSWFScriptObject& root = GetSWFObject()->GetRootObject(); if( !BindSprite( root ) || GetSprite() == NULL ) { return; } const saveGameDetailsList_t& saveGameInfo = session->GetSaveGameManager().GetEnumeratedSavegames(); saveGameDetailsList_t sortedSaves = saveGameInfo; sortedSaves.Sort( idSort_SavesByDate() ); for( int slot = 0; slot < sortedSaves.Num(); ++slot ) { const idSaveGameDetails& details = sortedSaves[slot]; if( forSaveScreen && details.slotName.Icmp( "autosave" ) == 0 ) { sortedSaves.RemoveIndex( slot ); slot--; } } idStr info; if( loadIndex >= 0 && sortedSaves.Num() != 0 && loadIndex < sortedSaves.Num() ) { const idSaveGameDetails& details = sortedSaves[ loadIndex ]; info.Append( Sys_TimeStampToStr( details.date ) ); info.Append( "\n" ); // PS3 only strings that use the dict just set const char* expansionStr = ""; switch( details.GetExpansion() ) { case GAME_D3XP: expansionStr = idLocalization::GetString( "#str_swf_resurrection" ); break; case GAME_D3LE: expansionStr = idLocalization::GetString( "#str_swf_lost_episodes" ); break; case GAME_BASE: expansionStr = idLocalization::GetString( "#str_swf_doom3" ); break; default: expansionStr = idLocalization::GetString( "#str_savegame_title" ); break; } const char* difficultyStr = ""; switch( details.GetDifficulty() ) { case 0: difficultyStr = idLocalization::GetString( "#str_swf_difficulty_easy" ); // easy break; case 1: difficultyStr = idLocalization::GetString( "#str_swf_difficulty_medium" ); // medium break; case 2: difficultyStr = idLocalization::GetString( "#str_swf_difficulty_hard" ); // hard break; case 3: difficultyStr = idLocalization::GetString( "#str_swf_difficulty_impossible" ); // impossible break; } idStr summary; summary.Format( idLocalization::GetString( "#str_swf_save_info_format" ), difficultyStr, Sys_SecToStr( details.GetPlaytime() ), expansionStr ); info.Append( summary ); if( details.damaged ) { info.Append( "\n" ); info.Append( va( "^1%s^0", idLocalization::GetString( "#str_swf_damaged" ) ) ); } else if( details.GetSaveVersion() > BUILD_NUMBER ) { info.Append( "\n" ); info.Append( va( "^1%s^0", idLocalization::GetString( "#str_swf_wrong_version" ) ) ); } } idSWFTextInstance* infoSprite = GetSprite()->GetScriptObject()->GetNestedText( "txtDesc" ); if( infoSprite != NULL ) { infoSprite->SetText( info ); } idSWFSpriteInstance* img = GetSprite()->GetScriptObject()->GetNestedSprite( "img" ); if( img != NULL ) { // TODO_SPARTY: until we have a thumbnail hide the image if(forSaveScreen ) img->SetVisible( false ); else img->SetVisible( true ); if( saveGameThumbnails[loadIndex] != NULL ) { // Use Detected Thumbnail img->SetMaterial( saveGameThumbnails[loadIndex] ); } else { if(saveThumbDefault != NULL) { // Use Default Thumbnail. img->SetMaterial( saveThumbDefault ); } else { // No thumbnail Image exists. img->SetVisible( false ); } } } }