author | koda |
Sun, 09 Oct 2011 00:24:58 +0200 | |
changeset 6107 | 0741c0f0203e |
parent 6078 | 8c0cc07731e5 |
child 6108 | 7a8da11a6144 |
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 13/06/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "SchemeWeaponConfigViewController.h" |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5455
diff
changeset
|
23 |
|
3547 | 24 |
|
4349 | 25 |
#define LABEL_TAG 57423 |
26 |
||
3547 | 27 |
@implementation SchemeWeaponConfigViewController |
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
28 |
@synthesize listOfSchemes, listOfWeapons, listOfScripts, lastIndexPath_sc, lastIndexPath_we, lastIndexPath_lu, |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
29 |
selectedScheme, selectedWeapon, selectedScript, scriptCommand, topControl, hideSections; |
3547 | 30 |
|
31 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
32 |
return rotationManager(interfaceOrientation); |
|
33 |
} |
|
34 |
||
35 |
#pragma mark - |
|
6107 | 36 |
#pragma mark custom setters/getters |
37 |
-(NSString *)selectedScheme { |
|
38 |
if (selectedScheme == nil) |
|
39 |
self.selectedScheme = @"Default.plist"; |
|
40 |
return selectedScheme; |
|
41 |
} |
|
42 |
||
43 |
-(NSString *)selectedWeapon { |
|
44 |
if (selectedWeapon == nil) |
|
45 |
self.selectedWeapon = @"Default.plist"; |
|
46 |
return selectedWeapon; |
|
47 |
} |
|
48 |
||
49 |
-(NSString *)selectedScript { |
|
50 |
if (selectedScript == nil) |
|
51 |
self.selectedScript = @"Normal.plist"; |
|
52 |
return selectedScript; |
|
53 |
} |
|
54 |
||
55 |
-(NSString *)scriptCommand { |
|
56 |
if (scriptCommand == nil) |
|
57 |
self.scriptCommand = @""; |
|
58 |
return scriptCommand; |
|
59 |
} |
|
60 |
||
61 |
-(NSArray *)listOfSchemes { |
|
62 |
if (listOfSchemes == nil) |
|
63 |
self.listOfSchemes = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SCHEMES_DIRECTORY() error:NULL]; |
|
64 |
return listOfSchemes; |
|
65 |
} |
|
66 |
||
67 |
-(NSArray *)listOfWeapons { |
|
68 |
if (listOfWeapons == nil) |
|
69 |
self.listOfWeapons = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:WEAPONS_DIRECTORY() error:NULL]; |
|
70 |
return listOfWeapons; |
|
71 |
} |
|
72 |
||
73 |
-(NSArray *)listOfScripts { |
|
74 |
if (listOfScripts == nil) |
|
75 |
self.listOfScripts = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SCRIPTS_DIRECTORY() error:NULL]; |
|
76 |
return listOfScripts; |
|
77 |
} |
|
78 |
||
79 |
-(UISegmentedControl *)topControl { |
|
80 |
if (topControl == nil) { |
|
81 |
NSArray *array = [[NSArray alloc] initWithObjects: |
|
82 |
NSLocalizedString(@"Scheme",@""), |
|
83 |
NSLocalizedString(@"Weapon",@""), |
|
84 |
NSLocalizedString(@"Style",@""),nil]; |
|
85 |
UISegmentedControl *controller = [[UISegmentedControl alloc] initWithItems:array]; |
|
86 |
[array release]; |
|
87 |
[controller addTarget:self.tableView action:@selector(reloadData) forControlEvents:UIControlEventValueChanged]; |
|
88 |
controller.segmentedControlStyle = UISegmentedControlStyleBar; |
|
89 |
controller.tintColor = [UIColor lightGrayColor]; |
|
90 |
controller.selectedSegmentIndex = 0; |
|
91 |
self.topControl = controller; |
|
92 |
[controller release]; |
|
93 |
} |
|
94 |
return topControl; |
|
95 |
} |
|
96 |
||
97 |
-(void) viewWillAppear:(BOOL) animated { |
|
98 |
[super viewWillAppear:animated]; |
|
99 |
[self.tableView reloadData]; |
|
100 |
} |
|
101 |
||
102 |
#pragma mark - |
|
3547 | 103 |
#pragma mark View lifecycle |
104 |
-(void) viewDidLoad { |
|
105 |
[super viewDidLoad]; |
|
106 |
||
107 |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
|
108 |
self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
|
3697 | 109 |
|
4244 | 110 |
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) { |
111 |
if (IS_IPAD()) |
|
112 |
[self.tableView setBackgroundView:nil]; |
|
113 |
else { |
|
4356 | 114 |
UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:@"background~iphone.png"]; |
4244 | 115 |
UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage]; |
116 |
[backgroundImage release]; |
|
117 |
[self.tableView setBackgroundView:background]; |
|
118 |
[background release]; |
|
119 |
} |
|
120 |
} else { |
|
121 |
self.view.backgroundColor = [UIColor blackColor]; |
|
122 |
} |
|
123 |
||
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5455
diff
changeset
|
124 |
self.tableView.separatorColor = [UIColor darkYellowColor]; |
3659 | 125 |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
3547 | 126 |
} |
127 |
||
128 |
#pragma mark - |
|
129 |
#pragma mark Table view data source |
|
130 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
6107 | 131 |
return (self.hideSections ? 0 : 1); |
3547 | 132 |
} |
133 |
||
134 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
135 |
if (self.topControl.selectedSegmentIndex == 0) |
3547 | 136 |
return [self.listOfSchemes count]; |
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
137 |
else if (self.topControl.selectedSegmentIndex == 1) |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
138 |
return [self.listOfWeapons count]; |
5451
e359a79e3d08
rip out the sync weapons/schemes switch and place it into settings; also perform some runtime check on what can be enabled
koda
parents:
5208
diff
changeset
|
139 |
else |
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
140 |
return [self.listOfScripts count]; |
3547 | 141 |
} |
142 |
||
143 |
// Customize the appearance of table view cells. |
|
144 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
145 |
static NSString *CellIdentifier = @"Cell"; |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
146 |
NSInteger index = self.topControl.selectedSegmentIndex; |
3547 | 147 |
NSInteger row = [indexPath row]; |
3697 | 148 |
|
3547 | 149 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3780
diff
changeset
|
150 |
if (cell == nil) |
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3780
diff
changeset
|
151 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; |
3697 | 152 |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
153 |
cell.accessoryView = nil; |
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
154 |
if (0 == index) { |
3547 | 155 |
cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension]; |
3782 | 156 |
NSString *str = [NSString stringWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),[self.listOfSchemes objectAtIndex:row]]; |
157 |
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str]; |
|
158 |
cell.detailTextLabel.text = [dict objectForKey:@"description"]; |
|
159 |
[dict release]; |
|
3547 | 160 |
if ([[self.listOfSchemes objectAtIndex:row] isEqualToString:self.selectedScheme]) { |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
161 |
UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
162 |
cell.accessoryView = checkbox; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
163 |
[checkbox release]; |
3547 | 164 |
self.lastIndexPath_sc = indexPath; |
165 |
} |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
166 |
} else if (1 == index) { |
3547 | 167 |
cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension]; |
3782 | 168 |
NSString *str = [NSString stringWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),[self.listOfWeapons objectAtIndex:row]]; |
169 |
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str]; |
|
170 |
cell.detailTextLabel.text = [dict objectForKey:@"description"]; |
|
171 |
[dict release]; |
|
3547 | 172 |
if ([[self.listOfWeapons objectAtIndex:row] isEqualToString:self.selectedWeapon]) { |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
173 |
UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
174 |
cell.accessoryView = checkbox; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
175 |
[checkbox release]; |
3547 | 176 |
self.lastIndexPath_we = indexPath; |
177 |
} |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
178 |
} else { |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
179 |
cell.textLabel.text = [[self.listOfScripts objectAtIndex:row] stringByDeletingPathExtension]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
180 |
NSString *str = [NSString stringWithFormat:@"%@/%@",SCRIPTS_DIRECTORY(),[self.listOfScripts objectAtIndex:row]]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
181 |
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
182 |
cell.detailTextLabel.text = [dict objectForKey:@"description"]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
183 |
[dict release]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
184 |
if ([[self.listOfScripts objectAtIndex:row] isEqualToString:self.selectedScript]) { |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
185 |
UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
186 |
cell.accessoryView = checkbox; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
187 |
[checkbox release]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
188 |
self.lastIndexPath_lu = indexPath; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
189 |
} |
3547 | 190 |
} |
4287 | 191 |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5455
diff
changeset
|
192 |
cell.backgroundColor = [UIColor blackColorTransparent]; |
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5455
diff
changeset
|
193 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3780
diff
changeset
|
194 |
cell.detailTextLabel.textColor = [UIColor whiteColor]; |
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
195 |
cell.textLabel.adjustsFontSizeToFitWidth = YES; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
196 |
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; |
3547 | 197 |
return cell; |
198 |
} |
|
199 |
||
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
200 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
201 |
return 50.0; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
202 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
203 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
204 |
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
205 |
UIView *theView = [[[UIView alloc] init] autorelease]; |
6107 | 206 |
self.topControl.frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30); |
207 |
self.topControl.center = CGPointMake(self.view.frame.size.width/2, 24); |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
208 |
[theView addSubview:self.topControl]; |
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
209 |
return theView; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
210 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
211 |
|
3547 | 212 |
#pragma mark - |
213 |
#pragma mark Table view delegate |
|
214 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
215 |
NSIndexPath *lastIndexPath; |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
216 |
NSInteger index = self.topControl.selectedSegmentIndex; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
217 |
if (index == 0) |
3547 | 218 |
lastIndexPath = self.lastIndexPath_sc; |
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
219 |
else if (index == 1) |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
220 |
lastIndexPath = self.lastIndexPath_we; |
3547 | 221 |
else |
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
222 |
lastIndexPath = self.lastIndexPath_lu; |
3697 | 223 |
|
3547 | 224 |
int newRow = [indexPath row]; |
225 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 226 |
|
3547 | 227 |
if (newRow != oldRow) { |
228 |
//TODO: this code works only for a single section table |
|
229 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
230 |
UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
231 |
newCell.accessoryView = checkbox; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
232 |
[checkbox release]; |
3547 | 233 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
234 |
oldCell.accessoryView = nil; |
3697 | 235 |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
236 |
if (index == 0) { |
3547 | 237 |
self.lastIndexPath_sc = indexPath; |
238 |
self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow]; |
|
5451
e359a79e3d08
rip out the sync weapons/schemes switch and place it into settings; also perform some runtime check on what can be enabled
koda
parents:
5208
diff
changeset
|
239 |
|
6107 | 240 |
// also set weaponset when selecting scheme, if set |
5451
e359a79e3d08
rip out the sync weapons/schemes switch and place it into settings; also perform some runtime check on what can be enabled
koda
parents:
5208
diff
changeset
|
241 |
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
e359a79e3d08
rip out the sync weapons/schemes switch and place it into settings; also perform some runtime check on what can be enabled
koda
parents:
5208
diff
changeset
|
242 |
if ([[settings objectForKey:@"sync_ws"] boolValue]) { |
4287 | 243 |
for (NSString *str in self.listOfWeapons) { |
244 |
if ([str isEqualToString:self.selectedScheme]) { |
|
245 |
int index = [self.listOfSchemes indexOfObject:str]; |
|
246 |
self.selectedWeapon = str; |
|
247 |
self.lastIndexPath_we = [NSIndexPath indexPathForRow:index inSection:1]; |
|
248 |
[self.tableView reloadData]; |
|
249 |
break; |
|
250 |
} |
|
251 |
} |
|
252 |
} |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
253 |
} else if (index == 1) { |
3547 | 254 |
self.lastIndexPath_we = indexPath; |
255 |
self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow]; |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
256 |
} else { |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
257 |
self.lastIndexPath_lu = indexPath; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
258 |
self.selectedScript = [self.listOfScripts objectAtIndex:newRow]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
259 |
|
6107 | 260 |
// some styles disable or force the choice of a particular scheme/weaponset |
261 |
NSString *path = [[NSString alloc] initWithFormat:@"%@/%@",SCRIPTS_DIRECTORY(),self.selectedScript]; |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
262 |
NSDictionary *scriptDict = [[NSDictionary alloc] initWithContentsOfFile:path]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
263 |
[path release]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
264 |
self.scriptCommand = [scriptDict objectForKey:@"command"]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
265 |
NSString *scheme = [scriptDict objectForKey:@"scheme"]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
266 |
if ([scheme isEqualToString:@""]) { |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
267 |
self.selectedScheme = @"Default.plist"; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
268 |
[self.topControl setEnabled:NO forSegmentAtIndex:0]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
269 |
} else { |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
270 |
self.selectedScheme = scheme; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
271 |
[self.topControl setEnabled:YES forSegmentAtIndex:0]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
272 |
} |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
273 |
|
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
274 |
NSString *weapon = [scriptDict objectForKey:@"weapon"]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
275 |
if ([weapon isEqualToString:@""]) { |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
276 |
self.selectedWeapon = @"Default.plist"; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
277 |
[self.topControl setEnabled:NO forSegmentAtIndex:1]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
278 |
} else { |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
279 |
self.selectedWeapon = weapon; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
280 |
[self.topControl setEnabled:YES forSegmentAtIndex:1]; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
281 |
} |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
282 |
|
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
283 |
[scriptDict release]; |
3697 | 284 |
} |
285 |
||
3547 | 286 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
287 |
} |
|
288 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
289 |
} |
|
290 |
||
6107 | 291 |
#pragma mark - |
292 |
#pragma mark called externally to empty or fill the sections completely |
|
4349 | 293 |
-(void) fillSections { |
6107 | 294 |
if (self.hideSections == YES) { |
295 |
self.hideSections = NO; |
|
4349 | 296 |
NSRange range; |
297 |
range.location = 0; |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
298 |
range.length = 1; |
4349 | 299 |
NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:range]; |
300 |
[self.tableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
|
301 |
self.tableView.scrollEnabled = YES; |
|
302 |
||
303 |
[[self.view viewWithTag:LABEL_TAG] removeFromSuperview]; |
|
304 |
} |
|
305 |
} |
|
306 |
||
307 |
-(void) emptySections { |
|
308 |
hideSections = YES; |
|
309 |
NSRange range; |
|
310 |
range.location = 0; |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
311 |
range.length = 1; |
4349 | 312 |
NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:range]; |
313 |
[self.tableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
|
314 |
self.tableView.scrollEnabled = NO; |
|
315 |
||
316 |
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 60); |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5455
diff
changeset
|
317 |
UILabel *theLabel = [[UILabel alloc] initWithFrame:frame |
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5455
diff
changeset
|
318 |
andTitle:NSLocalizedString(@"Missions don't need further configuration",@"")]; |
4349 | 319 |
theLabel.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2); |
320 |
theLabel.numberOfLines = 2; |
|
321 |
theLabel.tag = LABEL_TAG; |
|
322 |
||
323 |
[self.view addSubview:theLabel]; |
|
324 |
[theLabel release]; |
|
325 |
} |
|
326 |
||
3547 | 327 |
#pragma mark - |
328 |
#pragma mark Memory management |
|
329 |
-(void) didReceiveMemoryWarning { |
|
5002
a9c44a8ffec8
we get our own AppDelegate, subclassing SDL_UikitAppDelegate so that we don't have to mess with sdl build system
koda
parents:
4976
diff
changeset
|
330 |
if ([[HedgewarsAppDelegate sharedAppDelegate] isInGame]) { |
3971 | 331 |
self.lastIndexPath_sc = nil; |
332 |
self.lastIndexPath_we = nil; |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
333 |
self.lastIndexPath_lu = nil; |
6107 | 334 |
self.selectedScheme = nil; |
335 |
self.selectedWeapon = nil; |
|
336 |
self.selectedScript = nil; |
|
337 |
self.scriptCommand = nil; |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
338 |
self.topControl = nil; |
3971 | 339 |
} |
6107 | 340 |
self.listOfSchemes = nil; |
341 |
self.listOfWeapons = nil; |
|
342 |
self.listOfScripts = nil; |
|
343 |
MSG_MEMCLEAN(); |
|
3547 | 344 |
[super didReceiveMemoryWarning]; |
345 |
} |
|
346 |
||
347 |
-(void) viewDidUnload { |
|
348 |
self.listOfSchemes = nil; |
|
349 |
self.listOfWeapons = nil; |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
350 |
self.listOfScripts = nil; |
3547 | 351 |
self.lastIndexPath_sc = nil; |
352 |
self.lastIndexPath_we = nil; |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
353 |
self.lastIndexPath_lu = nil; |
3547 | 354 |
self.selectedScheme = nil; |
355 |
self.selectedWeapon = nil; |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
356 |
self.selectedScript = nil; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
357 |
self.scriptCommand = nil; |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
358 |
self.topControl = nil; |
3547 | 359 |
MSG_DIDUNLOAD(); |
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3659
diff
changeset
|
360 |
[super viewDidUnload]; |
3547 | 361 |
} |
362 |
||
363 |
-(void) dealloc { |
|
5208 | 364 |
releaseAndNil(listOfSchemes); |
365 |
releaseAndNil(listOfWeapons); |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
366 |
releaseAndNil(listOfScripts); |
5208 | 367 |
releaseAndNil(lastIndexPath_sc); |
368 |
releaseAndNil(lastIndexPath_we); |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
369 |
releaseAndNil(lastIndexPath_lu); |
5208 | 370 |
releaseAndNil(selectedScheme); |
371 |
releaseAndNil(selectedWeapon); |
|
5455
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
372 |
releaseAndNil(selectedScript); |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
373 |
releaseAndNil(scriptCommand); |
df05cdb998ed
add support for 'gameplay modes' on ios, renamed into 'style'; also colored in grey some segmented controls and moved some ui objects
koda
parents:
5451
diff
changeset
|
374 |
releaseAndNil(topControl); |
3547 | 375 |
[super dealloc]; |
376 |
} |
|
377 |
||
378 |
||
379 |
@end |
|
380 |