Oolite 1.93.0.7767-260207-f2a8cb5
Loading...
Searching...
No Matches
PlayerEntity(OOLoadSavePrivate) Category Reference

Instance Methods

(BOOL) - loadPlayerWithPanel
(void) - savePlayerWithPanel
(void) - setGuiToLoadCommanderScreen
(void) - setGuiToSaveCommanderScreen:
(void) - setGuiToOverwriteScreen:
(void) - lsCommanders:directory:pageNumber:highlightName:
(void) - showCommanderShip:
(int- findIndexOfCommander:
(void) - nativeSavePlayer:
(BOOL) - existingNativeSave:
(void) - writePlayerToPath:
(NSComparisonResult) - sortCommanders [implementation]

Detailed Description

Definition at line 72 of file PlayerEntityLoadSave.m.

Method Documentation

◆ existingNativeSave:

- (BOOL) existingNativeSave: (NSString *) cdrName

Extends class PlayerEntity.

Definition at line 1194 of file PlayerEntityLoadSave.m.

1194 : (NSString *)cdrName
1195{
1196 NSString* dir = [[UNIVERSE gameController] playerFileDirectory];
1197
1198 NSString *savePath=[dir stringByAppendingPathComponent:[cdrName stringByAppendingPathExtension:@"oolite-save"]];
1199 return [[NSFileManager defaultManager] fileExistsAtPath:savePath];
1200}

◆ findIndexOfCommander:

- (int) findIndexOfCommander: (NSString *) cdrName

Extends class PlayerEntity.

Definition at line 1330 of file PlayerEntityLoadSave.m.

1330 : (NSString *)cdrName
1331{
1332 unsigned i;
1333 for (i=0; i < [cdrDetailArray count]; i++)
1334 {
1335 NSString *currentName = [[cdrDetailArray oo_dictionaryAtIndex: i] oo_stringForKey:@"player_save_name" defaultValue:[[cdrDetailArray oo_dictionaryAtIndex: i] oo_stringForKey:@"player_name"]];
1336 if([cdrName compare: currentName] == NSOrderedSame)
1337 {
1338 return i;
1339 }
1340 }
1341
1342 // not found!
1343 return -1;
1344}

References int().

Here is the call graph for this function:

◆ loadPlayerWithPanel

- (BOOL) loadPlayerWithPanel

Extends class PlayerEntity.

Definition at line 815 of file PlayerEntityLoadSave.m.

816{
817 NSOpenPanel *oPanel = [NSOpenPanel openPanel];
818
819 oPanel.allowsMultipleSelection = NO;
820 oPanel.allowedFileTypes = [NSArray arrayWithObject:@"oolite-save"];
821
822 if ([oPanel runModal] == NSOKButton)
823 {
824 NSURL *url = oPanel.URL;
825 if (url.isFileURL)
826 {
827 return [self loadPlayerFromFile:url.path asNew:NO];
828 }
829 }
830
831 return NO;
832}

References PlayerEntity::loadPlayerFromFile:asNew:, and loadPlayerWithPanel.

Referenced by loadPlayerWithPanel.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lsCommanders:directory:pageNumber:highlightName:

- (void) lsCommanders: (GuiDisplayGen *) gui
directory: (NSString*) directory
pageNumber: (int) page
highlightName: (NSString *) highlightName 

Extends class PlayerEntity.

Definition at line 1009 of file PlayerEntityLoadSave.m.

1009 : (GuiDisplayGen *)gui
1010 directory: (NSString*) directory
1011 pageNumber: (int)page
1012 highlightName: (NSString *)highlightName
1013{
1014 NSFileManager *cdrFileManager=[NSFileManager defaultManager];
1015 int rangeStart=STARTROW;
1016 unsigned lastIndex;
1017 unsigned i;
1018 int row=STARTROW;
1019
1020 // cdrArray defined in PlayerEntity.h
1021 NSArray *cdrArray=[cdrFileManager commanderContentsOfPath: directory];
1022
1023 // get commander details so a brief rundown of the commander's details may
1024 // be displayed.
1025 if (!cdrDetailArray)
1026 cdrDetailArray=[[NSMutableArray alloc] init]; // alloc retains this so the retain further on in the code was unnecessary
1027 else
1028 [cdrDetailArray removeAllObjects];
1029
1030 [cdrDetailArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
1031 @"YES", @"isParentFolder",
1032 [directory stringByDeletingLastPathComponent], @"saved_game_path", nil]];
1033
1034 for(i = 0; i < [cdrArray count]; i++)
1035 {
1036 NSString* path = [cdrArray objectAtIndex:i];
1037 BOOL exists, isDirectory = NO;
1038
1039 exists = [cdrFileManager fileExistsAtPath:path isDirectory:&isDirectory];
1040
1041 if (exists)
1042 {
1043 if (!isDirectory && [[[path pathExtension] lowercaseString] isEqualToString:@"oolite-save"])
1044 {
1045 NSDictionary *cdr = OODictionaryFromFile(path);
1046 if(cdr)
1047 {
1048 // okay use the same dictionary but add a 'saved_game_path' attribute
1049 NSMutableDictionary* cdr1 = [NSMutableDictionary dictionaryWithDictionary:cdr];
1050 [cdr1 setObject: @"YES" forKey:@"isSavedGame"];
1051 [cdr1 setObject: path forKey:@"saved_game_path"];
1052 [cdrDetailArray addObject: cdr1];
1053 }
1054 }
1055 if (isDirectory && ![[path lastPathComponent] hasPrefix:@"."])
1056 {
1057 [cdrDetailArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: @"YES", @"isFolder", path, @"saved_game_path", nil]];
1058 }
1059 }
1060 }
1061
1062 if(![cdrDetailArray count])
1063 {
1064 // Empty directory; tell the user and exit immediately.
1065 [gui setText:DESC(@"loadsavescreen-no-commanders-found") forRow:STARTROW align:GUI_ALIGN_CENTER];
1066 return;
1067 }
1068
1069 [cdrDetailArray sortUsingFunction:sortCommanders context:NULL];
1070
1071 // Do we need to highlight a name?
1072 int highlightRowOnPage=STARTROW;
1073 int highlightIdx=0;
1074 if(highlightName)
1075 {
1076 highlightIdx=[self findIndexOfCommander: highlightName];
1077 if(highlightIdx < 0)
1078 {
1079 OOLog(@"save.list.commanders.commanderNotFound", @"Commander %@ doesn't exist, very bad", highlightName);
1080 highlightIdx=0;
1081 }
1082
1083 // figure out what page we need to be on
1084 page=highlightIdx/NUMROWS;
1085 highlightRowOnPage=highlightIdx % NUMROWS + STARTROW;
1086 }
1087
1088 // We now know for certain what page we're on -
1089 // set the first index of the first commander on this page.
1090 unsigned firstIndex=page * NUMROWS;
1091
1092 // Set up the GUI.
1093 OOGUITabSettings tabStop;
1094 tabStop[0]=0;
1095 tabStop[1]=160;
1096 tabStop[2]=270;
1097 [gui setTabStops: tabStop];
1098
1099 // clear text lines here
1100 for (i = EXITROW ; i < ENDROW + 1; i++)
1101 {
1102 [gui setText:@"" forRow:i align:GUI_ALIGN_LEFT];
1103 [gui setColor: [OOColor yellowColor] forRow: i];
1104 [gui setKey:GUI_KEY_SKIP forRow:i];
1105 }
1106
1107 [gui setColor: [OOColor greenColor] forRow: LABELROW];
1108 [gui setArray: [NSArray arrayWithObjects: DESC(@"loadsavescreen-commander-name"), DESC(@"loadsavescreen-rating"), nil]
1109 forRow:LABELROW];
1110
1111 if (page)
1112 {
1113 [gui setColor:[OOColor greenColor] forRow:STARTROW-1];
1114 [gui setArray:[NSArray arrayWithObjects:DESC(@"gui-back"), @" <-- ", nil]
1115 forRow:STARTROW-1];
1116 [gui setKey:GUI_KEY_OK forRow:STARTROW-1];
1117 rangeStart=STARTROW-1;
1118 }
1119
1120 if ([self status] == STATUS_START_GAME)
1121 {
1122 [gui setArray:[NSArray arrayWithObjects:DESC(@"oolite-loadsave-exit"), @" <----- ", nil] forRow:EXITROW];
1123 [gui setColor:[OOColor redColor] forRow:EXITROW];
1124 [gui setKey:GUI_KEY_OK forRow:EXITROW];
1125 rangeStart = EXITROW;
1126 }
1127
1128
1129 if (firstIndex + NUMROWS >= [cdrDetailArray count])
1130 {
1131 lastIndex=[cdrDetailArray count];
1132 [gui setSelectableRange: NSMakeRange(rangeStart, rangeStart + NUMROWS + 2)];
1133 }
1134 else
1135 {
1136 lastIndex=(page * NUMROWS) + NUMROWS;
1137 [gui setColor:[OOColor greenColor] forRow:ENDROW];
1138 [gui setArray:[NSArray arrayWithObjects:DESC(@"gui-more"), @" --> ", nil]
1139 forRow:ENDROW];
1140 [gui setKey:GUI_KEY_OK forRow:ENDROW];
1141 [gui setSelectableRange: NSMakeRange(rangeStart, MOREROW)];
1142 }
1143
1144 for (i=firstIndex; i < lastIndex; i++)
1145 {
1146 NSDictionary *cdr=[cdrDetailArray objectAtIndex: i];
1147 if ([cdr oo_boolForKey:@"isSavedGame"])
1148 {
1149 NSString *ratingDesc = OODisplayRatingStringFromKillCount([cdr oo_unsignedIntForKey:@"ship_kills"]);
1150 [gui setArray:[NSArray arrayWithObjects:
1151 [NSString stringWithFormat:@" %@ ",[cdr oo_stringForKey:@"player_save_name" defaultValue:[cdr oo_stringForKey:@"player_name"]]],
1152 [NSString stringWithFormat:@" %@ ",ratingDesc],
1153 nil]
1154 forRow:row];
1155 if ([[self lastsaveName] isEqualToString:[cdr oo_stringForKey:@"player_save_name" defaultValue:[cdr oo_stringForKey:@"player_name"]]])
1156 {
1157 highlightRowOnPage = row;
1158 }
1159
1160 [gui setKey:GUI_KEY_OK forRow:row];
1161 row++;
1162 }
1163 if ([cdr oo_boolForKey:@"isParentFolder"])
1164 {
1165 [gui setArray:[NSArray arrayWithObjects:
1166 [NSString stringWithFormat:@" (..) %@ ", [[cdr oo_stringForKey:@"saved_game_path"] lastPathComponent]],
1167 @"",
1168 nil]
1169 forRow:row];
1170 [gui setColor: [OOColor orangeColor] forRow: row];
1171 [gui setKey:GUI_KEY_OK forRow:row];
1172 row++;
1173 }
1174 if ([cdr oo_boolForKey:@"isFolder"])
1175 {
1176 [gui setArray:[NSArray arrayWithObjects:
1177 [NSString stringWithFormat:@" >> %@ ", [[cdr oo_stringForKey:@"saved_game_path"] lastPathComponent]],
1178 @"",
1179 nil]
1180 forRow:row];
1181 [gui setColor: [OOColor orangeColor] forRow: row];
1182 [gui setKey:GUI_KEY_OK forRow:row];
1183 row++;
1184 }
1185 }
1186 [gui setSelectedRow: highlightRowOnPage];
1187 highlightIdx = (highlightRowOnPage - STARTROW) + (currentPage * NUMROWS);
1188 // show the first ship, this will be the selected row
1189 [self showCommanderShip: highlightIdx];
1190}
OOGUITabStop OOGUITabSettings[GUI_MAX_COLUMNS]
#define OOLog(class, format,...)
Definition OOLogging.h:88
NSDictionary * OODictionaryFromFile(NSString *path)
unsigned count
#define ENDROW
#define EXITROW
#define NUMROWS
#define STARTROW
NSString * OODisplayRatingStringFromKillCount(unsigned kills)
BOOL setSelectedRow:(OOGUIRow row)
void setText:forRow:align:(NSString *str,[forRow] OOGUIRow row,[align] OOGUIAlignment alignment)
void setSelectableRange:(NSRange range)
void setColor:forRow:(OOColor *color,[forRow] OOGUIRow row)
void setTabStops:(OOGUITabSettings stops)
void setArray:forRow:(NSArray *arr,[forRow] OOGUIRow row)
void setKey:forRow:(NSString *str,[forRow] OOGUIRow row)
OOColor * orangeColor()
Definition OOColor.m:304
OOColor * redColor()
Definition OOColor.m:268
OOColor * greenColor()
Definition OOColor.m:274
OOColor * yellowColor()
Definition OOColor.m:292
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

References count, ENDROW, EXITROW, PlayerEntity::findIndexOfCommander:, OOColor::greenColor, NUMROWS, OODictionaryFromFile(), OODisplayRatingStringFromKillCount(), OOLog, OOColor::orangeColor, OOColor::redColor, GuiDisplayGen::setArray:forRow:, GuiDisplayGen::setColor:forRow:, GuiDisplayGen::setKey:forRow:, GuiDisplayGen::setSelectableRange:, GuiDisplayGen::setSelectedRow:, GuiDisplayGen::setTabStops:, GuiDisplayGen::setText:forRow:align:, PlayerEntity::showCommanderShip:, STARTROW, and OOColor::yellowColor.

Here is the call graph for this function:

◆ nativeSavePlayer:

- (void) nativeSavePlayer: (NSString *) cdrName

Extends class PlayerEntity.

Definition at line 900 of file PlayerEntityLoadSave.m.

900 :(NSString *)cdrName
901{
902 NSString* dir = [[UNIVERSE gameController] playerFileDirectory];
903 NSString *savePath = [dir stringByAppendingPathComponent:[cdrName stringByAppendingPathExtension:@"oolite-save"]];
904
905 ShipScriptEventNoCx(self, "playerWillSaveGame", OOJSSTR("STANDARD_SAVE"));
906
907 [self setLastsaveName:cdrName];
908
909 [self writePlayerToPath:savePath];
910}
#define OOJSSTR(str)
#define ShipScriptEventNoCx(ship, event,...)

