author | koda |
Thu, 15 Jul 2010 03:28:29 +0200 | |
changeset 3643 | 858b20bafb6e |
parent 3623 | f14db208f2fa |
child 3659 | f8d5ac50e307 |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// SingleSchemeViewController.m |
|
3 |
// Hedgewars |
|
4 |
// |
|
5 |
// Created by Vittorio on 23/05/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "SingleSchemeViewController.h" |
|
10 |
#import <QuartzCore/QuartzCore.h> |
|
11 |
#import "CommodityFunctions.h" |
|
12 |
#import "UIImageExtra.h" |
|
13 |
||
3573 | 14 |
#define LABEL_TAG 12345 |
15 |
#define SLIDER_TAG 54321 |
|
16 |
||
3547 | 17 |
@implementation SingleSchemeViewController |
18 |
@synthesize textFieldBeingEdited, schemeArray, basicSettingList, gameModifierArray; |
|
19 |
||
20 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
21 |
return rotationManager(interfaceOrientation); |
|
22 |
} |
|
23 |
||
24 |
#pragma mark - |
|
25 |
#pragma mark View lifecycle |
|
26 |
-(void) viewDidLoad { |
|
27 |
[super viewDidLoad]; |
|
28 |
||
29 |
NSArray *mods = [[NSArray alloc] initWithObjects: |
|
30 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Fort Mode",@""),@"title", |
|
31 |
NSLocalizedString(@"Defend your fort and destroy the opponents (two team colours max)",@""),@"description", |
|
32 |
@"Forts",@"image",nil], |
|
33 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Divide Team",@""),@"title", |
|
34 |
NSLocalizedString(@"Teams will start on opposite sides of the terrain (two team colours max)",@""),@"description", |
|
35 |
@"TeamsDivide",@"image",nil], |
|
36 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Solid Land",@""),@"title", |
|
37 |
NSLocalizedString(@"Land can not be destroyed",@""),@"description", |
|
38 |
@"Solid",@"image",nil], |
|
39 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Add Border",@""),@"title", |
|
40 |
NSLocalizedString(@"Add an indestructable border around the terrain",@""),@"description", |
|
41 |
@"Border",@"image",nil], |
|
42 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Low Gravity",@""),@"title", |
|
43 |
NSLocalizedString(@"Lower gravity",@""),@"description", |
|
44 |
@"LowGravity",@"image",nil], |
|
45 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Laser Sight",@""),@"title", |
|
46 |
NSLocalizedString(@"Assisted aiming with laser sight",@""),@"description", |
|
47 |
@"LaserSight",@"image",nil], |
|
48 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Invulnerable",@""),@"title", |
|
49 |
NSLocalizedString(@"All hogs have a personal forcefield",@""),@"description", |
|
50 |
@"Invulnerable",@"image",nil], |
|
51 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Add Mines",@""),@"title", |
|
52 |
NSLocalizedString(@"Enable random mines",@""),@"description", |
|
53 |
@"Mines",@"image",nil], |
|
54 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Vampirism Mode",@""),@"title", |
|
55 |
NSLocalizedString(@"Gain 80% of the damage you do back in health",@""),@"description", |
|
56 |
@"Vampiric",@"image",nil], |
|
57 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Karma Mode",@""),@"title", |
|
58 |
NSLocalizedString(@"Share your opponents pain, share their damage",@""),@"description", |
|
59 |
@"Karma",@"image",nil], |
|
60 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Artillery Mode",@""),@"title", |
|
61 |
NSLocalizedString(@"Your hogs are unable to move, test your aim",@""),@"description", |
|
62 |
@"Artillery",@"image",nil], |
|
63 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Random Order",@""),@"title", |
|
64 |
NSLocalizedString(@"Order of play is random instead of in room order",@""),@"description", |
|
65 |
@"RandomOrder",@"image",nil], |
|
66 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"King Mode",@""),@"title", |
|
67 |
NSLocalizedString(@"Play with a King. If he dies, your side loses",@""),@"description", |
|
68 |
@"King",@"image",nil], |
|
69 |
[NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Place Hedgehogs",@""),@"title", |
|
70 |
NSLocalizedString(@"Take turns placing your hedgehogs pre-game",@""),@"description", |
|
71 |
@"PlaceHog",@"image",nil], |
|
72 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Clan Shares Ammo",@""),@"title", |
|
73 |
NSLocalizedString(@"Ammo is shared between all clan teams",@""),@"description", |
|
74 |
@"SharedAmmo",@"image",nil], |
|
75 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Disable Girders",@""),@"title", |
|
76 |
NSLocalizedString(@"Disable girders when generating random maps",@""),@"description", |
|
77 |
@"DisableGirders",@"image",nil], |
|
78 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Disable Land Objects",@""),@"title", |
|
79 |
NSLocalizedString(@"Disable land objects when generating maps",@""),@"description", |
|
80 |
@"DisableLandObjects",@"image",nil], |
|
81 |
nil]; |
|
82 |
self.gameModifierArray = mods; |
|
83 |
[mods release]; |
|
84 |
||
85 |
NSArray *basicSettings = [[NSArray alloc] initWithObjects: |
|
3573 | 86 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Damage Modifier",@""),@"title",@"Damage",@"image", |
87 |
[NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:10],@"min",[NSNumber numberWithInt:300],@"max",nil], |
|
88 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Turn Time",@""),@"title",@"Time",@"image", |
|
89 |
[NSNumber numberWithInt:45],@"default",[NSNumber numberWithInt:1],@"min",[NSNumber numberWithInt:99],@"max",nil], |
|
90 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Initial Health",@""),@"title",@"Health",@"image", |
|
91 |
[NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:50],@"min",[NSNumber numberWithInt:200],@"max",nil], |
|
92 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Sudden Death Timeout",@""),@"title",@"SuddenDeath",@"image", |
|
93 |
[NSNumber numberWithInt:15],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:50],@"max",nil], |
|
94 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Crate Drops",@""),@"title",@"Box",@"image", |
|
95 |
[NSNumber numberWithInt:5],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:9],@"max",nil], |
|
96 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Time",@""),@"title",@"Time",@"image", |
|
97 |
[NSNumber numberWithInt:3],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:3],@"max",nil], |
|
98 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Number",@""),@"title",@"Mine",@"image", |
|
99 |
[NSNumber numberWithInt:4],@"default",[NSNumber numberWithInt:1],@"min",[NSNumber numberWithInt:80],@"max",nil], |
|
100 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Dud Mines Probability",@""),@"title",@"Dud",@"image", |
|
101 |
[NSNumber numberWithInt:0],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:100],@"max",nil], |
|
102 |
[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Explosives",@""),@"title",@"Damage",@"image", |
|
103 |
[NSNumber numberWithInt:2],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:40],@"max",nil], |
|
3547 | 104 |
nil]; |
105 |
self.basicSettingList = basicSettings; |
|
106 |
[basicSettings release]; |
|
107 |
} |
|
108 |
||
109 |
// load from file |
|
110 |
-(void) viewWillAppear:(BOOL) animated { |
|
111 |
[super viewWillAppear:animated]; |
|
112 |
||
113 |
NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title]; |
|
114 |
NSMutableArray *scheme = [[NSMutableArray alloc] initWithContentsOfFile:schemeFile]; |
|
3621 | 115 |
[schemeFile release]; |
3547 | 116 |
self.schemeArray = scheme; |
117 |
[scheme release]; |
|
118 |
||
119 |
[self.tableView reloadData]; |
|
120 |
} |
|
121 |
||
122 |
// save to file |
|
123 |
-(void) viewWillDisappear:(BOOL) animated { |
|
124 |
[super viewWillDisappear:animated]; |
|
125 |
||
126 |
NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title]; |
|
127 |
[self.schemeArray writeToFile:schemeFile atomically:YES]; |
|
128 |
[schemeFile release]; |
|
129 |
} |
|
130 |
||
131 |
#pragma mark - |
|
132 |
#pragma mark textfield methods |
|
133 |
-(void) cancel:(id) sender { |
|
134 |
if (textFieldBeingEdited != nil) |
|
135 |
[self.textFieldBeingEdited resignFirstResponder]; |
|
136 |
} |
|
137 |
||
138 |
// set the new value |
|
139 |
-(BOOL) save:(id) sender { |
|
140 |
if (textFieldBeingEdited != nil) { |
|
3574 | 141 |
if ([textFieldBeingEdited.text length] == 0) |
142 |
textFieldBeingEdited.text = self.title; |
|
143 |
||
3547 | 144 |
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title] error:NULL]; |
145 |
self.title = self.textFieldBeingEdited.text; |
|
146 |
[self.schemeArray writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title] atomically:YES]; |
|
147 |
[self.textFieldBeingEdited resignFirstResponder]; |
|
148 |
return YES; |
|
149 |
} |
|
150 |
return NO; |
|
151 |
} |
|
152 |
||
153 |
// the textfield is being modified, update the navigation controller |
|
154 |
-(void) textFieldDidBeginEditing:(UITextField *)aTextField{ |
|
155 |
self.textFieldBeingEdited = aTextField; |
|
156 |
||
157 |
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"from schemes table") |
|
158 |
style:UIBarButtonItemStylePlain |
|
159 |
target:self |
|
160 |
action:@selector(cancel:)]; |
|
161 |
self.navigationItem.leftBarButtonItem = cancelButton; |
|
162 |
[cancelButton release]; |
|
163 |
||
164 |
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Save",@"from schemes table") |
|
165 |
style:UIBarButtonItemStyleDone |
|
166 |
target:self |
|
167 |
action:@selector(save:)]; |
|
168 |
self.navigationItem.rightBarButtonItem = saveButton; |
|
169 |
[saveButton release]; |
|
170 |
} |
|
171 |
||
172 |
// the textfield has been modified, check for empty strings and restore original navigation bar |
|
173 |
-(void) textFieldDidEndEditing:(UITextField *)aTextField{ |
|
174 |
if ([textFieldBeingEdited.text length] == 0) |
|
175 |
textFieldBeingEdited.text = [NSString stringWithFormat:@"New Scheme"]; |
|
176 |
||
177 |
self.textFieldBeingEdited = nil; |
|
178 |
self.navigationItem.rightBarButtonItem = self.navigationItem.backBarButtonItem; |
|
179 |
self.navigationItem.leftBarButtonItem = nil; |
|
180 |
} |
|
181 |
||
182 |
// limit the size of the field to 64 characters like in original frontend |
|
183 |
-(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { |
|
184 |
int limit = 64; |
|
185 |
return !([textField.text length] > limit && [string length] > range.length); |
|
186 |
} |
|
187 |
||
188 |
||
189 |
#pragma mark - |
|
190 |
#pragma mark Table view data source |
|
191 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
192 |
return 3; |
|
193 |
} |
|
194 |
||
195 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
196 |
switch (section) { |
|
197 |
case 0: |
|
198 |
return 1; |
|
199 |
break; |
|
200 |
case 1: |
|
201 |
return [self.basicSettingList count]; |
|
202 |
break; |
|
203 |
case 2: |
|
204 |
return [self.gameModifierArray count]; |
|
205 |
default: |
|
206 |
break; |
|
207 |
} |
|
208 |
return 0; |
|
209 |
} |
|
210 |
||
3573 | 211 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3547 | 212 |
static NSString *CellIdentifier0 = @"Cell0"; |
213 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
214 |
static NSString *CellIdentifier2 = @"Cell2"; |
|
215 |
||
216 |
UITableViewCell *cell = nil; |
|
217 |
NSInteger row = [indexPath row]; |
|
218 |
||
219 |
switch ([indexPath section]) { |
|
220 |
case 0: |
|
3573 | 221 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
3547 | 222 |
if (cell == nil) { |
223 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
|
224 |
reuseIdentifier:CellIdentifier0] autorelease]; |
|
225 |
// create a uitextfield for each row, expand it to take the maximum size |
|
226 |
UITextField *aTextField = [[UITextField alloc] |
|
227 |
initWithFrame:CGRectMake(5, 12, (cell.frame.size.width + cell.frame.size.width/3) - 42, 25)]; |
|
228 |
aTextField.clearsOnBeginEditing = NO; |
|
229 |
aTextField.returnKeyType = UIReturnKeyDone; |
|
230 |
aTextField.adjustsFontSizeToFitWidth = YES; |
|
231 |
aTextField.delegate = self; |
|
232 |
aTextField.tag = [indexPath row]; |
|
233 |
aTextField.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2]; |
|
234 |
aTextField.clearButtonMode = UITextFieldViewModeWhileEditing; |
|
235 |
[aTextField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit]; |
|
236 |
[cell.contentView addSubview:aTextField]; |
|
237 |
[aTextField release]; |
|
238 |
} |
|
239 |
||
240 |
for (UIView *oneView in cell.contentView.subviews) { |
|
241 |
if ([oneView isMemberOfClass:[UITextField class]]) { |
|
242 |
// we find the uitextfied and we'll use its tag to understand which one is being edited |
|
243 |
UITextField *textFieldFound = (UITextField *)oneView; |
|
244 |
textFieldFound.text = self.title; |
|
245 |
} |
|
246 |
} |
|
247 |
cell.detailTextLabel.text = nil; |
|
248 |
cell.imageView.image = nil; |
|
3574 | 249 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
3547 | 250 |
break; |
251 |
case 1: |
|
3573 | 252 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
253 |
NSDictionary *detail = [self.basicSettingList objectAtIndex:row]; |
|
254 |
// need to offset this section (see format in CommodityFunctions.m and above) |
|
255 |
NSInteger gmSize = [self.gameModifierArray count]; |
|
3547 | 256 |
if (cell == nil) { |
3573 | 257 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 |
3547 | 258 |
reuseIdentifier:CellIdentifier1] autorelease]; |
3643
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3623
diff
changeset
|
259 |
|
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3623
diff
changeset
|
260 |
int offset = 0; |
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3623
diff
changeset
|
261 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3623
diff
changeset
|
262 |
offset = 45; |
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3623
diff
changeset
|
263 |
|
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3623
diff
changeset
|
264 |
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(offset+260, 12, offset+150, 23)]; |
3573 | 265 |
slider.maximumValue = [[detail objectForKey:@"max"] floatValue]; |
266 |
slider.minimumValue = [[detail objectForKey:@"min"] floatValue]; |
|
267 |
slider.tag = row+gmSize; |
|
268 |
[slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged]; |
|
269 |
[cell.contentView addSubview:slider]; |
|
270 |
[slider release]; |
|
271 |
||
272 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 200, 30)]; |
|
273 |
label.tag = LABEL_TAG; |
|
274 |
label.backgroundColor = [UIColor clearColor]; |
|
275 |
label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
|
276 |
[cell.contentView addSubview:label]; |
|
277 |
[label release]; |
|
3547 | 278 |
} |
279 |
||
280 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/icon%@.png",BTN_DIRECTORY(),[[self.basicSettingList objectAtIndex:row] objectForKey:@"image"]]]; |
|
3623 | 281 |
cell.imageView.image = img; |
3547 | 282 |
[img release]; |
3573 | 283 |
|
284 |
UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG]; |
|
285 |
cellLabel.text = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"]; |
|
286 |
||
287 |
UISlider *cellSlider = (UISlider *)[cell.contentView viewWithTag:row+gmSize]; |
|
288 |
cellSlider.value = [[self.schemeArray objectAtIndex:row+gmSize] floatValue]; |
|
289 |
||
290 |
// forced to use this weird format otherwise the label disappears when size of the text is bigger than the original |
|
3574 | 291 |
NSString *prestring = [NSString stringWithFormat:@"%d",[[self.schemeArray objectAtIndex:row+gmSize] intValue]]; |
292 |
while ([prestring length] <= 4) |
|
293 |
prestring = [NSString stringWithFormat:@" %@",prestring]; |
|
294 |
cell.detailTextLabel.text = prestring; |
|
295 |
||
296 |
cell.selectionStyle = UITableViewCellSelectionStyleBlue; |
|
3547 | 297 |
break; |
298 |
case 2: |
|
3573 | 299 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier2]; |
3547 | 300 |
if (cell == nil) { |
301 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
|
302 |
reuseIdentifier:CellIdentifier2] autorelease]; |
|
303 |
UISwitch *onOff = [[UISwitch alloc] init]; |
|
304 |
onOff.tag = row; |
|
305 |
[onOff addTarget:self action:@selector(toggleSwitch:) forControlEvents:UIControlEventValueChanged]; |
|
306 |
cell.accessoryView = onOff; |
|
307 |
[onOff release]; |
|
308 |
} |
|
309 |
||
310 |
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/btn%@.png",BTN_DIRECTORY(),[[self.gameModifierArray objectAtIndex:row] objectForKey:@"image"]]]; |
|
311 |
cell.imageView.image = image; |
|
312 |
[image release]; |
|
313 |
[cell.imageView.layer setCornerRadius:7.0f]; |
|
3573 | 314 |
[cell.imageView.layer setBorderWidth:1]; |
3547 | 315 |
[cell.imageView.layer setMasksToBounds:YES]; |
316 |
cell.textLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"]; |
|
317 |
cell.detailTextLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"]; |
|
318 |
[(UISwitch *)cell.accessoryView setOn:[[self.schemeArray objectAtIndex:row] boolValue] animated:NO]; |
|
3574 | 319 |
|
320 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
3547 | 321 |
} |
322 |
||
323 |
return cell; |
|
324 |
} |
|
325 |
||
326 |
-(void) toggleSwitch:(id) sender { |
|
327 |
UISwitch *theSwitch = (UISwitch *)sender; |
|
328 |
[self.schemeArray replaceObjectAtIndex:theSwitch.tag withObject:[NSNumber numberWithBool:theSwitch.on]]; |
|
329 |
} |
|
330 |
||
3573 | 331 |
-(void) sliderChanged:(id) sender { |
332 |
// need to offset this section (see format in CommodityFunctions.m and above) |
|
333 |
NSInteger gmSize = [self.gameModifierArray count]; |
|
334 |
// the slider that changed is sent as object |
|
335 |
UISlider *theSlider = (UISlider *)sender; |
|
336 |
// create the indexPath of the row of the slider |
|
337 |
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:theSlider.tag-gmSize inSection:1]; |
|
338 |
// get its cell |
|
339 |
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; |
|
340 |
// grab the associated label |
|
341 |
UILabel *label = (UILabel *)cell.detailTextLabel; |
|
342 |
// modify it |
|
3574 | 343 |
label.text = [NSString stringWithFormat:@"%d",(int)theSlider.value]; |
3573 | 344 |
// save changes in the main array (remember that you need to offset it) |
345 |
[self.schemeArray replaceObjectAtIndex:theSlider.tag withObject:[NSNumber numberWithInt:(int)theSlider.value]]; |
|
346 |
} |
|
3547 | 347 |
|
348 |
#pragma mark - |
|
349 |
#pragma mark Table view delegate |
|
350 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
3573 | 351 |
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; |
352 |
UISwitch *sw = nil; |
|
353 |
UISlider *cellSlider = nil; |
|
3547 | 354 |
|
3573 | 355 |
switch ([indexPath section]) { |
356 |
case 0: |
|
357 |
for (UIView *oneView in cell.contentView.subviews) { |
|
358 |
if ([oneView isMemberOfClass:[UITextField class]]) { |
|
359 |
textFieldBeingEdited = (UITextField *)oneView; |
|
360 |
[textFieldBeingEdited becomeFirstResponder]; |
|
361 |
} |
|
3547 | 362 |
} |
3573 | 363 |
break; |
364 |
case 1: |
|
365 |
cellSlider = (UISlider *)[cell.contentView viewWithTag:[indexPath row]+[self.gameModifierArray count]]; |
|
366 |
[cellSlider setValue:[[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] floatValue] animated:YES]; |
|
367 |
[self sliderChanged:cellSlider]; |
|
368 |
//cell.detailTextLabel.text = [[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] stringValue]; |
|
369 |
break; |
|
370 |
case 2: |
|
3574 | 371 |
/*sw = (UISwitch *)cell.accessoryView; |
3573 | 372 |
[sw setOn:!sw.on animated:YES]; |
3574 | 373 |
[self toggleSwitch:sw];*/ |
3573 | 374 |
break; |
375 |
default: |
|
376 |
break; |
|
3547 | 377 |
} |
3573 | 378 |
|
3547 | 379 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
380 |
} |
|
381 |
||
382 |
||
383 |
#pragma mark - |
|
384 |
#pragma mark Memory management |
|
385 |
-(void) didReceiveMemoryWarning { |
|
386 |
[super didReceiveMemoryWarning]; |
|
387 |
} |
|
388 |
||
389 |
-(void) viewDidUnload { |
|
390 |
self.textFieldBeingEdited = nil; |
|
391 |
self.schemeArray = nil; |
|
392 |
self.basicSettingList = nil; |
|
393 |
self.gameModifierArray = nil; |
|
394 |
[super viewDidUnload]; |
|
395 |
MSG_DIDUNLOAD(); |
|
396 |
} |
|
397 |
||
398 |
-(void) dealloc { |
|
399 |
[textFieldBeingEdited release]; |
|
400 |
[schemeArray release]; |
|
401 |
[basicSettingList release]; |
|
402 |
[gameModifierArray release]; |
|
403 |
[super dealloc]; |
|
404 |
} |
|
405 |
||
406 |
||
407 |
@end |
|
408 |