project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
changeset 6261 7050772ae46a
parent 6259 02765411a912
child 6263 ec41637ceb64
equal deleted inserted replaced
6260:025d50a6aeb0 6261:7050772ae46a
    25 #import "StatsPageViewController.h"
    25 #import "StatsPageViewController.h"
    26 #import "AudioManagerController.h"
    26 #import "AudioManagerController.h"
    27 #import "ObjcExports.h"
    27 #import "ObjcExports.h"
    28 
    28 
    29 @implementation GameInterfaceBridge
    29 @implementation GameInterfaceBridge
    30 @synthesize parentController, savePath, engineProtocol, ipcPort;
    30 @synthesize savePath, engineProtocol, ipcPort;
    31 
    31 
    32 -(id) initWithController:(id) viewController {
    32 -(id) initWithController:(id) viewController {
    33     if (self = [super init]) {
    33     if (self = [super init]) {
    34         self.ipcPort = [HWUtils randomPort];
    34         self.ipcPort = [HWUtils randomPort];
    35         self.savePath = nil;
    35         self.savePath = nil;
    36 
    36 
    37         self.parentController = (UIViewController *)viewController;
       
    38         self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort];
    37         self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort];
    39     }
    38     }
    40     return self;
    39     return self;
    41 }
    40 }
    42 
    41 
   114     Game(gameArgs);
   113     Game(gameArgs);
   115 }
   114 }
   116 
   115 
   117 // prepares the controllers for hosting a game
   116 // prepares the controllers for hosting a game
   118 -(void) prepareEngineLaunch {
   117 -(void) prepareEngineLaunch {
       
   118     CGRect theFrame = [[UIScreen mainScreen] bounds];
       
   119     UIWindow *thisWindow = [[HedgewarsAppDelegate sharedAppDelegate] uiwindow];
   119     // we add a black view hiding the background
   120     // we add a black view hiding the background
   120     CGRect theFrame = CGRectMake(0, 0, self.parentController.view.frame.size.height, self.parentController.view.frame.size.width);
       
   121     UIView *blackView = [[UIView alloc] initWithFrame:theFrame];
   121     UIView *blackView = [[UIView alloc] initWithFrame:theFrame];
   122     [self.parentController.view addSubview:blackView];
   122     [thisWindow addSubview:blackView];
   123     blackView.opaque = YES;
   123     blackView.opaque = YES;
   124     blackView.backgroundColor = [UIColor blackColor];
   124     blackView.backgroundColor = [UIColor blackColor];
   125     blackView.alpha = 0;
   125     blackView.alpha = 0;
       
   126 
   126     // when dual screen we apply a little transition
   127     // when dual screen we apply a little transition
   127     if (IS_DUALHEAD()) {
   128     if (IS_DUALHEAD()) {
   128         [UIView beginAnimations:@"fade out" context:NULL];
   129         [UIView beginAnimations:@"fade out" context:NULL];
   129         [UIView setAnimationDuration:1];
   130         [UIView setAnimationDuration:1];
   130         blackView.alpha = 1;
   131         blackView.alpha = 1;
   157     [blackView release];
   158     [blackView release];
   158 
   159 
   159     // the overlay is not needed any more and can be removed
   160     // the overlay is not needed any more and can be removed
   160     [[OverlayViewController mainOverlay] removeOverlay];
   161     [[OverlayViewController mainOverlay] removeOverlay];
   161 
   162 
   162     // warn our host that it's going to be visible again
       
   163     [self.parentController viewWillAppear:YES];
       
   164 
       
   165     [AudioManagerController playBackgroundMusic];
   163     [AudioManagerController playBackgroundMusic];
   166 }
   164 }
   167 
   165 
   168 // set up variables for a local game
   166 // set up variables for a local game
   169 -(void) startLocalGame:(NSDictionary *)withOptions {
   167 -(void) startLocalGame:(NSDictionary *)withOptions {
   202     [missionPath release];
   200     [missionPath release];
   203     [self.engineProtocol spawnThread:nil withOptions:config];
   201     [self.engineProtocol spawnThread:nil withOptions:config];
   204     [self prepareEngineLaunch];
   202     [self prepareEngineLaunch];
   205 }
   203 }
   206 
   204 
       
   205 /*
   207 -(void) gameHasEndedWithStats:(NSArray *)stats {
   206 -(void) gameHasEndedWithStats:(NSArray *)stats {
   208     // wrap this around a retain/realse to prevent being deallocated too soon
   207     // wrap this around a retain/realse to prevent being deallocated too soon
   209     [self retain];
   208     [self retain];
   210     // display stats page if there is something to display
   209     // display stats page if there is something to display
   211     if (stats != nil) {
   210     if (stats != nil) {
   222     // can remove the savefile if the replay has ended
   221     // can remove the savefile if the replay has ended
   223     if ([HWUtils gameType] == gtSave)
   222     if ([HWUtils gameType] == gtSave)
   224         [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil];
   223         [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil];
   225     [self release];
   224     [self release];
   226 }
   225 }
       
   226 */
   227 
   227 
   228 @end
   228 @end