author | koda |
Sun, 20 Jun 2010 23:05:11 +0200 | |
changeset 3525 | 1d7b056ff866 |
parent 3523 | 6592fbb969da |
child 3546 | ccf4854df294 |
permissions | -rw-r--r-- |
3356 | 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" |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
12 |
#import "MapConfigViewController.h" |
3361 | 13 |
#import "TeamConfigViewController.h" |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
14 |
#import "SchemeWeaponConfigViewController.h" |
3356 | 15 |
|
16 |
@implementation GameConfigViewController |
|
17 |
||
18 |
||
19 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
20 |
return rotationManager(interfaceOrientation); |
|
21 |
} |
|
22 |
||
23 |
-(IBAction) buttonPressed:(id) sender { |
|
3361 | 24 |
// works even if it's not actually a button |
3356 | 25 |
UIButton *theButton = (UIButton *)sender; |
26 |
switch (theButton.tag) { |
|
27 |
case 0: |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
28 |
[[self parentViewController] dismissModalViewControllerAnimated:YES]; |
3356 | 29 |
break; |
30 |
case 1: |
|
3523 | 31 |
theButton.enabled = NO; |
32 |
[self performSelector:@selector(startGame:) |
|
33 |
withObject:theButton |
|
3364 | 34 |
afterDelay:0.25]; |
3356 | 35 |
break; |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
36 |
default: |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
37 |
break; |
3356 | 38 |
} |
39 |
} |
|
40 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
41 |
-(IBAction) segmentPressed:(id) sender { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
42 |
UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
43 |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
44 |
switch (theSegment.selectedSegmentIndex) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
45 |
case 0: |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
46 |
// this init here is just aestetic as this controller was already set up in viewDidLoad |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
47 |
if (mapConfigViewController == nil) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
48 |
mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
49 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
50 |
activeController = mapConfigViewController; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
51 |
break; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
52 |
case 1: |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
53 |
if (teamConfigViewController == nil) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
54 |
teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
55 |
// this message is compulsory otherwise the table won't be loaded at all |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
56 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
57 |
activeController = teamConfigViewController; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
58 |
break; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
59 |
case 2: |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
60 |
if (schemeWeaponConfigViewController == nil) { |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
61 |
schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
62 |
} |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
63 |
activeController = schemeWeaponConfigViewController; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
64 |
break; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
65 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
66 |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
67 |
// this message is compulsory otherwise the table won't be loaded at all |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
68 |
[activeController viewWillAppear:NO]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
69 |
[self.view addSubview:activeController.view]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
70 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
71 |
|
3523 | 72 |
-(void) startGame:(UIButton *)button { |
73 |
button.enabled = YES; |
|
74 |
||
3490 | 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 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
87 |
// play only if there is more than one team |
3364 | 88 |
if ([teamConfigViewController.listOfSelectedTeams count] < 2) { |
89 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"") |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
90 |
message:NSLocalizedString(@"You need to select at least two teams to play a game",@"") |
3364 | 91 |
delegate:nil |
92 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
93 |
otherButtonTitles:nil]; |
|
94 |
[alert show]; |
|
95 |
[alert release]; |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
96 |
return; |
3364 | 97 |
} |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
98 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
99 |
// play if there's room for enough hogs in the selected map |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
100 |
int hogs = 0; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
101 |
for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams) |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
102 |
hogs += [[teamData objectForKey:@"number"] intValue]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
103 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
104 |
if (hogs > mapConfigViewController.maxHogs) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
105 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too many hogs",@"") |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
106 |
message:NSLocalizedString(@"The map you selected is too small for that many hogs",@"") |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
107 |
delegate:nil |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
108 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
109 |
otherButtonTitles:nil]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
110 |
[alert show]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
111 |
[alert release]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
112 |
return; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
113 |
} |
3490 | 114 |
|
115 |
// create the configuration file that is going to be sent to engine |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
116 |
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command", |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
117 |
mapConfigViewController.templateFilterCommand,@"templatefilter_command", |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
118 |
mapConfigViewController.mapGenCommand,@"mapgen_command", |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
119 |
mapConfigViewController.mazeSizeCommand,@"mazesize_command", |
3373 | 120 |
mapConfigViewController.themeCommand,@"theme_command", |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
121 |
teamConfigViewController.listOfSelectedTeams,@"teams_list", |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
122 |
schemeWeaponConfigViewController.selectedScheme,@"scheme", |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
123 |
schemeWeaponConfigViewController.selectedWeapon,@"weapon", |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
124 |
nil]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
125 |
[dict writeToFile:GAMECONFIG_FILE() atomically:YES]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
126 |
[dict release]; |
3490 | 127 |
|
128 |
// finally launch game and remove this controller |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
129 |
[[self parentViewController] dismissModalViewControllerAnimated:YES]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
130 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
3356 | 131 |
} |
132 |
||
3361 | 133 |
-(void) viewDidLoad { |
3525 | 134 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
135 |
self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
|
136 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
137 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
138 |
if (mapConfigViewController == nil) |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
139 |
mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil]; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
140 |
if (teamConfigViewController == nil) |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
141 |
teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStylePlain]; |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
142 |
teamConfigViewController.view.frame = CGRectMake(0, 224, 300, 500); |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
143 |
teamConfigViewController.view.backgroundColor = [UIColor clearColor]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
144 |
[mapConfigViewController.view addSubview:teamConfigViewController.view]; |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
145 |
if (schemeWeaponConfigViewController == nil) |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
146 |
schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
147 |
schemeWeaponConfigViewController.view.frame = CGRectMake(362, 224, 300, 500); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
148 |
schemeWeaponConfigViewController.view.backgroundColor = [UIColor clearColor]; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
149 |
[mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view]; |
3525 | 150 |
for (UIView *oneView in self.view.subviews) { |
151 |
if ([oneView isMemberOfClass:[UIToolbar class]]) { |
|
152 |
[[oneView viewWithTag:12345] setHidden:YES]; |
|
153 |
break; |
|
154 |
} |
|
155 |
} |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
156 |
} else |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
157 |
mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
158 |
activeController = mapConfigViewController; |
3361 | 159 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
160 |
[self.view addSubview:mapConfigViewController.view]; |
3361 | 161 |
|
3356 | 162 |
[super viewDidLoad]; |
163 |
} |
|
164 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
165 |
-(void) viewWillAppear:(BOOL)animated { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
166 |
[mapConfigViewController viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
167 |
[teamConfigViewController viewWillAppear:animated]; |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
168 |
[schemeWeaponConfigViewController viewWillAppear:animated]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
169 |
// ADD other controllers here |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
170 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
171 |
[super viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
172 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
173 |
|
3373 | 174 |
-(void) viewDidAppear:(BOOL)animated { |
175 |
[mapConfigViewController viewDidAppear:animated]; |
|
176 |
[teamConfigViewController viewDidAppear:animated]; |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
177 |
[schemeWeaponConfigViewController viewDidAppear:animated]; |
3373 | 178 |
[super viewDidAppear:animated]; |
179 |
} |
|
180 |
||
3356 | 181 |
-(void) didReceiveMemoryWarning { |
182 |
// Releases the view if it doesn't have a superview. |
|
183 |
[super didReceiveMemoryWarning]; |
|
184 |
// Release any cached data, images, etc that aren't in use. |
|
3490 | 185 |
if (mapConfigViewController.view.superview == nil) |
3487 | 186 |
mapConfigViewController = nil; |
187 |
if (teamConfigViewController.view.superview == nil) |
|
188 |
teamConfigViewController = nil; |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
189 |
if (schemeWeaponConfigViewController.view.superview == nil) |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
190 |
schemeWeaponConfigViewController = nil; |
3487 | 191 |
activeController = nil; |
192 |
MSG_MEMCLEAN(); |
|
3356 | 193 |
} |
194 |
||
195 |
-(void) viewDidUnload { |
|
3361 | 196 |
activeController = nil; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
197 |
mapConfigViewController = nil; |
3361 | 198 |
teamConfigViewController = nil; |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
199 |
schemeWeaponConfigViewController = nil; |
3356 | 200 |
[super viewDidUnload]; |
3490 | 201 |
MSG_DIDUNLOAD(); |
3356 | 202 |
} |
203 |
||
204 |
-(void) dealloc { |
|
3361 | 205 |
[activeController release]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
206 |
[mapConfigViewController release]; |
3361 | 207 |
[teamConfigViewController release]; |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
208 |
[schemeWeaponConfigViewController release]; |
3356 | 209 |
[super dealloc]; |
210 |
} |
|
211 |
||
212 |
@end |