author | Wuzzy <almikes@aol.com> |
Sat, 30 Sep 2017 23:52:08 +0200 | |
changeset 12627 | 07fdda8c13a2 |
parent 11296 | 83738cdd750d |
child 12877 | 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:
8441
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3829 | 17 |
*/ |
18 |
||
3547 | 19 |
|
20 |
#import "SingleSchemeViewController.h" |
|
21 |
#import <QuartzCore/QuartzCore.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:
5982
diff
changeset
|
22 |
|
3547 | 23 |
|
3573 | 24 |
#define LABEL_TAG 12345 |
25 |
#define SLIDER_TAG 54321 |
|
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
26 |
#define SWITCH_TAG 67890 |
3573 | 27 |
|
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
28 |
|
3547 | 29 |
@implementation SingleSchemeViewController |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
30 |
@synthesize schemeName, schemeDictionary, basicSettingList, gameModifierArray; |
3547 | 31 |
|
32 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
33 |
return rotationManager(interfaceOrientation); |
|
34 |
} |
|
35 |
||
36 |
#pragma mark - |
|
37 |
#pragma mark View lifecycle |
|
38 |
-(void) viewDidLoad { |
|
39 |
[super viewDidLoad]; |
|
40 |
||
3753 | 41 |
// title, description, image name (+btn) |
5185
7607a64e1853
remove the trailing _en from scheme data and use the macros available instead of creating a string every time
koda
parents:
5181
diff
changeset
|
42 |
NSArray *mods = [[NSArray alloc] initWithContentsOfFile:GAMEMODS_FILE()]; |
3547 | 43 |
self.gameModifierArray = mods; |
44 |
[mods release]; |
|
3697 | 45 |
|
3753 | 46 |
// title, image name (+icon), default value, max value, min value |
5185
7607a64e1853
remove the trailing _en from scheme data and use the macros available instead of creating a string every time
koda
parents:
5181
diff
changeset
|
47 |
NSArray *basicSettings = [[NSArray alloc] initWithContentsOfFile:BASICFLAGS_FILE()]; |
3547 | 48 |
self.basicSettingList = basicSettings; |
49 |
[basicSettings release]; |
|
3697 | 50 |
|
3659 | 51 |
self.title = NSLocalizedString(@"Edit scheme preferences",@""); |
3547 | 52 |
} |
53 |
||
54 |
// load from file |
|
55 |
-(void) viewWillAppear:(BOOL) animated { |
|
56 |
[super viewWillAppear:animated]; |
|
3697 | 57 |
|
3659 | 58 |
NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName]; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
59 |
NSMutableDictionary *scheme = [[NSMutableDictionary alloc] initWithContentsOfFile:schemeFile]; |
3621 | 60 |
[schemeFile release]; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
61 |
self.schemeDictionary = scheme; |
3547 | 62 |
[scheme release]; |
3697 | 63 |
|
3547 | 64 |
[self.tableView reloadData]; |
65 |
} |
|
66 |
||
67 |
// save to file |
|
68 |
-(void) viewWillDisappear:(BOOL) animated { |
|
69 |
[super viewWillDisappear:animated]; |
|
3697 | 70 |
|
3659 | 71 |
NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName]; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
72 |
[self.schemeDictionary writeToFile:schemeFile atomically:YES]; |
3547 | 73 |
[schemeFile release]; |
74 |
} |
|
75 |
||
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
76 |
// force a redraw of the game mod section to reposition the slider |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
77 |
-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
78 |
if (IS_IPAD() == NO) |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
79 |
return; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
80 |
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade]; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
81 |
} |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
82 |
|
3547 | 83 |
#pragma mark - |
3659 | 84 |
#pragma mark editableCellView delegate |
3547 | 85 |
// set the new value |
3697 | 86 |
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue { |
3782 | 87 |
if (tagValue == 0) { |
88 |
// delete old file |
|
89 |
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] error:NULL]; |
|
90 |
// update filename |
|
91 |
self.schemeName = textString; |
|
92 |
// save new file |
|
93 |
[self.schemeDictionary writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] atomically:YES]; |
|
94 |
} else { |
|
95 |
[self.schemeDictionary setObject:textString forKey:@"description"]; |
|
96 |
} |
|
3547 | 97 |
} |
98 |
||
99 |
#pragma mark - |
|
100 |
#pragma mark Table view data source |
|
101 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
102 |
return 3; |
|
103 |
} |
|
104 |
||
105 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
106 |
switch (section) { |
|
107 |
case 0: |
|
3782 | 108 |
return 2; |
3547 | 109 |
break; |
110 |
case 1: |
|
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
111 |
return [[self.schemeDictionary objectForKey:@"basic"] count]; |
3547 | 112 |
break; |
113 |
case 2: |
|
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
114 |
return [[self.schemeDictionary objectForKey:@"gamemod"] count]; |
3547 | 115 |
default: |
116 |
break; |
|
117 |
} |
|
118 |
return 0; |
|
119 |
} |
|
120 |
||
3573 | 121 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3547 | 122 |
static NSString *CellIdentifier0 = @"Cell0"; |
123 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
124 |
static NSString *CellIdentifier2 = @"Cell2"; |
|
3697 | 125 |
|
3547 | 126 |
UITableViewCell *cell = nil; |
3659 | 127 |
EditableCellView *editableCell = nil; |
3547 | 128 |
NSInteger row = [indexPath row]; |
3697 | 129 |
|
3547 | 130 |
switch ([indexPath section]) { |
131 |
case 0: |
|
3659 | 132 |
editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
133 |
if (editableCell == nil) { |
|
3697 | 134 |
editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault |
3547 | 135 |
reuseIdentifier:CellIdentifier0] autorelease]; |
3659 | 136 |
editableCell.delegate = self; |
3547 | 137 |
} |
3782 | 138 |
editableCell.tag = row; |
139 |
editableCell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
140 |
editableCell.imageView.image = nil; |
|
3659 | 141 |
editableCell.detailTextLabel.text = nil; |
8441 | 142 |
|
3782 | 143 |
if (row == 0) { |
144 |
editableCell.textField.text = self.schemeName; |
|
4284
57a501a69e5f
update iFrontend with new schemes and weaps, fix up smaller glitches
koda
parents:
4213
diff
changeset
|
145 |
editableCell.textField.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
3782 | 146 |
} else { |
3825 | 147 |
editableCell.minimumCharacters = 0; |
3782 | 148 |
editableCell.textField.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; |
149 |
editableCell.textField.text = [self.schemeDictionary objectForKey:@"description"]; |
|
150 |
editableCell.textField.placeholder = NSLocalizedString(@"You can add a description if you wish",@""); |
|
151 |
} |
|
3659 | 152 |
cell = editableCell; |
3547 | 153 |
break; |
154 |
case 1: |
|
3573 | 155 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
156 |
NSDictionary *detail = [self.basicSettingList objectAtIndex:row]; |
|
157 |
// need to offset this section (see format in CommodityFunctions.m and above) |
|
3547 | 158 |
if (cell == nil) { |
3697 | 159 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 |
3547 | 160 |
reuseIdentifier:CellIdentifier1] autorelease]; |
3697 | 161 |
|
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
162 |
UISlider *slider = [[UISlider alloc] init]; |
3573 | 163 |
[slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged]; |
164 |
[cell.contentView addSubview:slider]; |
|
165 |
[slider release]; |
|
3697 | 166 |
|
3573 | 167 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 200, 30)]; |
168 |
label.tag = LABEL_TAG; |
|
169 |
label.backgroundColor = [UIColor clearColor]; |
|
170 |
label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
|
171 |
[cell.contentView addSubview:label]; |
|
172 |
[label release]; |
|
3547 | 173 |
} |
3697 | 174 |
|
5982
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5208
diff
changeset
|
175 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/icon%@.png",ICONS_DIRECTORY(), |
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5208
diff
changeset
|
176 |
[[self.basicSettingList objectAtIndex:row] objectForKey:@"image"]]]; |
3623 | 177 |
cell.imageView.image = img; |
3547 | 178 |
[img release]; |
3697 | 179 |
|
3573 | 180 |
UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG]; |
11131
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
181 |
NSString *basicSettingTitleKey = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"]; |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
182 |
cellLabel.text = NSLocalizedStringFromTable(basicSettingTitleKey, @"Scheme", nil); |
5181 | 183 |
cellLabel.adjustsFontSizeToFitWidth = YES; |
3697 | 184 |
|
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
185 |
// can't use the viewWithTag method because row is dynamic |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
186 |
UISlider *cellSlider = nil; |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
187 |
for (UIView *oneView in cell.contentView.subviews) { |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
188 |
if ([oneView isMemberOfClass:[UISlider class]]) { |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
189 |
cellSlider = (UISlider *)oneView; |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
190 |
break; |
8441 | 191 |
} |
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
192 |
} |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
193 |
cellSlider.tag = SLIDER_TAG + row; |
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
194 |
cellSlider.maximumValue = [[detail objectForKey:@"max"] floatValue]; |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
195 |
cellSlider.minimumValue = [[detail objectForKey:@"min"] floatValue]; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
196 |
cellSlider.value = [[[self.schemeDictionary objectForKey:@"basic"] objectAtIndex:row] floatValue]; |
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
197 |
// redraw the slider here |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
198 |
NSInteger hOffset = 260; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
199 |
NSInteger vOffset = 12; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
200 |
NSInteger sliderLength = 150; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
201 |
if (IS_IPAD()) { |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
202 |
hOffset = 310; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
203 |
sliderLength = 230; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
204 |
if (IS_ON_PORTRAIT()) { |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
205 |
hOffset = 50; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
206 |
vOffset = 40; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
207 |
sliderLength = 285; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
208 |
} |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
209 |
} |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
210 |
cellSlider.frame = CGRectMake(hOffset, vOffset, sliderLength, 23); |
3697 | 211 |
|
11295
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
212 |
NSString *prestring = [self localizedValueStringForKey:basicSettingTitleKey andSlider:cellSlider]; |
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
213 |
|
4210
caa9b08990eb
revert 4200:dd54999c2822 - it was breaking schemes. koda. just leave this alone until next release
nemo
parents:
4208
diff
changeset
|
214 |
// forced to use this weird format otherwise the label disappears when size of the text is bigger than the original |
3574 | 215 |
while ([prestring length] <= 4) |
216 |
prestring = [NSString stringWithFormat:@" %@",prestring]; |
|
217 |
cell.detailTextLabel.text = prestring; |
|
3697 | 218 |
|
3574 | 219 |
cell.selectionStyle = UITableViewCellSelectionStyleBlue; |
3547 | 220 |
break; |
221 |
case 2: |
|
3573 | 222 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier2]; |
3547 | 223 |
if (cell == nil) { |
224 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
|
225 |
reuseIdentifier:CellIdentifier2] autorelease]; |
|
226 |
UISwitch *onOff = [[UISwitch alloc] init]; |
|
227 |
[onOff addTarget:self action:@selector(toggleSwitch:) forControlEvents:UIControlEventValueChanged]; |
|
228 |
cell.accessoryView = onOff; |
|
229 |
[onOff release]; |
|
230 |
} |
|
3697 | 231 |
|
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
232 |
UISwitch *switcher = (UISwitch *)cell.accessoryView; |
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
233 |
switcher.tag = SWITCH_TAG + row; |
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
234 |
[switcher setOn:[[[self.schemeDictionary objectForKey:@"gamemod"] objectAtIndex:row] boolValue] animated:NO]; |
8441 | 235 |
|
5982
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5208
diff
changeset
|
236 |
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/btn%@.png",ICONS_DIRECTORY(), |
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5208
diff
changeset
|
237 |
[[self.gameModifierArray objectAtIndex:row] objectForKey:@"image"]]]; |
3547 | 238 |
cell.imageView.image = image; |
239 |
[image release]; |
|
6095 | 240 |
cell.imageView.layer.cornerRadius = 6.0f; |
241 |
cell.imageView.layer.masksToBounds = YES; |
|
11131
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
242 |
NSString *gameModTitleKey = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"]; |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
243 |
cell.textLabel.text = NSLocalizedStringFromTable(gameModTitleKey, @"Scheme", nil); |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
244 |
NSString *gameModDescKey = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"]; |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
245 |
cell.detailTextLabel.text = NSLocalizedStringFromTable(gameModDescKey, @"Scheme", nil); |
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
246 |
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; |
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
247 |
cell.detailTextLabel.minimumFontSize = 6; |
3697 | 248 |
|
3574 | 249 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
3547 | 250 |
} |
3697 | 251 |
|
3547 | 252 |
return cell; |
253 |
} |
|
254 |
||
255 |
-(void) toggleSwitch:(id) sender { |
|
256 |
UISwitch *theSwitch = (UISwitch *)sender; |
|
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
257 |
NSMutableArray *array = [self.schemeDictionary objectForKey:@"gamemod"]; |
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
258 |
[array replaceObjectAtIndex:theSwitch.tag-SWITCH_TAG withObject:[NSNumber numberWithBool:theSwitch.on]]; |
3547 | 259 |
} |
260 |
||
3573 | 261 |
-(void) sliderChanged:(id) sender { |
262 |
// the slider that changed is sent as object |
|
263 |
UISlider *theSlider = (UISlider *)sender; |
|
264 |
// create the indexPath of the row of the slider |
|
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
265 |
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:theSlider.tag-SLIDER_TAG inSection:1]; |
3573 | 266 |
// get its cell |
267 |
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; |
|
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
268 |
// grab the associated labels |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
269 |
UILabel *detailLabel = (UILabel *)cell.detailTextLabel; |
3573 | 270 |
// modify it |
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
271 |
|
11286
c0d6f6ffa798
- Fix for localization of game settings detailLabel in SingleSchemeViewController
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
272 |
NSString *basicSettingTitleKey = [[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"title"]; |
11295
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
273 |
detailLabel.text = [self localizedValueStringForKey:basicSettingTitleKey andSlider:theSlider]; |
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
274 |
|
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
275 |
// save changes in the main array |
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
276 |
NSMutableArray *array = [self.schemeDictionary objectForKey:@"basic"]; |
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
11131
diff
changeset
|
277 |
[array replaceObjectAtIndex:theSlider.tag-SLIDER_TAG withObject:[NSNumber numberWithInteger:theSlider.value]]; |
3573 | 278 |
} |
3547 | 279 |
|
280 |
#pragma mark - |
|
281 |
#pragma mark Table view delegate |
|
282 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
3573 | 283 |
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; |
3659 | 284 |
EditableCellView *editableCell = nil; |
3573 | 285 |
UISlider *cellSlider = nil; |
3697 | 286 |
|
3573 | 287 |
switch ([indexPath section]) { |
288 |
case 0: |
|
3659 | 289 |
editableCell = (EditableCellView *)cell; |
290 |
[editableCell replyKeyboard]; |
|
3573 | 291 |
break; |
292 |
case 1: |
|
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
293 |
cellSlider = (UISlider *)[cell.contentView viewWithTag:[indexPath row]+SLIDER_TAG]; |
3573 | 294 |
[cellSlider setValue:[[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] floatValue] animated:YES]; |
295 |
[self sliderChanged:cellSlider]; |
|
296 |
//cell.detailTextLabel.text = [[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] stringValue]; |
|
297 |
break; |
|
298 |
case 2: |
|
3574 | 299 |
/*sw = (UISwitch *)cell.accessoryView; |
3573 | 300 |
[sw setOn:!sw.on animated:YES]; |
3574 | 301 |
[self toggleSwitch:sw];*/ |
3573 | 302 |
break; |
303 |
default: |
|
304 |
break; |
|
3547 | 305 |
} |
3697 | 306 |
|
3547 | 307 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
308 |
} |
|
309 |
||
3659 | 310 |
-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { |
311 |
NSString *sectionTitle = nil; |
|
312 |
switch (section) { |
|
313 |
case 0: |
|
314 |
sectionTitle = NSLocalizedString(@"Scheme Name", @""); |
|
315 |
break; |
|
316 |
case 1: |
|
317 |
sectionTitle = NSLocalizedString(@"Game Settings", @""); |
|
318 |
break; |
|
319 |
case 2: |
|
320 |
sectionTitle = NSLocalizedString(@"Game Modifiers", @""); |
|
321 |
break; |
|
322 |
default: |
|
323 |
DLog(@"nope"); |
|
324 |
break; |
|
325 |
} |
|
326 |
return sectionTitle; |
|
327 |
} |
|
3547 | 328 |
|
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
329 |
-(CGFloat) tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
330 |
if ([indexPath section] == 0) |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
331 |
return aTableView.rowHeight; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
332 |
else if ([indexPath section] == 1) |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
333 |
return IS_ON_PORTRAIT() ? 72 : aTableView.rowHeight; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
334 |
else |
4113 | 335 |
return 56; |
336 |
} |
|
337 |
||
11295
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
338 |
#pragma mark - Helper methods |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
339 |
|
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
340 |
- (NSString *)localizedValueStringForKey:(NSString *)keyString andSlider:(UISlider *)slider |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
341 |
{ |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
342 |
NSInteger sliderValue = (NSInteger)slider.value; |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
343 |
|
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
344 |
if ([keyString isEqualToString:@"Turn Time"] && sliderValue == 100) |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
345 |
return @"∞"; |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
346 |
else if ([keyString isEqualToString:@"Water Rise Amount"] && sliderValue == 100) |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
347 |
return NSLocalizedString(@"Nvr", @"Short for 'Never'"); |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
348 |
else if ([keyString isEqualToString:@"Crate Drop Turns"] && sliderValue == 0) |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
349 |
return NSLocalizedString(@"Nvr", @"Short for 'Never'"); |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
350 |
else if ([keyString isEqualToString:@"Mines Time"] && sliderValue == -1) |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
351 |
return NSLocalizedString(@"Rnd", @"Short for 'Random'"); |
11296
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
352 |
else if ([keyString isEqualToString:@"World Edge"]) |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
353 |
switch (sliderValue) |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
354 |
{ |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
355 |
case 0: |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
356 |
return NSLocalizedString(@"None", nil); |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
357 |
|
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
358 |
case 1: |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
359 |
return NSLocalizedString(@"Wrap", nil); |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
360 |
|
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
361 |
case 2: |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
362 |
return NSLocalizedString(@"Bounce", nil); |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
363 |
|
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
364 |
case 3: |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
365 |
return NSLocalizedString(@"Sea", nil); |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
366 |
|
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
367 |
default: |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
368 |
return @""; |
83738cdd750d
- Added 'World Edge' flag for Scheme Settings
antonc27 <antonc27@mail.ru>
parents:
11295
diff
changeset
|
369 |
} |
11295
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
370 |
else |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
371 |
return [NSString stringWithFormat:@"%ld", (long)sliderValue]; |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
372 |
} |
6b6d96077395
- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
antonc27 <antonc27@mail.ru>
parents:
11286
diff
changeset
|
373 |
|
3547 | 374 |
#pragma mark - |
375 |
#pragma mark Memory management |
|
376 |
-(void) didReceiveMemoryWarning { |
|
377 |
[super didReceiveMemoryWarning]; |
|
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
378 |
self.basicSettingList = nil; |
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
379 |
self.gameModifierArray = nil; |
3547 | 380 |
} |
381 |
||
382 |
-(void) viewDidUnload { |
|
3659 | 383 |
self.schemeName = nil; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3753
diff
changeset
|
384 |
self.schemeDictionary = nil; |
3547 | 385 |
self.basicSettingList = nil; |
386 |
self.gameModifierArray = nil; |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3660
diff
changeset
|
387 |
MSG_DIDUNLOAD(); |
3547 | 388 |
[super viewDidUnload]; |
389 |
} |
|
390 |
||
391 |
-(void) dealloc { |
|
5208 | 392 |
releaseAndNil(schemeName); |
393 |
releaseAndNil(schemeDictionary); |
|
394 |
releaseAndNil(basicSettingList); |
|
395 |
releaseAndNil(gameModifierArray); |
|
3547 | 396 |
[super dealloc]; |
397 |
} |
|
398 |
||
399 |
@end |