# HG changeset patch # User koda # Date 1293750638 -3600 # Node ID 224c31b3ce7d3e102235c509cb3e5cd871f06597 # Parent 7ca9ebb6895dc98e02f771bbfdaf92f0fe19add6 simplify stats handling diff -r 7ca9ebb6895d -r 224c31b3ce7d project_files/HedgewarsMobile/Classes/GameConfigViewController.m --- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Thu Dec 30 04:54:25 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Fri Dec 31 00:10:38 2010 +0100 @@ -239,12 +239,15 @@ StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped]; [self presentModalViewController:statsPage animated:NO]; - statsPage.statsDictionary = [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary]; - if (statsPage.statsDictionary == nil) + NSArray *stats = [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary]; + if ([stats count] == 0) [statsPage dismissModalViewControllerAnimated:NO]; - else + else { + statsPage.statsArray = stats; [statsPage.tableView reloadData]; - DLog(@"%@",statsPage.statsDictionary); + [statsPage viewWillAppear:YES]; + } + [statsPage release]; } diff -r 7ca9ebb6895d -r 224c31b3ce7d project_files/HedgewarsMobile/Classes/GameSetup.h --- a/project_files/HedgewarsMobile/Classes/GameSetup.h Thu Dec 30 04:54:25 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/GameSetup.h Fri Dec 31 00:10:38 2010 +0100 @@ -25,7 +25,7 @@ @interface GameSetup : NSObject { NSDictionary *systemSettings; NSDictionary *gameConfig; - NSMutableDictionary *statsDictionary; + NSMutableArray *statsArray; NSInteger ipcPort; // Port on which engine will listen TCPsocket csd; // Client socket descriptor @@ -38,7 +38,7 @@ @property (nonatomic, retain) NSDictionary *systemSettings; @property (nonatomic, retain) NSDictionary *gameConfig; -@property (nonatomic, retain) NSMutableDictionary *statsDictionary; +@property (nonatomic, retain) NSMutableArray *statsArray; @property (nonatomic, retain) NSString *savePath; @property (assign) BOOL menuStyle; diff -r 7ca9ebb6895d -r 224c31b3ce7d project_files/HedgewarsMobile/Classes/GameSetup.m --- a/project_files/HedgewarsMobile/Classes/GameSetup.m Thu Dec 30 04:54:25 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/GameSetup.m Fri Dec 31 00:10:38 2010 +0100 @@ -28,7 +28,7 @@ #define BUFFER_SIZE 255 // like in original frontend @implementation GameSetup -@synthesize systemSettings, gameConfig, statsDictionary, savePath, menuStyle; +@synthesize systemSettings, gameConfig, statsArray, savePath, menuStyle; -(id) initWithDictionary:(NSDictionary *)gameDictionary { if (self = [super init]) { @@ -58,13 +58,13 @@ } else self.savePath = path; - self.statsDictionary = nil; + self.statsArray = nil; } return self; } -(void) dealloc { - [statsDictionary release]; + [statsArray release]; [gameConfig release]; [systemSettings release]; [savePath release]; @@ -349,50 +349,35 @@ } break; case 'i': + if (self.statsArray == nil) + self.statsArray = [[NSMutableArray alloc] initWithCapacity:statMaxCapacity]; switch (buffer[1]) { - case 'r': - if (self.statsDictionary == nil) - self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; - [self.statsDictionary setObject:[NSString stringWithUTF8String:&buffer[2]] forKey:@"winning_team"]; + case 'r': // winning team + [self.statsArray insertObject:[NSString stringWithUTF8String:&buffer[2]] atIndex:0]; break; - case 'D': - if (self.statsDictionary == nil) - self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; - [self.statsDictionary setObject:[NSString stringWithFormat:@"Best shot: %s", &buffer[2]] forKey:@"best_shot"]; + case 'D': // best shot + [self.statsArray addObject:[NSString stringWithFormat:@"Best shot by %s", &buffer[2]]]; break; - case 'k': - if (self.statsDictionary == nil) - self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; - [self.statsDictionary setObject:[NSString stringWithFormat:@"Best hedgehog: %s", &buffer[2]] forKey:@"best_hog"]; + case 'k': // best hedgehog + [self.statsArray addObject:[NSString stringWithFormat:@"Best hedgehog: %s", &buffer[2]]]; break; - case 'K': - if (self.statsDictionary == nil) - self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; - [self.statsDictionary setObject:[NSString stringWithFormat:@"%s hogs killed", &buffer[2]] forKey:@"kills"]; + case 'K': // number of hogs killed + [self.statsArray addObject:[NSString stringWithFormat:@"%s hogs killed", &buffer[2]]]; break; - case 'H': - //something about team health + case 'H': //something about team health break; - case 'T': - // local team stats + case 'T': // local team stats break; - case 'P': - // player postion + case 'P': // player postion break; - case 's': - if (self.statsDictionary == nil) - self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; - [self.statsDictionary setObject:[NSString stringWithFormat:@"%s hit himself", &buffer[2]] forKey:@"self_dmg"]; + case 's': // self damage + [self.statsArray addObject:[NSString stringWithFormat:@"%s hit himself", &buffer[2]]]; break; - case 'S': - if (self.statsDictionary == nil) - self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; - [self.statsDictionary setObject:[NSString stringWithFormat:@"%s hit his friends", &buffer[2]] forKey:@"friendly_fire"]; + case 'S': // friendly fire + [self.statsArray addObject:[NSString stringWithFormat:@"%s hit his friends", &buffer[2]]]; break; - case 'B': - if (self.statsDictionary == nil) - self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; - [self.statsDictionary setObject:[NSString stringWithFormat:@"%s skipped most turns", &buffer[2]] forKey:@"turn_skips"]; + case 'B': // turn skipped + [self.statsArray addObject:[NSString stringWithFormat:@"%s skipped most turns", &buffer[2]]]; break; default: DLog(@"Unhandled stat message, see statsPage.cpp"); diff -r 7ca9ebb6895d -r 224c31b3ce7d project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.h --- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.h Thu Dec 30 04:54:25 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.h Fri Dec 31 00:10:38 2010 +0100 @@ -40,7 +40,7 @@ @property (nonatomic,retain) UIWindow *secondWindow; +(SDLUIKitDelegate *)sharedAppDelegate; --(NSDictionary *)startSDLgame:(NSDictionary *)gameDictionary; +-(NSArray *)startSDLgame:(NSDictionary *)gameDictionary; -(void) displayOverlayLater:(id) object; @end diff -r 7ca9ebb6895d -r 224c31b3ce7d project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m --- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Thu Dec 30 04:54:25 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Fri Dec 31 00:10:38 2010 +0100 @@ -85,7 +85,7 @@ } // main routine for calling the actual game engine --(NSDictionary *)startSDLgame:(NSDictionary *)gameDictionary { +-(NSArray *)startSDLgame:(NSDictionary *)gameDictionary { UIWindow *gameWindow; if (IS_DUALHEAD()) gameWindow = self.secondWindow; @@ -144,7 +144,7 @@ self.isInGame = NO; free(gameArgs); - NSDictionary *stat = setup.statsDictionary; + NSArray *stats = setup.statsArray; [setup release]; @@ -161,7 +161,7 @@ [refBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; [refSecondBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2]; - return stat; + return stats; } // overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created diff -r 7ca9ebb6895d -r 224c31b3ce7d project_files/HedgewarsMobile/Classes/StatsPageViewController.h --- a/project_files/HedgewarsMobile/Classes/StatsPageViewController.h Thu Dec 30 04:54:25 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/StatsPageViewController.h Fri Dec 31 00:10:38 2010 +0100 @@ -22,9 +22,9 @@ #import @interface StatsPageViewController : UITableViewController { - NSDictionary *statsDictionary; + NSArray *statsArray; } -@property (nonatomic,retain) NSDictionary *statsDictionary; +@property (nonatomic,retain) NSArray *statsArray; @end \ No newline at end of file diff -r 7ca9ebb6895d -r 224c31b3ce7d project_files/HedgewarsMobile/Classes/StatsPageViewController.m --- a/project_files/HedgewarsMobile/Classes/StatsPageViewController.m Thu Dec 30 04:54:25 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/StatsPageViewController.m Fri Dec 31 00:10:38 2010 +0100 @@ -23,7 +23,7 @@ #import "CommodityFunctions.h" @implementation StatsPageViewController -@synthesize statsDictionary; +@synthesize statsArray; -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { return rotationManager(interfaceOrientation); @@ -32,26 +32,30 @@ #pragma mark - #pragma mark Table view data source -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { - return 2; + return 3; } -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - if (section == 0) - return [[self.statsDictionary allValues] count]; + if (section == 0 || section == 2) + return 1; else - return 1; + return [self.statsArray count] - 1; } -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier0 = @"Cell0"; + NSInteger section = [indexPath section]; + NSInteger row = [indexPath row]; UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; if (cell == nil) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; cell.textLabel.textAlignment = UITextAlignmentCenter; - if ([indexPath section] == 0) { - cell.textLabel.text = [[self.statsDictionary allValues] objectAtIndex:[indexPath row]]; + if (section == 0) { + cell.textLabel.text = [self.statsArray objectAtIndex:row]; + } else if (section == 1) { + cell.textLabel.text = [self.statsArray objectAtIndex:row + 1]; } else { cell.textLabel.text = NSLocalizedString(@"Back",@""); } @@ -59,7 +63,6 @@ return cell; } - #pragma mark - #pragma mark Table view delegate -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { @@ -72,11 +75,11 @@ -(void) didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; - // Relinquish ownership any cached data, images, etc. that aren't in use. + self.statsArray = nil; } -(void) dealloc { - [statsDictionary release]; + [statsArray release]; [super dealloc]; }