References OOJSSTR, PlayerEntity::setLastsaveName:, ShipScriptEventNoCx, and PlayerEntity::writePlayerToPath:.

Here is the call graph for this function:

◆ savePlayerWithPanel

- (void) savePlayerWithPanel

Extends class PlayerEntity.

Definition at line 835 of file PlayerEntityLoadSave.m.

836{
837 NSSavePanel *sPanel = [NSSavePanel savePanel];
838
839 sPanel.allowedFileTypes = [NSArray arrayWithObject:@"oolite-save"];
840 sPanel.canSelectHiddenExtension = YES;
841 sPanel.nameFieldStringValue = self.lastsaveName;
842
843 if ([sPanel runModal] == NSOKButton)
844 {
845 NSURL *url = sPanel.URL;
846 NSAssert(url.isFileURL, @"Save panel with default configuration should not provide non-file URLs.");
847
848 NSString *path = url.path;
849 NSString *newName = [path.lastPathComponent stringByDeletingPathExtension];
850
851 ShipScriptEventNoCx(self, "playerWillSaveGame", OOJSSTR("STANDARD_SAVE"));
852
853 self.lastsaveName = newName;
854 [self writePlayerToPath:path];
855 }
856 [self setGuiToStatusScreen];
857}

References OOJSSTR, savePlayerWithPanel, PlayerEntity::setGuiToStatusScreen, ShipScriptEventNoCx, and PlayerEntity::writePlayerToPath:.

