DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

MenuWidget_Shell_SaveInfo.cpp (5874B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 #pragma hdrstop
     29 #include "../../idLib/precompiled.h"
     30 #include "../Game_local.h"
     31 
     32 /*
     33 ========================
     34 idMenuWidget_Shell_SaveInfo::Update
     35 ========================
     36 */
     37 void idMenuWidget_Shell_SaveInfo::Update() {
     38 
     39 	if ( GetSWFObject() == NULL ) {
     40 		return;
     41 	}
     42 
     43 	idSWFScriptObject & root = GetSWFObject()->GetRootObject();
     44 	if ( !BindSprite( root ) || GetSprite() == NULL ) {
     45 		return;
     46 	}
     47 
     48 	const saveGameDetailsList_t & saveGameInfo = session->GetSaveGameManager().GetEnumeratedSavegames();
     49 
     50 	saveGameDetailsList_t sortedSaves = saveGameInfo;
     51 	sortedSaves.Sort( idSort_SavesByDate() );
     52 
     53 	for ( int slot = 0; slot < sortedSaves.Num(); ++slot ) {
     54 		const idSaveGameDetails & details = sortedSaves[slot];	
     55 		if ( forSaveScreen && details.slotName.Icmp( "autosave" ) == 0 ) {
     56 			sortedSaves.RemoveIndex( slot );
     57 			slot--;
     58 		}
     59 	}
     60 
     61 	idStr info;
     62 	if ( loadIndex >= 0 && sortedSaves.Num() != 0 && loadIndex < sortedSaves.Num() ) {
     63 		const idSaveGameDetails & details = sortedSaves[ loadIndex ];		
     64 		
     65 		info.Append( Sys_TimeStampToStr( details.date ) );
     66 		info.Append( "\n" );
     67 
     68 		// PS3 only strings that use the dict just set
     69 		const char * expansionStr = "";
     70 		switch ( details.GetExpansion() ) {
     71 		case GAME_D3XP: expansionStr = idLocalization::GetString( "#str_swf_resurrection" ); break;
     72 		case GAME_D3LE: expansionStr = idLocalization::GetString( "#str_swf_lost_episodes" ); break;
     73 		case GAME_BASE: expansionStr = idLocalization::GetString( "#str_swf_doom3" ); break;
     74 		default: expansionStr = idLocalization::GetString( "#str_savegame_title" ); break;
     75 		}
     76 
     77 		const char * difficultyStr = "";
     78 		switch ( details.GetDifficulty() ) {
     79 		case 0: difficultyStr = idLocalization::GetString( "#str_04089" ); break;
     80 		case 1: difficultyStr = idLocalization::GetString( "#str_04091" ); break;
     81 		case 2: difficultyStr = idLocalization::GetString( "#str_04093" ); break;
     82 		case 3: difficultyStr = idLocalization::GetString( "#str_02357" ); break;
     83 		}
     84 
     85 		idStr summary;
     86 		summary.Format( idLocalization::GetString( "#str_swf_save_info_format" ), difficultyStr, Sys_SecToStr( details.GetPlaytime() ), expansionStr );
     87 
     88 		info.Append( summary );
     89 
     90 		if ( details.damaged ) {
     91 			info.Append( "\n" );
     92 			info.Append( va( "^1%s^0", idLocalization::GetString( "#str_swf_damaged" ) ) );
     93 		} else if ( details.GetSaveVersion() > BUILD_NUMBER ) {
     94 			info.Append( "\n" );
     95 			info.Append( va( "^1%s^0", idLocalization::GetString( "#str_swf_wrong_version" ) ) );
     96 		}
     97 	}
     98 
     99 	idSWFTextInstance * infoSprite = GetSprite()->GetScriptObject()->GetNestedText( "txtDesc" );
    100 	if ( infoSprite != NULL ) {
    101 		infoSprite->SetText( info );
    102 	}
    103 
    104 	idSWFSpriteInstance * img = GetSprite()->GetScriptObject()->GetNestedSprite( "img" );
    105 	if ( img != NULL ) {
    106 		// TODO_SPARTY: until we have a thumbnail hide the image
    107 		img->SetVisible( false );
    108 	}
    109 }
    110 
    111 /*
    112 ========================
    113 idMenuWidget_Help::ObserveEvent
    114 ========================
    115 */
    116 void idMenuWidget_Shell_SaveInfo::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) {
    117 	const idMenuWidget_Button * const button = dynamic_cast< const idMenuWidget_Button * >( &widget );
    118 	if ( button == NULL ) {
    119 		return;
    120 	}
    121 
    122 	const idMenuWidget * const listWidget = button->GetParent();
    123 
    124 	if ( listWidget == NULL ) {
    125 		return;
    126 	}
    127 
    128 	switch ( event.type ) {
    129 		case WIDGET_EVENT_FOCUS_ON: {
    130 			const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );			
    131 			loadIndex = list->GetViewIndex();
    132 
    133 			const saveGameDetailsList_t & detailList = session->GetSaveGameManager().GetEnumeratedSavegames();
    134 			bool hasAutoSave = false;
    135 			for ( int i = 0; i < detailList.Num(); ++i ) {
    136 				if ( detailList[i].slotName.Icmp( "autosave" ) == 0 ) {
    137 					hasAutoSave = true;
    138 				}
    139 			}
    140 
    141 
    142 			if ( forSaveScreen && ( ( detailList.Num() < MAX_SAVEGAMES - 1 ) || ( ( detailList.Num() == MAX_SAVEGAMES - 1 ) && hasAutoSave ) ) ) {
    143 				loadIndex -= 1;
    144 			}
    145 
    146 			Update();
    147 
    148 			idMenuScreen_Shell_Load * loadScreen = dynamic_cast< idMenuScreen_Shell_Load * >( GetParent() );
    149 			if ( loadScreen ) {
    150 				loadScreen->UpdateSaveEnumerations();
    151 			}
    152 
    153 			idMenuScreen_Shell_Save * saveScreen = dynamic_cast< idMenuScreen_Shell_Save * >( GetParent() );
    154 			if ( saveScreen ) {
    155 				saveScreen->UpdateSaveEnumerations();
    156 			}
    157 
    158 			break;
    159 		}
    160 	}
    161 }