author | koda |
Sun, 25 Apr 2010 13:33:49 +0000 | |
changeset 3366 | f0e5ff24fb72 |
parent 3365 | 37ac593e9027 |
child 3369 | c7289e42f0ee |
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 |
|
3361 | 16 |
@synthesize availableTeamsTableView, weaponsButton, schemesButton, mapButton, randomButton, startButton; |
3356 | 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; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
35 |
|
3356 | 36 |
} |
37 |
} |
|
38 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
39 |
-(IBAction) segmentPressed:(id) sender { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
40 |
UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
41 |
NSLog(@"%d", theSegment.selectedSegmentIndex); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
42 |
switch (theSegment.selectedSegmentIndex) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
43 |
case 0: |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
44 |
// 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
|
45 |
if (mapConfigViewController == nil) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
46 |
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
|
47 |
[mapConfigViewController viewWillAppear:NO]; |
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]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
54 |
// 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
|
55 |
[teamConfigViewController viewWillAppear:NO]; |
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: |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
60 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
61 |
break; |
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 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
64 |
[self.view addSubview:activeController.view]; |
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 |
|
3364 | 67 |
-(void) startGame { |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
68 |
// play only if there is more than one team |
3364 | 69 |
if ([teamConfigViewController.listOfSelectedTeams count] < 2) { |
70 |
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
|
71 |
message:NSLocalizedString(@"You need to select at least two teams to play a game",@"") |
3364 | 72 |
delegate:nil |
73 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
74 |
otherButtonTitles:nil]; |
|
75 |
[alert show]; |
|
76 |
[alert release]; |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
77 |
return; |
3364 | 78 |
} |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
79 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
80 |
// 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
|
81 |
int hogs = 0; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
82 |
for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams) |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
83 |
hogs += [[teamData objectForKey:@"number"] intValue]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
84 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
85 |
if (hogs > mapConfigViewController.maxHogs) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
delegate:nil |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
89 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
90 |
otherButtonTitles:nil]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
91 |
[alert show]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
92 |
[alert release]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
93 |
return; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
94 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
95 |
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command", |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
96 |
teamConfigViewController.listOfSelectedTeams,@"teams_list",nil]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
97 |
[dict writeToFile:GAMECONFIG_FILE() atomically:YES]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
98 |
[dict release]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
99 |
[[self parentViewController] dismissModalViewControllerAnimated:YES]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
100 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
3356 | 101 |
} |
102 |
||
3361 | 103 |
-(void) viewDidLoad { |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
104 |
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
|
105 |
activeController = mapConfigViewController; |
3361 | 106 |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
107 |
[self.view insertSubview:mapConfigViewController.view atIndex:0]; |
3361 | 108 |
|
3356 | 109 |
[super viewDidLoad]; |
110 |
} |
|
111 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
112 |
-(void) viewWillAppear:(BOOL)animated { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
113 |
[mapConfigViewController viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
114 |
[teamConfigViewController viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
115 |
// ADD other controllers here |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
116 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
117 |
[super viewWillAppear:animated]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
118 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
119 |
|
3356 | 120 |
-(void) didReceiveMemoryWarning { |
121 |
// Releases the view if it doesn't have a superview. |
|
122 |
[super didReceiveMemoryWarning]; |
|
123 |
// Release any cached data, images, etc that aren't in use. |
|
124 |
} |
|
125 |
||
126 |
||
127 |
-(void) viewDidUnload { |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
128 |
NSLog(@"unloading"); |
3361 | 129 |
activeController = nil; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
130 |
mapConfigViewController = nil; |
3361 | 131 |
teamConfigViewController = nil; |
3356 | 132 |
self.availableTeamsTableView = nil; |
133 |
self.weaponsButton = nil; |
|
134 |
self.schemesButton = nil; |
|
135 |
self.mapButton = nil; |
|
136 |
self.randomButton = nil; |
|
137 |
self.startButton = nil; |
|
138 |
[super viewDidUnload]; |
|
139 |
} |
|
140 |
||
141 |
||
142 |
-(void) dealloc { |
|
3361 | 143 |
[activeController release]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3364
diff
changeset
|
144 |
[mapConfigViewController release]; |
3361 | 145 |
[teamConfigViewController release]; |
3356 | 146 |
[availableTeamsTableView release]; |
147 |
[weaponsButton release]; |
|
148 |
[schemesButton release]; |
|
149 |
[mapButton release]; |
|
150 |
[randomButton release]; |
|
151 |
[startButton release]; |
|
152 |
[super dealloc]; |
|
153 |
} |
|
154 |
||
155 |
@end |