Referenced by savePlayerWithPanel.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setGuiToLoadCommanderScreen

- (void) setGuiToLoadCommanderScreen

Extends class PlayerEntity.

Definition at line 915 of file PlayerEntityLoadSave.m.

916{
917 GuiDisplayGen *gui=[UNIVERSE gui];
918 NSString* dir = [[UNIVERSE gameController] playerFileDirectory];
919
920 gui_screen = GUI_SCREEN_LOAD;
921
922 [gui clear];
923 [gui setTitle:DESC(@"loadscreen-title")];
924
925 currentPage = 0;
926 [self lsCommanders:gui directory:dir pageNumber: currentPage highlightName:nil];
927
928 [gui setForegroundTextureKey:@"docked_overlay"];
929 [gui setBackgroundTextureKey:@"load_save"];
930
931 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
932
933 [self setShowDemoShips:YES];
934 [UNIVERSE enterGUIViewModeWithMouseInteraction:YES];
935}
BOOL setBackgroundTextureKey:(NSString *key)
BOOL setForegroundTextureKey:(NSString *key)
void setTitle:(NSString *str)

References GuiDisplayGen::clear, PlayerEntity::lsCommanders:directory:pageNumber:highlightName:, GuiDisplayGen::setBackgroundTextureKey:, GuiDisplayGen::setForegroundTextureKey:, setGuiToLoadCommanderScreen, PlayerEntity::setShowDemoShips:, and GuiDisplayGen::setTitle:.

