things are a little sanier
authorkoda
Tue, 19 Apr 2011 00:19:01 +0200
changeset 5157 a5a6ffc56141
parent 5156 641abe679bf0
child 5158 4941df038b95
things are a little sanier
project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h
project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
project_files/HedgewarsMobile/Classes/SavedGamesViewController.m
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h	Mon Apr 18 02:45:51 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h	Tue Apr 19 00:19:01 2011 +0200
@@ -37,7 +37,6 @@
 
     NSInteger ipcPort;  // Port on which engine will listen
     TGameType gameType;
-    TGameStatus gameStatus;
 }
 
 @property (nonatomic,retain) UIViewController *parentController;
@@ -49,7 +48,6 @@
 
 @property (assign) NSInteger ipcPort;
 @property (assign) TGameType gameType;
-@property (assign) TGameStatus gameStatus;
 
 
 -(id)   initWithController:(id) viewController;
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Mon Apr 18 02:45:51 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Tue Apr 19 00:19:01 2011 +0200
@@ -25,13 +25,12 @@
 #import "OverlayViewController.h"
 
 @implementation GameInterfaceBridge
-@synthesize parentController, systemSettings, savePath, overlayController, engineProtocol, ipcPort, gameType, gameStatus;
+@synthesize parentController, systemSettings, savePath, overlayController, engineProtocol, ipcPort, gameType;
 
 -(id) initWithController:(id) viewController {
     if (self = [super init]) {
         self.ipcPort = randomPort();
         self.gameType = gtNone;
-        self.gameStatus = gsNone;
         self.savePath = nil;
 
         self.parentController = (UIViewController *)viewController;
@@ -128,46 +127,50 @@
     [ipcString release];
 
     // this is the pascal fuction that starts the game, wrapped around isInGame
-    self.gameStatus = gsInGame;
     [HedgewarsAppDelegate sharedAppDelegate].isInGame = YES;
     Game(gameArgs);
     [HedgewarsAppDelegate sharedAppDelegate].isInGame = NO;
-    if (self.gameStatus != gsEnded)
-        self.gameStatus = gsInterrupted;
 }
 
 // prepares the controllers for hosting a game
 -(void) prepareEngineLaunch {
-    NSDictionary *overlayOptions = [[NSDictionary alloc] initWithObjectsAndKeys:
-                                    [NSNumber numberWithInt:self.parentController.interfaceOrientation],@"orientation",
-                                    [self.systemSettings objectForKey:@"menu"],@"menu",
-                                    nil];
-    [self performSelector:@selector(displayOverlayLater:) withObject:overlayOptions afterDelay:4];
-    [overlayOptions release];
-
-    [self startGameEngine];
-
+    // we add a black view hiding the background
     CGRect theFrame = CGRectMake(0, 0, self.parentController.view.frame.size.height, self.parentController.view.frame.size.width);
     UIView *blackView = [[UIView alloc] initWithFrame:theFrame];
     [self.parentController.view addSubview:blackView];
     blackView.opaque = YES;
     blackView.backgroundColor = [UIColor blackColor];
+    blackView.alpha = 0;
+    // when dual screen we apply a little transition
+    if (IS_DUALHEAD()) {
+        [UIView beginAnimations:@"fade out" context:NULL];
+        [UIView setAnimationDuration:1];
+        blackView.alpha = 1;
+        [UIView commitAnimations];
+    }
+
+    // prepare options for overlay and add it to the future sdl uiwindow
+    NSDictionary *overlayOptions = [[NSDictionary alloc] initWithObjectsAndKeys:
+                                    [NSNumber numberWithInt:self.parentController.interfaceOrientation],@"orientation",
+                                    [self.systemSettings objectForKey:@"menu"],@"menu",
+                                    nil];
+    [self performSelector:@selector(displayOverlayLater:) withObject:overlayOptions afterDelay:3];
+    [overlayOptions release];
+
+    // SYSTEMS ARE GO!!
+    [self startGameEngine];
+
+    // now we can remove the cover with a transition
     blackView.alpha = 1;
-
     [UIView beginAnimations:@"fade in" context:NULL];
     [UIView setAnimationDuration:1];
     blackView.alpha = 0;
     [UIView commitAnimations];
     [blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
     [blackView release];
-    NSError *error = nil;
-    // can remove the savefile if the replay has ended
-    if (self.gameType == gtSave && self.gameStatus == gsEnded)
-        [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:&error];
-    DLog(@"%@",error);
 
-    if (IS_DUALHEAD())
-        [self.overlayController removeOverlay];
+    // the overlay is not needed any more and can be removed
+    [self.overlayController removeOverlay];
 }
 
 // set up variables for a local game
@@ -195,9 +198,10 @@
 
 -(void) gameHasEndedWithStats:(NSArray *)stats {
     DLog(@"%@",stats);
-    self.gameStatus = gsEnded;
 
-    [self.overlayController removeOverlay];
+    // can remove the savefile if the replay has ended
+    if (self.gameType == gtSave)
+        [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil];
 }
 
 @end
--- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m	Mon Apr 18 02:45:51 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m	Tue Apr 19 00:19:01 2011 +0200
@@ -215,7 +215,11 @@
     [bridge startSaveGame:filePath];
     [filePath release];
     [bridge release];
-   /* // also modify GameConfigViewController.m
+
+    // 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:)])
@@ -240,8 +244,7 @@
         [statsPage.tableView reloadData];
         [statsPage viewWillAppear:YES];
     }*/
-    // reload needed because when ending game the entry remains there
-    [self.tableView reloadData];
+
 }
 
 #pragma mark -