author | antonc27 <antonc27@mail.ru> |
Thu, 05 Nov 2015 04:45:20 +0100 | |
branch | ios-revival |
changeset 11306 | 7a9464f9e992 |
parent 11217 | e68b3e392091 |
child 12872 | 00215a7ec5f5 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
6700 | 3 |
* Copyright (c) 2009-2012 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
6869
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3829 | 17 |
*/ |
18 |
||
3547 | 19 |
|
6075
0173cd44c3bc
rename the ios settings files into something more appropriate
koda
parents:
6074
diff
changeset
|
20 |
#import "SettingsBaseViewController.h" |
3547 | 21 |
#import "GeneralSettingsViewController.h" |
22 |
#import "TeamSettingsViewController.h" |
|
23 |
#import "WeaponSettingsViewController.h" |
|
24 |
#import "SchemeSettingsViewController.h" |
|
3884 | 25 |
#import "SupportViewController.h" |
3547 | 26 |
|
6832 | 27 |
|
6075
0173cd44c3bc
rename the ios settings files into something more appropriate
koda
parents:
6074
diff
changeset
|
28 |
@implementation SettingsBaseViewController |
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
29 |
@synthesize targetController, controllerNames, lastIndexPath; |
3547 | 30 |
|
31 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
32 |
return rotationManager(interfaceOrientation); |
|
33 |
} |
|
34 |
||
35 |
#pragma mark - |
|
36 |
#pragma mark View lifecycle |
|
37 |
-(void) viewDidLoad { |
|
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
38 |
// the list of available controllers |
3701 | 39 |
NSArray *array = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
40 |
NSLocalizedString(@"Teams",@""), |
|
41 |
NSLocalizedString(@"Weapons",@""), |
|
42 |
NSLocalizedString(@"Schemes",@""), |
|
3884 | 43 |
NSLocalizedString(@"Support",@""), |
3701 | 44 |
nil]; |
45 |
self.controllerNames = array; |
|
46 |
[array release]; |
|
47 |
||
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
48 |
if (IS_IPAD()) |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
49 |
{ |
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
50 |
// this class gets loaded twice, we tell the difference by looking at targetController |
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
51 |
if (self.targetController != nil) |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
52 |
{ |
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
53 |
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; |
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
54 |
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
55 |
tableView.delegate = self; |
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
56 |
tableView.dataSource = self; |
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
57 |
[tableView reloadData]; |
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
58 |
[self.view addSubview:tableView]; |
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
59 |
[self tableView:tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; |
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
60 |
[tableView release]; |
11216
76fd61a88c1e
- Better way of creating/using doneButton in Settings
antonc27 <antonc27@mail.ru>
parents:
11214
diff
changeset
|
61 |
self.navigationItem.leftBarButtonItem = [self doneButton]; |
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
62 |
} |
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
63 |
} |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
64 |
else |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
65 |
{ |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
66 |
//iPhone part moved to MainMenuViewController |
3701 | 67 |
} |
11216
76fd61a88c1e
- Better way of creating/using doneButton in Settings
antonc27 <antonc27@mail.ru>
parents:
11214
diff
changeset
|
68 |
|
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
69 |
[super viewDidLoad]; |
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
70 |
} |
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
71 |
|
11216
76fd61a88c1e
- Better way of creating/using doneButton in Settings
antonc27 <antonc27@mail.ru>
parents:
11214
diff
changeset
|
72 |
- (UIBarButtonItem *)doneButton |
76fd61a88c1e
- Better way of creating/using doneButton in Settings
antonc27 <antonc27@mail.ru>
parents:
11214
diff
changeset
|
73 |
{ |
76fd61a88c1e
- Better way of creating/using doneButton in Settings
antonc27 <antonc27@mail.ru>
parents:
11214
diff
changeset
|
74 |
return [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
76fd61a88c1e
- Better way of creating/using doneButton in Settings
antonc27 <antonc27@mail.ru>
parents:
11214
diff
changeset
|
75 |
target:self |
76fd61a88c1e
- Better way of creating/using doneButton in Settings
antonc27 <antonc27@mail.ru>
parents:
11214
diff
changeset
|
76 |
action:@selector(dismissSplitView)] autorelease]; |
76fd61a88c1e
- Better way of creating/using doneButton in Settings
antonc27 <antonc27@mail.ru>
parents:
11214
diff
changeset
|
77 |
} |
76fd61a88c1e
- Better way of creating/using doneButton in Settings
antonc27 <antonc27@mail.ru>
parents:
11214
diff
changeset
|
78 |
|
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
79 |
-(void) dismissSplitView { |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
80 |
[[AudioManagerController mainManager] playBackSound]; |
11116
102684240fe8
- Interscreen transitions fixed
Anton Malmygin <antonc27@mail.ru>
parents:
10108
diff
changeset
|
81 |
[[[HedgewarsAppDelegate sharedAppDelegate] mainViewController] dismissViewControllerAnimated:YES completion:nil]; |
3547 | 82 |
} |
83 |
||
84 |
#pragma mark - |
|
85 |
#pragma mark Table view data source |
|
86 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
87 |
return 1; |
|
88 |
} |
|
89 |
||
90 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
91 |
return [self.controllerNames count]; |
3547 | 92 |
} |
93 |
||
94 |
// Customize the appearance of table view cells. |
|
95 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
96 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 97 |
|
3547 | 98 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
3783 | 99 |
if (cell == nil) |
3547 | 100 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
3783 | 101 |
|
102 |
NSString *iconStr = nil; |
|
103 |
switch ([indexPath row]) { |
|
104 |
case 0: |
|
105 |
iconStr = [NSString stringWithFormat:@"%@/TargetBee.png",GRAPHICS_DIRECTORY()]; |
|
106 |
break; |
|
107 |
case 1: |
|
108 |
iconStr = [NSString stringWithFormat:@"%@/Egg.png",GRAPHICS_DIRECTORY()]; |
|
109 |
break; |
|
110 |
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
|
111 |
iconStr = [NSString stringWithFormat:@"%@/cheese.png",GRAPHICS_DIRECTORY()]; |
3783 | 112 |
break; |
113 |
case 3: |
|
114 |
iconStr = [NSString stringWithFormat:@"%@/Target.png",GRAPHICS_DIRECTORY()]; |
|
115 |
break; |
|
3884 | 116 |
case 4: |
117 |
iconStr = [NSString stringWithFormat:@"%@/Seduction.png",GRAPHICS_DIRECTORY()]; |
|
118 |
break; |
|
3783 | 119 |
default: |
120 |
DLog(@"Nope"); |
|
121 |
break; |
|
3547 | 122 |
} |
6075
0173cd44c3bc
rename the ios settings files into something more appropriate
koda
parents:
6074
diff
changeset
|
123 |
|
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
124 |
cell.accessoryType = UITableViewCellAccessoryNone; |
3701 | 125 |
cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]]; |
3783 | 126 |
UIImage *icon = [[UIImage alloc] initWithContentsOfFile:iconStr]; |
127 |
cell.imageView.image = icon; |
|
128 |
[icon release]; |
|
3701 | 129 |
|
3547 | 130 |
return cell; |
131 |
} |
|
132 |
||
133 |
#pragma mark - |
|
134 |
#pragma mark Table view delegate |
|
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
135 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
136 |
{ |
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
11116
diff
changeset
|
137 |
NSInteger newRow = [indexPath row]; |
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
11116
diff
changeset
|
138 |
NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
3547 | 139 |
UIViewController *nextController = nil; |
3697 | 140 |
|
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
141 |
if (newRow != oldRow) |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
142 |
{ |
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
143 |
[tableView deselectRowAtIndexPath:lastIndexPath animated:YES]; |
3701 | 144 |
[targetController.navigationController popToRootViewControllerAnimated:NO]; |
3697 | 145 |
|
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
146 |
switch (newRow) |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
147 |
{ |
3547 | 148 |
case 0: |
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
149 |
nextController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];; |
3547 | 150 |
break; |
151 |
case 1: |
|
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
152 |
nextController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3547 | 153 |
break; |
154 |
case 2: |
|
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
155 |
nextController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3547 | 156 |
break; |
157 |
case 3: |
|
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
158 |
nextController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3547 | 159 |
break; |
3884 | 160 |
case 4: |
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
161 |
nextController = [[SupportViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3884 | 162 |
break; |
3547 | 163 |
} |
3697 | 164 |
|
3547 | 165 |
self.lastIndexPath = indexPath; |
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
166 |
[tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
3701 | 167 |
|
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
168 |
nextController.navigationItem.hidesBackButton = YES; |
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
169 |
[nextController viewWillAppear:NO]; |
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
6000
diff
changeset
|
170 |
[targetController.navigationController pushViewController:nextController animated:NO]; |
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
171 |
[nextController release]; |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
172 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
173 |
[[AudioManagerController mainManager] playClickSound]; |
3547 | 174 |
} |
175 |
} |
|
176 |
||
177 |
||
178 |
#pragma mark - |
|
179 |
#pragma mark Memory management |
|
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
180 |
-(void) didReceiveMemoryWarning |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
181 |
{ |
3547 | 182 |
MSG_MEMCLEAN(); |
3971 | 183 |
[super didReceiveMemoryWarning]; |
3547 | 184 |
} |
185 |
||
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
186 |
-(void) viewDidUnload |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
187 |
{ |
3547 | 188 |
self.controllerNames = nil; |
189 |
self.lastIndexPath = nil; |
|
6076 | 190 |
self.targetController = 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
|
191 |
MSG_DIDUNLOAD(); |
3547 | 192 |
[super viewDidUnload]; |
193 |
} |
|
194 |
||
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
195 |
-(void) dealloc |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
11216
diff
changeset
|
196 |
{ |
5219 | 197 |
releaseAndNil(targetController); |
5208 | 198 |
releaseAndNil(controllerNames); |
199 |
releaseAndNil(lastIndexPath); |
|
3547 | 200 |
[super dealloc]; |
201 |
} |
|
202 |
||
203 |
@end |
|
204 |