author | koda |
Fri, 26 Oct 2012 14:19:43 +0100 | |
branch | 0.9.16 |
changeset 6007 | b3b9e995ae90 |
parent 5976 | 306cedbeb213 |
child 6000 | dbcebcd3d79f |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
4976 | 3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
3829 | 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 |
|
5219 | 31 |
@synthesize rootController, 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 |
|
3996 | 55 |
if (targetController == nil && IS_IPAD()) { |
3701 | 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: |
|
5976
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5219
diff
changeset
|
95 |
iconStr = [NSString stringWithFormat:@"%@/cheese.png",GRAPHICS_DIRECTORY()]; |
3783 | 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) |
|
4115 | 156 |
supportViewController = [[SupportViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3884 | 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 |
if (generalSettingsViewController.view.superview == nil) |
|
181 |
generalSettingsViewController = nil; |
|
182 |
if (teamSettingsViewController.view.superview == nil) |
|
183 |
teamSettingsViewController = nil; |
|
184 |
if (weaponSettingsViewController.view.superview == nil) |
|
185 |
weaponSettingsViewController = nil; |
|
186 |
if (schemeSettingsViewController.view.superview == nil) |
|
187 |
schemeSettingsViewController = nil; |
|
3884 | 188 |
if (supportViewController.view.superview == nil) |
189 |
supportViewController = nil; |
|
3547 | 190 |
MSG_MEMCLEAN(); |
3971 | 191 |
[super didReceiveMemoryWarning]; |
3547 | 192 |
} |
193 |
||
194 |
-(void) viewDidUnload { |
|
5219 | 195 |
//self.rootController = nil; |
196 |
//self.targetController = nil; |
|
3547 | 197 |
self.controllerNames = nil; |
198 |
self.lastIndexPath = nil; |
|
199 |
generalSettingsViewController = nil; |
|
200 |
teamSettingsViewController = nil; |
|
201 |
weaponSettingsViewController = nil; |
|
202 |
schemeSettingsViewController = nil; |
|
3884 | 203 |
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
|
204 |
MSG_DIDUNLOAD(); |
3547 | 205 |
[super viewDidUnload]; |
206 |
} |
|
207 |
||
208 |
-(void) dealloc { |
|
5219 | 209 |
releaseAndNil(rootController); |
210 |
releaseAndNil(targetController); |
|
5208 | 211 |
releaseAndNil(controllerNames); |
212 |
releaseAndNil(lastIndexPath); |
|
213 |
releaseAndNil(generalSettingsViewController); |
|
214 |
releaseAndNil(teamSettingsViewController); |
|
215 |
releaseAndNil(weaponSettingsViewController); |
|
216 |
releaseAndNil(schemeSettingsViewController); |
|
217 |
releaseAndNil(supportViewController); |
|
3547 | 218 |
[super dealloc]; |
219 |
} |
|
220 |
||
221 |
-(IBAction) dismissSplitView { |
|
5219 | 222 |
[self.rootController dismissModalViewControllerAnimated:YES]; |
3547 | 223 |
} |
224 |
||
225 |
@end |
|
226 |