81 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
81 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
82 } |
82 } |
83 activeController = schemeWeaponConfigViewController; |
83 activeController = schemeWeaponConfigViewController; |
84 break; |
84 break; |
85 } |
85 } |
86 |
86 |
87 // this message is compulsory otherwise the table won't be loaded at all |
87 // this message is compulsory otherwise the table won't be loaded at all |
88 [activeController viewWillAppear:NO]; |
88 [activeController viewWillAppear:NO]; |
89 [self.view addSubview:activeController.view]; |
89 [self.view addSubview:activeController.view]; |
90 } |
90 } |
91 |
91 |
92 -(void) startGame:(UIButton *)button { |
92 -(void) startGame:(UIButton *)button { |
93 button.enabled = YES; |
93 button.enabled = YES; |
129 otherButtonTitles:nil]; |
129 otherButtonTitles:nil]; |
130 [alert show]; |
130 [alert show]; |
131 [alert release]; |
131 [alert release]; |
132 return; |
132 return; |
133 } |
133 } |
134 |
134 |
135 if ([schemeWeaponConfigViewController.selectedScheme length] == 0 || [schemeWeaponConfigViewController.selectedWeapon length] == 0 ) { |
135 if ([schemeWeaponConfigViewController.selectedScheme length] == 0 || [schemeWeaponConfigViewController.selectedWeapon length] == 0 ) { |
136 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Missing detail",@"") |
136 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Missing detail",@"") |
137 message:NSLocalizedString(@"Select one Scheme and one Weapon for this game",@"") |
137 message:NSLocalizedString(@"Select one Scheme and one Weapon for this game",@"") |
138 delegate:nil |
138 delegate:nil |
139 cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
139 cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
140 otherButtonTitles:nil]; |
140 otherButtonTitles:nil]; |
141 [alert show]; |
141 [alert show]; |
142 [alert release]; |
142 [alert release]; |
143 return; |
143 return; |
144 } |
144 } |
145 |
145 |
146 // create the configuration file that is going to be sent to engine |
146 // create the configuration file that is going to be sent to engine |
147 NSDictionary *gameDictionary = [NSDictionary dictionaryWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command", |
147 NSDictionary *gameDictionary = [NSDictionary dictionaryWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command", |
148 mapConfigViewController.templateFilterCommand,@"templatefilter_command", |
148 mapConfigViewController.templateFilterCommand,@"templatefilter_command", |
149 mapConfigViewController.mapGenCommand,@"mapgen_command", |
149 mapConfigViewController.mapGenCommand,@"mapgen_command", |
150 mapConfigViewController.mazeSizeCommand,@"mazesize_command", |
150 mapConfigViewController.mazeSizeCommand,@"mazesize_command", |
152 mapConfigViewController.staticMapCommand,@"staticmap_command", |
152 mapConfigViewController.staticMapCommand,@"staticmap_command", |
153 teamConfigViewController.listOfSelectedTeams,@"teams_list", |
153 teamConfigViewController.listOfSelectedTeams,@"teams_list", |
154 schemeWeaponConfigViewController.selectedScheme,@"scheme", |
154 schemeWeaponConfigViewController.selectedScheme,@"scheme", |
155 schemeWeaponConfigViewController.selectedWeapon,@"weapon", |
155 schemeWeaponConfigViewController.selectedWeapon,@"weapon", |
156 nil]; |
156 nil]; |
157 |
157 |
158 // finally launch game and remove this controller |
158 // finally launch game and remove this controller |
159 DLog(@"sending config %@", gameDictionary); |
159 DLog(@"sending config %@", gameDictionary); |
160 |
160 |
161 if ([[gameDictionary allKeys] count] == 9) { |
161 if ([[gameDictionary allKeys] count] == 9) { |
162 [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:gameDictionary]; |
162 [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:gameDictionary]; |
163 } else { |
163 } else { |
164 DLog(@"gameconfig data not complete!!\nmapConfigViewController = %@\nteamConfigViewController = %@\nschemeWeaponConfigViewController = %@\n", |
164 DLog(@"gameconfig data not complete!!\nmapConfigViewController = %@\nteamConfigViewController = %@\nschemeWeaponConfigViewController = %@\n", |
165 mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController); |
165 mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController); |
166 [self.parentViewController dismissModalViewControllerAnimated:YES]; |
166 [self.parentViewController dismissModalViewControllerAnimated:YES]; |
167 |
167 |
168 // present an alert to the user, with an image on the ipad (too big for the iphone) |
168 // present an alert to the user, with an image on the ipad (too big for the iphone) |
169 NSString *msg = NSLocalizedString(@"Something went wrong with your configuration. Please try again.",@""); |
169 NSString *msg = NSLocalizedString(@"Something went wrong with your configuration. Please try again.",@""); |
170 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
170 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
171 msg = [msg stringByAppendingString:@"\n\n\n\n\n\n\n\n"]; // this makes space for the image |
171 msg = [msg stringByAppendingString:@"\n\n\n\n\n\n\n\n"]; // this makes space for the image |
172 |
172 |
173 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops" |
173 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops" |
174 message:msg |
174 message:msg |
175 delegate:nil |
175 delegate:nil |
176 cancelButtonTitle:@"Ok" |
176 cancelButtonTitle:@"Ok" |
177 otherButtonTitles:nil]; |
177 otherButtonTitles:nil]; |
178 |
178 |
179 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
179 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
180 UIImageView *deniedImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"denied.png"]]; |
180 UIImageView *deniedImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"denied.png"]]; |
181 deniedImg.frame = CGRectMake(25, 80, 240, 160); |
181 deniedImg.frame = CGRectMake(25, 80, 240, 160); |
182 [alert addSubview:deniedImg]; |
182 [alert addSubview:deniedImg]; |
183 [deniedImg release]; |
183 [deniedImg release]; |
188 |
188 |
189 } |
189 } |
190 |
190 |
191 -(void) viewDidLoad { |
191 -(void) viewDidLoad { |
192 self.view.backgroundColor = [UIColor blackColor]; |
192 self.view.backgroundColor = [UIColor blackColor]; |
193 |
193 |
194 CGRect screen = [[UIScreen mainScreen] bounds]; |
194 CGRect screen = [[UIScreen mainScreen] bounds]; |
195 self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
195 self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
196 |
196 |
197 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
197 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
198 if (mapConfigViewController == nil) |
198 if (mapConfigViewController == nil) |
218 // this must be loaded & added to auto set default scheme and ammo |
218 // this must be loaded & added to auto set default scheme and ammo |
219 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
219 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
220 [self.view addSubview:schemeWeaponConfigViewController.view]; |
220 [self.view addSubview:schemeWeaponConfigViewController.view]; |
221 } |
221 } |
222 activeController = mapConfigViewController; |
222 activeController = mapConfigViewController; |
223 |
223 |
224 [self.view addSubview:mapConfigViewController.view]; |
224 [self.view addSubview:mapConfigViewController.view]; |
225 |
225 |
226 [super viewDidLoad]; |
226 [super viewDidLoad]; |
227 } |
227 } |
228 |
228 |
229 -(void) viewWillAppear:(BOOL)animated { |
229 -(void) viewWillAppear:(BOOL)animated { |
230 [mapConfigViewController viewWillAppear:animated]; |
230 [mapConfigViewController viewWillAppear:animated]; |
231 [teamConfigViewController viewWillAppear:animated]; |
231 [teamConfigViewController viewWillAppear:animated]; |
232 [schemeWeaponConfigViewController viewWillAppear:animated]; |
232 [schemeWeaponConfigViewController viewWillAppear:animated]; |
233 // ADD other controllers here |
233 // ADD other controllers here |
234 |
234 |
235 [super viewWillAppear:animated]; |
235 [super viewWillAppear:animated]; |
236 } |
236 } |
237 |
237 |
238 -(void) viewDidAppear:(BOOL)animated { |
238 -(void) viewDidAppear:(BOOL)animated { |
239 [mapConfigViewController viewDidAppear:animated]; |
239 [mapConfigViewController viewDidAppear:animated]; |
241 [schemeWeaponConfigViewController viewDidAppear:animated]; |
241 [schemeWeaponConfigViewController viewDidAppear:animated]; |
242 [super viewDidAppear:animated]; |
242 [super viewDidAppear:animated]; |
243 } |
243 } |
244 |
244 |
245 -(void) didReceiveMemoryWarning { |
245 -(void) didReceiveMemoryWarning { |
246 if (activeController.view.superview == nil) |
246 if (activeController.view.superview == nil) |
247 activeController = nil; |
247 activeController = nil; |
248 // Releases the view if it doesn't have a superview. |
248 // Releases the view if it doesn't have a superview. |
249 [super didReceiveMemoryWarning]; |
249 [super didReceiveMemoryWarning]; |
250 // Release any cached data, images, etc that aren't in use. |
250 // Release any cached data, images, etc that aren't in use. |
251 if (mapConfigViewController.view.superview == nil) |
251 if (mapConfigViewController.view.superview == nil) |
252 mapConfigViewController = nil; |
252 mapConfigViewController = nil; |
253 if (teamConfigViewController.view.superview == nil) |
253 if (teamConfigViewController.view.superview == nil) |
254 teamConfigViewController = nil; |
254 teamConfigViewController = nil; |
255 if (schemeWeaponConfigViewController.view.superview == nil) |
255 if (schemeWeaponConfigViewController.view.superview == nil) |
256 schemeWeaponConfigViewController = nil; |
256 schemeWeaponConfigViewController = nil; |