Oolite 1.91.0.7646-241128-10e222e
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 1003 of file PlayerEntityLoadSave.m.

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

◆ findIndexOfCommander:

- (int) findIndexOfCommander: (NSString *) cdrName

Extends class PlayerEntity.

Definition at line 1003 of file PlayerEntityLoadSave.m.

1329 : (NSString *)cdrName
1330{
1331 unsigned i;
1332 for (i=0; i < [cdrDetailArray count]; i++)
1333 {
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)
1336 {
1337 return i;
1338 }
1339 }
1340
1341 // not found!
1342 return -1;
1343}

◆ loadPlayerWithPanel

- (BOOL) loadPlayerWithPanel

Extends class PlayerEntity.

Definition at line 1412 of file PlayerEntityLoadSave.m.

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

◆ lsCommanders:directory:pageNumber:highlightName:

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

Extends class PlayerEntity.

Definition at line 1003 of file PlayerEntityLoadSave.m.

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

◆ nativeSavePlayer:

- (void) nativeSavePlayer: (NSString *) cdrName

Extends class PlayerEntity.

Definition at line 1412 of file PlayerEntityLoadSave.m.

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

◆ savePlayerWithPanel

- (void) savePlayerWithPanel

Extends class PlayerEntity.

Definition at line 1412 of file PlayerEntityLoadSave.m.

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

◆ setGuiToLoadCommanderScreen

- (void) setGuiToLoadCommanderScreen

Extends class PlayerEntity.

Definition at line 1412 of file PlayerEntityLoadSave.m.

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

◆ setGuiToOverwriteScreen:

- (void) setGuiToOverwriteScreen: (NSString *) cdrName

Extends class PlayerEntity.

Definition at line 1412 of file PlayerEntityLoadSave.m.

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

◆ setGuiToSaveCommanderScreen:

- (void) setGuiToSaveCommanderScreen: (NSString *) cdrName

Extends class PlayerEntity.

Definition at line 1412 of file PlayerEntityLoadSave.m.

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

◆ showCommanderShip:

- (void) showCommanderShip: (int) cdrArrayIndex

Extends class PlayerEntity.

Definition at line 1003 of file PlayerEntityLoadSave.m.

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

◆ sortCommanders

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

Extends class PlayerEntity.

Definition at line 1003 of file PlayerEntityLoadSave.m.

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

◆ writePlayerToPath:

- (void) writePlayerToPath: (NSString *) path

Extends class PlayerEntity.

Definition at line 1412 of file PlayerEntityLoadSave.m.

861 :(NSString *)path
862{
863 NSString *errDesc = nil;
864 NSDictionary *dict = nil;
865 BOOL didSave = NO;
866 [[UNIVERSE gameView] resetTypedString];
867
868 if (!path)
869 {
870 OOLog(@"save.failed", @"***** SAVE ERROR: %s called with nil path.", __PRETTY_FUNCTION__);
871 return;
872 }
873
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];
877 if (didSave)
878 {
879 [UNIVERSE clearPreviousMessage]; // allow this to be given time and again
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];
885 // no duplicated autosave immediately after a save.
886 [UNIVERSE setAutoSaveNow:NO];
887 }
888 else
889 {
890 OOLog(@"save.failed", @"***** SAVE ERROR: %@", errDesc);
891 [NSException raise:@"OoliteException"
892 format:@"Attempt to save game to file '%@' failed: %@", path, errDesc];
893 }
894 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
895 [self setGuiToStatusScreen];
896}

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