author | koda |
Wed, 06 Oct 2010 02:31:04 +0200 | |
changeset 3926 | 668b71f31e51 |
parent 3884 | d7479079a8a8 |
child 3971 | 5c82ee165ed5 |
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" |
|
3884 | 23 |
#import "CommodityFunctions.h" |
3547 | 24 |
#import "GeneralSettingsViewController.h" |
25 |
#import "TeamSettingsViewController.h" |
|
26 |
#import "WeaponSettingsViewController.h" |
|
27 |
#import "SchemeSettingsViewController.h" |
|
3884 | 28 |
#import "SupportViewController.h" |
3547 | 29 |
|
30 |
@implementation MasterViewController |
|
3701 | 31 |
@synthesize targetController, controllerNames, lastIndexPath; |
3547 | 32 |
|
33 |
||
34 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
35 |
return rotationManager(interfaceOrientation); |
|
36 |
} |
|
37 |
||
38 |
||
39 |
#pragma mark - |
|
40 |
#pragma mark View lifecycle |
|
41 |
-(void) viewDidLoad { |
|
42 |
[super viewDidLoad]; |
|
3697 | 43 |
|
3547 | 44 |
// the list of selectable controllers |
3701 | 45 |
NSArray *array = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
46 |
NSLocalizedString(@"Teams",@""), |
|
47 |
NSLocalizedString(@"Weapons",@""), |
|
48 |
NSLocalizedString(@"Schemes",@""), |
|
3884 | 49 |
NSLocalizedString(@"Support",@""), |
3701 | 50 |
nil]; |
51 |
self.controllerNames = array; |
|
52 |
[array release]; |
|
53 |
||
54 |
// targetControllers tells whether we're on the right or left side of the splitview -- on iphone we only use the right side |
|
55 |
if (targetController == nil && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
56 |
if (nil == generalSettingsViewController) |
|
57 |
generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
58 |
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
|
59 |
[generalSettingsViewController viewWillAppear:YES]; |
3701 | 60 |
[self.navigationController pushViewController:generalSettingsViewController animated:NO]; |
61 |
} else { |
|
62 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
|
63 |
target:self |
|
64 |
action:@selector(dismissSplitView)]; |
|
65 |
} |
|
3547 | 66 |
} |
67 |
||
68 |
#pragma mark - |
|
69 |
#pragma mark Table view data source |
|
70 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
71 |
return 1; |
|
72 |
} |
|
73 |
||
74 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
75 |
return [controllerNames count]; |
|
76 |
} |
|
77 |
||
78 |
// Customize the appearance of table view cells. |
|
79 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
80 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 81 |
|
3547 | 82 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
3783 | 83 |
if (cell == nil) |
3547 | 84 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
3783 | 85 |
|
86 |
NSString *iconStr = nil; |
|
87 |
switch ([indexPath row]) { |
|
88 |
case 0: |
|
89 |
iconStr = [NSString stringWithFormat:@"%@/TargetBee.png",GRAPHICS_DIRECTORY()]; |
|
90 |
break; |
|
91 |
case 1: |
|
92 |
iconStr = [NSString stringWithFormat:@"%@/Egg.png",GRAPHICS_DIRECTORY()]; |
|
93 |
break; |
|
94 |
case 2: |
|
95 |
iconStr = [NSString stringWithFormat:@"%@/Molotov.png",GRAPHICS_DIRECTORY()]; |
|
96 |
break; |
|
97 |
case 3: |
|
98 |
iconStr = [NSString stringWithFormat:@"%@/Target.png",GRAPHICS_DIRECTORY()]; |
|
99 |
break; |
|
3884 | 100 |
case 4: |
101 |
iconStr = [NSString stringWithFormat:@"%@/Seduction.png",GRAPHICS_DIRECTORY()]; |
|
102 |
break; |
|
3783 | 103 |
default: |
104 |
//seduction.png for support page |
|
105 |
DLog(@"Nope"); |
|
106 |
break; |
|
3547 | 107 |
} |
3783 | 108 |
|
109 |
if (nil == targetController) |
|
110 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
111 |
else |
|
112 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
3697 | 113 |
|
3701 | 114 |
cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]]; |
3783 | 115 |
UIImage *icon = [[UIImage alloc] initWithContentsOfFile:iconStr]; |
116 |
cell.imageView.image = icon; |
|
117 |
[icon release]; |
|
3701 | 118 |
|
3547 | 119 |
return cell; |
120 |
} |
|
121 |
||
122 |
#pragma mark - |
|
123 |
#pragma mark Table view delegate |
|
124 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
125 |
int newRow = [indexPath row]; |
|
126 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
127 |
UIViewController *nextController = nil; |
|
3697 | 128 |
|
3547 | 129 |
if (newRow != oldRow) { |
130 |
[self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES]; |
|
3701 | 131 |
[targetController.navigationController popToRootViewControllerAnimated:NO]; |
3697 | 132 |
|
3547 | 133 |
switch (newRow) { |
134 |
case 0: |
|
135 |
if (nil == generalSettingsViewController) |
|
136 |
generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
137 |
nextController = generalSettingsViewController; |
|
138 |
break; |
|
139 |
case 1: |
|
140 |
if (nil == teamSettingsViewController) |
|
141 |
teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
142 |
nextController = teamSettingsViewController; |
|
143 |
break; |
|
144 |
case 2: |
|
145 |
if (nil == weaponSettingsViewController) |
|
146 |
weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
147 |
nextController = weaponSettingsViewController; |
|
148 |
break; |
|
149 |
case 3: |
|
150 |
if (nil == schemeSettingsViewController) |
|
151 |
schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
152 |
nextController = schemeSettingsViewController; |
|
153 |
break; |
|
3884 | 154 |
case 4: |
155 |
if (nil == supportViewController) |
|
156 |
supportViewController = [[SupportViewController alloc] initWithNibName:@"SupportViewController" bundle:nil]; |
|
157 |
nextController = supportViewController; |
|
158 |
break; |
|
3547 | 159 |
} |
3697 | 160 |
|
3547 | 161 |
nextController.title = [controllerNames objectAtIndex:newRow]; |
162 |
self.lastIndexPath = indexPath; |
|
163 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
3701 | 164 |
|
165 |
if (nil == targetController) { |
|
166 |
nextController.navigationItem.hidesBackButton = NO; |
|
167 |
[self.navigationController pushViewController:nextController animated:YES]; |
|
168 |
} else { |
|
3783 | 169 |
playSound(@"clickSound"); |
3701 | 170 |
nextController.navigationItem.hidesBackButton = YES; |
171 |
[targetController.navigationController pushViewController:nextController animated:NO]; |
|
172 |
} |
|
3547 | 173 |
} |
174 |
} |
|
175 |
||
176 |
||
177 |
#pragma mark - |
|
178 |
#pragma mark Memory management |
|
179 |
-(void) didReceiveMemoryWarning { |
|
180 |
// Releases the view if it doesn't have a superview. |
|
181 |
[super didReceiveMemoryWarning]; |
|
3697 | 182 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
3547 | 183 |
if (generalSettingsViewController.view.superview == nil) |
184 |
generalSettingsViewController = nil; |
|
185 |
if (teamSettingsViewController.view.superview == nil) |
|
186 |
teamSettingsViewController = nil; |
|
187 |
if (weaponSettingsViewController.view.superview == nil) |
|
188 |
weaponSettingsViewController = nil; |
|
189 |
if (schemeSettingsViewController.view.superview == nil) |
|
190 |
schemeSettingsViewController = nil; |
|
3884 | 191 |
if (supportViewController.view.superview == nil) |
192 |
supportViewController = nil; |
|
3547 | 193 |
MSG_MEMCLEAN(); |
194 |
} |
|
195 |
||
196 |
-(void) viewDidUnload { |
|
3701 | 197 |
self.targetController = nil; |
3547 | 198 |
self.controllerNames = nil; |
199 |
self.lastIndexPath = nil; |
|
200 |
generalSettingsViewController = nil; |
|
201 |
teamSettingsViewController = nil; |
|
202 |
weaponSettingsViewController = nil; |
|
203 |
schemeSettingsViewController = nil; |
|
3884 | 204 |
supportViewController = 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
|
205 |
MSG_DIDUNLOAD(); |
3547 | 206 |
[super viewDidUnload]; |
207 |
} |
|
208 |
||
209 |
-(void) dealloc { |
|
3701 | 210 |
targetController = nil; |
3547 | 211 |
[controllerNames release]; |
212 |
[lastIndexPath release]; |
|
213 |
[generalSettingsViewController release]; |
|
214 |
[teamSettingsViewController release]; |
|
215 |
[weaponSettingsViewController release]; |
|
216 |
[schemeSettingsViewController release]; |
|
3884 | 217 |
[supportViewController release]; |
3547 | 218 |
[super dealloc]; |
219 |
} |
|
220 |
||
221 |
-(IBAction) dismissSplitView { |
|
3783 | 222 |
playSound(@"backSound"); |
3547 | 223 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; |
224 |
} |
|
225 |
||
226 |
@end |
|
227 |