26 |
26 |
27 |
27 |
28 @implementation SettingsBaseViewController |
28 @implementation SettingsBaseViewController |
29 @synthesize targetController, controllerNames, lastIndexPath; |
29 @synthesize targetController, controllerNames, lastIndexPath; |
30 |
30 |
31 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
31 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
32 return rotationManager(interfaceOrientation); |
32 return rotationManager(interfaceOrientation); |
33 } |
33 } |
34 |
34 |
35 #pragma mark - |
35 #pragma mark - |
36 #pragma mark View lifecycle |
36 #pragma mark View lifecycle |
37 -(void) viewDidLoad { |
37 - (void)viewDidLoad { |
38 // the list of available controllers |
38 // the list of available controllers |
39 NSArray *array = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
39 NSArray *array = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
40 NSLocalizedString(@"Teams",@""), |
40 NSLocalizedString(@"Teams",@""), |
41 NSLocalizedString(@"Weapons",@""), |
41 NSLocalizedString(@"Weapons",@""), |
42 NSLocalizedString(@"Schemes",@""), |
42 NSLocalizedString(@"Schemes",@""), |
43 NSLocalizedString(@"Support",@""), |
43 NSLocalizedString(@"Support",@""), |
44 nil]; |
44 nil]; |
45 self.controllerNames = array; |
45 self.controllerNames = array; |
46 [array release]; |
|
47 |
46 |
48 if (IS_IPAD()) |
47 if (IS_IPAD()) |
49 { |
48 { |
50 // this class gets loaded twice, we tell the difference by looking at targetController |
49 // this class gets loaded twice, we tell the difference by looking at targetController |
51 if (self.targetController != nil) |
50 if (self.targetController != nil) |
55 tableView.delegate = self; |
54 tableView.delegate = self; |
56 tableView.dataSource = self; |
55 tableView.dataSource = self; |
57 [tableView reloadData]; |
56 [tableView reloadData]; |
58 [self.view addSubview:tableView]; |
57 [self.view addSubview:tableView]; |
59 [self tableView:tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; |
58 [self tableView:tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; |
60 [tableView release]; |
|
61 self.navigationItem.leftBarButtonItem = [self doneButton]; |
59 self.navigationItem.leftBarButtonItem = [self doneButton]; |
62 } |
60 } |
63 } |
61 } |
64 else |
62 else |
65 { |
63 { |
69 [super viewDidLoad]; |
67 [super viewDidLoad]; |
70 } |
68 } |
71 |
69 |
72 - (UIBarButtonItem *)doneButton |
70 - (UIBarButtonItem *)doneButton |
73 { |
71 { |
74 return [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
72 return [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
75 target:self |
73 target:self |
76 action:@selector(dismissSplitView)] autorelease]; |
74 action:@selector(dismissSplitView)]; |
77 } |
75 } |
78 |
76 |
79 -(void) dismissSplitView { |
77 - (void)dismissSplitView { |
80 [[AudioManagerController mainManager] playBackSound]; |
78 [[AudioManagerController mainManager] playBackSound]; |
81 [[[HedgewarsAppDelegate sharedAppDelegate] mainViewController] dismissViewControllerAnimated:YES completion:nil]; |
79 UIViewController *vc = [[HedgewarsAppDelegate sharedAppDelegate] mainViewController]; |
|
80 [vc dismissViewControllerAnimated:YES completion:nil]; |
82 } |
81 } |
83 |
82 |
84 #pragma mark - |
83 #pragma mark - |
85 #pragma mark Table view data source |
84 #pragma mark Table view data source |
86 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
85 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
87 return 1; |
86 return 1; |
88 } |
87 } |
89 |
88 |
90 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
89 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
91 return [self.controllerNames count]; |
90 return [self.controllerNames count]; |
92 } |
91 } |
93 |
92 |
94 // Customize the appearance of table view cells. |
93 // Customize the appearance of table view cells. |
95 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
94 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
96 static NSString *CellIdentifier = @"Cell"; |
95 static NSString *CellIdentifier = @"Cell"; |
97 |
96 |
98 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
97 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
99 if (cell == nil) |
98 if (cell == nil) |
100 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
99 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; |
101 |
100 |
102 NSString *iconStr = nil; |
101 NSString *iconStr = nil; |
103 switch ([indexPath row]) { |
102 switch ([indexPath row]) { |
104 case 0: |
103 case 0: |
105 iconStr = [NSString stringWithFormat:@"%@/TargetBee.png",GRAPHICS_DIRECTORY()]; |
104 iconStr = [NSString stringWithFormat:@"%@/TargetBee.png",GRAPHICS_DIRECTORY()]; |
123 |
122 |
124 cell.accessoryType = UITableViewCellAccessoryNone; |
123 cell.accessoryType = UITableViewCellAccessoryNone; |
125 cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]]; |
124 cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]]; |
126 UIImage *icon = [[UIImage alloc] initWithContentsOfFile:iconStr]; |
125 UIImage *icon = [[UIImage alloc] initWithContentsOfFile:iconStr]; |
127 cell.imageView.image = icon; |
126 cell.imageView.image = icon; |
128 [icon release]; |
|
129 |
127 |
130 return cell; |
128 return cell; |
131 } |
129 } |
132 |
130 |
133 #pragma mark - |
131 #pragma mark - |
134 #pragma mark Table view delegate |
132 #pragma mark Table view delegate |
135 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath |
133 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath |
136 { |
134 { |
137 NSInteger newRow = [indexPath row]; |
135 NSInteger newRow = [indexPath row]; |
138 NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
136 NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
139 UIViewController *nextController = nil; |
137 UIViewController *nextController = nil; |
140 |
138 |
166 [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
164 [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
167 |
165 |
168 nextController.navigationItem.hidesBackButton = YES; |
166 nextController.navigationItem.hidesBackButton = YES; |
169 [nextController viewWillAppear:NO]; |
167 [nextController viewWillAppear:NO]; |
170 [targetController.navigationController pushViewController:nextController animated:NO]; |
168 [targetController.navigationController pushViewController:nextController animated:NO]; |
171 [nextController release]; |
|
172 |
169 |
173 [[AudioManagerController mainManager] playClickSound]; |
170 [[AudioManagerController mainManager] playClickSound]; |
174 } |
171 } |
175 } |
172 } |
176 |
173 |
177 |
174 |
178 #pragma mark - |
175 #pragma mark - |
179 #pragma mark Memory management |
176 #pragma mark Memory management |
180 -(void) didReceiveMemoryWarning |
177 |
|
178 - (void)didReceiveMemoryWarning |
181 { |
179 { |
182 MSG_MEMCLEAN(); |
180 MSG_MEMCLEAN(); |
183 [super didReceiveMemoryWarning]; |
181 [super didReceiveMemoryWarning]; |
184 } |
182 } |
185 |
183 |
186 -(void) viewDidUnload |
|
187 { |
|
188 self.controllerNames = nil; |
|
189 self.lastIndexPath = nil; |
|
190 self.targetController = nil; |
|
191 MSG_DIDUNLOAD(); |
|
192 [super viewDidUnload]; |
|
193 } |
|
194 |
|
195 -(void) dealloc |
|
196 { |
|
197 releaseAndNil(targetController); |
|
198 releaseAndNil(controllerNames); |
|
199 releaseAndNil(lastIndexPath); |
|
200 [super dealloc]; |
|
201 } |
|
202 |
|
203 @end |
184 @end |
204 |
185 |