author | antonc27 <antonc27@mail.ru> |
Thu, 10 Sep 2015 01:49:15 +0200 | |
branch | ios-revival |
changeset 11148 | 064a53861759 |
parent 11131 | 29d0a5c04b3b |
child 11279 | c0d6f6ffa798 |
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 |
#define checkValueString(detailString,labelSting,sliderRef); \ |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
29 |
if ([labelSting isEqualToString:@"Turn Time"] && (NSInteger) sliderRef.value == 100) \ |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
30 |
detailString = @"∞"; \ |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
31 |
else if ([labelSting isEqualToString:@"Water Rise Amount"] && (NSInteger) sliderRef.value == 100) \ |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
32 |
detailString = NSLocalizedString(@"Nvr",@"Short for 'Never'"); \ |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
33 |
else if ([labelSting isEqualToString:@"Crate Drop Turns"] && (NSInteger) sliderRef.value == 0) \ |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
34 |
detailString = NSLocalizedString(@"Nvr",@"Short for 'Never'"); \ |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
35 |
else if ([labelSting isEqualToString:@"Mines Time"] && (NSInteger) sliderRef.value == -1) \ |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
36 |
detailString = NSLocalizedString(@"Rnd",@"Short for 'Random'"); \ |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
37 |
else \ |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
38 |
detailString = [NSString stringWithFormat:@"%d",(NSInteger) sliderRef.value]; |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
39 |
|
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
40 |
|
3547 | 41 |
@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
|
42 |
@synthesize schemeName, schemeDictionary, basicSettingList, gameModifierArray; |
3547 | 43 |
|
44 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
45 |
return rotationManager(interfaceOrientation); |
|
46 |
} |
|
47 |
||
48 |
#pragma mark - |
|
49 |
#pragma mark View lifecycle |
|
50 |
-(void) viewDidLoad { |
|
51 |
[super viewDidLoad]; |
|
52 |
||
3753 | 53 |
// 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
|
54 |
NSArray *mods = [[NSArray alloc] initWithContentsOfFile:GAMEMODS_FILE()]; |
3547 | 55 |
self.gameModifierArray = mods; |
56 |
[mods release]; |
|
3697 | 57 |
|
3753 | 58 |
// 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
|
59 |
NSArray *basicSettings = [[NSArray alloc] initWithContentsOfFile:BASICFLAGS_FILE()]; |
3547 | 60 |
self.basicSettingList = basicSettings; |
61 |
[basicSettings release]; |
|
3697 | 62 |
|
3659 | 63 |
self.title = NSLocalizedString(@"Edit scheme preferences",@""); |
3547 | 64 |
} |
65 |
||
66 |
// load from file |
|
67 |
-(void) viewWillAppear:(BOOL) animated { |
|
68 |
[super viewWillAppear:animated]; |
|
3697 | 69 |
|
3659 | 70 |
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
|
71 |
NSMutableDictionary *scheme = [[NSMutableDictionary alloc] initWithContentsOfFile:schemeFile]; |
3621 | 72 |
[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
|
73 |
self.schemeDictionary = scheme; |
3547 | 74 |
[scheme release]; |
3697 | 75 |
|
3547 | 76 |
[self.tableView reloadData]; |
77 |
} |
|
78 |
||
79 |
// save to file |
|
80 |
-(void) viewWillDisappear:(BOOL) animated { |
|
81 |
[super viewWillDisappear:animated]; |
|
3697 | 82 |
|
3659 | 83 |
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
|
84 |
[self.schemeDictionary writeToFile:schemeFile atomically:YES]; |
3547 | 85 |
[schemeFile release]; |
86 |
} |
|
87 |
||
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
88 |
// 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
|
89 |
-(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
|
90 |
if (IS_IPAD() == NO) |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
91 |
return; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
92 |
[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
|
93 |
} |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
94 |
|
3547 | 95 |
#pragma mark - |
3659 | 96 |
#pragma mark editableCellView delegate |
3547 | 97 |
// set the new value |
3697 | 98 |
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue { |
3782 | 99 |
if (tagValue == 0) { |
100 |
// delete old file |
|
101 |
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] error:NULL]; |
|
102 |
// update filename |
|
103 |
self.schemeName = textString; |
|
104 |
// save new file |
|
105 |
[self.schemeDictionary writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] atomically:YES]; |
|
106 |
} else { |
|
107 |
[self.schemeDictionary setObject:textString forKey:@"description"]; |
|
108 |
} |
|
3547 | 109 |
} |
110 |
||
111 |
#pragma mark - |
|
112 |
#pragma mark Table view data source |
|
113 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
114 |
return 3; |
|
115 |
} |
|
116 |
||
117 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
118 |
switch (section) { |
|
119 |
case 0: |
|
3782 | 120 |
return 2; |
3547 | 121 |
break; |
122 |
case 1: |
|
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
123 |
return [[self.schemeDictionary objectForKey:@"basic"] count]; |
3547 | 124 |
break; |
125 |
case 2: |
|
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
126 |
return [[self.schemeDictionary objectForKey:@"gamemod"] count]; |
3547 | 127 |
default: |
128 |
break; |
|
129 |
} |
|
130 |
return 0; |
|
131 |
} |
|
132 |
||
3573 | 133 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3547 | 134 |
static NSString *CellIdentifier0 = @"Cell0"; |
135 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
136 |
static NSString *CellIdentifier2 = @"Cell2"; |
|
3697 | 137 |
|
3547 | 138 |
UITableViewCell *cell = nil; |
3659 | 139 |
EditableCellView *editableCell = nil; |
3547 | 140 |
NSInteger row = [indexPath row]; |
3697 | 141 |
|
3547 | 142 |
switch ([indexPath section]) { |
143 |
case 0: |
|
3659 | 144 |
editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
145 |
if (editableCell == nil) { |
|
3697 | 146 |
editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault |
3547 | 147 |
reuseIdentifier:CellIdentifier0] autorelease]; |
3659 | 148 |
editableCell.delegate = self; |
3547 | 149 |
} |
3782 | 150 |
editableCell.tag = row; |
151 |
editableCell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
152 |
editableCell.imageView.image = nil; |
|
3659 | 153 |
editableCell.detailTextLabel.text = nil; |
8441 | 154 |
|
3782 | 155 |
if (row == 0) { |
156 |
editableCell.textField.text = self.schemeName; |
|
4284
57a501a69e5f
update iFrontend with new schemes and weaps, fix up smaller glitches
koda
parents:
4213
diff
changeset
|
157 |
editableCell.textField.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
3782 | 158 |
} else { |
3825 | 159 |
editableCell.minimumCharacters = 0; |
3782 | 160 |
editableCell.textField.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; |
161 |
editableCell.textField.text = [self.schemeDictionary objectForKey:@"description"]; |
|
162 |
editableCell.textField.placeholder = NSLocalizedString(@"You can add a description if you wish",@""); |
|
163 |
} |
|
3659 | 164 |
cell = editableCell; |
3547 | 165 |
break; |
166 |
case 1: |
|
3573 | 167 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
168 |
NSDictionary *detail = [self.basicSettingList objectAtIndex:row]; |
|
169 |
// need to offset this section (see format in CommodityFunctions.m and above) |
|
3547 | 170 |
if (cell == nil) { |
3697 | 171 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 |
3547 | 172 |
reuseIdentifier:CellIdentifier1] autorelease]; |
3697 | 173 |
|
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
174 |
UISlider *slider = [[UISlider alloc] init]; |
3573 | 175 |
[slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged]; |
176 |
[cell.contentView addSubview:slider]; |
|
177 |
[slider release]; |
|
3697 | 178 |
|
3573 | 179 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 200, 30)]; |
180 |
label.tag = LABEL_TAG; |
|
181 |
label.backgroundColor = [UIColor clearColor]; |
|
182 |
label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
|
183 |
[cell.contentView addSubview:label]; |
|
184 |
[label release]; |
|
3547 | 185 |
} |
3697 | 186 |
|
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
|
187 |
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
|
188 |
[[self.basicSettingList objectAtIndex:row] objectForKey:@"image"]]]; |
3623 | 189 |
cell.imageView.image = img; |
3547 | 190 |
[img release]; |
3697 | 191 |
|
3573 | 192 |
UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG]; |
11131
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
193 |
NSString *basicSettingTitleKey = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"]; |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
194 |
cellLabel.text = NSLocalizedStringFromTable(basicSettingTitleKey, @"Scheme", nil); |
5181 | 195 |
cellLabel.adjustsFontSizeToFitWidth = YES; |
3697 | 196 |
|
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
197 |
// 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
|
198 |
UISlider *cellSlider = nil; |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
199 |
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
|
200 |
if ([oneView isMemberOfClass:[UISlider class]]) { |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
201 |
cellSlider = (UISlider *)oneView; |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
202 |
break; |
8441 | 203 |
} |
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
204 |
} |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
// redraw the slider here |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
210 |
NSInteger hOffset = 260; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
211 |
NSInteger vOffset = 12; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
212 |
NSInteger sliderLength = 150; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
213 |
if (IS_IPAD()) { |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
214 |
hOffset = 310; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
215 |
sliderLength = 230; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
216 |
if (IS_ON_PORTRAIT()) { |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
217 |
hOffset = 50; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
218 |
vOffset = 40; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
219 |
sliderLength = 285; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
220 |
} |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
221 |
} |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
222 |
cellSlider.frame = CGRectMake(hOffset, vOffset, sliderLength, 23); |
3697 | 223 |
|
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
224 |
NSString *prestring = nil; |
11131
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
225 |
checkValueString(prestring,basicSettingTitleKey,cellSlider); |
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
226 |
|
4210
caa9b08990eb
revert 4200:dd54999c2822 - it was breaking schemes. koda. just leave this alone until next release
nemo
parents:
4208
diff
changeset
|
227 |
// forced to use this weird format otherwise the label disappears when size of the text is bigger than the original |
3574 | 228 |
while ([prestring length] <= 4) |
229 |
prestring = [NSString stringWithFormat:@" %@",prestring]; |
|
230 |
cell.detailTextLabel.text = prestring; |
|
3697 | 231 |
|
3574 | 232 |
cell.selectionStyle = UITableViewCellSelectionStyleBlue; |
3547 | 233 |
break; |
234 |
case 2: |
|
3573 | 235 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier2]; |
3547 | 236 |
if (cell == nil) { |
237 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
|
238 |
reuseIdentifier:CellIdentifier2] autorelease]; |
|
239 |
UISwitch *onOff = [[UISwitch alloc] init]; |
|
240 |
[onOff addTarget:self action:@selector(toggleSwitch:) forControlEvents:UIControlEventValueChanged]; |
|
241 |
cell.accessoryView = onOff; |
|
242 |
[onOff release]; |
|
243 |
} |
|
3697 | 244 |
|
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
245 |
UISwitch *switcher = (UISwitch *)cell.accessoryView; |
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
246 |
switcher.tag = SWITCH_TAG + row; |
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
247 |
[switcher setOn:[[[self.schemeDictionary objectForKey:@"gamemod"] objectAtIndex:row] boolValue] animated:NO]; |
8441 | 248 |
|
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
|
249 |
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
|
250 |
[[self.gameModifierArray objectAtIndex:row] objectForKey:@"image"]]]; |
3547 | 251 |
cell.imageView.image = image; |
252 |
[image release]; |
|
6095 | 253 |
cell.imageView.layer.cornerRadius = 6.0f; |
254 |
cell.imageView.layer.masksToBounds = YES; |
|
11131
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
255 |
NSString *gameModTitleKey = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"]; |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
256 |
cell.textLabel.text = NSLocalizedStringFromTable(gameModTitleKey, @"Scheme", nil); |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
257 |
NSString *gameModDescKey = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"]; |
29d0a5c04b3b
- Localization for SingleSchemeViewController fixed
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
258 |
cell.detailTextLabel.text = NSLocalizedStringFromTable(gameModDescKey, @"Scheme", nil); |
4000
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
259 |
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; |
ddc4a09889e7
engine: reorder GameFlags and update files, frontend and other stuff
koda
parents:
3996
diff
changeset
|
260 |
cell.detailTextLabel.minimumFontSize = 6; |
3697 | 261 |
|
3574 | 262 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
3547 | 263 |
} |
3697 | 264 |
|
3547 | 265 |
return cell; |
266 |
} |
|
267 |
||
268 |
-(void) toggleSwitch:(id) sender { |
|
269 |
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
|
270 |
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
|
271 |
[array replaceObjectAtIndex:theSwitch.tag-SWITCH_TAG withObject:[NSNumber numberWithBool:theSwitch.on]]; |
3547 | 272 |
} |
273 |
||
3573 | 274 |
-(void) sliderChanged:(id) sender { |
275 |
// the slider that changed is sent as object |
|
276 |
UISlider *theSlider = (UISlider *)sender; |
|
277 |
// 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
|
278 |
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:theSlider.tag-SLIDER_TAG inSection:1]; |
3573 | 279 |
// get its cell |
280 |
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
|
281 |
// grab the associated labels |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
282 |
UILabel *detailLabel = (UILabel *)cell.detailTextLabel; |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
283 |
UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG]; |
3573 | 284 |
// modify it |
4211
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
285 |
|
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
286 |
checkValueString(detailLabel.text,cellLabel.text,theSlider); |
7dcbd236ca59
this time i got it right, i'm sure of it; TEST ANYWAYS
koda
parents:
4210
diff
changeset
|
287 |
|
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
|
288 |
// 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
|
289 |
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
|
290 |
[array replaceObjectAtIndex:theSlider.tag-SLIDER_TAG withObject:[NSNumber numberWithInteger:theSlider.value]]; |
3573 | 291 |
} |
3547 | 292 |
|
293 |
#pragma mark - |
|
294 |
#pragma mark Table view delegate |
|
295 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
3573 | 296 |
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; |
3659 | 297 |
EditableCellView *editableCell = nil; |
3573 | 298 |
UISlider *cellSlider = nil; |
3697 | 299 |
|
3573 | 300 |
switch ([indexPath section]) { |
301 |
case 0: |
|
3659 | 302 |
editableCell = (EditableCellView *)cell; |
303 |
[editableCell replyKeyboard]; |
|
3573 | 304 |
break; |
305 |
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
|
306 |
cellSlider = (UISlider *)[cell.contentView viewWithTag:[indexPath row]+SLIDER_TAG]; |
3573 | 307 |
[cellSlider setValue:[[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] floatValue] animated:YES]; |
308 |
[self sliderChanged:cellSlider]; |
|
309 |
//cell.detailTextLabel.text = [[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] stringValue]; |
|
310 |
break; |
|
311 |
case 2: |
|
3574 | 312 |
/*sw = (UISwitch *)cell.accessoryView; |
3573 | 313 |
[sw setOn:!sw.on animated:YES]; |
3574 | 314 |
[self toggleSwitch:sw];*/ |
3573 | 315 |
break; |
316 |
default: |
|
317 |
break; |
|
3547 | 318 |
} |
3697 | 319 |
|
3547 | 320 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
321 |
} |
|
322 |
||
3659 | 323 |
-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { |
324 |
NSString *sectionTitle = nil; |
|
325 |
switch (section) { |
|
326 |
case 0: |
|
327 |
sectionTitle = NSLocalizedString(@"Scheme Name", @""); |
|
328 |
break; |
|
329 |
case 1: |
|
330 |
sectionTitle = NSLocalizedString(@"Game Settings", @""); |
|
331 |
break; |
|
332 |
case 2: |
|
333 |
sectionTitle = NSLocalizedString(@"Game Modifiers", @""); |
|
334 |
break; |
|
335 |
default: |
|
336 |
DLog(@"nope"); |
|
337 |
break; |
|
338 |
} |
|
339 |
return sectionTitle; |
|
340 |
} |
|
3547 | 341 |
|
6672
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
342 |
-(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
|
343 |
if ([indexPath section] == 0) |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
344 |
return aTableView.rowHeight; |
4f728ccdd06b
fixed a little event propagation problem, added rotation support to the scheme setting page
koda
parents:
6095
diff
changeset
|
345 |
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
|
346 |
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
|
347 |
else |
4113 | 348 |
return 56; |
349 |
} |
|
350 |
||
3547 | 351 |
#pragma mark - |
352 |
#pragma mark Memory management |
|
353 |
-(void) didReceiveMemoryWarning { |
|
354 |
[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
|
355 |
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
|
356 |
self.gameModifierArray = nil; |
3547 | 357 |
} |
358 |
||
359 |
-(void) viewDidUnload { |
|
3659 | 360 |
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
|
361 |
self.schemeDictionary = nil; |
3547 | 362 |
self.basicSettingList = nil; |
363 |
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
|
364 |
MSG_DIDUNLOAD(); |
3547 | 365 |
[super viewDidUnload]; |
366 |
} |
|
367 |
||
368 |
-(void) dealloc { |
|
5208 | 369 |
releaseAndNil(schemeName); |
370 |
releaseAndNil(schemeDictionary); |
|
371 |
releaseAndNil(basicSettingList); |
|
372 |
releaseAndNil(gameModifierArray); |
|
3547 | 373 |
[super dealloc]; |
374 |
} |
|
375 |
||
376 |
@end |