62 return self; |
60 return self; |
63 } |
61 } |
64 |
62 |
65 -(void) dealloc { |
63 -(void) dealloc { |
66 [mainViewController release]; |
64 [mainViewController release]; |
67 [overlayController release]; |
|
68 [uiwindow release]; |
65 [uiwindow release]; |
69 [secondWindow release]; |
66 [secondWindow release]; |
70 [super dealloc]; |
67 [super dealloc]; |
71 } |
|
72 |
|
73 // main routine for calling the actual game engine |
|
74 -(NSArray *)startSDLgame:(NSDictionary *)gameDictionary { |
|
75 UIWindow *gameWindow; |
|
76 if (IS_DUALHEAD()) |
|
77 gameWindow = self.secondWindow; |
|
78 else |
|
79 gameWindow = self.uiwindow; |
|
80 |
|
81 UIView *blackView = [[UIView alloc] initWithFrame:gameWindow.frame]; |
|
82 blackView.backgroundColor = [UIColor blackColor]; |
|
83 blackView.opaque = YES; |
|
84 blackView.tag = BLACKVIEW_TAG; |
|
85 [gameWindow addSubview:blackView]; |
|
86 if (IS_DUALHEAD()) { |
|
87 blackView.alpha = 0; |
|
88 [UIView beginAnimations:@"fading to game first" context:NULL]; |
|
89 [UIView setAnimationDuration:1]; |
|
90 blackView.alpha = 1; |
|
91 [UIView commitAnimations]; |
|
92 |
|
93 UIView *secondBlackView = [[UIView alloc] initWithFrame:self.uiwindow.frame]; |
|
94 secondBlackView.backgroundColor = [UIColor blackColor]; |
|
95 secondBlackView.opaque = YES; |
|
96 secondBlackView.tag = SECONDBLACKVIEW_TAG; |
|
97 secondBlackView.alpha = 0; |
|
98 [self.uiwindow addSubview:secondBlackView]; |
|
99 [UIView beginAnimations:@"fading to game second" context:NULL]; |
|
100 [UIView setAnimationDuration:1]; |
|
101 secondBlackView.alpha = 1; |
|
102 [UIView commitAnimations]; |
|
103 [secondBlackView release]; |
|
104 } |
|
105 [blackView release]; |
|
106 |
|
107 |
|
108 // pull out useful configuration info from various files |
|
109 GameSetup *setup = [[GameSetup alloc] initWithDictionary:gameDictionary]; |
|
110 NSNumber *isNetGameNum = [gameDictionary objectForKey:@"netgame"]; |
|
111 |
|
112 [NSThread detachNewThreadSelector:@selector(engineProtocol) |
|
113 toTarget:setup |
|
114 withObject:nil]; |
|
115 |
|
116 NSNumber *menuStyle = [NSNumber numberWithBool:setup.menuStyle]; |
|
117 NSNumber *orientation = [[gameDictionary objectForKey:@"game_dictionary"] objectForKey:@"orientation"]; |
|
118 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: |
|
119 isNetGameNum,@"net", |
|
120 menuStyle,@"menu", |
|
121 orientation,@"orientation", |
|
122 nil]; |
|
123 [self performSelector:@selector(displayOverlayLater:) withObject:dict afterDelay:1]; |
|
124 |
|
125 // need to set again [gameDictionary objectForKey:@"savefile"] because if it's empty it means it's a normal game |
|
126 const char **gameArgs = [setup getGameSettings:[gameDictionary objectForKey:@"savefile"]]; |
|
127 self.isInGame = YES; |
|
128 // this is the pascal fuction that starts the game |
|
129 Game(gameArgs); |
|
130 self.isInGame = NO; |
|
131 free(gameArgs); |
|
132 |
|
133 NSArray *stats = setup.statsArray; |
|
134 [setup release]; |
|
135 |
|
136 |
|
137 [self.uiwindow makeKeyAndVisible]; |
|
138 [self.uiwindow bringSubviewToFront:self.mainViewController.view]; |
|
139 |
|
140 UIView *refBlackView = [gameWindow viewWithTag:BLACKVIEW_TAG]; |
|
141 UIView *refSecondBlackView = [self.uiwindow viewWithTag:SECONDBLACKVIEW_TAG]; |
|
142 [UIView beginAnimations:@"fading in from ingame" context:NULL]; |
|
143 [UIView setAnimationDuration:1]; |
|
144 refBlackView.alpha = 0; |
|
145 refSecondBlackView.alpha = 0; |
|
146 [UIView commitAnimations]; |
|
147 [refBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
|
148 [refSecondBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2]; |
|
149 |
|
150 return stats; |
|
151 } |
|
152 |
|
153 // overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created |
|
154 -(void) displayOverlayLater:(id) object { |
|
155 NSDictionary *dict = (NSDictionary *)object; |
|
156 self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil]; |
|
157 self.overlayController.isNetGame = [[dict objectForKey:@"net"] boolValue]; |
|
158 self.overlayController.useClassicMenu = [[dict objectForKey:@"menu"] boolValue]; |
|
159 self.overlayController.initialOrientation = [[dict objectForKey:@"orientation"] intValue]; |
|
160 |
|
161 UIWindow *gameWindow; |
|
162 if (IS_DUALHEAD()) |
|
163 gameWindow = self.uiwindow; |
|
164 else |
|
165 gameWindow = [[UIApplication sharedApplication] keyWindow]; |
|
166 [gameWindow addSubview:self.overlayController.view]; |
|
167 } |
68 } |
168 |
69 |
169 // override the direct execution of SDL_main to allow us to implement our own frontend |
70 // override the direct execution of SDL_main to allow us to implement our own frontend |
170 -(void) postFinishLaunch { |
71 -(void) postFinishLaunch { |
171 [[UIApplication sharedApplication] setStatusBarHidden:YES]; |
72 [[UIApplication sharedApplication] setStatusBarHidden:YES]; |
172 [Appirater appLaunched]; |
73 [Appirater appLaunched]; |
173 |
74 |
174 self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
75 self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
175 |
76 |
176 if (IS_IPAD()) |
77 NSString *controllerName = (IS_IPAD() ? @"MainMenuViewController-iPad" : @"MainMenuViewController-iPhone"); |
177 self.mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil]; |
78 self.mainViewController = [[MainMenuViewController alloc] initWithNibName:controllerName bundle:nil]; |
178 else |
|
179 self.mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil]; |
|
180 |
79 |
181 [self.uiwindow addSubview:self.mainViewController.view]; |
80 [self.uiwindow addSubview:self.mainViewController.view]; |
182 [self.mainViewController release]; |
81 [self.mainViewController release]; |
183 self.uiwindow.backgroundColor = [UIColor blackColor]; |
82 self.uiwindow.backgroundColor = [UIColor blackColor]; |
184 [self.uiwindow makeKeyAndVisible]; |
83 [self.uiwindow makeKeyAndVisible]; |
185 |
84 |
186 // check for dual monitor support |
85 // check for dual monitor support |
187 if (IS_DUALHEAD()) { |
86 if (IS_DUALHEAD()) { |
188 DLog(@"dual head mode ftw"); |
87 DLog(@"Dualhead mode"); |
189 self.secondWindow = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:1] bounds]]; |
88 self.secondWindow = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:1] bounds]]; |
190 self.secondWindow.backgroundColor = [UIColor blackColor]; |
89 self.secondWindow.backgroundColor = [UIColor blackColor]; |
191 self.secondWindow.screen = [[UIScreen screens] objectAtIndex:1]; |
90 self.secondWindow.screen = [[UIScreen screens] objectAtIndex:1]; |
192 UIImage *titleImage = [UIImage imageWithContentsOfFile:@"title.png"]; |
91 UIImage *titleImage = [UIImage imageWithContentsOfFile:@"title.png"]; |
193 UIImageView *titleView = [[UIImageView alloc] initWithImage:titleImage]; |
92 UIImageView *titleView = [[UIImageView alloc] initWithImage:titleImage]; |