project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
changeset 6259 02765411a912
parent 6247 6dfad55fd71c
child 6261 7050772ae46a
equal deleted inserted replaced
6258:ba9defb98a70 6259:02765411a912
    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, overlayController, engineProtocol, ipcPort;
    30 @synthesize parentController, 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;
    37         self.parentController = (UIViewController *)viewController;
    38         self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort];
    38         self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort];
    39 
       
    40         self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
       
    41     }
    39     }
    42     return self;
    40     return self;
    43 }
    41 }
    44 
    42 
    45 -(void) dealloc {
    43 -(void) dealloc {
    46     releaseAndNil(engineProtocol);
    44     releaseAndNil(engineProtocol);
    47     releaseAndNil(savePath);
    45     releaseAndNil(savePath);
    48     releaseAndNil(overlayController);
       
    49     [super dealloc];
    46     [super dealloc];
    50 }
    47 }
    51 
    48 
    52 #pragma mark -
    49 #pragma mark -
    53 // overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created
       
    54 -(void) displayOverlayLater:(id) object {
       
    55     // in order to get rotation events we have to insert the view inside the first view of the second window
       
    56     // when multihead we have to make sure that overlay is displayed in the touch-enabled window
       
    57     UIView *injected = (IS_DUALHEAD() ? self.parentController.view : UIVIEW_HW_SDLVIEW);
       
    58     [injected addSubview:self.overlayController.view];
       
    59 }
       
    60 
       
    61 // main routine for calling the actual game engine
    50 // main routine for calling the actual game engine
    62 -(void) engineLaunch {
    51 -(void) engineLaunch {
    63     const char *gameArgs[11];
    52     const char *gameArgs[11];
    64     CGFloat width, height;
    53     CGFloat width, height;
    65     CGFloat screenScale = [[UIScreen mainScreen] safeScale];
    54     CGFloat screenScale = [[UIScreen mainScreen] safeScale];
   141         blackView.alpha = 1;
   130         blackView.alpha = 1;
   142         [UIView commitAnimations];
   131         [UIView commitAnimations];
   143     } else
   132     } else
   144         blackView.alpha = 1;
   133         blackView.alpha = 1;
   145 
   134 
   146     // prepare options for overlay and add it to the future sdl uiwindow
       
   147     [self performSelector:@selector(displayOverlayLater:) withObject:nil afterDelay:3];
       
   148 
       
   149     // keep track of uncompleted games
   135     // keep track of uncompleted games
   150     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
   136     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
   151     [userDefaults setObject:self.savePath forKey:@"savedGamePath"];
   137     [userDefaults setObject:self.savePath forKey:@"savedGamePath"];
   152     [userDefaults synchronize];
   138     [userDefaults synchronize];
   153 
   139 
   169     [UIView commitAnimations];
   155     [UIView commitAnimations];
   170     [blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
   156     [blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
   171     [blackView release];
   157     [blackView release];
   172 
   158 
   173     // the overlay is not needed any more and can be removed
   159     // the overlay is not needed any more and can be removed
   174     [self.overlayController removeOverlay];
   160     [[OverlayViewController mainOverlay] removeOverlay];
   175 
   161 
   176     // warn our host that it's going to be visible again
   162     // warn our host that it's going to be visible again
   177     [self.parentController viewWillAppear:YES];
   163     [self.parentController viewWillAppear:YES];
   178 
   164 
   179     [AudioManagerController playBackgroundMusic];
   165     [AudioManagerController playBackgroundMusic];