this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
authorkoda
Sun, 25 Sep 2011 02:28:33 +0200
changeset 6020 c792d4b3e080
parent 6019 8843ea756cfc
child 6021 652a199d4f38
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
project_files/HedgewarsMobile/Classes/MainMenuViewController.m
project_files/HedgewarsMobile/Classes/RestoreViewController.h
project_files/HedgewarsMobile/Classes/RestoreViewController.m
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Sat Sep 24 22:35:31 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Sun Sep 25 02:28:33 2011 +0200
@@ -165,6 +165,8 @@
     [userDefaults synchronize];
 
     // now we can remove the cover with a transition
+    blackView.frame = theFrame;
+    blackView.alpha = 1;
     [UIView beginAnimations:@"fade in" context:NULL];
     [UIView setAnimationDuration:1];
     blackView.alpha = 0;
@@ -210,7 +212,9 @@
 }
 
 -(void) gameHasEndedWithStats:(NSArray *)stats {
-    // display stats page
+    // wrap this around a retain/realse to prevent being deallocated too soon
+    [self retain];
+    // display stats page if there is something to display
     if (stats != nil) {
         StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped];
         statsPage.statsArray = stats;
@@ -225,6 +229,7 @@
     // can remove the savefile if the replay has ended
     if (self.gameType == gtSave)
         [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil];
+    [self release];
 }
 
 @end
--- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.m	Sat Sep 24 22:35:31 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.m	Sun Sep 25 02:28:33 2011 +0200
@@ -27,6 +27,7 @@
 #import "AboutViewController.h"
 #import "SavedGamesViewController.h"
 #import "RestoreViewController.h"
+#import "GameInterfaceBridge.h"
 #import "Appirater.h"
 #import "ServerSetup.h"
 
@@ -119,6 +120,7 @@
     // prompt for restoring any previous game
     NSString *saveString = [userDefaults objectForKey:@"savedGamePath"];
     if (saveString != nil && [saveString isEqualToString:@""] == NO) {
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(launchRestoredGame) name:@"launchRestoredGame" object:nil];
         if (self.restoreViewController == nil) {
             NSString *xibName = [@"RestoreViewController-" stringByAppendingString:(IS_IPAD() ? @"iPad" : @"iPhone")];
             RestoreViewController *restored = [[RestoreViewController alloc] initWithNibName:xibName bundle:nil];
@@ -127,7 +129,7 @@
             self.restoreViewController = restored;
             [restored release];
         }
-        [self performSelector:@selector(presentModalViewController:animated:) withObject:self.restoreViewController afterDelay:0.3];
+        [self performSelector:@selector(presentModalViewController:animated:) withObject:self.restoreViewController afterDelay:0.25];
     } else {
         // let's not prompt for rating when app crashed >_>
         [Appirater appLaunched];
@@ -237,6 +239,15 @@
     }
 }
 
+#pragma mark -
+-(void) launchRestoredGame {
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+    GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self];
+    [bridge startSaveGame:[[NSUserDefaults standardUserDefaults] objectForKey:@"savedGamePath"]];
+    [bridge release];
+}
+
+#pragma mark -
 -(void) viewDidUnload {
     self.gameConfigViewController = nil;
     self.settingsViewController = nil;
--- a/project_files/HedgewarsMobile/Classes/RestoreViewController.h	Sat Sep 24 22:35:31 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/RestoreViewController.h	Sun Sep 25 02:28:33 2011 +0200
@@ -21,14 +21,11 @@
 
 #import <UIKit/UIKit.h>
 
-@class GameInterfaceBridge;
 
 @interface RestoreViewController : UIViewController {
-    GameInterfaceBridge *interfaceBridge;
+
 }
 
-@property (nonatomic,retain) GameInterfaceBridge *interfaceBridge;
-
 -(IBAction) buttonReleased:(id) sender;
 
 @end
--- a/project_files/HedgewarsMobile/Classes/RestoreViewController.m	Sat Sep 24 22:35:31 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/RestoreViewController.m	Sun Sep 25 02:28:33 2011 +0200
@@ -23,7 +23,6 @@
 #import "GameInterfaceBridge.h"
 
 @implementation RestoreViewController
-@synthesize interfaceBridge;
 
 // Override to allow orientations other than the default portrait orientation.
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
@@ -37,16 +36,8 @@
 
     if (theButton.tag != 0) {
         [AudioManagerController playClickSound];
-        if (self.interfaceBridge == nil) {
-            GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self.parentViewController];
-            self.interfaceBridge = bridge;
-            [bridge release];
-        }
-        // TODO: it is useless to keep the modalcontroller around when calling interfacebridge
-        // but as long as it is an instance we mustn't release it beforehand
-        // moreover in this way the stats don't show up :/
-        [self.interfaceBridge startSaveGame:[defaults objectForKey:@"savedGamePath"]];
         [self.parentViewController dismissModalViewControllerAnimated:NO];
+        [[NSNotificationCenter defaultCenter] postNotificationName:@"launchRestoredGame" object:nil];
     } else {
         [AudioManagerController playBackSound];
         [defaults setObject:@"" forKey:@"savedGamePath"];
@@ -68,18 +59,14 @@
 }
 
 -(void) didReceiveMemoryWarning {
-    // don't nil this one or it won't be able to send messages
-    //self.interfaceBridge = nil;
     [super didReceiveMemoryWarning];
 }
 
 -(void) viewDidUnload {
-    self.interfaceBridge = nil;
     [super viewDidUnload];
 }
 
 -(void) dealloc {
-    releaseAndNil(interfaceBridge);
     [super dealloc];
 }