author | koda |
Sat, 03 Jul 2010 05:51:24 +0200 | |
changeset 3617 | 1df21e06b8ba |
parent 3616 | 85d69ddb41b6 |
child 3619 | 1155d8970646 |
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 "MapConfigViewController.h" |
|
13 |
#import "TeamConfigViewController.h" |
|
14 |
#import "SchemeWeaponConfigViewController.h" |
|
15 |
||
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: |
|
28 |
[[self parentViewController] dismissModalViewControllerAnimated:YES]; |
|
29 |
break; |
|
30 |
case 1: |
|
31 |
theButton.enabled = NO; |
|
32 |
[self performSelector:@selector(startGame:) |
|
33 |
withObject:theButton |
|
34 |
afterDelay:0.25]; |
|
35 |
break; |
|
36 |
default: |
|
37 |
break; |
|
38 |
} |
|
39 |
} |
|
40 |
||
41 |
-(IBAction) segmentPressed:(id) sender { |
|
42 |
UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
|
43 |
||
44 |
switch (theSegment.selectedSegmentIndex) { |
|
45 |
case 0: |
|
46 |
// this init here is just aestetic as this controller was already set up in viewDidLoad |
|
47 |
if (mapConfigViewController == nil) { |
|
48 |
mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
|
49 |
} |
|
50 |
activeController = mapConfigViewController; |
|
51 |
break; |
|
52 |
case 1: |
|
53 |
if (teamConfigViewController == nil) { |
|
54 |
teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
55 |
// this message is compulsory otherwise the table won't be loaded at all |
|
56 |
} |
|
57 |
activeController = teamConfigViewController; |
|
58 |
break; |
|
59 |
case 2: |
|
60 |
if (schemeWeaponConfigViewController == nil) { |
|
61 |
schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
62 |
} |
|
63 |
activeController = schemeWeaponConfigViewController; |
|
64 |
break; |
|
65 |
} |
|
66 |
||
67 |
// this message is compulsory otherwise the table won't be loaded at all |
|
68 |
[activeController viewWillAppear:NO]; |
|
69 |
[self.view addSubview:activeController.view]; |
|
70 |
} |
|
71 |
||
72 |
-(void) startGame:(UIButton *)button { |
|
73 |
button.enabled = YES; |
|
74 |
||
75 |
// don't start playing if the preview is in progress |
|
76 |
if ([mapConfigViewController busy]) { |
|
77 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"") |
|
78 |
message:NSLocalizedString(@"Before playing the preview needs to be generated",@"") |
|
79 |
delegate:nil |
|
80 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
81 |
otherButtonTitles:nil]; |
|
82 |
[alert show]; |
|
83 |
[alert release]; |
|
84 |
return; |
|
85 |
} |
|
86 |
||
87 |
// play only if there is more than one team |
|
88 |
if ([teamConfigViewController.listOfSelectedTeams count] < 2) { |
|
89 |
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
|
90 |
message:NSLocalizedString(@"Select at least two teams to play a game",@"") |
3547 | 91 |
delegate:nil |
92 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
93 |
otherButtonTitles:nil]; |
|
94 |
[alert show]; |
|
95 |
[alert release]; |
|
96 |
return; |
|
97 |
} |
|
98 |
||
99 |
// play if there's room for enough hogs in the selected map |
|
100 |
int hogs = 0; |
|
101 |
for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams) |
|
102 |
hogs += [[teamData objectForKey:@"number"] intValue]; |
|
103 |
||
104 |
if (hogs > mapConfigViewController.maxHogs) { |
|
105 |
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
|
106 |
message:NSLocalizedString(@"The map is too small for that many hogs",@"") |
3547 | 107 |
delegate:nil |
108 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
109 |
otherButtonTitles:nil]; |
|
110 |
[alert show]; |
|
111 |
[alert release]; |
|
112 |
return; |
|
113 |
} |
|
114 |
||
3548
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
115 |
if ([schemeWeaponConfigViewController.selectedScheme length] == 0 || [schemeWeaponConfigViewController.selectedWeapon length] == 0 ) { |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
116 |
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
|
117 |
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
|
118 |
delegate:nil |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
119 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
120 |
otherButtonTitles:nil]; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
121 |
[alert show]; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
122 |
[alert release]; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
123 |
return; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
124 |
} |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
125 |
|
3547 | 126 |
// create the configuration file that is going to be sent to engine |
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
|
127 |
NSDictionary *gameDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command", |
3547 | 128 |
mapConfigViewController.templateFilterCommand,@"templatefilter_command", |
129 |
mapConfigViewController.mapGenCommand,@"mapgen_command", |
|
130 |
mapConfigViewController.mazeSizeCommand,@"mazesize_command", |
|
131 |
mapConfigViewController.themeCommand,@"theme_command", |
|
132 |
teamConfigViewController.listOfSelectedTeams,@"teams_list", |
|
133 |
schemeWeaponConfigViewController.selectedScheme,@"scheme", |
|
134 |
schemeWeaponConfigViewController.selectedWeapon,@"weapon", |
|
135 |
nil]; |
|
136 |
||
137 |
// finally launch game and remove this controller |
|
138 |
[[self parentViewController] dismissModalViewControllerAnimated:YES]; |
|
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
|
139 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame:gameDictionary]; |
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
|
140 |
[gameDictionary release]; |
3547 | 141 |
} |
142 |
||
143 |
-(void) viewDidLoad { |
|
144 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
|
145 |
self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
|
146 |
||
147 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
148 |
if (mapConfigViewController == nil) |
|
149 |
mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil]; |
|
150 |
if (teamConfigViewController == nil) |
|
151 |
teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStylePlain]; |
|
152 |
teamConfigViewController.view.frame = CGRectMake(0, 224, 300, 500); |
|
153 |
teamConfigViewController.view.backgroundColor = [UIColor clearColor]; |
|
154 |
[mapConfigViewController.view addSubview:teamConfigViewController.view]; |
|
155 |
if (schemeWeaponConfigViewController == nil) |
|
156 |
schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
157 |
schemeWeaponConfigViewController.view.frame = CGRectMake(362, 224, 300, 500); |
|
158 |
schemeWeaponConfigViewController.view.backgroundColor = [UIColor clearColor]; |
|
159 |
[mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view]; |
|
160 |
for (UIView *oneView in self.view.subviews) { |
|
161 |
if ([oneView isMemberOfClass:[UIToolbar class]]) { |
|
162 |
[[oneView viewWithTag:12345] setHidden:YES]; |
|
163 |
break; |
|
164 |
} |
|
165 |
} |
|
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
|
166 |
} 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
|
167 |
// this is the visible controller |
3547 | 168 |
mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
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
|
169 |
// this must be loaded to auto set default scheme and ammo |
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
|
170 |
schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
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
|
171 |
} |
3547 | 172 |
activeController = mapConfigViewController; |
173 |
||
174 |
[self.view addSubview:mapConfigViewController.view]; |
|
175 |
||
176 |
[super viewDidLoad]; |
|
177 |
} |
|
178 |
||
179 |
-(void) viewWillAppear:(BOOL)animated { |
|
180 |
[mapConfigViewController viewWillAppear:animated]; |
|
181 |
[teamConfigViewController viewWillAppear:animated]; |
|
182 |
[schemeWeaponConfigViewController viewWillAppear:animated]; |
|
183 |
// ADD other controllers here |
|
184 |
||
185 |
[super viewWillAppear:animated]; |
|
186 |
} |
|
187 |
||
188 |
-(void) viewDidAppear:(BOOL)animated { |
|
189 |
[mapConfigViewController viewDidAppear:animated]; |
|
190 |
[teamConfigViewController viewDidAppear:animated]; |
|
191 |
[schemeWeaponConfigViewController viewDidAppear:animated]; |
|
192 |
[super viewDidAppear:animated]; |
|
193 |
} |
|
194 |
||
195 |
-(void) didReceiveMemoryWarning { |
|
196 |
// Releases the view if it doesn't have a superview. |
|
197 |
[super didReceiveMemoryWarning]; |
|
198 |
// Release any cached data, images, etc that aren't in use. |
|
199 |
if (mapConfigViewController.view.superview == nil) |
|
200 |
mapConfigViewController = nil; |
|
201 |
if (teamConfigViewController.view.superview == nil) |
|
202 |
teamConfigViewController = nil; |
|
203 |
if (schemeWeaponConfigViewController.view.superview == nil) |
|
204 |
schemeWeaponConfigViewController = nil; |
|
205 |
activeController = nil; |
|
206 |
MSG_MEMCLEAN(); |
|
207 |
} |
|
208 |
||
209 |
-(void) viewDidUnload { |
|
210 |
activeController = nil; |
|
211 |
mapConfigViewController = nil; |
|
212 |
teamConfigViewController = nil; |
|
213 |
schemeWeaponConfigViewController = nil; |
|
214 |
[super viewDidUnload]; |
|
215 |
MSG_DIDUNLOAD(); |
|
216 |
} |
|
217 |
||
218 |
-(void) dealloc { |
|
219 |
[activeController release]; |
|
220 |
[mapConfigViewController release]; |
|
221 |
[teamConfigViewController release]; |
|
222 |
[schemeWeaponConfigViewController release]; |
|
223 |
[super dealloc]; |
|
224 |
} |
|
225 |
||
226 |
@end |