Referenced by setGuiToLoadCommanderScreen.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setGuiToOverwriteScreen:

- (void) setGuiToOverwriteScreen: (NSString *) cdrName

Extends class PlayerEntity.

Definition at line 969 of file PlayerEntityLoadSave.m.

969 :(NSString *)cdrName
970{
971 GuiDisplayGen *gui=[UNIVERSE gui];
972 MyOpenGLView* gameView = [UNIVERSE gameView];
973
974 // Don't poll controls
975 pollControls=NO;
976
977 gui_screen = GUI_SCREEN_SAVE_OVERWRITE;
978
979 [gui clear];
980 [gui setTitle:[NSString stringWithFormat:DESC(@"overwrite-save-commander-@"), cdrName]];
981
982 [gui setText:[NSString stringWithFormat:DESC(@"overwritescreen-commander-@-already-exists-overwrite-query"), cdrName]
983 forRow:SAVE_OVERWRITE_WARN_ROW align: GUI_ALIGN_CENTER];
984
985 [gui setText:DESC(@"overwritescreen-yes") forRow: SAVE_OVERWRITE_YES_ROW align: GUI_ALIGN_CENTER];
986 [gui setKey:GUI_KEY_OK forRow: SAVE_OVERWRITE_YES_ROW];
987
988 [gui setText:DESC(@"overwritescreen-no") forRow: SAVE_OVERWRITE_NO_ROW align: GUI_ALIGN_CENTER];
989 [gui setKey:GUI_KEY_OK forRow: SAVE_OVERWRITE_NO_ROW];
990
991 [gui setSelectableRange: NSMakeRange(SAVE_OVERWRITE_YES_ROW, 2)];
992 [gui setSelectedRow: SAVE_OVERWRITE_NO_ROW];
993
994 // We can only leave this screen by answering yes or no, or esc. Therefore
995 // use a specific overlay, to allow visual reminders of the available options.
996 [gui setForegroundTextureKey:@"overwrite_overlay"];
997 [gui setBackgroundTextureKey:@"load_save"];
998
999 [self setShowDemoShips:NO];
1000 [gameView setStringInput:gvStringInputNo];
1001 [UNIVERSE enterGUIViewModeWithMouseInteraction:NO]; // FIXME: should be YES, but was NO before introducing new mouse mode stuff. If set to YES, choices can be selected but not activated.
1002}
void setStringInput:(enum StringInput value)

References GuiDisplayGen::clear, GuiDisplayGen::setBackgroundTextureKey:, GuiDisplayGen::setForegroundTextureKey:, GuiDisplayGen::setKey:forRow:, GuiDisplayGen::setSelectableRange:, GuiDisplayGen::setSelectedRow:, PlayerEntity::setShowDemoShips:, MyOpenGLView::setStringInput:, GuiDisplayGen::setText:forRow:align:, and GuiDisplayGen::setTitle:.

Here is the call graph for this function:

◆ setGuiToSaveCommanderScreen:

- (void) setGuiToSaveCommanderScreen: (NSString *) cdrName

Extends class PlayerEntity.

Definition at line 938 of file PlayerEntityLoadSave.m.

938 :(NSString *)cdrName
939{
940 GuiDisplayGen *gui=[UNIVERSE gui];
941 MyOpenGLView *gameView = [UNIVERSE gameView];
942 NSString *dir = [[UNIVERSE gameController] playerFileDirectory];
943
944 pollControls = NO;
945 gui_screen = GUI_SCREEN_SAVE;
946
947 [gui clear];
948 [gui setTitle:DESC(@"savescreen-title")];
949
950 currentPage = 0;
951 [self lsCommanders:gui directory:dir pageNumber: currentPage highlightName:nil];
952
953 [gui setText:DESC(@"savescreen-commander-name") forRow: INPUTROW];
954 [gui setColor:[OOColor cyanColor] forRow:INPUTROW];
955 [gui setShowTextCursor: YES];
956 [gui setCurrentRow: INPUTROW];
957
958 [gui setForegroundTextureKey:@"docked_overlay"];
959 [gui setBackgroundTextureKey:@"load_save"];
960
961 [gameView setTypedString:cdrName];
962 [gameView suppressKeysUntilKeyUp];
963
964 [self setShowDemoShips:YES];
965 [UNIVERSE enterGUIViewModeWithMouseInteraction:YES];
966}
void setText:forRow:(NSString *str,[forRow] OOGUIRow row)
void setShowTextCursor:(BOOL yesno)
void setCurrentRow:(OOGUIRow value)
void suppressKeysUntilKeyUp()
void setTypedString:(NSString *value)
OOColor * cyanColor()
Definition OOColor.m:286

References GuiDisplayGen::clear, OOColor::cyanColor, PlayerEntity::lsCommanders:directory:pageNumber:highlightName:, GuiDisplayGen::setBackgroundTextureKey:, GuiDisplayGen::setColor:forRow:, GuiDisplayGen::setCurrentRow:, GuiDisplayGen::setForegroundTextureKey:, PlayerEntity::setShowDemoShips:, GuiDisplayGen::setShowTextCursor:, GuiDisplayGen::setText:forRow:, GuiDisplayGen::setTitle:, MyOpenGLView::setTypedString:, and MyOpenGLView::suppressKeysUntilKeyUp.

Here is the call graph for this function:

◆ showCommanderShip:

- (void) showCommanderShip: (int) cdrArrayIndex

Extends class PlayerEntity.

Definition at line 1204 of file PlayerEntityLoadSave.m.

