project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
changeset 6870 f72cac290325
parent 6869 a187c280dd3d
child 7943 0b03ac28212d
equal deleted inserted replaced
6869:a187c280dd3d 6870:f72cac290325
    23 
    23 
    24 
    24 
    25 static UIViewController *callingController;
    25 static UIViewController *callingController;
    26 
    26 
    27 @implementation GameInterfaceBridge
    27 @implementation GameInterfaceBridge
    28 @synthesize blackView, savePath, proto;
    28 @synthesize blackView, savePath, port;
    29 
    29 
    30 #pragma mark -
    30 #pragma mark -
    31 #pragma mark Instance methods for engine interaction
    31 #pragma mark Instance methods for engine interaction
    32 // prepares the controllers for hosting a game
    32 // prepares the controllers for hosting a game
    33 -(void) earlyEngineLaunch:(NSDictionary *)optionsOrNil {
    33 -(void) earlyEngineLaunch:(NSDictionary *)optionsOrNil {
    34     [self retain];
    34     [self retain];
    35     [[AudioManagerController mainManager] fadeOutBackgroundMusic];
    35     [[AudioManagerController mainManager] fadeOutBackgroundMusic];
    36 
    36 
    37     EngineProtocolNetwork *engineProtocol = [[EngineProtocolNetwork alloc] init];
    37     EngineProtocolNetwork *engineProtocol = [[EngineProtocolNetwork alloc] init];
    38     self.proto = engineProtocol;
    38     self.port = engineProtocol.enginePort;
       
    39     engineProtocol.delegate = self;
       
    40     [engineProtocol spawnThread:self.savePath withOptions:optionsOrNil];
    39     [engineProtocol release];
    41     [engineProtocol release];
    40     [self.proto spawnThread:self.savePath withOptions:optionsOrNil];
       
    41 
    42 
    42     // add a black view hiding the background
    43     // add a black view hiding the background
    43     UIWindow *thisWindow = [[HedgewarsAppDelegate sharedAppDelegate] uiwindow];
    44     UIWindow *thisWindow = [[HedgewarsAppDelegate sharedAppDelegate] uiwindow];
    44     self.blackView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    45     self.blackView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    45     self.blackView.opaque = YES;
    46     self.blackView.opaque = YES;
    80     [UIView setAnimationDuration:1];
    81     [UIView setAnimationDuration:1];
    81     self.blackView.alpha = 0;
    82     self.blackView.alpha = 0;
    82     [UIView commitAnimations];
    83     [UIView commitAnimations];
    83     [self.blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
    84     [self.blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
    84 
    85 
    85     // engine thread *should* be done by now
       
    86     NSArray *stats = [[NSArray alloc] initWithArray:self.proto.statsArray copyItems:YES];
       
    87     if ([HWUtils gameStatus] == gsEnded && stats != nil) {
       
    88         StatsPageViewController *statsPage = [[StatsPageViewController alloc] init];
       
    89         statsPage.statsArray = stats;
       
    90         statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
       
    91         if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)])
       
    92             statsPage.modalPresentationStyle = UIModalPresentationPageSheet;
       
    93 
       
    94         [callingController presentModalViewController:statsPage animated:YES];
       
    95         [statsPage release];
       
    96     }
       
    97     [stats release];
       
    98 
       
    99     // can remove the savefile if the replay has ended
    86     // can remove the savefile if the replay has ended
   100     if ([HWUtils gameType] == gtSave)
    87     if ([HWUtils gameType] == gtSave)
   101         [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil];
    88         [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil];
   102 
    89 
   103     // restart music and we're done
    90     // restart music and we're done
   109 
    96 
   110 // main routine for calling the actual game engine
    97 // main routine for calling the actual game engine
   111 -(void) engineLaunch {
    98 -(void) engineLaunch {
   112     const char *gameArgs[11];
    99     const char *gameArgs[11];
   113     CGFloat width, height;
   100     CGFloat width, height;
   114     NSInteger enginePort = self.proto.enginePort;
       
   115     CGFloat screenScale = [[UIScreen mainScreen] safeScale];
   101     CGFloat screenScale = [[UIScreen mainScreen] safeScale];
   116     NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",enginePort];
   102     NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",self.port];
   117     NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt",[[NSLocale preferredLanguages] objectAtIndex:0]];
   103     NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt",[[NSLocale preferredLanguages] objectAtIndex:0]];
   118     NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
   104     NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
   119 
   105 
   120     CGRect screenBounds = [[UIScreen mainScreen] safeBounds];
   106     CGRect screenBounds = [[UIScreen mainScreen] safeBounds];
   121     width = screenBounds.size.width;
   107     width = screenBounds.size.width;
   173 }
   159 }
   174 
   160 
   175 -(void) dealloc {
   161 -(void) dealloc {
   176     releaseAndNil(blackView);
   162     releaseAndNil(blackView);
   177     releaseAndNil(savePath);
   163     releaseAndNil(savePath);
   178     releaseAndNil(proto);
       
   179     [super dealloc];
   164     [super dealloc];
       
   165 }
       
   166 
       
   167 #pragma mark -
       
   168 #pragma mark EngineProtocolDelegate methods
       
   169 -(void) gameEndedWithStatistics:(NSArray *)stats {
       
   170     if (stats != nil) {
       
   171         StatsPageViewController *statsPage = [[StatsPageViewController alloc] init];
       
   172         statsPage.statsArray = stats;
       
   173         statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
       
   174 
       
   175         [callingController presentModalViewController:statsPage animated:YES];
       
   176         [statsPage release];
       
   177     }
   180 }
   178 }
   181 
   179 
   182 #pragma mark -
   180 #pragma mark -
   183 #pragma mark Class methods for setting up the engine from outsite
   181 #pragma mark Class methods for setting up the engine from outsite
   184 +(void) registerCallingController:(UIViewController *)controller {
   182 +(void) registerCallingController:(UIViewController *)controller {