author | koda |
Thu, 29 Apr 2010 17:19:06 +0000 | |
changeset 3374 | 0d522416d97f |
parent 3373 | c1ff724a5c34 |
child 3487 | b1d00f1950c8 |
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" |
3356 | 14 |
|
15 |
@implementation GameConfigViewController |
|
16 |
||
17 |
||
18 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
19 |
return rotationManager(interfaceOrientation); |
|
20 |
} |
|
21 |
||
22 |
-(IBAction) buttonPressed:(id) sender { |
|
3361 | 23 |
// works even if it's not actually a button |
3356 | 24 |
UIButton *theButton = (UIButton *)sender; |
25 |
switch (theButton.tag) { |
|
26 |
case 0: |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
27 |
[[self parentViewController] dismissModalViewControllerAnimated:YES]; |
3356 | 28 |
break; |
29 |
case 1: |
|
3364 | 30 |
[self performSelector:@selector(startGame) |
3356 | 31 |
withObject:nil |
3364 | 32 |
afterDelay:0.25]; |
3356 | 33 |
break; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
34 |
|
3356 | 35 |
} |
36 |
} |
|
37 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
38 |
-(IBAction) segmentPressed:(id) sender { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
39 |
UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
40 |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
41 |
switch (theSegment.selectedSegmentIndex) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
42 |
case 0: |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
43 |
// 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
|
44 |
if (mapConfigViewController == nil) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
45 |
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
|
46 |
[mapConfigViewController viewWillAppear:NO]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
47 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
48 |
activeController = mapConfigViewController; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
49 |
break; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
50 |
case 1: |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
51 |
if (teamConfigViewController == nil) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
52 |
teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
53 |
// this message is compulsory otherwise the team table won't be loaded at all |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
54 |
[teamConfigViewController viewWillAppear:NO]; |
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: |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
59 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
60 |
break; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
61 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
62 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
63 |
[self.view addSubview:activeController.view]; |
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 |
|
3364 | 66 |
-(void) startGame { |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
67 |
// play only if there is more than one team |
3364 | 68 |
if ([teamConfigViewController.listOfSelectedTeams count] < 2) { |
69 |
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
|
70 |
message:NSLocalizedString(@"You need to select at least two teams to play a game",@"") |
3364 | 71 |
delegate:nil |
72 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
73 |
otherButtonTitles:nil]; |
|
74 |
[alert show]; |
|
75 |
[alert release]; |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
76 |
return; |
3364 | 77 |
} |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
78 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
79 |
// 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
|
80 |
int hogs = 0; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
81 |
for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams) |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
82 |
hogs += [[teamData objectForKey:@"number"] intValue]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
83 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
84 |
if (hogs > mapConfigViewController.maxHogs) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
85 |
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
|
86 |
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
|
87 |
delegate:nil |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
88 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
89 |
otherButtonTitles:nil]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
90 |
[alert show]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
91 |
[alert release]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
92 |
return; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
93 |
} |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
94 |
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
|
95 |
mapConfigViewController.templateFilterCommand,@"templatefilter_command", |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
96 |
mapConfigViewController.mapGenCommand,@"mapgen_command", |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
97 |
mapConfigViewController.mazeSizeCommand,@"mazesize_command", |
3373 | 98 |
mapConfigViewController.themeCommand,@"theme_command", |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
99 |
teamConfigViewController.listOfSelectedTeams,@"teams_list",nil]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
100 |
[dict writeToFile:GAMECONFIG_FILE() atomically:YES]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
101 |
[dict release]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
102 |
[[self parentViewController] dismissModalViewControllerAnimated:YES]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
103 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
3356 | 104 |
} |
105 |
||
3361 | 106 |
-(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
|
107 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
108 |
mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
109 |
teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStylePlain]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
110 |
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
|
111 |
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
|
112 |
[mapConfigViewController.view addSubview:teamConfigViewController.view]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
113 |
} else |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
114 |
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
|
115 |
activeController = mapConfigViewController; |
3361 | 116 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
117 |
[self.view addSubview:mapConfigViewController.view]; |
3361 | 118 |
|
3356 | 119 |
[super viewDidLoad]; |
120 |
} |
|
121 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
122 |
-(void) viewWillAppear:(BOOL)animated { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
123 |
[mapConfigViewController viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
124 |
[teamConfigViewController viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
125 |
// ADD other controllers here |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
126 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
127 |
[super viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
128 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
129 |
|
3373 | 130 |
-(void) viewDidAppear:(BOOL)animated { |
131 |
[mapConfigViewController viewDidAppear:animated]; |
|
132 |
[teamConfigViewController viewDidAppear:animated]; |
|
133 |
[super viewDidAppear:animated]; |
|
134 |
} |
|
135 |
||
3356 | 136 |
-(void) didReceiveMemoryWarning { |
137 |
// Releases the view if it doesn't have a superview. |
|
138 |
[super didReceiveMemoryWarning]; |
|
139 |
// Release any cached data, images, etc that aren't in use. |
|
140 |
} |
|
141 |
||
142 |
||
143 |
-(void) viewDidUnload { |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
144 |
NSLog(@"unloading"); |
3361 | 145 |
activeController = nil; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
146 |
mapConfigViewController = nil; |
3361 | 147 |
teamConfigViewController = nil; |
3356 | 148 |
[super viewDidUnload]; |
149 |
} |
|
150 |
||
151 |
||
152 |
-(void) dealloc { |
|
3361 | 153 |
[activeController release]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
154 |
[mapConfigViewController release]; |
3361 | 155 |
[teamConfigViewController release]; |
3356 | 156 |
[super dealloc]; |
157 |
} |
|
158 |
||
159 |
@end |