1204 :(int)cdrArrayIndex
1205{
1206 GuiDisplayGen *gui=[UNIVERSE gui];
1207 [UNIVERSE removeDemoShips];
1208 NSDictionary *cdr=[cdrDetailArray objectAtIndex: cdrArrayIndex];
1209
1210 [gui setText:@"" forRow:CDRDESCROW align:GUI_ALIGN_LEFT];
1211 [gui setText:@"" forRow:CDRDESCROW + 1 align:GUI_ALIGN_LEFT];
1212 [gui setText:@"" forRow:CDRDESCROW + 2 align:GUI_ALIGN_LEFT];
1213
1214 if ([cdr oo_boolForKey:@"isFolder"])
1215 {
1216 NSString *folderDesc=[NSString stringWithFormat: DESC(@"loadsavescreen-hold-@-and-press-return-to-open-folder-@"), @COMMAND_MODIFIER_KEY, [[cdr oo_stringForKey:@"saved_game_path"] lastPathComponent]];
1217 [gui setColor: [OOColor orangeColor] forRow: CDRDESCROW];
1218 [gui addLongText: folderDesc startingAtRow: CDRDESCROW align: GUI_ALIGN_LEFT];
1219 return;
1220 }
1221
1222 if ([cdr oo_boolForKey:@"isParentFolder"])
1223 {
1224 NSString *folderDesc=[NSString stringWithFormat: DESC(@"loadsavescreen-hold-@-and-press-return-to-open-parent-folder-@"), @COMMAND_MODIFIER_KEY, [[cdr oo_stringForKey:@"saved_game_path"] lastPathComponent]];
1225 [gui setColor: [OOColor orangeColor] forRow: CDRDESCROW];
1226 [gui addLongText: folderDesc startingAtRow: CDRDESCROW align: GUI_ALIGN_LEFT];
1227 return;
1228 }
1229 [gui setColor:[gui colorFromSetting:nil defaultValue:nil] forRow: CDRDESCROW];
1230
1231 if (![cdr oo_boolForKey:@"isSavedGame"]) return; // don't show things that aren't saved games
1232
1233 if ([self dockedStation] == nil) [self setDockedAtMainStation];
1234
1235 // Display the commander's ship.
1236 NSString *shipDesc = [cdr oo_stringForKey:@"ship_desc"];
1237 NSString *shipName = nil;
1238 NSDictionary *shipDict = nil;
1239 NSString *rating = nil;
1240 uint16_t personality = PersonalityForCommanderDict(cdr);
1241
1242 shipDict = [[OOShipRegistry sharedRegistry] shipInfoForKey:shipDesc];
1243 if(shipDict != nil)
1244 {
1245 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:[shipDict count] + 1];
1246 [dict setDictionary:shipDict];
1247 id subEntStatus = [cdr objectForKey:@"subentities_status"];
1248 // don't add it to the dictionary if there's no subentities_status key
1249 if (subEntStatus != nil) [dict setObject:subEntStatus forKey:@"subentities_status"];
1250 [self showShipyardModel:shipDesc shipData:dict personality:personality];
1251 [dict release];
1252 shipName = [shipDict oo_stringForKey:@"display_name"];
1253 if (shipName == nil) shipName = [shipDict oo_stringForKey:KEY_NAME];
1254 }
1255 else
1256 {
1257 [self showShipyardModel:@"oolite-unknown-ship" shipData:nil personality:personality];
1258 shipName = [cdr oo_stringForKey:@"ship_name" defaultValue:@"unknown"];
1259 if (![[UNIVERSE useAddOns] isEqualToString:SCENARIO_OXP_DEFINITION_ALL])
1260 {
1261 shipName = [shipName stringByAppendingString:@" - OXPs disabled or not installed"];
1262 }
1263 else
1264 {
1265 shipName = [shipName stringByAppendingString:@" - OXP not installed"];
1266 }
1267 }
1268
1269 // Make a short description of the commander
1270 NSString *legalDesc = OODisplayStringFromLegalStatus([cdr oo_intForKey:@"legal_status"]);
1271
1272 rating = KillCountToRatingAndKillString([cdr oo_unsignedIntForKey:@"ship_kills"]);
1273 OOCreditsQuantity money = OODeciCreditsFromObject([cdr objectForKey:@"credits"]);
1274
1275 // Nikos - Add some more information in the load game screen (current location, galaxy number and timestamp).
1276 //-------------------------------------------------------------------------------------------------------------------------
1277
1278 int galNumber;
1279 NSString *timeStamp = nil;
1280 NSString *locationName = [cdr oo_stringForKey:@"current_system_name"];
1281
1282 // If there is no key containing the name of the current system in
1283 // the savefile, calculating what it should have been is going to
1284 // be tricky now that system generation isn't seed based - but
1285 // this implies a save game well over 5 years old.
1286 if (locationName == nil)
1287 {
1288 // Leaving the location blank in this case is probably okay
1289 locationName = @"";
1290 }
1291
1292 galNumber = [cdr oo_intForKey:@"galaxy_number"] + 1; // Galaxy numbering starts at 0.
1293
1294 NSString *locationGov = @"";
1295 NSString *locationEco = @"";
1296 NSString *locationTL = [cdr objectForKey:@"current_system_techlevel"] ? [NSString stringWithFormat:@"%u", [cdr oo_unsignedIntForKey:@"current_system_techlevel"] + 1] : nil;
1297 if (locationTL)
1298 {
1299 locationGov = [NSString stringWithFormat:@"%c", [cdr oo_unsignedCharForKey:@"current_system_government"]];
1300 locationEco = [NSString stringWithFormat:@" %c", (7 - [cdr oo_unsignedCharForKey:@"current_system_economy"]) + 16];
1301 }
1302 else locationTL = @"";
1303
1304 timeStamp = ClockToString([cdr oo_doubleForKey:@"ship_clock" defaultValue:PLAYER_SHIP_CLOCK_START], NO);
1305
1306 //-------------------------------------------------------------------------------------------------------------------------
1307
1308 NSString *cdrDesc = nil;
1309
1310 cdrDesc = [NSString stringWithFormat:DESC(@"loadsavescreen-commander-@-rated-@-has-@-legal-status-@-ship-@-location-@-g-@-eco-@-gov-@-tl-@-timestamp-@"),
1311 [cdr oo_stringForKey:@"player_name"],
1312 rating,
1313 OOCredits(money),
1314 legalDesc,
1315 shipName,
1316 locationName,
1317 galNumber,
1318 locationEco,
1319 locationGov,
1320 locationTL,
1321 timeStamp];
1322
1323 //-------------------------------------------------------------------------------------------------------------------------
1324
1325 [gui addLongText:cdrDesc startingAtRow:CDRDESCROW align:GUI_ALIGN_LEFT];
1326
1327}
return nil
NSString * ClockToString(double clock, BOOL adjusting)
uint64_t OOCreditsQuantity
Definition OOTypes.h:182
OOCreditsQuantity OODeciCreditsFromObject(id object)
static uint16_t PersonalityForCommanderDict(NSDictionary *dict)
NSString * OODisplayStringFromLegalStatus(int legalStatus)
NSString * KillCountToRatingAndKillString(unsigned kills)
#define PLAYER_SHIP_CLOCK_START
#define SCENARIO_OXP_DEFINITION_ALL
#define UNIVERSE
Definition Universe.h:844
OOColor * colorFromSetting:defaultValue:(NSString *setting,[defaultValue] OOColor *def)
OOGUIRow addLongText:startingAtRow:align:(NSString *str,[startingAtRow] OOGUIRow row,[align] OOGUIAlignment alignment)
OOShipRegistry * sharedRegistry()
NSDictionary * shipInfoForKey:(NSString *key)

