1017 directory: (NSString*) directory
1018 pageNumber: (
int)page
1019 highlightName: (NSString *)highlightName
1020{
1021 NSFileManager *cdrFileManager=[NSFileManager defaultManager];
1023 unsigned lastIndex;
1024 unsigned i;
1026
1027
1028 NSArray *cdrArray=[cdrFileManager commanderContentsOfPath: directory];
1029
1030
1031
1032 if (!cdrDetailArray)
1033 cdrDetailArray=[[NSMutableArray alloc] init];
1034 else
1035 [cdrDetailArray removeAllObjects];
1036
1037 [cdrDetailArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
1038 @"YES", @"isParentFolder",
1039 [directory stringByDeletingLastPathComponent], @"saved_game_path", nil]];
1040
1041 for(i = 0; i < [cdrArray count]; i++)
1042 {
1043 NSString* path = [cdrArray objectAtIndex:i];
1044 BOOL exists, isDirectory = NO;
1045
1046 exists = [cdrFileManager fileExistsAtPath:path isDirectory:&isDirectory];
1047
1048 if (exists)
1049 {
1050 if (!isDirectory && [[[path pathExtension] lowercaseString] isEqualToString:@"oolite-save"])
1051 {
1053 if(cdr)
1054 {
1055
1056 NSMutableDictionary* cdr1 = [NSMutableDictionary dictionaryWithDictionary:cdr];
1057 [cdr1 setObject: @"YES" forKey:@"isSavedGame"];
1058 [cdr1 setObject: path forKey:@"saved_game_path"];
1059 [cdrDetailArray addObject: cdr1];
1060 }
1061 }
1062 if (isDirectory && ![[path lastPathComponent] hasPrefix:@"."])
1063 {
1064 [cdrDetailArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: @"YES", @"isFolder", path, @"saved_game_path", nil]];
1065 }
1066 }
1067 }
1068
1069 if(![cdrDetailArray
count])
1070 {
1071
1072 [gui
setText:DESC(@"loadsavescreen-no-commanders-found")
forRow:STARTROW
align:GUI_ALIGN_CENTER];
1073 return;
1074 }
1075
1076 [cdrDetailArray sortUsingFunction:sortCommanders context:NULL];
1077
1078
1080 int highlightIdx=0;
1081 if(highlightName)
1082 {
1083 highlightIdx=[self findIndexOfCommander: highlightName];
1084 if(highlightIdx < 0)
1085 {
1086 OOLog(
@"save.list.commanders.commanderNotFound",
@"Commander %@ doesn't exist, very bad", highlightName);
1087 highlightIdx=0;
1088 }
1089
1090
1093 }
1094
1095
1096
1097 unsigned firstIndex=page *
NUMROWS;
1098
1099
1101 tabStop[0]=0;
1102 tabStop[1]=160;
1103 tabStop[2]=270;
1105
1106
1108 {
1112 }
1113
1115 [gui
setArray: [NSArray arrayWithObjects: DESC(@"loadsavescreen-commander-name"), DESC(@"loadsavescreen-rating"), nil]
1117
1118 if (page)
1119 {
1121 [gui
setArray:[NSArray arrayWithObjects:DESC(@"gui-back"), @" <-- ", nil]
1125 }
1126
1127 if ([self status] == STATUS_START_GAME)
1128 {
1129 [gui
setArray:[NSArray arrayWithObjects:DESC(@"oolite-loadsave-exit"), @" <----- ", nil]
forRow:EXITROW];
1133 }
1134
1135
1137 {
1138 lastIndex=[cdrDetailArray count];
1140 }
1141 else
1142 {
1145 [gui
setArray:[NSArray arrayWithObjects:DESC(@"gui-more"), @" --> ", nil]
1149 }
1150
1151 for (i=firstIndex; i < lastIndex; i++)
1152 {
1153 NSDictionary *cdr=[cdrDetailArray objectAtIndex: i];
1154 if ([cdr oo_boolForKey:@"isSavedGame"])
1155 {
1157 [gui
setArray:[NSArray arrayWithObjects:
1158 [NSString stringWithFormat:@" %@ ",[cdr oo_stringForKey:@"player_save_name" defaultValue:[cdr oo_stringForKey:@"player_name"]]],
1159 [NSString stringWithFormat:@" %@ ",ratingDesc],
1160 nil]
1162 if ([[self lastsaveName] isEqualToString:[cdr oo_stringForKey:@"player_save_name" defaultValue:[cdr oo_stringForKey:@"player_name"]]])
1163 {
1164 highlightRowOnPage = row;
1165 }
1166
1168 row++;
1169 }
1170 if ([cdr oo_boolForKey:@"isParentFolder"])
1171 {
1172 [gui
setArray:[NSArray arrayWithObjects:
1173 [NSString stringWithFormat:@" (..) %@ ", [[cdr oo_stringForKey:@"saved_game_path"] lastPathComponent]],
1174 @"",
1175 nil]
1179 row++;
1180 }
1181 if ([cdr oo_boolForKey:@"isFolder"])
1182 {
1183 [gui
setArray:[NSArray arrayWithObjects:
1184 [NSString stringWithFormat:@" >> %@ ", [[cdr oo_stringForKey:@"saved_game_path"] lastPathComponent]],
1185 @"",
1186 nil]
1190 row++;
1191 }
1192 }
1194 highlightIdx = (highlightRowOnPage -
STARTROW) + (currentPage *
NUMROWS);
1195
1196 [self showCommanderShip: highlightIdx];
1197}
OOGUITabStop OOGUITabSettings[GUI_MAX_COLUMNS]
#define OOLog(class, format,...)
NSDictionary * OODictionaryFromFile(NSString *path)
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)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque