# HG changeset patch # User koda # Date 1293681265 -3600 # Node ID 7ca9ebb6895dc98e02f771bbfdaf92f0fe19add6 # Parent a0fd8211c00f2952d5a7a761e1c8526e633520ce initial stats display diff -r a0fd8211c00f -r 7ca9ebb6895d project_files/HedgewarsMobile/Classes/GameConfigViewController.m --- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Thu Dec 30 02:03:24 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Thu Dec 30 04:54:25 2010 +0100 @@ -25,6 +25,7 @@ #import "TeamConfigViewController.h" #import "SchemeWeaponConfigViewController.h" #import "HelpPageViewController.h" +#import "StatsPageViewController.h" #import "CommodityFunctions.h" #import "UIImageExtra.h" #import "PascalImports.h" @@ -226,19 +227,25 @@ [NSNumber numberWithInt:self.interfaceOrientation],@"orientation", nil]; - NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys:gameDictionary,@"game_dictionary", + NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys: + gameDictionary,@"game_dictionary", + [NSNumber numberWithBool:NO],@"netgame", @"",@"savefile", - [NSNumber numberWithBool:NO],@"netgame", nil]; if (IS_IPAD()) [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary]; else { // this causes a sporadic crash on the ipad but without this rotation doesn't work on iphone - UIViewController *dummy = [[UIViewController alloc] init]; - [self presentModalViewController:dummy animated:NO]; - [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary]; - [self dismissModalViewControllerAnimated:NO]; - [dummy release]; + StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped]; + [self presentModalViewController:statsPage animated:NO]; + + statsPage.statsDictionary = [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary]; + if (statsPage.statsDictionary == nil) + [statsPage dismissModalViewControllerAnimated:NO]; + else + [statsPage.tableView reloadData]; + DLog(@"%@",statsPage.statsDictionary); + [statsPage release]; } } diff -r a0fd8211c00f -r 7ca9ebb6895d project_files/HedgewarsMobile/Classes/GameSetup.m --- a/project_files/HedgewarsMobile/Classes/GameSetup.m Thu Dec 30 02:03:24 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/GameSetup.m Thu Dec 30 04:54:25 2010 +0100 @@ -243,6 +243,7 @@ BOOL clientQuit; char const buffer[BUFFER_SIZE]; uint8_t msgSize; + int statMaxCapacity = 10-3; clientQuit = NO; csd = NULL; @@ -348,25 +349,26 @@ } break; case 'i': - // initialized with maximum - if (self.statsDictionary == nil) - self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:10]; switch (buffer[1]) { case 'r': - DLog(@"Winning team: %s", &buffer[2]); + if (self.statsDictionary == nil) + self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; [self.statsDictionary setObject:[NSString stringWithUTF8String:&buffer[2]] forKey:@"winning_team"]; break; case 'D': - DLog(@"Best Shot: %s", &buffer[2]); - [self.statsDictionary setObject:[NSString stringWithUTF8String:&buffer[2]] forKey:@"best_shot"]; + if (self.statsDictionary == nil) + self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; + [self.statsDictionary setObject:[NSString stringWithFormat:@"Best shot: %s", &buffer[2]] forKey:@"best_shot"]; break; case 'k': - DLog(@"Best Hedgehog: %s", &buffer[2]); - [self.statsDictionary setObject:[NSString stringWithUTF8String:&buffer[2]] forKey:@"best_hog"]; + if (self.statsDictionary == nil) + self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; + [self.statsDictionary setObject:[NSString stringWithFormat:@"Best hedgehog: %s", &buffer[2]] forKey:@"best_hog"]; break; case 'K': - DLog(@"Hogs Killed: %s", &buffer[2]); - [self.statsDictionary setObject:[NSString stringWithUTF8String:&buffer[2]] forKey:@"kills"]; + if (self.statsDictionary == nil) + self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; + [self.statsDictionary setObject:[NSString stringWithFormat:@"%s hogs killed", &buffer[2]] forKey:@"kills"]; break; case 'H': //something about team health @@ -378,16 +380,19 @@ // player postion break; case 's': - DLog(@"Most self damage: %s", &buffer[2]); - [self.statsDictionary setObject:[NSString stringWithUTF8String:&buffer[2]] forKey:@"self_dmg"]; + if (self.statsDictionary == nil) + self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; + [self.statsDictionary setObject:[NSString stringWithFormat:@"%s hit himself", &buffer[2]] forKey:@"self_dmg"]; break; case 'S': - DLog(@"Most friendly fire: %s", &buffer[2]); - [self.statsDictionary setObject:[NSString stringWithUTF8String:&buffer[2]] forKey:@"friendly_fire"]; + if (self.statsDictionary == nil) + self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; + [self.statsDictionary setObject:[NSString stringWithFormat:@"%s hit his friends", &buffer[2]] forKey:@"friendly_fire"]; break; case 'B': - DLog(@"Most turn skipped by: %s", &buffer[2]); - [self.statsDictionary setObject:[NSString stringWithUTF8String:&buffer[2]] forKey:@"turn_skips"]; + if (self.statsDictionary == nil) + self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity]; + [self.statsDictionary setObject:[NSString stringWithFormat:@"%s skipped most turns", &buffer[2]] forKey:@"turn_skips"]; break; default: DLog(@"Unhandled stat message, see statsPage.cpp"); diff -r a0fd8211c00f -r 7ca9ebb6895d project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.h --- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.h Thu Dec 30 02:03:24 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.h Thu Dec 30 04:54:25 2010 +0100 @@ -40,7 +40,7 @@ @property (nonatomic,retain) UIWindow *secondWindow; +(SDLUIKitDelegate *)sharedAppDelegate; --(void) startSDLgame:(NSDictionary *)gameDictionary; +-(NSDictionary *)startSDLgame:(NSDictionary *)gameDictionary; -(void) displayOverlayLater:(id) object; @end diff -r a0fd8211c00f -r 7ca9ebb6895d project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m --- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Thu Dec 30 02:03:24 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Thu Dec 30 04:54:25 2010 +0100 @@ -85,7 +85,7 @@ } // main routine for calling the actual game engine --(void) startSDLgame:(NSDictionary *)gameDictionary { +-(NSDictionary *)startSDLgame:(NSDictionary *)gameDictionary { UIWindow *gameWindow; if (IS_DUALHEAD()) gameWindow = self.secondWindow; @@ -161,7 +161,7 @@ [refBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; [refSecondBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2]; - DLog(@"%@",stat); + return stat; } // overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created diff -r a0fd8211c00f -r 7ca9ebb6895d project_files/HedgewarsMobile/Classes/StatsPageViewController.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/HedgewarsMobile/Classes/StatsPageViewController.h Thu Dec 30 04:54:25 2010 +0100 @@ -0,0 +1,30 @@ +/* + * Hedgewars-iOS, a Hedgewars port for iOS devices + * Copyright (c) 2009-2010 Vittorio Giovara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * File created on 30/12/2010. + */ + + +#import + +@interface StatsPageViewController : UITableViewController { + NSDictionary *statsDictionary; +} + +@property (nonatomic,retain) NSDictionary *statsDictionary; + +@end \ No newline at end of file diff -r a0fd8211c00f -r 7ca9ebb6895d project_files/HedgewarsMobile/Classes/StatsPageViewController.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/HedgewarsMobile/Classes/StatsPageViewController.m Thu Dec 30 04:54:25 2010 +0100 @@ -0,0 +1,85 @@ +/* + * Hedgewars-iOS, a Hedgewars port for iOS devices + * Copyright (c) 2009-2010 Vittorio Giovara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * File created on 30/12/2010. + */ + + +#import "StatsPageViewController.h" +#import "CommodityFunctions.h" + +@implementation StatsPageViewController +@synthesize statsDictionary; + +-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { + return rotationManager(interfaceOrientation); +} + +#pragma mark - +#pragma mark Table view data source +-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { + return 2; +} + +-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + if (section == 0) + return [[self.statsDictionary allValues] count]; + else + return 1; +} + +-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *CellIdentifier0 = @"Cell0"; + + 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]]; + } else { + cell.textLabel.text = NSLocalizedString(@"Back",@""); + } + + return cell; +} + + +#pragma mark - +#pragma mark Table view delegate +-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + if ([indexPath section] == 2) + [self dismissModalViewControllerAnimated:YES]; +} + +#pragma mark - +#pragma mark Memory management +-(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. +} + +-(void) dealloc { + [statsDictionary release]; + [super dealloc]; +} + + +@end + diff -r a0fd8211c00f -r 7ca9ebb6895d project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj --- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Thu Dec 30 02:03:24 2010 +0100 +++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Thu Dec 30 04:54:25 2010 +0100 @@ -184,6 +184,7 @@ 61A670C212747DBD00B06CE7 /* MapConfigViewController-iPhone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165924E11CA9CB400D6E256 /* MapConfigViewController-iPhone.xib */; }; 61AC067412B2E32D000B52A2 /* Appirater.m in Sources */ = {isa = PBXBuildFile; fileRef = 61AC067312B2E32D000B52A2 /* Appirater.m */; }; 61B3D71C11EA6F2700EC7420 /* uKeys.pas in Sources */ = {isa = PBXBuildFile; fileRef = 617987FE114AA34C00BA94A9 /* uKeys.pas */; }; + 61B7A33812CC21080086B604 /* StatsPageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B7A33712CC21080086B604 /* StatsPageViewController.m */; }; 61C079E411F35A300072BF46 /* EditableCellView.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C079E311F35A300072BF46 /* EditableCellView.m */; }; 61D205A1127CDD1100ABD83E /* ObjcExports.m in Sources */ = {isa = PBXBuildFile; fileRef = 61D205A0127CDD1100ABD83E /* ObjcExports.m */; }; 61D3D2A51290E03A003CE7C3 /* irc.png in Resources */ = {isa = PBXBuildFile; fileRef = 61D3D2A41290E03A003CE7C3 /* irc.png */; }; @@ -962,6 +963,8 @@ 61A4A3A112A5CD56004D81E6 /* uCaptions.pas */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = uCaptions.pas; path = ../../hedgewars/uCaptions.pas; sourceTree = SOURCE_ROOT; }; 61AC067212B2E32D000B52A2 /* Appirater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Appirater.h; path = Classes/Appirater.h; sourceTree = ""; }; 61AC067312B2E32D000B52A2 /* Appirater.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Appirater.m; path = Classes/Appirater.m; sourceTree = ""; }; + 61B7A33612CC21080086B604 /* StatsPageViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StatsPageViewController.h; sourceTree = ""; }; + 61B7A33712CC21080086B604 /* StatsPageViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StatsPageViewController.m; sourceTree = ""; }; 61C079E211F35A300072BF46 /* EditableCellView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EditableCellView.h; path = Classes/EditableCellView.h; sourceTree = ""; }; 61C079E311F35A300072BF46 /* EditableCellView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EditableCellView.m; path = Classes/EditableCellView.m; sourceTree = ""; }; 61D2059F127CDD1100ABD83E /* ObjcExports.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ObjcExports.h; path = Classes/ObjcExports.h; sourceTree = ""; }; @@ -1154,6 +1157,8 @@ 611D9BF312497B7700008271 /* Other Controllers */ = { isa = PBXGroup; children = ( + 61B7A33612CC21080086B604 /* StatsPageViewController.h */, + 61B7A33712CC21080086B604 /* StatsPageViewController.m */, 61F2E7CB1205EDE0005734F7 /* AboutViewController.h */, 61F2E7CC1205EDE0005734F7 /* AboutViewController.m */, 61F2E7CD1205EDE0005734F7 /* AboutViewController.xib */, @@ -2424,6 +2429,7 @@ 61F544C712AF1748007FD913 /* HoldTableViewCell.m in Sources */, 61AC067412B2E32D000B52A2 /* Appirater.m in Sources */, 61E2E12E12BAAEE30051B659 /* ServerSetup.m in Sources */, + 61B7A33812CC21080086B604 /* StatsPageViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };