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