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