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, engineProtocol, ipcPort, gameType, gameStatus; |
28 @synthesize parentController, systemSettings, savePath, overlayController, engineProtocol, ipcPort, gameType; |
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; |
|
35 self.savePath = nil; |
34 self.savePath = nil; |
36 |
35 |
37 self.parentController = (UIViewController *)viewController; |
36 self.parentController = (UIViewController *)viewController; |
38 self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort]; |
37 self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort]; |
39 self.engineProtocol.delegate = self; |
38 self.engineProtocol.delegate = self; |
126 [rotation release]; |
125 [rotation release]; |
127 [localeString release]; |
126 [localeString release]; |
128 [ipcString release]; |
127 [ipcString release]; |
129 |
128 |
130 // this is the pascal fuction that starts the game, wrapped around isInGame |
129 // this is the pascal fuction that starts the game, wrapped around isInGame |
131 self.gameStatus = gsInGame; |
|
132 [HedgewarsAppDelegate sharedAppDelegate].isInGame = YES; |
130 [HedgewarsAppDelegate sharedAppDelegate].isInGame = YES; |
133 Game(gameArgs); |
131 Game(gameArgs); |
134 [HedgewarsAppDelegate sharedAppDelegate].isInGame = NO; |
132 [HedgewarsAppDelegate sharedAppDelegate].isInGame = NO; |
135 if (self.gameStatus != gsEnded) |
|
136 self.gameStatus = gsInterrupted; |
|
137 } |
133 } |
138 |
134 |
139 // prepares the controllers for hosting a game |
135 // prepares the controllers for hosting a game |
140 -(void) prepareEngineLaunch { |
136 -(void) prepareEngineLaunch { |
141 NSDictionary *overlayOptions = [[NSDictionary alloc] initWithObjectsAndKeys: |
137 // we add a black view hiding the background |
142 [NSNumber numberWithInt:self.parentController.interfaceOrientation],@"orientation", |
|
143 [self.systemSettings objectForKey:@"menu"],@"menu", |
|
144 nil]; |
|
145 [self performSelector:@selector(displayOverlayLater:) withObject:overlayOptions afterDelay:4]; |
|
146 [overlayOptions release]; |
|
147 |
|
148 [self startGameEngine]; |
|
149 |
|
150 CGRect theFrame = CGRectMake(0, 0, self.parentController.view.frame.size.height, self.parentController.view.frame.size.width); |
138 CGRect theFrame = CGRectMake(0, 0, self.parentController.view.frame.size.height, self.parentController.view.frame.size.width); |
151 UIView *blackView = [[UIView alloc] initWithFrame:theFrame]; |
139 UIView *blackView = [[UIView alloc] initWithFrame:theFrame]; |
152 [self.parentController.view addSubview:blackView]; |
140 [self.parentController.view addSubview:blackView]; |
153 blackView.opaque = YES; |
141 blackView.opaque = YES; |
154 blackView.backgroundColor = [UIColor blackColor]; |
142 blackView.backgroundColor = [UIColor blackColor]; |
|
143 blackView.alpha = 0; |
|
144 // when dual screen we apply a little transition |
|
145 if (IS_DUALHEAD()) { |
|
146 [UIView beginAnimations:@"fade out" context:NULL]; |
|
147 [UIView setAnimationDuration:1]; |
|
148 blackView.alpha = 1; |
|
149 [UIView commitAnimations]; |
|
150 } |
|
151 |
|
152 // prepare options for overlay and add it to the future sdl uiwindow |
|
153 NSDictionary *overlayOptions = [[NSDictionary alloc] initWithObjectsAndKeys: |
|
154 [NSNumber numberWithInt:self.parentController.interfaceOrientation],@"orientation", |
|
155 [self.systemSettings objectForKey:@"menu"],@"menu", |
|
156 nil]; |
|
157 [self performSelector:@selector(displayOverlayLater:) withObject:overlayOptions afterDelay:3]; |
|
158 [overlayOptions release]; |
|
159 |
|
160 // SYSTEMS ARE GO!! |
|
161 [self startGameEngine]; |
|
162 |
|
163 // now we can remove the cover with a transition |
155 blackView.alpha = 1; |
164 blackView.alpha = 1; |
156 |
|
157 [UIView beginAnimations:@"fade in" context:NULL]; |
165 [UIView beginAnimations:@"fade in" context:NULL]; |
158 [UIView setAnimationDuration:1]; |
166 [UIView setAnimationDuration:1]; |
159 blackView.alpha = 0; |
167 blackView.alpha = 0; |
160 [UIView commitAnimations]; |
168 [UIView commitAnimations]; |
161 [blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
169 [blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
162 [blackView release]; |
170 [blackView release]; |
163 NSError *error = nil; |
171 |
164 // can remove the savefile if the replay has ended |
172 // the overlay is not needed any more and can be removed |
165 if (self.gameType == gtSave && self.gameStatus == gsEnded) |
173 [self.overlayController removeOverlay]; |
166 [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:&error]; |
|
167 DLog(@"%@",error); |
|
168 |
|
169 if (IS_DUALHEAD()) |
|
170 [self.overlayController removeOverlay]; |
|
171 } |
174 } |
172 |
175 |
173 // set up variables for a local game |
176 // set up variables for a local game |
174 -(void) startLocalGame:(NSDictionary *)withDictionary { |
177 -(void) startLocalGame:(NSDictionary *)withDictionary { |
175 self.gameType = gtLocal; |
178 self.gameType = gtLocal; |