author | koda |
Sun, 20 Jun 2010 18:35:59 +0200 | |
changeset 3523 | 6592fbb969da |
parent 3514 | 59dbd31e9953 |
child 3525 | 1d7b056ff866 |
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 { |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
[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
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
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
|
146 |
[mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view]; |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
147 |
} else |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
148 |
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
|
149 |
activeController = mapConfigViewController; |
3361 | 150 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
151 |
[self.view addSubview:mapConfigViewController.view]; |
3361 | 152 |
|
3356 | 153 |
[super viewDidLoad]; |
154 |
} |
|
155 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
156 |
-(void) viewWillAppear:(BOOL)animated { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
157 |
[mapConfigViewController viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
158 |
[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
|
159 |
[schemeWeaponConfigViewController viewWillAppear:animated]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
160 |
// ADD other controllers here |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
161 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
162 |
[super viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
163 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
164 |
|
3373 | 165 |
-(void) viewDidAppear:(BOOL)animated { |
166 |
[mapConfigViewController viewDidAppear:animated]; |
|
167 |
[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
|
168 |
[schemeWeaponConfigViewController viewDidAppear:animated]; |
3373 | 169 |
[super viewDidAppear:animated]; |
170 |
} |
|
171 |
||
3356 | 172 |
-(void) didReceiveMemoryWarning { |
173 |
// Releases the view if it doesn't have a superview. |
|
174 |
[super didReceiveMemoryWarning]; |
|
175 |
// Release any cached data, images, etc that aren't in use. |
|
3490 | 176 |
if (mapConfigViewController.view.superview == nil) |
3487 | 177 |
mapConfigViewController = nil; |
178 |
if (teamConfigViewController.view.superview == nil) |
|
179 |
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
|
180 |
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
|
181 |
schemeWeaponConfigViewController = nil; |
3487 | 182 |
activeController = nil; |
183 |
MSG_MEMCLEAN(); |
|
3356 | 184 |
} |
185 |
||
186 |
-(void) viewDidUnload { |
|
3361 | 187 |
activeController = nil; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
188 |
mapConfigViewController = nil; |
3361 | 189 |
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
|
190 |
schemeWeaponConfigViewController = nil; |
3356 | 191 |
[super viewDidUnload]; |
3490 | 192 |
MSG_DIDUNLOAD(); |
3356 | 193 |
} |
194 |
||
195 |
-(void) dealloc { |
|
3361 | 196 |
[activeController release]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
197 |
[mapConfigViewController release]; |
3361 | 198 |
[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
|
199 |
[schemeWeaponConfigViewController release]; |
3356 | 200 |
[super dealloc]; |
201 |
} |
|
202 |
||
203 |
@end |