stats implemented once again! refactoring complete \o/
authorkoda
Tue, 19 Apr 2011 00:43:14 +0200
changeset 5158 4941df038b95
parent 5157 a5a6ffc56141
child 5159 cb19cb531435
stats implemented once again! refactoring complete \o/
project_files/HedgewarsMobile/Classes/GameConfigViewController.m
project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
project_files/HedgewarsMobile/Classes/SavedGamesViewController.m
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Tue Apr 19 00:19:01 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Tue Apr 19 00:43:14 2011 +0200
@@ -224,7 +224,6 @@
                                     self.teamConfigViewController.listOfSelectedTeams,@"teams_list",
                                     self.schemeWeaponConfigViewController.selectedScheme,@"scheme",
                                     self.schemeWeaponConfigViewController.selectedWeapon,@"weapon",
-                                    [NSNumber numberWithInt:self.interfaceOrientation],@"orientation",
                                     nil];
 
     GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self];
@@ -232,31 +231,6 @@
     [bridge startLocalGame:gameDictionary];
 
     [bridge release];
-    // also modify SavedGamesViewController.m
-   /* StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped];
-    statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
-    if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)])
-        statsPage.modalPresentationStyle = UIModalPresentationPageSheet;
-
-    NSArray *stats;
-    if (IS_DUALHEAD()) {
-        stats = [[HedgewarsAppDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
-        [self presentModalViewController:statsPage animated:NO];
-    } else {
-        [self performSelector:@selector(presentModalViewController:animated:) withObject:statsPage afterDelay:3];
-        stats = [[HedgewarsAppDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
-    }
-
-    if ([stats count] <= 1) {
-        DLog(@"%@",stats);
-        [statsPage dismissModalViewControllerAnimated:NO];
-    } else {
-        statsPage.statsArray = stats;
-        [statsPage.tableView reloadData];
-        [statsPage viewWillAppear:YES];
-    }
-
-    [statsPage release];*/
 }
 
 -(void) loadNiceHogs {
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Tue Apr 19 00:19:01 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Tue Apr 19 00:43:14 2011 +0200
@@ -23,6 +23,7 @@
 #import "PascalImports.h"
 #import "EngineProtocolNetwork.h"
 #import "OverlayViewController.h"
+#import "StatsPageViewController.h"
 
 @implementation GameInterfaceBridge
 @synthesize parentController, systemSettings, savePath, overlayController, engineProtocol, ipcPort, gameType;
@@ -171,6 +172,9 @@
 
     // the overlay is not needed any more and can be removed
     [self.overlayController removeOverlay];
+
+    // warn our host that it's going to be visible again
+    [self.parentController viewWillAppear:YES];
 }
 
 // set up variables for a local game
@@ -183,6 +187,10 @@
     self.savePath = [SAVES_DIRECTORY() stringByAppendingFormat:@"%@.hws", newDateString];
     [outputFormatter release];
 
+    // in the rare case in which a savefile with the same name exists the older one must be removed (or it gets corrupted)
+    if ([[NSFileManager defaultManager] fileExistsAtPath:self.savePath])
+        [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil];
+
     [self.engineProtocol spawnThread:self.savePath withOptions:withDictionary];
     [self prepareEngineLaunch];
 }
@@ -197,7 +205,17 @@
 }
 
 -(void) gameHasEndedWithStats:(NSArray *)stats {
-    DLog(@"%@",stats);
+    // display stats page
+    if (stats != nil) {
+        StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped];
+        statsPage.statsArray = stats;
+        statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
+        if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)])
+            statsPage.modalPresentationStyle = UIModalPresentationPageSheet;
+
+        [self.parentController presentModalViewController:statsPage animated:YES];
+        [statsPage release];
+    }
 
     // can remove the savefile if the replay has ended
     if (self.gameType == gtSave)
--- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m	Tue Apr 19 00:19:01 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m	Tue Apr 19 00:43:14 2011 +0200
@@ -214,37 +214,8 @@
     NSString *filePath = [[NSString alloc] initWithFormat:@"%@/%@",SAVES_DIRECTORY(),[self.listOfSavegames objectAtIndex:[indexPath row]]];
     [bridge startSaveGame:filePath];
     [filePath release];
+
     [bridge release];
-
-    // reload needed because when ending game the entry remains there
-    [self viewWillAppear:YES];
-
-    /* // also modify GameConfigViewController.m
-    StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped];
-    statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
-    if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)])
-        statsPage.modalPresentationStyle = UIModalPresentationPageSheet;
-    // avoid showing the stat page immediately, but wait for 3 seconds
-    [self performSelector:@selector(presentModalViewController:animated:) withObject:statsPage afterDelay:3];
-
-    NSArray *stats;
-    if (IS_DUALHEAD()) {
-        stats = [[HedgewarsAppDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
-        [self presentModalViewController:statsPage animated:NO];
-    } else {
-        [self performSelector:@selector(presentModalViewController:animated:) withObject:statsPage afterDelay:3];
-        stats = [[HedgewarsAppDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
-    }
-
-    if ([stats count] <= 1) {
-        DLog(@"%@",stats);
-        [statsPage dismissModalViewControllerAnimated:NO];
-    } else {
-        statsPage.statsArray = stats;
-        [statsPage.tableView reloadData];
-        [statsPage viewWillAppear:YES];
-    }*/
-
 }
 
 #pragma mark -