author | koda |
Fri, 13 Aug 2010 02:13:18 +0200 | |
changeset 3737 | 2ba6ac8a114b |
parent 3705 | e1959819a542 |
child 3739 | 97cf933e5bd2 |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// GameConfigViewController.m |
|
3 |
// HedgewarsMobile |
|
4 |
// |
|
5 |
// Created by Vittorio on 18/04/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "GameConfigViewController.h" |
|
10 |
#import "SDL_uikitappdelegate.h" |
|
11 |
#import "CommodityFunctions.h" |
|
12 |
#import "TeamConfigViewController.h" |
|
13 |
#import "SchemeWeaponConfigViewController.h" |
|
14 |
||
3705 | 15 |
|
3547 | 16 |
@implementation GameConfigViewController |
17 |
||
18 |
||
19 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
3616
85d69ddb41b6
tackling the iphoneos todo (another trial for the beginning sporadic bug, remove curl animation, don't need to go to detail page)
koda
parents:
3548
diff
changeset
|
20 |
return rotationManager(interfaceOrientation); |
3547 | 21 |
} |
22 |
||
23 |
-(IBAction) buttonPressed:(id) sender { |
|
24 |
// works even if it's not actually a button |
|
25 |
UIButton *theButton = (UIButton *)sender; |
|
26 |
switch (theButton.tag) { |
|
27 |
case 0: |
|
3625 | 28 |
if ([mapConfigViewController busy]) { |
29 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"") |
|
30 |
message:NSLocalizedString(@"Before returning the preview needs to be generated",@"") |
|
31 |
delegate:nil |
|
32 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
33 |
otherButtonTitles:nil]; |
|
34 |
[alert show]; |
|
35 |
[alert release]; |
|
36 |
} else { |
|
37 |
[[self parentViewController] dismissModalViewControllerAnimated:YES]; |
|
3697 | 38 |
|
3625 | 39 |
} |
3547 | 40 |
break; |
41 |
case 1: |
|
42 |
theButton.enabled = NO; |
|
3626 | 43 |
[self startGame:theButton]; |
44 |
// [self performSelector:@selector(startGame:) |
|
45 |
// withObject:theButton |
|
46 |
// afterDelay:0.25]; |
|
3547 | 47 |
break; |
48 |
default: |
|
49 |
break; |
|
50 |
} |
|
51 |
} |
|
52 |
||
53 |
-(IBAction) segmentPressed:(id) sender { |
|
54 |
UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
|
55 |
||
56 |
switch (theSegment.selectedSegmentIndex) { |
|
57 |
case 0: |
|
58 |
// this init here is just aestetic as this controller was already set up in viewDidLoad |
|
59 |
if (mapConfigViewController == nil) { |
|
60 |
mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
|
61 |
} |
|
62 |
activeController = mapConfigViewController; |
|
63 |
break; |
|
64 |
case 1: |
|
65 |
if (teamConfigViewController == nil) { |
|
66 |
teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
67 |
// this message is compulsory otherwise the table won't be loaded at all |
|
68 |
} |
|
69 |
activeController = teamConfigViewController; |
|
70 |
break; |
|
71 |
case 2: |
|
72 |
if (schemeWeaponConfigViewController == nil) { |
|
73 |
schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
74 |
} |
|
75 |
activeController = schemeWeaponConfigViewController; |
|
76 |
break; |
|
77 |
} |
|
3697 | 78 |
|
3547 | 79 |
// this message is compulsory otherwise the table won't be loaded at all |
3697 | 80 |
[activeController viewWillAppear:NO]; |
3547 | 81 |
[self.view addSubview:activeController.view]; |
82 |
} |
|
83 |
||
84 |
-(void) startGame:(UIButton *)button { |
|
85 |
button.enabled = YES; |
|
86 |
||
87 |
// don't start playing if the preview is in progress |
|
88 |
if ([mapConfigViewController busy]) { |
|
89 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"") |
|
90 |
message:NSLocalizedString(@"Before playing the preview needs to be generated",@"") |
|
91 |
delegate:nil |
|
92 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
93 |
otherButtonTitles:nil]; |
|
94 |
[alert show]; |
|
95 |
[alert release]; |
|
96 |
return; |
|
97 |
} |
|
3697 | 98 |
|
3547 | 99 |
// play only if there is more than one team |
100 |
if ([teamConfigViewController.listOfSelectedTeams count] < 2) { |
|
101 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"") |
|
3616
85d69ddb41b6
tackling the iphoneos todo (another trial for the beginning sporadic bug, remove curl animation, don't need to go to detail page)
koda
parents:
3548
diff
changeset
|
102 |
message:NSLocalizedString(@"Select at least two teams to play a game",@"") |
3547 | 103 |
delegate:nil |
104 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
105 |
otherButtonTitles:nil]; |
|
106 |
[alert show]; |
|
107 |
[alert release]; |
|
108 |
return; |
|
109 |
} |
|
3697 | 110 |
|
3547 | 111 |
// play if there's room for enough hogs in the selected map |
112 |
int hogs = 0; |
|
113 |
for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams) |
|
114 |
hogs += [[teamData objectForKey:@"number"] intValue]; |
|
115 |
||
116 |
if (hogs > mapConfigViewController.maxHogs) { |
|
117 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too many hogs",@"") |
|
3616
85d69ddb41b6
tackling the iphoneos todo (another trial for the beginning sporadic bug, remove curl animation, don't need to go to detail page)
koda
parents:
3548
diff
changeset
|
118 |
message:NSLocalizedString(@"The map is too small for that many hogs",@"") |
3547 | 119 |
delegate:nil |
120 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
121 |
otherButtonTitles:nil]; |
|
122 |
[alert show]; |
|
123 |
[alert release]; |
|
124 |
return; |
|
125 |
} |
|
3697 | 126 |
|
3548
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
127 |
if ([schemeWeaponConfigViewController.selectedScheme length] == 0 || [schemeWeaponConfigViewController.selectedWeapon length] == 0 ) { |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
128 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Missing detail",@"") |
3616
85d69ddb41b6
tackling the iphoneos todo (another trial for the beginning sporadic bug, remove curl animation, don't need to go to detail page)
koda
parents:
3548
diff
changeset
|
129 |
message:NSLocalizedString(@"Select one Scheme and one Weapon for this game",@"") |
3548
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
130 |
delegate:nil |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
131 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
132 |
otherButtonTitles:nil]; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
133 |
[alert show]; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
134 |
[alert release]; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
135 |
return; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
136 |
} |
3697 | 137 |
|
3632 | 138 |
// create the configuration file that is going to be sent to engine |
139 |
NSDictionary *gameDictionary = [NSDictionary dictionaryWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command", |
|
3547 | 140 |
mapConfigViewController.templateFilterCommand,@"templatefilter_command", |
141 |
mapConfigViewController.mapGenCommand,@"mapgen_command", |
|
142 |
mapConfigViewController.mazeSizeCommand,@"mazesize_command", |
|
143 |
mapConfigViewController.themeCommand,@"theme_command", |
|
3642 | 144 |
mapConfigViewController.staticMapCommand,@"staticmap_command", |
3547 | 145 |
teamConfigViewController.listOfSelectedTeams,@"teams_list", |
146 |
schemeWeaponConfigViewController.selectedScheme,@"scheme", |
|
147 |
schemeWeaponConfigViewController.selectedWeapon,@"weapon", |
|
148 |
nil]; |
|
3697 | 149 |
|
3547 | 150 |
// finally launch game and remove this controller |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3626
diff
changeset
|
151 |
DLog(@"sending config %@", gameDictionary); |
3697 | 152 |
|
3642 | 153 |
if ([[gameDictionary allKeys] count] == 9) { |
3630 | 154 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame:gameDictionary]; |
155 |
} else { |
|
3632 | 156 |
DLog(@"gameconfig data not complete!!\nmapConfigViewController = %@\nteamConfigViewController = %@\nschemeWeaponConfigViewController = %@\n", |
157 |
mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController); |
|
3635
38d3e31556d3
improvements to touch interface (tap to select weap, don't move camera for spourious taps, ask for confirmation when using click-weapons)
koda
parents:
3632
diff
changeset
|
158 |
[self.parentViewController dismissModalViewControllerAnimated:YES]; |
3697 | 159 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
160 |
// present an alert to the user, with an image on the ipad (too big for the iphone) |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
161 |
NSString *msg = NSLocalizedString(@"Something went wrong with your configuration. Please try again.",@""); |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
162 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
163 |
msg = [msg stringByAppendingString:@"\n\n\n\n\n\n\n\n"]; // this makes space for the image |
3697 | 164 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
165 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops" |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
166 |
message:msg |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
167 |
delegate:nil |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
168 |
cancelButtonTitle:@"Ok" |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
169 |
otherButtonTitles:nil]; |
3697 | 170 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
171 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
172 |
UIImageView *deniedImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"denied.png"]]; |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
173 |
deniedImg.frame = CGRectMake(25, 80, 240, 160); |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
174 |
[alert addSubview:deniedImg]; |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
175 |
[deniedImg release]; |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
176 |
} |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
177 |
[alert show]; |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3642
diff
changeset
|
178 |
[alert release]; |
3630 | 179 |
} |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3626
diff
changeset
|
180 |
|
3547 | 181 |
} |
182 |
||
183 |
-(void) viewDidLoad { |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3626
diff
changeset
|
184 |
self.view.backgroundColor = [UIColor blackColor]; |
3697 | 185 |
|
3547 | 186 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
187 |
self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
|
188 |
||
189 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
190 |
if (mapConfigViewController == nil) |
|
191 |
mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil]; |
|
3705 | 192 |
mapConfigViewController.delegate = self; |
3547 | 193 |
if (teamConfigViewController == nil) |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
194 |
teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3705
diff
changeset
|
195 |
teamConfigViewController.view.frame = CGRectMake(362, 200, 300, 480); |
3547 | 196 |
teamConfigViewController.view.backgroundColor = [UIColor clearColor]; |
197 |
[mapConfigViewController.view addSubview:teamConfigViewController.view]; |
|
198 |
if (schemeWeaponConfigViewController == nil) |
|
199 |
schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3705
diff
changeset
|
200 |
schemeWeaponConfigViewController.view.frame = CGRectMake(10, 70, 300, 550); |
3547 | 201 |
[mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3705
diff
changeset
|
202 |
mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
3616
85d69ddb41b6
tackling the iphoneos todo (another trial for the beginning sporadic bug, remove curl animation, don't need to go to detail page)
koda
parents:
3548
diff
changeset
|
203 |
} else { |
85d69ddb41b6
tackling the iphoneos todo (another trial for the beginning sporadic bug, remove curl animation, don't need to go to detail page)
koda
parents:
3548
diff
changeset
|
204 |
// this is the visible controller |
3547 | 205 |
mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3626
diff
changeset
|
206 |
// this must be loaded & added to auto set default scheme and ammo |
3616
85d69ddb41b6
tackling the iphoneos todo (another trial for the beginning sporadic bug, remove curl animation, don't need to go to detail page)
koda
parents:
3548
diff
changeset
|
207 |
schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3626
diff
changeset
|
208 |
[self.view addSubview:schemeWeaponConfigViewController.view]; |
3616
85d69ddb41b6
tackling the iphoneos todo (another trial for the beginning sporadic bug, remove curl animation, don't need to go to detail page)
koda
parents:
3548
diff
changeset
|
209 |
} |
3547 | 210 |
activeController = mapConfigViewController; |
3697 | 211 |
|
3547 | 212 |
[self.view addSubview:mapConfigViewController.view]; |
3697 | 213 |
|
3547 | 214 |
[super viewDidLoad]; |
215 |
} |
|
216 |
||
217 |
-(void) viewWillAppear:(BOOL)animated { |
|
218 |
[mapConfigViewController viewWillAppear:animated]; |
|
219 |
[teamConfigViewController viewWillAppear:animated]; |
|
220 |
[schemeWeaponConfigViewController viewWillAppear:animated]; |
|
221 |
// ADD other controllers here |
|
3697 | 222 |
|
3547 | 223 |
[super viewWillAppear:animated]; |
224 |
} |
|
225 |
||
226 |
-(void) viewDidAppear:(BOOL)animated { |
|
227 |
[mapConfigViewController viewDidAppear:animated]; |
|
228 |
[teamConfigViewController viewDidAppear:animated]; |
|
229 |
[schemeWeaponConfigViewController viewDidAppear:animated]; |
|
230 |
[super viewDidAppear:animated]; |
|
231 |
} |
|
232 |
||
233 |
-(void) didReceiveMemoryWarning { |
|
3697 | 234 |
if (activeController.view.superview == nil) |
3661 | 235 |
activeController = nil; |
3547 | 236 |
// Releases the view if it doesn't have a superview. |
237 |
[super didReceiveMemoryWarning]; |
|
238 |
// Release any cached data, images, etc that aren't in use. |
|
3697 | 239 |
if (mapConfigViewController.view.superview == nil) |
3547 | 240 |
mapConfigViewController = nil; |
241 |
if (teamConfigViewController.view.superview == nil) |
|
242 |
teamConfigViewController = nil; |
|
243 |
if (schemeWeaponConfigViewController.view.superview == nil) |
|
244 |
schemeWeaponConfigViewController = nil; |
|
245 |
MSG_MEMCLEAN(); |
|
246 |
} |
|
247 |
||
248 |
-(void) viewDidUnload { |
|
249 |
activeController = nil; |
|
250 |
mapConfigViewController = nil; |
|
251 |
teamConfigViewController = nil; |
|
252 |
schemeWeaponConfigViewController = nil; |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3661
diff
changeset
|
253 |
MSG_DIDUNLOAD(); |
3547 | 254 |
[super viewDidUnload]; |
255 |
} |
|
256 |
||
257 |
-(void) dealloc { |
|
258 |
[mapConfigViewController release]; |
|
259 |
[teamConfigViewController release]; |
|
260 |
[schemeWeaponConfigViewController release]; |
|
261 |
[super dealloc]; |
|
262 |
} |
|
263 |
||
264 |
@end |