author | koda |
Sat, 19 Jun 2010 00:48:47 +0200 | |
changeset 3522 | 156c04c6a3d8 |
parent 3514 | 59dbd31e9953 |
child 3523 | 6592fbb969da |
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: |
|
3364 | 31 |
[self performSelector:@selector(startGame) |
3356 | 32 |
withObject:nil |
3364 | 33 |
afterDelay:0.25]; |
3356 | 34 |
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
|
35 |
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
|
36 |
break; |
3356 | 37 |
} |
38 |
} |
|
39 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
40 |
-(IBAction) segmentPressed:(id) sender { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
41 |
UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
42 |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
43 |
switch (theSegment.selectedSegmentIndex) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
44 |
case 0: |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
45 |
// 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
|
46 |
if (mapConfigViewController == nil) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
47 |
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
|
48 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
49 |
activeController = mapConfigViewController; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
50 |
break; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
51 |
case 1: |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
52 |
if (teamConfigViewController == nil) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
53 |
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
|
54 |
// 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
|
55 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
56 |
activeController = teamConfigViewController; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
57 |
break; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
} |
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 |
activeController = schemeWeaponConfigViewController; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
63 |
break; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
64 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
65 |
|
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
|
66 |
// 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
|
67 |
[activeController viewWillAppear:NO]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
68 |
[self.view addSubview:activeController.view]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
69 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
70 |
|
3364 | 71 |
-(void) startGame { |
3490 | 72 |
// don't start playing if the preview is in progress |
73 |
if ([mapConfigViewController busy]) { |
|
74 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"") |
|
75 |
message:NSLocalizedString(@"Before playing the preview needs to be generated",@"") |
|
76 |
delegate:nil |
|
77 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
78 |
otherButtonTitles:nil]; |
|
79 |
[alert show]; |
|
80 |
[alert release]; |
|
81 |
return; |
|
82 |
} |
|
83 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
84 |
// play only if there is more than one team |
3364 | 85 |
if ([teamConfigViewController.listOfSelectedTeams count] < 2) { |
86 |
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
|
87 |
message:NSLocalizedString(@"You need to select at least two teams to play a game",@"") |
3364 | 88 |
delegate:nil |
89 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
90 |
otherButtonTitles:nil]; |
|
91 |
[alert show]; |
|
92 |
[alert release]; |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
93 |
return; |
3364 | 94 |
} |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
95 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
96 |
// 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
|
97 |
int hogs = 0; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
98 |
for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams) |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
99 |
hogs += [[teamData objectForKey:@"number"] intValue]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
100 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
101 |
if (hogs > mapConfigViewController.maxHogs) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
102 |
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
|
103 |
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
|
104 |
delegate:nil |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
105 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
106 |
otherButtonTitles:nil]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
107 |
[alert show]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
108 |
[alert release]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
109 |
return; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
110 |
} |
3490 | 111 |
|
112 |
// 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
|
113 |
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
|
114 |
mapConfigViewController.templateFilterCommand,@"templatefilter_command", |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
115 |
mapConfigViewController.mapGenCommand,@"mapgen_command", |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
116 |
mapConfigViewController.mazeSizeCommand,@"mazesize_command", |
3373 | 117 |
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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
nil]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
122 |
[dict writeToFile:GAMECONFIG_FILE() atomically:YES]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
123 |
[dict release]; |
3490 | 124 |
|
125 |
// 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
|
126 |
[[self parentViewController] dismissModalViewControllerAnimated:YES]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
127 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
3356 | 128 |
} |
129 |
||
3361 | 130 |
-(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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
[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
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
[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
|
144 |
} else |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
145 |
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
|
146 |
activeController = mapConfigViewController; |
3361 | 147 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
148 |
[self.view addSubview:mapConfigViewController.view]; |
3361 | 149 |
|
3356 | 150 |
[super viewDidLoad]; |
151 |
} |
|
152 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
153 |
-(void) viewWillAppear:(BOOL)animated { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
154 |
[mapConfigViewController viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
155 |
[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
|
156 |
[schemeWeaponConfigViewController viewWillAppear:animated]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
157 |
// ADD other controllers here |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
158 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
159 |
[super viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
160 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
161 |
|
3373 | 162 |
-(void) viewDidAppear:(BOOL)animated { |
163 |
[mapConfigViewController viewDidAppear:animated]; |
|
164 |
[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
|
165 |
[schemeWeaponConfigViewController viewDidAppear:animated]; |
3373 | 166 |
[super viewDidAppear:animated]; |
167 |
} |
|
168 |
||
3356 | 169 |
-(void) didReceiveMemoryWarning { |
170 |
// Releases the view if it doesn't have a superview. |
|
171 |
[super didReceiveMemoryWarning]; |
|
172 |
// Release any cached data, images, etc that aren't in use. |
|
3490 | 173 |
if (mapConfigViewController.view.superview == nil) |
3487 | 174 |
mapConfigViewController = nil; |
175 |
if (teamConfigViewController.view.superview == nil) |
|
176 |
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
|
177 |
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
|
178 |
schemeWeaponConfigViewController = nil; |
3487 | 179 |
activeController = nil; |
180 |
MSG_MEMCLEAN(); |
|
3356 | 181 |
} |
182 |
||
183 |
-(void) viewDidUnload { |
|
3361 | 184 |
activeController = nil; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
185 |
mapConfigViewController = nil; |
3361 | 186 |
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
|
187 |
schemeWeaponConfigViewController = nil; |
3356 | 188 |
[super viewDidUnload]; |
3490 | 189 |
MSG_DIDUNLOAD(); |
3356 | 190 |
} |
191 |
||
192 |
-(void) dealloc { |
|
3361 | 193 |
[activeController release]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
194 |
[mapConfigViewController release]; |
3361 | 195 |
[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
|
196 |
[schemeWeaponConfigViewController release]; |
3356 | 197 |
[super dealloc]; |
198 |
} |
|
199 |
||
200 |
@end |