23 #import "PascalImports.h" |
23 #import "PascalImports.h" |
24 #import "EngineProtocolNetwork.h" |
24 #import "EngineProtocolNetwork.h" |
25 #import "OverlayViewController.h" |
25 #import "OverlayViewController.h" |
26 |
26 |
27 @implementation GameInterfaceBridge |
27 @implementation GameInterfaceBridge |
28 @synthesize parentController, systemSettings, savePath, overlayController, ipcPort, gameType, engineProtocol; |
28 @synthesize parentController, systemSettings, savePath, overlayController, engineProtocol, ipcPort, gameType, gameStatus; |
29 |
29 |
30 -(id) initWithController:(id) viewController { |
30 -(id) initWithController:(id) viewController { |
31 if (self = [super init]) { |
31 if (self = [super init]) { |
32 self.ipcPort = randomPort(); |
32 self.ipcPort = randomPort(); |
33 self.gameType = gtNone; |
33 self.gameType = gtNone; |
|
34 self.gameStatus = gsNone; |
34 self.savePath = nil; |
35 self.savePath = nil; |
35 |
36 |
36 self.parentController = (UIViewController *)viewController; |
37 self.parentController = (UIViewController *)viewController; |
37 self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort]; |
38 self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort]; |
38 self.engineProtocol.delegate = self; |
39 self.engineProtocol.delegate = self; |
64 [gameWindow addSubview:self.overlayController.view]; |
65 [gameWindow addSubview:self.overlayController.view]; |
65 } |
66 } |
66 |
67 |
67 // main routine for calling the actual game engine |
68 // main routine for calling the actual game engine |
68 -(void) startGameEngine { |
69 -(void) startGameEngine { |
69 const char *gameArgs[10]; |
70 const char *gameArgs[11]; |
70 NSInteger width, height, orientation; |
71 NSInteger width, height, orientation; |
71 NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort]; |
72 NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort]; |
72 NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; |
73 NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; |
73 |
74 |
74 if (IS_DUALHEAD()) { |
75 if (IS_DUALHEAD()) { |
125 [rotation release]; |
126 [rotation release]; |
126 [localeString release]; |
127 [localeString release]; |
127 [ipcString release]; |
128 [ipcString release]; |
128 |
129 |
129 // this is the pascal fuction that starts the game, wrapped around isInGame |
130 // this is the pascal fuction that starts the game, wrapped around isInGame |
|
131 self.gameStatus = gsInGame; |
130 [HedgewarsAppDelegate sharedAppDelegate].isInGame = YES; |
132 [HedgewarsAppDelegate sharedAppDelegate].isInGame = YES; |
131 Game(gameArgs); |
133 Game(gameArgs); |
132 [HedgewarsAppDelegate sharedAppDelegate].isInGame = NO; |
134 [HedgewarsAppDelegate sharedAppDelegate].isInGame = NO; |
|
135 if (self.gameStatus != gsEnded) |
|
136 self.gameStatus = gsInterrupted; |
133 } |
137 } |
134 |
138 |
135 // prepares the controllers for hosting a game |
139 // prepares the controllers for hosting a game |
136 -(void) prepareEngineLaunch { |
140 -(void) prepareEngineLaunch { |
137 self.parentController.view.opaque = YES; |
|
138 self.parentController.view.backgroundColor = [UIColor blackColor]; |
|
139 self.parentController.view.alpha = 0; |
|
140 |
|
141 [UIView beginAnimations:@"fade out to black" context:NULL]; |
|
142 [UIView setAnimationDuration:1]; |
|
143 self.parentController.view.alpha = 1; |
|
144 [UIView commitAnimations]; |
|
145 |
|
146 NSDictionary *overlayOptions = [[NSDictionary alloc] initWithObjectsAndKeys: |
141 NSDictionary *overlayOptions = [[NSDictionary alloc] initWithObjectsAndKeys: |
147 [NSNumber numberWithInt:self.parentController.interfaceOrientation],@"orientation", |
142 [NSNumber numberWithInt:self.parentController.interfaceOrientation],@"orientation", |
148 [self.systemSettings objectForKey:@"menu"],@"menu", |
143 [self.systemSettings objectForKey:@"menu"],@"menu", |
149 nil]; |
144 nil]; |
150 [self performSelector:@selector(displayOverlayLater:) withObject:overlayOptions afterDelay:1]; |
145 [self performSelector:@selector(displayOverlayLater:) withObject:overlayOptions afterDelay:4]; |
151 [overlayOptions release]; |
146 [overlayOptions release]; |
152 |
147 |
153 [self startGameEngine]; |
148 [self startGameEngine]; |
|
149 |
|
150 CGRect theFrame = CGRectMake(0, 0, self.parentController.view.frame.size.height, self.parentController.view.frame.size.width); |
|
151 UIView *blackView = [[UIView alloc] initWithFrame:theFrame]; |
|
152 [self.parentController.view addSubview:blackView]; |
|
153 blackView.opaque = YES; |
|
154 blackView.backgroundColor = [UIColor blackColor]; |
|
155 blackView.alpha = 1; |
154 |
156 |
155 [UIView beginAnimations:@"fade in" context:NULL]; |
157 [UIView beginAnimations:@"fade in" context:NULL]; |
156 [UIView setAnimationDuration:1]; |
158 [UIView setAnimationDuration:1]; |
157 self.parentController.view.alpha = 0; |
159 blackView.alpha = 0; |
158 [UIView commitAnimations]; |
160 [UIView commitAnimations]; |
|
161 [blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
|
162 [blackView release]; |
|
163 NSError *error = nil; |
|
164 // can remove the savefile if the replay has ended |
|
165 if (self.gameType == gtSave && self.gameStatus == gsEnded) |
|
166 [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:&error]; |
|
167 DLog(@"%@",error); |
|
168 |
|
169 if (IS_DUALHEAD()) |
|
170 [self.overlayController removeOverlay]; |
159 } |
171 } |
160 |
172 |
161 // set up variables for a local game |
173 // set up variables for a local game |
162 -(void) startLocalGame:(NSDictionary *)withDictionary { |
174 -(void) startLocalGame:(NSDictionary *)withDictionary { |
163 self.gameType = gtLocal; |
175 self.gameType = gtLocal; |