author | koda |
Sun, 10 Oct 2010 03:16:25 +0200 | |
changeset 3941 | 017b2b31e1c6 |
parent 3916 | e7d665a4ef42 |
child 3996 | eb549fd864a5 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
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> |
|
24 |
#import "CommodityFunctions.h" |
|
25 |
#import "UIImageExtra.h" |
|
26 |
||
3573 | 27 |
#define LABEL_TAG 12345 |
28 |
#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
|
29 |
#define SWITCH_TAG 67890 |
3573 | 30 |
|
3547 | 31 |
@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
|
32 |
@synthesize schemeName, schemeDictionary, basicSettingList, gameModifierArray; |
3547 | 33 |
|
34 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
35 |
return rotationManager(interfaceOrientation); |
|
36 |
} |
|
37 |
||
38 |
#pragma mark - |
|
39 |
#pragma mark View lifecycle |
|
40 |
-(void) viewDidLoad { |
|
41 |
[super viewDidLoad]; |
|
42 |
||
3753 | 43 |
// title, description, image name (+btn) |
3547 | 44 |
NSArray *mods = [[NSArray alloc] initWithObjects: |
45 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Fort Mode",@""),@"title", |
|
46 |
NSLocalizedString(@"Defend your fort and destroy the opponents (two team colours max)",@""),@"description", |
|
47 |
@"Forts",@"image",nil], |
|
48 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Divide Team",@""),@"title", |
|
49 |
NSLocalizedString(@"Teams will start on opposite sides of the terrain (two team colours max)",@""),@"description", |
|
50 |
@"TeamsDivide",@"image",nil], |
|
51 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Solid Land",@""),@"title", |
|
52 |
NSLocalizedString(@"Land can not be destroyed",@""),@"description", |
|
53 |
@"Solid",@"image",nil], |
|
54 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Add Border",@""),@"title", |
|
55 |
NSLocalizedString(@"Add an indestructable border around the terrain",@""),@"description", |
|
56 |
@"Border",@"image",nil], |
|
57 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Low Gravity",@""),@"title", |
|
58 |
NSLocalizedString(@"Lower gravity",@""),@"description", |
|
59 |
@"LowGravity",@"image",nil], |
|
60 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Laser Sight",@""),@"title", |
|
61 |
NSLocalizedString(@"Assisted aiming with laser sight",@""),@"description", |
|
62 |
@"LaserSight",@"image",nil], |
|
63 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Invulnerable",@""),@"title", |
|
64 |
NSLocalizedString(@"All hogs have a personal forcefield",@""),@"description", |
|
65 |
@"Invulnerable",@"image",nil], |
|
66 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Add Mines",@""),@"title", |
|
67 |
NSLocalizedString(@"Enable random mines",@""),@"description", |
|
68 |
@"Mines",@"image",nil], |
|
69 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Vampirism Mode",@""),@"title", |
|
70 |
NSLocalizedString(@"Gain 80% of the damage you do back in health",@""),@"description", |
|
71 |
@"Vampiric",@"image",nil], |
|
72 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Karma Mode",@""),@"title", |
|
73 |
NSLocalizedString(@"Share your opponents pain, share their damage",@""),@"description", |
|
74 |
@"Karma",@"image",nil], |
|
75 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Artillery Mode",@""),@"title", |
|
76 |
NSLocalizedString(@"Your hogs are unable to move, test your aim",@""),@"description", |
|
77 |
@"Artillery",@"image",nil], |
|
78 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Random Order",@""),@"title", |
|
79 |
NSLocalizedString(@"Order of play is random instead of in room order",@""),@"description", |
|
80 |
@"RandomOrder",@"image",nil], |
|
81 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"King Mode",@""),@"title", |
|
82 |
NSLocalizedString(@"Play with a King. If he dies, your side loses",@""),@"description", |
|
83 |
@"King",@"image",nil], |
|
84 |
[NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Place Hedgehogs",@""),@"title", |
|
85 |
NSLocalizedString(@"Take turns placing your hedgehogs pre-game",@""),@"description", |
|
86 |
@"PlaceHog",@"image",nil], |
|
87 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Clan Shares Ammo",@""),@"title", |
|
88 |
NSLocalizedString(@"Ammo is shared between all clan teams",@""),@"description", |
|
89 |
@"SharedAmmo",@"image",nil], |
|
90 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Disable Girders",@""),@"title", |
|
91 |
NSLocalizedString(@"Disable girders when generating random maps",@""),@"description", |
|
92 |
@"DisableGirders",@"image",nil], |
|
93 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Disable Land Objects",@""),@"title", |
|
94 |
NSLocalizedString(@"Disable land objects when generating maps",@""),@"description", |
|
95 |
@"DisableLandObjects",@"image",nil], |
|
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3697
diff
changeset
|
96 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"AI Survival Mode",@""),@"title", |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3697
diff
changeset
|
97 |
NSLocalizedString(@"AI-controlled hogs respawn on death",@""),@"description", |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3697
diff
changeset
|
98 |
@"AISurvival",@"image",nil], |
3547 | 99 |
nil]; |
100 |
self.gameModifierArray = mods; |
|
101 |
[mods release]; |
|
3697 | 102 |
|
3753 | 103 |
// title, image name (+icon), default value, max value, min value |
3547 | 104 |
NSArray *basicSettings = [[NSArray alloc] initWithObjects: |
3573 | 105 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Damage Modifier",@""),@"title",@"Damage",@"image", |
106 |
[NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:10],@"min",[NSNumber numberWithInt:300],@"max",nil], |
|
107 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Turn Time",@""),@"title",@"Time",@"image", |
|
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
108 |
[NSNumber numberWithInt:45],@"default",[NSNumber numberWithInt:1],@"min",[NSNumber numberWithInt:100],@"max",nil], |
3573 | 109 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Initial Health",@""),@"title",@"Health",@"image", |
110 |
[NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:50],@"min",[NSNumber numberWithInt:200],@"max",nil], |
|
111 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Sudden Death Timeout",@""),@"title",@"SuddenDeath",@"image", |
|
112 |
[NSNumber numberWithInt:15],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:50],@"max",nil], |
|
113 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Crate Drops",@""),@"title",@"Box",@"image", |
|
114 |
[NSNumber numberWithInt:5],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:9],@"max",nil], |
|
115 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Time",@""),@"title",@"Time",@"image", |
|
116 |
[NSNumber numberWithInt:3],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:3],@"max",nil], |
|
117 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Number",@""),@"title",@"Mine",@"image", |
|
118 |
[NSNumber numberWithInt:4],@"default",[NSNumber numberWithInt:1],@"min",[NSNumber numberWithInt:80],@"max",nil], |
|
119 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Dud Mines Probability",@""),@"title",@"Dud",@"image", |
|
120 |
[NSNumber numberWithInt:0],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:100],@"max",nil], |
|
121 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Explosives",@""),@"title",@"Damage",@"image", |
|
122 |
[NSNumber numberWithInt:2],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:40],@"max",nil], |
|
3547 | 123 |
nil]; |
124 |
self.basicSettingList = basicSettings; |
|
125 |
[basicSettings release]; |
|
3697 | 126 |
|
3659 | 127 |
self.title = NSLocalizedString(@"Edit scheme preferences",@""); |
3547 | 128 |
} |
129 |
||
130 |
// load from file |
|
131 |
-(void) viewWillAppear:(BOOL) animated { |
|
132 |
[super viewWillAppear:animated]; |
|
3697 | 133 |
|
3659 | 134 |
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
|
135 |
NSMutableDictionary *scheme = [[NSMutableDictionary alloc] initWithContentsOfFile:schemeFile]; |
3621 | 136 |
[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
|
137 |
self.schemeDictionary = scheme; |
3547 | 138 |
[scheme release]; |
3697 | 139 |
|
3547 | 140 |
[self.tableView reloadData]; |
141 |
} |
|
142 |
||
143 |
// save to file |
|
144 |
-(void) viewWillDisappear:(BOOL) animated { |
|
145 |
[super viewWillDisappear:animated]; |
|
3697 | 146 |
|
3659 | 147 |
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
|
148 |
[self.schemeDictionary writeToFile:schemeFile atomically:YES]; |
3547 | 149 |
[schemeFile release]; |
150 |
} |
|
151 |
||
152 |
#pragma mark - |
|
3659 | 153 |
#pragma mark editableCellView delegate |
3547 | 154 |
// set the new value |
3697 | 155 |
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue { |
3782 | 156 |
if (tagValue == 0) { |
157 |
// delete old file |
|
158 |
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] error:NULL]; |
|
159 |
// update filename |
|
160 |
self.schemeName = textString; |
|
161 |
// save new file |
|
162 |
[self.schemeDictionary writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] atomically:YES]; |
|
163 |
} else { |
|
164 |
[self.schemeDictionary setObject:textString forKey:@"description"]; |
|
165 |
} |
|
3547 | 166 |
} |
167 |
||
168 |
#pragma mark - |
|
169 |
#pragma mark Table view data source |
|
170 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
171 |
return 3; |
|
172 |
} |
|
173 |
||
174 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
175 |
switch (section) { |
|
176 |
case 0: |
|
3782 | 177 |
return 2; |
3547 | 178 |
break; |
179 |
case 1: |
|
180 |
return [self.basicSettingList count]; |
|
181 |
break; |
|
182 |
case 2: |
|
183 |
return [self.gameModifierArray count]; |
|
184 |
default: |
|
185 |
break; |
|
186 |
} |
|
187 |
return 0; |
|
188 |
} |
|
189 |
||
3573 | 190 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3547 | 191 |
static NSString *CellIdentifier0 = @"Cell0"; |
192 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
193 |
static NSString *CellIdentifier2 = @"Cell2"; |
|
3697 | 194 |
|
3547 | 195 |
UITableViewCell *cell = nil; |
3659 | 196 |
EditableCellView *editableCell = nil; |
3547 | 197 |
NSInteger row = [indexPath row]; |
3697 | 198 |
|
3547 | 199 |
switch ([indexPath section]) { |
200 |
case 0: |
|
3659 | 201 |
editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
202 |
if (editableCell == nil) { |
|
3697 | 203 |
editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault |
3547 | 204 |
reuseIdentifier:CellIdentifier0] autorelease]; |
3659 | 205 |
editableCell.delegate = self; |
3547 | 206 |
} |
3782 | 207 |
editableCell.tag = row; |
208 |
editableCell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
209 |
editableCell.imageView.image = nil; |
|
3659 | 210 |
editableCell.detailTextLabel.text = nil; |
3782 | 211 |
|
212 |
if (row == 0) { |
|
213 |
editableCell.textField.text = self.schemeName; |
|
214 |
} else { |
|
3825 | 215 |
editableCell.minimumCharacters = 0; |
3782 | 216 |
editableCell.textField.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; |
217 |
editableCell.textField.text = [self.schemeDictionary objectForKey:@"description"]; |
|
218 |
editableCell.textField.placeholder = NSLocalizedString(@"You can add a description if you wish",@""); |
|
219 |
} |
|
3659 | 220 |
cell = editableCell; |
3547 | 221 |
break; |
222 |
case 1: |
|
3573 | 223 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
224 |
NSDictionary *detail = [self.basicSettingList objectAtIndex:row]; |
|
225 |
// need to offset this section (see format in CommodityFunctions.m and above) |
|
3547 | 226 |
if (cell == nil) { |
3697 | 227 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 |
3547 | 228 |
reuseIdentifier:CellIdentifier1] autorelease]; |
3697 | 229 |
|
3643
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3623
diff
changeset
|
230 |
int offset = 0; |
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3623
diff
changeset
|
231 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
3659 | 232 |
offset = 50; |
3697 | 233 |
|
3643
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3623
diff
changeset
|
234 |
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(offset+260, 12, offset+150, 23)]; |
3573 | 235 |
slider.maximumValue = [[detail objectForKey:@"max"] floatValue]; |
236 |
slider.minimumValue = [[detail objectForKey:@"min"] floatValue]; |
|
237 |
[slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged]; |
|
238 |
[cell.contentView addSubview:slider]; |
|
239 |
[slider release]; |
|
3697 | 240 |
|
3573 | 241 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 200, 30)]; |
242 |
label.tag = LABEL_TAG; |
|
243 |
label.backgroundColor = [UIColor clearColor]; |
|
244 |
label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
|
245 |
[cell.contentView addSubview:label]; |
|
246 |
[label release]; |
|
3547 | 247 |
} |
3697 | 248 |
|
3547 | 249 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/icon%@.png",BTN_DIRECTORY(),[[self.basicSettingList objectAtIndex:row] objectForKey:@"image"]]]; |
3623 | 250 |
cell.imageView.image = img; |
3547 | 251 |
[img release]; |
3697 | 252 |
|
3573 | 253 |
UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG]; |
254 |
cellLabel.text = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"]; |
|
3697 | 255 |
|
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
256 |
// 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
|
257 |
UISlider *cellSlider = nil; |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
258 |
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
|
259 |
if ([oneView isMemberOfClass:[UISlider class]]) { |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
260 |
cellSlider = (UISlider *)oneView; |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
261 |
break; |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
262 |
} |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
263 |
} |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
264 |
cellSlider.tag = SLIDER_TAG + row; |
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 |
cellSlider.value = [[[self.schemeDictionary objectForKey:@"basic"] objectAtIndex:row] floatValue]; |
3697 | 266 |
|
3573 | 267 |
// forced to use this weird format otherwise the label disappears when size of the text is bigger than the original |
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
|
268 |
NSString *prestring = [NSString stringWithFormat:@"%d",(NSInteger) cellSlider.value]; |
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
269 |
// turntime 100 means unlimited time turns (set in GameSetup) |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
270 |
if (row == 1 && (NSInteger) cellSlider.value == 100) |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
271 |
prestring = @"∞"; |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
272 |
|
3574 | 273 |
while ([prestring length] <= 4) |
274 |
prestring = [NSString stringWithFormat:@" %@",prestring]; |
|
275 |
cell.detailTextLabel.text = prestring; |
|
3697 | 276 |
|
3574 | 277 |
cell.selectionStyle = UITableViewCellSelectionStyleBlue; |
3547 | 278 |
break; |
279 |
case 2: |
|
3573 | 280 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier2]; |
3547 | 281 |
if (cell == nil) { |
282 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
|
283 |
reuseIdentifier:CellIdentifier2] autorelease]; |
|
284 |
UISwitch *onOff = [[UISwitch alloc] init]; |
|
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
|
285 |
onOff.tag = SWITCH_TAG+row; |
3547 | 286 |
[onOff addTarget:self action:@selector(toggleSwitch:) forControlEvents:UIControlEventValueChanged]; |
287 |
cell.accessoryView = onOff; |
|
288 |
[onOff release]; |
|
289 |
} |
|
3697 | 290 |
|
3547 | 291 |
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/btn%@.png",BTN_DIRECTORY(),[[self.gameModifierArray objectAtIndex:row] objectForKey:@"image"]]]; |
292 |
cell.imageView.image = image; |
|
293 |
[image release]; |
|
294 |
[cell.imageView.layer setCornerRadius:7.0f]; |
|
3573 | 295 |
[cell.imageView.layer setBorderWidth:1]; |
3547 | 296 |
[cell.imageView.layer setMasksToBounds:YES]; |
297 |
cell.textLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"]; |
|
298 |
cell.detailTextLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"]; |
|
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
|
299 |
[(UISwitch *)cell.accessoryView setOn:[[[self.schemeDictionary objectForKey:@"gamemod"] objectAtIndex:row] boolValue] animated:NO]; |
3697 | 300 |
|
3574 | 301 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
3547 | 302 |
} |
3697 | 303 |
|
3547 | 304 |
return cell; |
305 |
} |
|
306 |
||
307 |
-(void) toggleSwitch:(id) sender { |
|
308 |
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
|
309 |
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
|
310 |
[array replaceObjectAtIndex:theSwitch.tag-SWITCH_TAG withObject:[NSNumber numberWithBool:theSwitch.on]]; |
3547 | 311 |
} |
312 |
||
3573 | 313 |
-(void) sliderChanged:(id) sender { |
314 |
// the slider that changed is sent as object |
|
315 |
UISlider *theSlider = (UISlider *)sender; |
|
316 |
// 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
|
317 |
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:theSlider.tag-SLIDER_TAG inSection:1]; |
3573 | 318 |
// get its cell |
319 |
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; |
|
320 |
// grab the associated label |
|
321 |
UILabel *label = (UILabel *)cell.detailTextLabel; |
|
322 |
// modify it |
|
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
323 |
if ([indexPath row] == 1 && [indexPath section] == 1 && (NSInteger) theSlider.value == 100) |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
324 |
label.text = @"∞"; |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
325 |
else |
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
326 |
label.text = [NSString stringWithFormat:@"%d",(NSInteger) theSlider.value]; |
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
|
327 |
// 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
|
328 |
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
|
329 |
[array replaceObjectAtIndex:theSlider.tag-SLIDER_TAG withObject:[NSNumber numberWithInt:(NSInteger) theSlider.value]]; |
3573 | 330 |
} |
3547 | 331 |
|
332 |
#pragma mark - |
|
333 |
#pragma mark Table view delegate |
|
334 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
3573 | 335 |
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; |
3659 | 336 |
EditableCellView *editableCell = nil; |
3573 | 337 |
UISlider *cellSlider = nil; |
3697 | 338 |
|
3573 | 339 |
switch ([indexPath section]) { |
340 |
case 0: |
|
3659 | 341 |
editableCell = (EditableCellView *)cell; |
342 |
[editableCell replyKeyboard]; |
|
3573 | 343 |
break; |
344 |
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
|
345 |
cellSlider = (UISlider *)[cell.contentView viewWithTag:[indexPath row]+SLIDER_TAG]; |
3573 | 346 |
[cellSlider setValue:[[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] floatValue] animated:YES]; |
347 |
[self sliderChanged:cellSlider]; |
|
348 |
//cell.detailTextLabel.text = [[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] stringValue]; |
|
349 |
break; |
|
350 |
case 2: |
|
3574 | 351 |
/*sw = (UISwitch *)cell.accessoryView; |
3573 | 352 |
[sw setOn:!sw.on animated:YES]; |
3574 | 353 |
[self toggleSwitch:sw];*/ |
3573 | 354 |
break; |
355 |
default: |
|
356 |
break; |
|
3547 | 357 |
} |
3697 | 358 |
|
3547 | 359 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
360 |
} |
|
361 |
||
3659 | 362 |
-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { |
363 |
NSString *sectionTitle = nil; |
|
364 |
switch (section) { |
|
365 |
case 0: |
|
366 |
sectionTitle = NSLocalizedString(@"Scheme Name", @""); |
|
367 |
break; |
|
368 |
case 1: |
|
369 |
sectionTitle = NSLocalizedString(@"Game Settings", @""); |
|
370 |
break; |
|
371 |
case 2: |
|
372 |
sectionTitle = NSLocalizedString(@"Game Modifiers", @""); |
|
373 |
break; |
|
374 |
default: |
|
375 |
DLog(@"nope"); |
|
376 |
break; |
|
377 |
} |
|
378 |
return sectionTitle; |
|
379 |
} |
|
3547 | 380 |
|
381 |
#pragma mark - |
|
382 |
#pragma mark Memory management |
|
383 |
-(void) didReceiveMemoryWarning { |
|
384 |
[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
|
385 |
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
|
386 |
self.gameModifierArray = nil; |
3547 | 387 |
} |
388 |
||
389 |
-(void) viewDidUnload { |
|
3659 | 390 |
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
|
391 |
self.schemeDictionary = nil; |
3547 | 392 |
self.basicSettingList = nil; |
393 |
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
|
394 |
MSG_DIDUNLOAD(); |
3547 | 395 |
[super viewDidUnload]; |
396 |
} |
|
397 |
||
398 |
-(void) dealloc { |
|
3659 | 399 |
[schemeName 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
|
400 |
[schemeDictionary release]; |
3547 | 401 |
[basicSettingList release]; |
402 |
[gameModifierArray release]; |
|
403 |
[super dealloc]; |
|
404 |
} |
|
405 |
||
406 |
@end |