author | koda |
Sat, 04 Sep 2010 16:24:00 +0200 | |
changeset 3829 | 81db3c85784b |
parent 3783 | 8e9daf967406 |
child 3884 | d7479079a8a8 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 27/03/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "MasterViewController.h" |
|
23 |
#import "GeneralSettingsViewController.h" |
|
24 |
#import "TeamSettingsViewController.h" |
|
25 |
#import "WeaponSettingsViewController.h" |
|
26 |
#import "SchemeSettingsViewController.h" |
|
27 |
#import "CommodityFunctions.h" |
|
28 |
||
29 |
@implementation MasterViewController |
|
3701 | 30 |
@synthesize targetController, controllerNames, lastIndexPath; |
3547 | 31 |
|
32 |
||
33 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
34 |
return rotationManager(interfaceOrientation); |
|
35 |
} |
|
36 |
||
37 |
||
38 |
#pragma mark - |
|
39 |
#pragma mark View lifecycle |
|
40 |
-(void) viewDidLoad { |
|
41 |
[super viewDidLoad]; |
|
3697 | 42 |
|
3547 | 43 |
// the list of selectable controllers |
3701 | 44 |
NSArray *array = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
45 |
NSLocalizedString(@"Teams",@""), |
|
46 |
NSLocalizedString(@"Weapons",@""), |
|
47 |
NSLocalizedString(@"Schemes",@""), |
|
48 |
nil]; |
|
49 |
self.controllerNames = array; |
|
50 |
[array release]; |
|
51 |
||
52 |
// targetControllers tells whether we're on the right or left side of the splitview -- on iphone we only use the right side |
|
53 |
if (targetController == nil && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
54 |
if (nil == generalSettingsViewController) |
|
55 |
generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
56 |
generalSettingsViewController.navigationItem.hidesBackButton = YES; |
|
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
57 |
[generalSettingsViewController viewWillAppear:YES]; |
3701 | 58 |
[self.navigationController pushViewController:generalSettingsViewController animated:NO]; |
59 |
} else { |
|
60 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
|
61 |
target:self |
|
62 |
action:@selector(dismissSplitView)]; |
|
63 |
} |
|
3547 | 64 |
} |
65 |
||
66 |
#pragma mark - |
|
67 |
#pragma mark Table view data source |
|
68 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
69 |
return 1; |
|
70 |
} |
|
71 |
||
72 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
73 |
return [controllerNames count]; |
|
74 |
} |
|
75 |
||
76 |
// Customize the appearance of table view cells. |
|
77 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
78 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 79 |
|
3547 | 80 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
3783 | 81 |
if (cell == nil) |
3547 | 82 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
3783 | 83 |
|
84 |
NSString *iconStr = nil; |
|
85 |
switch ([indexPath row]) { |
|
86 |
case 0: |
|
87 |
iconStr = [NSString stringWithFormat:@"%@/TargetBee.png",GRAPHICS_DIRECTORY()]; |
|
88 |
break; |
|
89 |
case 1: |
|
90 |
iconStr = [NSString stringWithFormat:@"%@/Egg.png",GRAPHICS_DIRECTORY()]; |
|
91 |
break; |
|
92 |
case 2: |
|
93 |
iconStr = [NSString stringWithFormat:@"%@/Molotov.png",GRAPHICS_DIRECTORY()]; |
|
94 |
break; |
|
95 |
case 3: |
|
96 |
iconStr = [NSString stringWithFormat:@"%@/Target.png",GRAPHICS_DIRECTORY()]; |
|
97 |
break; |
|
98 |
default: |
|
99 |
//seduction.png for support page |
|
100 |
DLog(@"Nope"); |
|
101 |
break; |
|
3547 | 102 |
} |
3783 | 103 |
|
104 |
if (nil == targetController) |
|
105 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
106 |
else |
|
107 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
3697 | 108 |
|
3701 | 109 |
cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]]; |
3783 | 110 |
UIImage *icon = [[UIImage alloc] initWithContentsOfFile:iconStr]; |
111 |
cell.imageView.image = icon; |
|
112 |
[icon release]; |
|
3701 | 113 |
|
3547 | 114 |
return cell; |
115 |
} |
|
116 |
||
117 |
#pragma mark - |
|
118 |
#pragma mark Table view delegate |
|
119 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
120 |
int newRow = [indexPath row]; |
|
121 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
122 |
UIViewController *nextController = nil; |
|
3697 | 123 |
|
3547 | 124 |
if (newRow != oldRow) { |
125 |
[self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES]; |
|
3701 | 126 |
[targetController.navigationController popToRootViewControllerAnimated:NO]; |
3697 | 127 |
|
3547 | 128 |
switch (newRow) { |
129 |
case 0: |
|
130 |
if (nil == generalSettingsViewController) |
|
131 |
generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
132 |
nextController = generalSettingsViewController; |
|
133 |
break; |
|
134 |
case 1: |
|
135 |
if (nil == teamSettingsViewController) |
|
136 |
teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
137 |
nextController = teamSettingsViewController; |
|
138 |
break; |
|
139 |
case 2: |
|
140 |
if (nil == weaponSettingsViewController) |
|
141 |
weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
142 |
nextController = weaponSettingsViewController; |
|
143 |
break; |
|
144 |
case 3: |
|
145 |
if (nil == schemeSettingsViewController) |
|
146 |
schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
147 |
nextController = schemeSettingsViewController; |
|
148 |
break; |
|
149 |
} |
|
3697 | 150 |
|
3547 | 151 |
nextController.title = [controllerNames objectAtIndex:newRow]; |
152 |
self.lastIndexPath = indexPath; |
|
153 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
3701 | 154 |
|
155 |
if (nil == targetController) { |
|
156 |
nextController.navigationItem.hidesBackButton = NO; |
|
157 |
[self.navigationController pushViewController:nextController animated:YES]; |
|
158 |
} else { |
|
3783 | 159 |
playSound(@"clickSound"); |
3701 | 160 |
nextController.navigationItem.hidesBackButton = YES; |
161 |
[targetController.navigationController pushViewController:nextController animated:NO]; |
|
162 |
} |
|
3547 | 163 |
} |
164 |
} |
|
165 |
||
166 |
||
167 |
#pragma mark - |
|
168 |
#pragma mark Memory management |
|
169 |
-(void) didReceiveMemoryWarning { |
|
170 |
// Releases the view if it doesn't have a superview. |
|
171 |
[super didReceiveMemoryWarning]; |
|
3697 | 172 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
3547 | 173 |
if (generalSettingsViewController.view.superview == nil) |
174 |
generalSettingsViewController = nil; |
|
175 |
if (teamSettingsViewController.view.superview == nil) |
|
176 |
teamSettingsViewController = nil; |
|
177 |
if (weaponSettingsViewController.view.superview == nil) |
|
178 |
weaponSettingsViewController = nil; |
|
179 |
if (schemeSettingsViewController.view.superview == nil) |
|
180 |
schemeSettingsViewController = nil; |
|
181 |
MSG_MEMCLEAN(); |
|
182 |
} |
|
183 |
||
184 |
-(void) viewDidUnload { |
|
3701 | 185 |
self.targetController = nil; |
3547 | 186 |
self.controllerNames = nil; |
187 |
self.lastIndexPath = nil; |
|
188 |
generalSettingsViewController = nil; |
|
189 |
teamSettingsViewController = nil; |
|
190 |
weaponSettingsViewController = nil; |
|
191 |
schemeSettingsViewController = nil; |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3547
diff
changeset
|
192 |
MSG_DIDUNLOAD(); |
3547 | 193 |
[super viewDidUnload]; |
194 |
} |
|
195 |
||
196 |
-(void) dealloc { |
|
3701 | 197 |
targetController = nil; |
3547 | 198 |
[controllerNames release]; |
199 |
[lastIndexPath release]; |
|
200 |
[generalSettingsViewController release]; |
|
201 |
[teamSettingsViewController release]; |
|
202 |
[weaponSettingsViewController release]; |
|
203 |
[schemeSettingsViewController release]; |
|
204 |
[super dealloc]; |
|
205 |
} |
|
206 |
||
207 |
-(IBAction) dismissSplitView { |
|
3783 | 208 |
playSound(@"backSound"); |
3547 | 209 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; |
210 |
} |
|
211 |
||
212 |
@end |
|
213 |