project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
changeset 5206 db775bddf771
parent 5195 1bfa81f0bc21
child 5207 4c9ae0f484da
equal deleted inserted replaced
5205:78138ae93820 5206:db775bddf771
    25 #import "OverlayViewController.h"
    25 #import "OverlayViewController.h"
    26 #import "StatsPageViewController.h"
    26 #import "StatsPageViewController.h"
    27 #import "ObjcExports.h"
    27 #import "ObjcExports.h"
    28 
    28 
    29 @implementation GameInterfaceBridge
    29 @implementation GameInterfaceBridge
    30 @synthesize parentController, systemSettings, savePath, overlayController, engineProtocol, ipcPort, gameType;
    30 @synthesize parentController, savePath, overlayController, engineProtocol, ipcPort, gameType;
    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 = randomPort();
    34         self.ipcPort = randomPort();
    35         self.gameType = gtNone;
    35         self.gameType = gtNone;
    37 
    37 
    38         self.parentController = (UIViewController *)viewController;
    38         self.parentController = (UIViewController *)viewController;
    39         self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort];
    39         self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort];
    40         self.engineProtocol.delegate = self;
    40         self.engineProtocol.delegate = self;
    41 
    41 
    42         self.systemSettings = [NSDictionary dictionaryWithContentsOfFile:SETTINGS_FILE()];
       
    43         self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
    42         self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
    44     }
    43     }
    45     return self;
    44     return self;
    46 }
    45 }
    47 
    46 
    48 -(void) dealloc {
    47 -(void) dealloc {
    49     releaseAndNil(parentController);
    48     releaseAndNil(parentController);
    50     releaseAndNil(engineProtocol);
    49     releaseAndNil(engineProtocol);
    51     releaseAndNil(systemSettings);
       
    52     releaseAndNil(savePath);
    50     releaseAndNil(savePath);
    53     releaseAndNil(overlayController);
    51     releaseAndNil(overlayController);
    54     [super dealloc];
    52     [super dealloc];
    55 }
    53 }
    56 
    54 
    57 #pragma mark -
    55 #pragma mark -
    58 // overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created
    56 // overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created
    59 -(void) displayOverlayLater:(id) object {
    57 -(void) displayOverlayLater:(id) object {
    60     [self.overlayController setUseClassicMenu:[[self.systemSettings objectForKey:@"menu"] boolValue]];
       
    61     [self.overlayController setInitialOrientation:self.parentController.interfaceOrientation];
    58     [self.overlayController setInitialOrientation:self.parentController.interfaceOrientation];
    62 
    59 
    63     UIWindow *gameWindow = (IS_DUALHEAD() ? [HedgewarsAppDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow]);
    60     UIWindow *gameWindow = (IS_DUALHEAD() ? [HedgewarsAppDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow]);
    64     [gameWindow addSubview:self.overlayController.view];
    61     [gameWindow addSubview:self.overlayController.view];
    65 }
    62 }
    68 -(void) startGameEngine {
    65 -(void) startGameEngine {
    69     const char *gameArgs[11];
    66     const char *gameArgs[11];
    70     NSInteger width, height, orientation;
    67     NSInteger width, height, orientation;
    71     NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort];
    68     NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort];
    72     NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]];
    69     NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]];
       
    70     NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
    73 
    71 
    74     if (IS_DUALHEAD()) {
    72     if (IS_DUALHEAD()) {
    75         CGRect screenBounds = [[[UIScreen screens] objectAtIndex:1] bounds];
    73         CGRect screenBounds = [[[UIScreen screens] objectAtIndex:1] bounds];
    76         width = (int) screenBounds.size.width;
    74         width = (int) screenBounds.size.width;
    77         height = (int) screenBounds.size.height;
    75         height = (int) screenBounds.size.height;
    84     }
    82     }
    85 
    83 
    86     NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", width];
    84     NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", width];
    87     NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", height];
    85     NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", height];
    88     NSString *rotation = [[NSString alloc] initWithFormat:@"%d", orientation];
    86     NSString *rotation = [[NSString alloc] initWithFormat:@"%d", orientation];
    89     BOOL enhanced = [[self.systemSettings objectForKey:@"enhanced"] boolValue];
    87     BOOL enhanced = [[settings objectForKey:@"enhanced"] boolValue];
    90 
    88 
    91     NSString *modelId = modelType();
    89     NSString *modelId = modelType();
    92     NSInteger tmpQuality;
    90     NSInteger tmpQuality;
    93     if ([modelId hasPrefix:@"iPhone1"] || [modelId hasPrefix:@"iPod1,1"] || [modelId hasPrefix:@"iPod2,1"])     // = iPhone and iPhone 3G or iPod Touch or iPod Touch 2G
    91     if ([modelId hasPrefix:@"iPhone1"] || [modelId hasPrefix:@"iPod1,1"] || [modelId hasPrefix:@"iPod2,1"])     // = iPhone and iPhone 3G or iPod Touch or iPod Touch 2G
    94         tmpQuality = 0x00000001 | 0x00000002 | 0x00000008 | 0x00000040;                 // rqLowRes | rqBlurryLand | rqSimpleRope | rqKillFlakes
    92         tmpQuality = 0x00000001 | 0x00000002 | 0x00000008 | 0x00000040;                 // rqLowRes | rqBlurryLand | rqSimpleRope | rqKillFlakes
   102     // disable tooltips on iPhone
   100     // disable tooltips on iPhone
   103     if (IS_IPAD() == NO)
   101     if (IS_IPAD() == NO)
   104         tmpQuality = tmpQuality | 0x00000400;
   102         tmpQuality = tmpQuality | 0x00000400;
   105 
   103 
   106     // prevents using an empty nickname
   104     // prevents using an empty nickname
   107     NSString *username = [self.systemSettings objectForKey:@"username"];
   105     NSString *username = [settings objectForKey:@"username"];
   108     if ([username length] == 0)
   106     if ([username length] == 0)
   109         username = [NSString stringWithFormat:@"MobileUser-%@",ipcString];
   107         username = [NSString stringWithFormat:@"MobileUser-%@",ipcString];
   110 
   108 
   111     gameArgs[ 0] = [ipcString UTF8String];                                                      //ipcPort
   109     gameArgs[ 0] = [ipcString UTF8String];                                                      //ipcPort
   112     gameArgs[ 1] = [horizontalSize UTF8String];                                                 //cScreenWidth
   110     gameArgs[ 1] = [horizontalSize UTF8String];                                                 //cScreenWidth
   113     gameArgs[ 2] = [verticalSize UTF8String];                                                   //cScreenHeight
   111     gameArgs[ 2] = [verticalSize UTF8String];                                                   //cScreenHeight
   114     gameArgs[ 3] = [[NSString stringWithFormat:@"%d",tmpQuality] UTF8String];                   //quality
   112     gameArgs[ 3] = [[NSString stringWithFormat:@"%d",tmpQuality] UTF8String];                   //quality
   115     gameArgs[ 4] = "en.txt";//[localeString UTF8String];                                        //cLocaleFName
   113     gameArgs[ 4] = "en.txt";//[localeString UTF8String];                                        //cLocaleFName
   116     gameArgs[ 5] = [username UTF8String];                                                       //UserNick
   114     gameArgs[ 5] = [username UTF8String];                                                       //UserNick
   117     gameArgs[ 6] = [[[self.systemSettings objectForKey:@"sound"] stringValue] UTF8String];      //isSoundEnabled
   115     gameArgs[ 6] = [[[settings objectForKey:@"sound"] stringValue] UTF8String];                 //isSoundEnabled
   118     gameArgs[ 7] = [[[self.systemSettings objectForKey:@"music"] stringValue] UTF8String];      //isMusicEnabled
   116     gameArgs[ 7] = [[[settings objectForKey:@"music"] stringValue] UTF8String];                 //isMusicEnabled
   119     gameArgs[ 8] = [[[self.systemSettings objectForKey:@"alternate"] stringValue] UTF8String];  //cAltDamage
   117     gameArgs[ 8] = [[[settings objectForKey:@"alternate"] stringValue] UTF8String];             //cAltDamage
   120     gameArgs[ 9] = [rotation UTF8String];                                                       //rotateQt
   118     gameArgs[ 9] = [rotation UTF8String];                                                       //rotateQt
   121     gameArgs[10] = (self.gameType == gtSave) ? [self.savePath UTF8String] : NULL;               //recordFileName
   119     gameArgs[10] = (self.gameType == gtSave) ? [self.savePath UTF8String] : NULL;               //recordFileName
   122 
   120 
   123     [verticalSize release];
   121     [verticalSize release];
   124     [horizontalSize release];
   122     [horizontalSize release];