References GuiDisplayGen::addLongText:startingAtRow:align:, ClockToString(), GuiDisplayGen::colorFromSetting:defaultValue:, KillCountToRatingAndKillString(), nil, OODeciCreditsFromObject(), OODisplayStringFromLegalStatus(), OOColor::orangeColor, PersonalityForCommanderDict(), PLAYER_SHIP_CLOCK_START, SCENARIO_OXP_DEFINITION_ALL, GuiDisplayGen::setColor:forRow:, PlayerEntity::setDockedAtMainStation, GuiDisplayGen::setText:forRow:align:, OOShipRegistry::sharedRegistry, OOShipRegistry::shipInfoForKey:, PlayerEntity::showShipyardModel:shipData:personality:, and UNIVERSE.

Here is the call graph for this function:

◆ sortCommanders

- (NSComparisonResult) sortCommanders (id) cdr1
(id) cdr2
(void *) context 
implementation

Extends class PlayerEntity.

Definition at line 1004 of file PlayerEntityLoadSave.m.

1005{
1006 return [[cdr1 objectForKey:@"saved_game_path"] localizedCompare:[cdr2 objectForKey:@"saved_game_path"]];
1007}

◆ writePlayerToPath:

- (void) writePlayerToPath: (NSString *) path

Extends class PlayerEntity.

Definition at line 862 of file PlayerEntityLoadSave.m.

862 :(NSString *)path
863{
864 NSString *errDesc = nil;
865 NSDictionary *dict = nil;
866 BOOL didSave = NO;
867 [[UNIVERSE gameView] resetTypedString];
868
869 if (!path)
870 {
871 OOLog(@"save.failed", @"***** SAVE ERROR: %s called with nil path.", __PRETTY_FUNCTION__);
872 return;
873 }
874
875 dict = [self commanderDataDictionary];
876 if (dict == nil) errDesc = @"could not construct commander data dictionary.";
877 else didSave = [dict writeOOXMLToFile:path atomically:YES errorDescription:&errDesc];
878 if (didSave)
879 {
880 [UNIVERSE clearPreviousMessage]; // allow this to be given time and again
881 [UNIVERSE addMessage:DESC(@"game-saved") forCount:2];
882 [save_path autorelease];
883 save_path = [path copy];
884 [[UNIVERSE gameController] setPlayerFileToLoad:save_path];
885 [[UNIVERSE gameController] setPlayerFileDirectory:save_path];
886 // no duplicated autosave immediately after a save.
887 [UNIVERSE setAutoSaveNow:NO];
888 }
889 else
890 {
891 OOLog(@"save.failed", @"***** SAVE ERROR: %@", errDesc);
892 [NSException raise:@"OoliteException"
893 format:@"Attempt to save game to file '%@' failed: %@", path, errDesc];
894 }
895 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
896 [self setGuiToStatusScreen];
897}

References PlayerEntity::commanderDataDictionary, nil, OOLog, and PlayerEntity::setGuiToStatusScreen.

Here is the call graph for this function:

The documentation for this category was generated from the following file: