53#if OO_USE_CUSTOM_LOAD_SAVE
54#define COMMAND_MODIFIER_KEY "Ctrl"
61#if OO_USE_CUSTOM_LOAD_SAVE
63@interface MyOpenGLView (OOLoadSaveExtensions)
72@interface PlayerEntity (OOLoadSavePrivate)
74#if OOLITE_USE_APPKIT_LOAD_SAVE
76- (BOOL) loadPlayerWithPanel;
77- (void) savePlayerWithPanel;
81#if OO_USE_CUSTOM_LOAD_SAVE
83- (void) setGuiToLoadCommanderScreen;
84- (void) setGuiToSaveCommanderScreen: (NSString *)cdrName;
85- (void) setGuiToOverwriteScreen: (NSString *)cdrName;
86- (void) lsCommanders: (
GuiDisplayGen *)gui directory: (NSString*)directory pageNumber: (
int)page highlightName: (NSString *)highlightName;
87- (void) showCommanderShip: (
int)cdrArrayIndex;
88- (
int) findIndexOfCommander: (NSString *)cdrName;
89- (void) nativeSavePlayer: (NSString *)cdrName;
90- (BOOL) existingNativeSave: (NSString *)cdrName;
94- (void) writePlayerToPath:(NSString *)path;
99@implementation PlayerEntity (LoadSave)
105#if OO_USE_APPKIT_LOAD_SAVE_ALWAYS
107#elif OOLITE_USE_APPKIT_LOAD_SAVE
109 if ([[
UNIVERSE gameController] inFullScreenMode])
127#if OO_USE_APPKIT_LOAD_SAVE_ALWAYS
128 [
self savePlayerWithPanel];
129#elif OOLITE_USE_APPKIT_LOAD_SAVE
131 if ([[
UNIVERSE gameController] inFullScreenMode])
133 [
self setGuiToSaveCommanderScreen:self.lastsaveName];
137 [
self savePlayerWithPanel];
141 [
self setGuiToSaveCommanderScreen:[
self lastsaveName]];
145- (void) autosavePlayer
147 NSString *tmp_path =
nil;
148 NSString *tmp_name =
nil;
149 NSString *dir = [[UNIVERSE gameController] playerFileDirectory];
151 tmp_name = [
self lastsaveName];
152 tmp_path = save_path;
156 NSString *saveName = [
self lastsaveName];
157 NSString *autosaveSuffix =
DESC(
@"autosave-commander-suffix");
159 if (![saveName hasSuffix:autosaveSuffix])
161 saveName = [saveName stringByAppendingString:autosaveSuffix];
163 NSString *savePath = [dir stringByAppendingPathComponent:[saveName stringByAppendingString:@".oolite-save"]];
165 [
self setLastsaveName:saveName];
169 [
self writePlayerToPath:savePath];
171 @catch (
id exception)
178 [save_path autorelease];
179 save_path = [tmp_path copy];
181 [
self setLastsaveName:tmp_name];
185- (void) quicksavePlayer
188 NSString *path =
nil;
194 OOLog(
@"quickSave.failed.noName",
@"%@",
@"ERROR no file name returned by [[gameView gameController] playerFileToLoad]");
195 [NSException raise:@"OoliteGameNotSavedException"
196 format:@"ERROR no file name returned by [[gameView gameController] playerFileToLoad]"];
201 [
self writePlayerToPath:path];
202 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
203 [
self setGuiToStatusScreen];
207- (void) setGuiToScenarioScreen:(
int)page
209 NSArray *scenarios = [UNIVERSE scenarios];
210 [UNIVERSE removeDemoShips];
216 BOOL guiChanged = (gui_screen != GUI_SCREEN_NEWGAME);
219 [gui
setTitle:DESC(@"oolite-newgame-title")];
227 NSUInteger i,
count = [scenarios count];
229 NSDictionary *scenario =
nil;
231 [gui
setArray:[NSArray arrayWithObjects:DESC(@"oolite-scenario-exit"), @" <----- ", nil]
forRow:start_row - 2];
238 [gui
setArray:[NSArray arrayWithObjects:DESC(@"gui-back"), @" <-- ", nil]
forRow:start_row - 1];
240 [gui
setKey:[NSString stringWithFormat:@"__page:%i",page-1]
forRow:start_row - 1];
243 [
self setShowDemoShips:NO];
245 for (i = page*n_rows ; i <
count && row < start_row + n_rows ; i++)
247 scenario = [[UNIVERSE scenarios] objectAtIndex:i];
248 NSString *scenarioName = [NSString stringWithFormat:@" %@ ",[scenario oo_stringForKey:@"name"]];
250 [gui
setKey:[NSString stringWithFormat:@"Scenario:%lu", (unsigned long)i]
forRow:row];
254 if ((page+1) * n_rows <
count)
256 [gui
setArray:[NSArray arrayWithObjects:DESC(@"gui-more"), @" --> ", nil]
forRow:row];
258 [gui
setKey:[NSString stringWithFormat:@"__page:%i",page+1]
forRow:row];
264 [
self showScenarioDetails];
266 gui_screen = GUI_SCREEN_NEWGAME;
275 [UNIVERSE enterGUIViewModeWithMouseInteraction:YES];
278- (void) addScenarioModel:(NSString *)shipKey
280 [
self showShipModelWithKey:shipKey shipData:nil personality:0 factorX:1.2 factorY:0.8 factorZ:6.4 inContext:@"scenario"];
284- (void) showScenarioDetails
288 [UNIVERSE removeDemoShips];
290 if ([key hasPrefix:
@"Scenario"])
292 int item = [[key componentsSeparatedByString:@":"] oo_intAtIndex:1];
293 NSDictionary *scenario = [[UNIVERSE scenarios] objectAtIndex:item];
294 [
self setShowDemoShips:NO];
302 NSString *shipKey = [scenario oo_stringForKey:@"model"];
305 [
self addScenarioModel:shipKey];
306 [
self setShowDemoShips:YES];
314- (BOOL) startScenario
319 if ([key isEqualToString:
@"exit"])
324 if ([key hasPrefix:
@"__page"])
326 int page = [[key componentsSeparatedByString:@":"] oo_intAtIndex:1];
327 [
self setGuiToScenarioScreen:page];
330 int selection = [[key componentsSeparatedByString:@":"] oo_intAtIndex:1];
332 NSDictionary *scenario = [[UNIVERSE scenarios] objectAtIndex:selection];
333 NSString *file = [scenario oo_stringForKey:@"file" defaultValue:nil];
336 OOLog(
@"scenario.init.error",
@"%@",
@"No file entry found for scenario");
342 OOLog(
@"scenario.init.error",
@"Game file not found for scenario %@",file);
345 BOOL result = [
self loadPlayerFromFile:path asNew:YES];
350 [scenarioKey release];
351 scenarioKey = [[scenario oo_stringForKey:@"scenario" defaultValue:nil] retain];
360#if OO_USE_CUSTOM_LOAD_SAVE
362- (NSString *)commanderSelector
366 NSString *dir = [[UNIVERSE gameController] playerFileDirectory];
369 if([
self handleGUIUpDownArrowKeys])
375 [
self showCommanderShip: idx];
379 [UNIVERSE removeDemoShips];
392 if (([
self checkKeyPress:n_key_gui_arrow_left] || [
self checkKeyPress:n_key_gui_page_up]) && [[gui keyForRow:
BACKROW] isEqual:
GUI_KEY_OK])
395 [
self playMenuPagePrevious];
396 [
self lsCommanders: gui directory: dir pageNumber: currentPage highlightName: nil];
399 if (([
self checkKeyPress:n_key_gui_arrow_right] || [
self checkKeyPress:n_key_gui_page_down]) && [[gui keyForRow:
MOREROW] isEqual:
GUI_KEY_OK])
402 [
self playMenuPageNext];
403 [
self lsCommanders: gui directory: dir pageNumber: currentPage highlightName: nil];
409 if ([
self checkKeyPress:n_key_gui_select ignore_ctrl:YES]||[gameView isDown:
gvMouseDoubleClick])
412 switch ([gui selectedRow])
415 if ([
self status] == STATUS_START_GAME)
417 [
self setGuiToIntroFirstGo:YES];
423 [
self lsCommanders: gui directory: dir pageNumber: currentPage highlightName: nil];
428 [
self lsCommanders: gui directory: dir pageNumber: currentPage highlightName: nil];
432 cdr=[cdrDetailArray objectAtIndex: idx];
433 if ([cdr oo_boolForKey:
@"isSavedGame"])
434 return [cdr oo_stringForKey:@"saved_game_path"];
440 NSString* newDir = [cdr oo_stringForKey:@"saved_game_path"];
441 [[UNIVERSE gameController] setPlayerFileDirectory: newDir];
444 [
self lsCommanders: gui directory: dir pageNumber: currentPage highlightName: nil];
451 if([gameView isDown: 27])
453 [
self setGuiToStatusScreen];
459- (void) saveCommanderInputHandler
463 NSString *dir = [[UNIVERSE gameController] playerFileDirectory];
465 if ([
self handleGUIUpDownArrowKeys])
471 [
self showCommanderShip: idx];
472 if ([(NSDictionary *)[cdrDetailArray objectAtIndex:idx] oo_boolForKey:
@"isSavedGame"])
473 commanderNameString = [[cdrDetailArray oo_dictionaryAtIndex:idx] oo_stringForKey:@"player_save_name" defaultValue:[[cdrDetailArray oo_dictionaryAtIndex:idx] oo_stringForKey:@"player_name"]];
479 [UNIVERSE removeDemoShips];
493 [NSString stringWithFormat:DESC(@"savescreen-commander-name-@"), commanderNameString]
498 if (((([gameView isDown:
gvMouseDoubleClick] || [
self checkKeyPress:n_key_gui_select]) && [gui selectedRow] ==
BACKROW) || ([
self checkKeyPress:n_key_gui_arrow_left] || [
self checkKeyPress:n_key_gui_page_up]))
502 [
self lsCommanders: gui directory: dir pageNumber: currentPage highlightName: nil];
506 if (((([gameView isDown:
gvMouseDoubleClick] || [
self checkKeyPress:n_key_gui_select]) && [gui selectedRow] ==
MOREROW) || ([
self checkKeyPress:n_key_gui_arrow_right] || [
self checkKeyPress:n_key_gui_page_down]))
510 [
self lsCommanders: gui directory: dir pageNumber: currentPage highlightName: nil];
515 if(([
self checkKeyPress:n_key_gui_select ignore_ctrl:YES]||[gameView isDown:
gvMouseDoubleClick]) && [commanderNameString length])
521 NSDictionary* cdr = [cdrDetailArray objectAtIndex:idx];
523 if (![cdr oo_boolForKey:
@"isSavedGame"])
526 NSString* newDir = [cdr oo_stringForKey:@"saved_game_path"];
527 [[UNIVERSE gameController] setPlayerFileDirectory: newDir];
530 [
self lsCommanders: gui directory: dir pageNumber: currentPage highlightName: nil];
537 if ([
self existingNativeSave: commanderNameString])
540 [
self setGuiToOverwriteScreen: commanderNameString];
544 [
self nativeSavePlayer: commanderNameString];
545 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
546 [
self setGuiToStatusScreen];
551 if([gameView isDown: 27])
555 [[UNIVERSE gameView] resetTypedString];
556 [
self setGuiToStatusScreen];
561- (void) overwriteCommanderInputHandler
566 [
self handleGUIUpDownArrowKeys];
569 id valueYes = [[[UNIVERSE descriptions] oo_stringForKey:@"load-previous-commander-yes" defaultValue:@"y"] lowercaseString];
570 id valueNo = [[[UNIVERSE descriptions] oo_stringForKey:@"load-previous-commander-no" defaultValue:@"n"] lowercaseString];
571 unsigned char cYes, cNo;
573 cYes = [valueYes characterAtIndex: 0] & 0x00ff;
574 cNo = [valueNo characterAtIndex: 0] & 0x00ff;
576 if (([
self checkKeyPress:n_key_gui_select] && ([gui selectedRow] ==
SAVE_OVERWRITE_YES_ROW))||[gameView isDown:cYes]||[gameView isDown:cYes - 32])
579 [
self nativeSavePlayer: commanderNameString];
580 [
self playSaveOverwriteYes];
581 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
582 [
self setGuiToStatusScreen];
585 if (([
self checkKeyPress:n_key_gui_select] && ([gui selectedRow] ==
SAVE_OVERWRITE_NO_ROW))||[gameView isDown:27]||[gameView isDown:cNo]||[gameView isDown:cNo - 32])
589 [
self playSaveOverwriteNo];
590 [
self setGuiToSaveCommanderScreen:@""];
597- (BOOL) loadPlayerFromFile:(NSString *)fileToOpen asNew:(BOOL)asNew
609 NSDictionary *fileDic =
nil;
610 NSString *fail_reason =
nil;
612 if (fileToOpen ==
nil)
614 fail_reason =
DESC(
@"loadfailed-no-file-specified");
620 OOLog(
@"load.progress",
@"%@",
@"Reading file");
624 fail_reason =
DESC(
@"loadfailed-could-not-load-file");
631 OOLog(
@"load.progress",
@"%@",
@"Restricting scenario");
632 NSString *scenarioRestrict = [fileDic oo_stringForKey:@"scenario_restriction" defaultValue:nil];
633 if (scenarioRestrict ==
nil)
636 BOOL strict = [fileDic oo_boolForKey:@"strict" defaultValue:NO];
647 if (![
UNIVERSE setUseAddOns:scenarioRestrict fromSaveGame:YES forceReinit:YES])
649 fail_reason =
DESC(
@"loadfailed-saved-game-failed-to-load");
657 OOLog(
@"load.progress",
@"%@",
@"Creating player ship");
659 NSString *shipKey =
nil;
660 NSDictionary *shipDict =
nil;
662 shipKey = [fileDic oo_stringForKey:@"ship_desc"];
668 if (shipKey !=
nil) fail_reason = [NSString stringWithFormat:DESC(@"loadfailed-could-not-find-ship-type-@-please-reinstall-the-appropriate-OXP"), shipKey];
669 else fail_reason =
DESC(
@"loadfailed-invalid-saved-game-no-ship-specified");
675 OOLog(
@"load.progress",
@"%@",
@"Initialising player entity");
676 if (![
self setUpAndConfirmOK:YES saveGame:YES])
678 fail_reason =
DESC(
@"loadfailed-could-not-reset-javascript");
685 OOLog(
@"load.progress",
@"%@",
@"Loading commander data");
686 if (![
self setCommanderDataFromDictionary:fileDic])
690 fail_reason =
DESC(
@"loadfailed-could-not-set-up-player-ship");
697 OOLog(
@"load.progress",
@"%@",
@"Recording save path");
700 [save_path autorelease];
701 save_path = [fileToOpen retain];
703 [[[UNIVERSE gameView] gameController] setPlayerFileToLoad:fileToOpen];
704 [[[UNIVERSE gameView] gameController] setPlayerFileDirectory:fileToOpen];
709 OOLog(
@"load.failed",
@"***** Failed to load saved game \"%@\
": %@", [fileToOpen lastPathComponent], fail_reason ? fail_reason : (NSString *)
@"unknown error");
710 [[UNIVERSE gameController] setPlayerFileToLoad:nil];
711 [UNIVERSE handleGameOver];
712 [UNIVERSE clearPreviousMessage];
713 [UNIVERSE addMessage:DESC(@"loadfailed-saved-game-failed-to-load") forCount: 9.0];
714 if (fail_reason !=
nil) [UNIVERSE addMessage: fail_reason forCount: 9.0];
718 OOLog(
@"load.progress",
@"%@",
@"Creating system");
719 [UNIVERSE setTimeAccelerationFactor:TIME_ACCELERATION_FACTOR_DEFAULT];
720 [UNIVERSE setSystemTo:system_id];
721 [UNIVERSE removeAllEntitiesExceptPlayer];
722 [UNIVERSE setGalaxyTo: galaxy_number andReinit:YES];
723 [UNIVERSE setUpSpace];
724 [UNIVERSE setAutoSaveNow:NO];
726 OOLog(
@"load.progress",
@"%@",
@"Resetting player flight variables");
727 [
self setDockedAtMainStation];
730 [UNIVERSE enterGUIViewModeWithMouseInteraction:NO];
734 position = [dockedStation
position];
735 [
self setOrientation: kIdentityQuaternion];
746 [
self setEntityPersonalityInt:PersonalityForCommanderDict(fileDic)];
748 OOLog(
@"load.progress",
@"%@",
@"Loading system market");
751 NSArray *market = [fileDic oo_arrayForKey:@"localMarket"];
754 [dockedStation setLocalMarket:market];
758 [dockedStation initialiseLocalMarket];
761 [
self calculateCurrentCargo];
763 OOLog(
@"load.progress",
@"%@",
@"Setting scenario key");
765 NSString *scenario = [fileDic oo_stringForKey:@"scenario_key" defaultValue:nil];
769 scenarioKey = [scenario retain];
772 OOLog(
@"load.progress",
@"%@",
@"Starting JS engine");
774 [
self completeSetUpAndSetTarget:NO];
776 OOLog(
@"load.progress",
@"%@",
@"Populating initial system");
777 [UNIVERSE populateNormalSpace];
785 HPVector dockedPos = [fileDic oo_hpvectorForKey:@"docked_station_position"];
786 NSString *dockedRole = [fileDic oo_stringForKey:@"docked_station_role" defaultValue:@""];
787 StationEntity *saveStation = [UNIVERSE stationWithRole:dockedRole andPosition:dockedPos];
788 if (saveStation !=
nil && [saveStation allowsSaving])
790 [
self setDockedStation:saveStation];
794 [UNIVERSE loadStationMarkets:[fileDic oo_arrayForKey:@"station_markets"]];
796 OOLog(
@"load.progress",
@"%@",
@"Completing JS startup");
797 [
self startUpComplete];
799 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
800 gui_screen = GUI_SCREEN_LOAD;
801 [
self setGuiToStatusScreen];
802 if (loadedOK) [
self doWorldEventUntilMissionScreen:OOJSID("missionScreenOpportunity")];
803 OOLog(
@"load.progress",
@"%@",
@"Loading complete");
810@implementation PlayerEntity (OOLoadSavePrivate)
812#if OOLITE_USE_APPKIT_LOAD_SAVE
814- (BOOL)loadPlayerWithPanel
816 NSOpenPanel *oPanel = [NSOpenPanel openPanel];
818 oPanel.allowsMultipleSelection = NO;
819 oPanel.allowedFileTypes = [NSArray arrayWithObject:@"oolite-save"];
821 if ([oPanel runModal] == NSOKButton)
823 NSURL *url = oPanel.URL;
826 return [
self loadPlayerFromFile:url.path asNew:NO];
834- (void) savePlayerWithPanel
836 NSSavePanel *sPanel = [NSSavePanel savePanel];
838 sPanel.allowedFileTypes = [NSArray arrayWithObject:@"oolite-save"];
839 sPanel.canSelectHiddenExtension = YES;
840 sPanel.nameFieldStringValue =
self.lastsaveName;
842 if ([sPanel runModal] == NSOKButton)
844 NSURL *url = sPanel.URL;
845 NSAssert(url.isFileURL,
@"Save panel with default configuration should not provide non-file URLs.");
847 NSString *path = url.path;
848 NSString *newName = [path.lastPathComponent stringByDeletingPathExtension];
852 self.lastsaveName = newName;
853 [
self writePlayerToPath:path];
855 [
self setGuiToStatusScreen];
861- (void) writePlayerToPath:(NSString *)path
863 NSString *errDesc =
nil;
864 NSDictionary *dict =
nil;
866 [[UNIVERSE gameView] resetTypedString];
870 OOLog(
@"save.failed",
@"***** SAVE ERROR: %s called with nil path.", __PRETTY_FUNCTION__);
874 dict = [
self commanderDataDictionary];
875 if (dict ==
nil) errDesc =
@"could not construct commander data dictionary.";
876 else didSave = [dict writeOOXMLToFile:path atomically:YES errorDescription:&errDesc];
879 [UNIVERSE clearPreviousMessage];
880 [UNIVERSE addMessage:DESC(@"game-saved") forCount:2];
881 [save_path autorelease];
882 save_path = [path copy];
883 [[UNIVERSE gameController] setPlayerFileToLoad:save_path];
884 [[UNIVERSE gameController] setPlayerFileDirectory:save_path];
886 [UNIVERSE setAutoSaveNow:NO];
890 OOLog(
@"save.failed",
@"***** SAVE ERROR: %@", errDesc);
891 [NSException raise:@"OoliteException"
892 format:@"Attempt to save game to file '%@' failed: %@", path, errDesc];
894 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
895 [
self setGuiToStatusScreen];
899- (void)nativeSavePlayer:(NSString *)cdrName
901 NSString* dir = [[UNIVERSE gameController] playerFileDirectory];
902 NSString *savePath = [dir stringByAppendingPathComponent:[cdrName stringByAppendingPathExtension:@"oolite-save"]];
906 [
self setLastsaveName:cdrName];
908 [
self writePlayerToPath:savePath];
912#if OO_USE_CUSTOM_LOAD_SAVE
914- (void) setGuiToLoadCommanderScreen
917 NSString* dir = [[UNIVERSE gameController] playerFileDirectory];
919 gui_screen = GUI_SCREEN_LOAD;
922 [gui
setTitle:DESC(@"loadscreen-title")];
925 [
self lsCommanders:gui directory:dir pageNumber: currentPage highlightName:nil];
930 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
932 [
self setShowDemoShips:YES];
933 [UNIVERSE enterGUIViewModeWithMouseInteraction:YES];
937- (void) setGuiToSaveCommanderScreen:(NSString *)cdrName
941 NSString *dir = [[UNIVERSE gameController] playerFileDirectory];
944 gui_screen = GUI_SCREEN_SAVE;
947 [gui
setTitle:DESC(@"savescreen-title")];
950 [
self lsCommanders:gui directory:dir pageNumber: currentPage highlightName:nil];
952 [gui
setText:DESC(@"savescreen-commander-name")
forRow: INPUTROW];
963 [
self setShowDemoShips:YES];
964 [UNIVERSE enterGUIViewModeWithMouseInteraction:YES];
968- (void) setGuiToOverwriteScreen:(NSString *)cdrName
976 gui_screen = GUI_SCREEN_SAVE_OVERWRITE;
979 [gui
setTitle:[NSString stringWithFormat:DESC(@"overwrite-save-commander-@"), cdrName]];
981 [gui
setText:[NSString stringWithFormat:DESC(@"overwritescreen-commander-@-already-exists-overwrite-query"), cdrName]
982 forRow:SAVE_OVERWRITE_WARN_ROW
align: GUI_ALIGN_CENTER];
984 [gui
setText:DESC(@"overwritescreen-yes")
forRow: SAVE_OVERWRITE_YES_ROW
align: GUI_ALIGN_CENTER];
987 [gui
setText:DESC(@"overwritescreen-no")
forRow: SAVE_OVERWRITE_NO_ROW
align: GUI_ALIGN_CENTER];
998 [
self setShowDemoShips:NO];
1000 [UNIVERSE enterGUIViewModeWithMouseInteraction:NO];
1003NSComparisonResult sortCommanders(
id cdr1,
id cdr2,
void *context)
1005 return [[cdr1 objectForKey:@"saved_game_path"] localizedCompare:[cdr2 objectForKey:@"saved_game_path"]];
1009 directory: (NSString*) directory
1010 pageNumber: (
int)page
1011 highlightName: (NSString *)highlightName
1013 NSFileManager *cdrFileManager=[NSFileManager defaultManager];
1020 NSArray *cdrArray=[cdrFileManager commanderContentsOfPath: directory];
1024 if (!cdrDetailArray)
1025 cdrDetailArray=[[NSMutableArray alloc] init];
1027 [cdrDetailArray removeAllObjects];
1029 [cdrDetailArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
1030 @"YES", @"isParentFolder",
1031 [directory stringByDeletingLastPathComponent], @"saved_game_path", nil]];
1033 for(i = 0; i < [cdrArray count]; i++)
1035 NSString* path = [cdrArray objectAtIndex:i];
1036 BOOL exists, isDirectory = NO;
1038 exists = [cdrFileManager fileExistsAtPath:path isDirectory:&isDirectory];
1042 if (!isDirectory && [[[path pathExtension] lowercaseString] isEqualToString:
@"oolite-save"])
1048 NSMutableDictionary* cdr1 = [NSMutableDictionary dictionaryWithDictionary:cdr];
1049 [cdr1 setObject: @"YES" forKey:@"isSavedGame"];
1050 [cdr1 setObject: path forKey:@"saved_game_path"];
1051 [cdrDetailArray addObject: cdr1];
1054 if (isDirectory && ![[path lastPathComponent] hasPrefix:
@"."])
1056 [cdrDetailArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: @"YES", @"isFolder", path, @"saved_game_path", nil]];
1061 if(![cdrDetailArray
count])
1064 [gui
setText:DESC(@"loadsavescreen-no-commanders-found")
forRow:STARTROW
align:GUI_ALIGN_CENTER];
1068 [cdrDetailArray sortUsingFunction:sortCommanders context:NULL];
1075 highlightIdx=[
self findIndexOfCommander: highlightName];
1076 if(highlightIdx < 0)
1078 OOLog(
@"save.list.commanders.commanderNotFound",
@"Commander %@ doesn't exist, very bad", highlightName);
1089 unsigned firstIndex=page *
NUMROWS;
1107 [gui
setArray: [NSArray arrayWithObjects: DESC(@"loadsavescreen-commander-name"), DESC(@"loadsavescreen-rating"), nil]
1113 [gui
setArray:[NSArray arrayWithObjects:DESC(@"gui-back"), @" <-- ", nil]
1119 if ([
self status] == STATUS_START_GAME)
1121 [gui
setArray:[NSArray arrayWithObjects:DESC(@"oolite-loadsave-exit"), @" <----- ", nil]
forRow:EXITROW];
1130 lastIndex=[cdrDetailArray count];
1137 [gui
setArray:[NSArray arrayWithObjects:DESC(@"gui-more"), @" --> ", nil]
1143 for (i=firstIndex; i < lastIndex; i++)
1145 NSDictionary *cdr=[cdrDetailArray objectAtIndex: i];
1146 if ([cdr oo_boolForKey:
@"isSavedGame"])
1149 [gui
setArray:[NSArray arrayWithObjects:
1150 [NSString stringWithFormat:@" %@ ",[cdr oo_stringForKey:@"player_save_name" defaultValue:[cdr oo_stringForKey:@"player_name"]]],
1151 [NSString stringWithFormat:@" %@ ",ratingDesc],
1154 if ([[
self lastsaveName] isEqualToString:[cdr oo_stringForKey:
@"player_save_name" defaultValue:[cdr oo_stringForKey:
@"player_name"]]])
1156 highlightRowOnPage = row;
1162 if ([cdr oo_boolForKey:
@"isParentFolder"])
1164 [gui
setArray:[NSArray arrayWithObjects:
1165 [NSString stringWithFormat:@" (..) %@ ", [[cdr oo_stringForKey:@"saved_game_path"] lastPathComponent]],
1173 if ([cdr oo_boolForKey:
@"isFolder"])
1175 [gui
setArray:[NSArray arrayWithObjects:
1176 [NSString stringWithFormat:@" >> %@ ", [[cdr oo_stringForKey:@"saved_game_path"] lastPathComponent]],
1186 highlightIdx = (highlightRowOnPage -
STARTROW) + (currentPage *
NUMROWS);
1188 [
self showCommanderShip: highlightIdx];
1193- (BOOL) existingNativeSave: (NSString *)cdrName
1195 NSString* dir = [[UNIVERSE gameController] playerFileDirectory];
1197 NSString *savePath=[dir stringByAppendingPathComponent:[cdrName stringByAppendingPathExtension:@"oolite-save"]];
1198 return [[NSFileManager defaultManager] fileExistsAtPath:savePath];
1203- (void) showCommanderShip:(
int)cdrArrayIndex
1206 [UNIVERSE removeDemoShips];
1207 NSDictionary *cdr=[cdrDetailArray objectAtIndex: cdrArrayIndex];
1213 if ([cdr oo_boolForKey:
@"isFolder"])
1215 NSString *folderDesc=[NSString stringWithFormat: DESC(@"loadsavescreen-hold-@-and-press-return-to-open-folder-@"), @COMMAND_MODIFIER_KEY, [[cdr oo_stringForKey:@"saved_game_path"] lastPathComponent]];
1221 if ([cdr oo_boolForKey:
@"isParentFolder"])
1223 NSString *folderDesc=[NSString stringWithFormat: DESC(@"loadsavescreen-hold-@-and-press-return-to-open-parent-folder-@"), @COMMAND_MODIFIER_KEY, [[cdr oo_stringForKey:@"saved_game_path"] lastPathComponent]];
1230 if (![cdr oo_boolForKey:
@"isSavedGame"])
return;
1232 if ([
self dockedStation] ==
nil) [
self setDockedAtMainStation];
1235 NSString *shipDesc = [cdr oo_stringForKey:@"ship_desc"];
1236 NSString *shipName =
nil;
1237 NSDictionary *shipDict =
nil;
1238 NSString *rating =
nil;
1244 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:[shipDict count] + 1];
1245 [dict setDictionary:shipDict];
1246 id subEntStatus = [cdr objectForKey:@"subentities_status"];
1248 if (subEntStatus !=
nil) [dict setObject:subEntStatus forKey:@"subentities_status"];
1249 [
self showShipyardModel:shipDesc shipData:dict personality:personality];
1251 shipName = [shipDict oo_stringForKey:@"display_name"];
1252 if (shipName ==
nil) shipName = [shipDict oo_stringForKey:KEY_NAME];
1256 [
self showShipyardModel:@"oolite-unknown-ship" shipData:nil personality:personality];
1257 shipName = [cdr oo_stringForKey:@"ship_name" defaultValue:@"unknown"];
1260 shipName = [shipName stringByAppendingString:@" - OXPs disabled or not installed"];
1264 shipName = [shipName stringByAppendingString:@" - OXP not installed"];
1278 NSString *timeStamp =
nil;
1279 NSString *locationName = [cdr oo_stringForKey:@"current_system_name"];
1285 if (locationName ==
nil)
1291 galNumber = [cdr oo_intForKey:@"galaxy_number"] + 1;
1293 NSString *locationGov =
@"";
1294 NSString *locationEco =
@"";
1295 NSString *locationTL = [cdr objectForKey:@"current_system_techlevel"] ? [NSString stringWithFormat:@"%u", [cdr oo_unsignedIntForKey:@"current_system_techlevel"] + 1] :
nil;
1298 locationGov = [NSString stringWithFormat:@"%c", [cdr oo_unsignedCharForKey:@"current_system_government"]];
1299 locationEco = [NSString stringWithFormat:@" %c", (7 - [cdr oo_unsignedCharForKey:@"current_system_economy"]) + 16];
1301 else locationTL =
@"";
1307 NSString *cdrDesc =
nil;
1309 cdrDesc = [NSString stringWithFormat:DESC(@"loadsavescreen-commander-@-rated-@-has-@-legal-status-@-ship-@-location-@-g-@-eco-@-gov-@-tl-@-timestamp-@"),
1310 [cdr oo_stringForKey:@"player_name"],
1329- (
int) findIndexOfCommander: (NSString *)cdrName
1332 for (i=0; i < [cdrDetailArray count]; i++)
1334 NSString *currentName = [[cdrDetailArray oo_dictionaryAtIndex: i] oo_stringForKey:@"player_save_name" defaultValue:[[cdrDetailArray oo_dictionaryAtIndex: i] oo_stringForKey:@"player_name"]];
1335 if([cdrName compare: currentName] == NSOrderedSame)
1350#if OO_USE_CUSTOM_LOAD_SAVE
1352@implementation MyOpenGLView (OOLoadSaveExtensions)
1356 return [
self isCtrlDown];
1366 uint16_t personality = [dict oo_unsignedShortForKey:@"entity_personality" defaultValue:ENTITY_PERSONALITY_INVALID];
1371 personality = [[dict oo_stringForKey:@"ship_desc"] oo_hash] * [[dict oo_stringForKey:@"player_name"] oo_hash];
1391 if (doubleDeciCredits > 0)
1393 doubleDeciCredits = round(doubleDeciCredits);
1396 if (doubleDeciCredits <= threshold)
1398 return doubleDeciCredits;
1414 if ([
object isKindOfClass:[NSNumber
class]] && [
object oo_isFloatingPointNumber])
OOGUITabStop OOGUITabSettings[GUI_MAX_COLUMNS]
#define OOLog(class, format,...)
NSDictionary * OODictionaryFromFile(NSString *path)
Vector vector_up_from_quaternion(Quaternion quat)
Vector vector_right_from_quaternion(Quaternion quat)
Vector vector_forward_from_quaternion(Quaternion quat)
NSString * ClockToString(double clock, BOOL adjusting)
uint64_t OOCreditsQuantity
#define SAVE_OVERWRITE_NO_ROW
#define SAVE_OVERWRITE_YES_ROW
OOCreditsQuantity OODeciCreditsFromObject(id object)
OOCreditsQuantity OODeciCreditsFromObject(id object)
OOCreditsQuantity OODeciCreditsFromDouble(double doubleDeciCredits)
static uint16_t PersonalityForCommanderDict(NSDictionary *dict)
@ GUI_ROW_SCENARIOS_START
@ GUI_ROW_SCENARIOS_DETAIL
NSString * OODisplayRatingStringFromKillCount(unsigned kills)
NSString * OODisplayStringFromLegalStatus(int legalStatus)
NSString * KillCountToRatingAndKillString(unsigned kills)
#define PLAYER_SHIP_CLOCK_START
#define SCENARIO_OXP_DEFINITION_NONE
#define SCENARIO_OXP_DEFINITION_ALL
#define ShipScriptEventNoCx(ship, event,...)
#define ENTITY_PERSONALITY_INVALID
#define ENTITY_PERSONALITY_MAX
BOOL isCommandModifierKeyDown()
NSString * playerFileToLoad
BOOL setBackgroundTextureKey:(NSString *key)
OOColor * colorFromSetting:defaultValue:(NSString *setting,[defaultValue] OOColor *def)
BOOL setSelectedRow:(OOGUIRow row)
OOGUIRow addLongText:startingAtRow:align:(NSString *str,[startingAtRow] OOGUIRow row,[align] OOGUIAlignment alignment)
BOOL setForegroundTextureKey:(NSString *key)
void setText:forRow:(NSString *str,[forRow] OOGUIRow row)
void setText:forRow:align:(NSString *str,[forRow] OOGUIRow row,[align] OOGUIAlignment alignment)
void clearAndKeepBackground:(BOOL keepBackground)
void setSelectableRange:(NSRange range)
void setColor:forRow:(OOColor *color,[forRow] OOGUIRow row)
NSString * selectedRowKey()
void setTitle:(NSString *str)
void setTabStops:(OOGUITabSettings stops)
void setShowTextCursor:(BOOL yesno)
void setCurrentRow:(OOGUIRow value)
void setArray:forRow:(NSArray *arr,[forRow] OOGUIRow row)
void setKey:forRow:(NSString *str,[forRow] OOGUIRow row)
void suppressKeysUntilKeyUp()
NSMutableString * typedString
void setStringInput:(enum StringInput value)
void setTypedString:(NSString *value)
GameController * gameController
OOJavaScriptEngine * sharedEngine()
void garbageCollectionOpportunity:(BOOL force)
OOShipRegistry * sharedRegistry()
NSDictionary * shipInfoForKey:(NSString *key)
void setGuiToLoadCommanderScreen()
BOOL loadPlayerWithPanel()
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque