78 nil]; |
81 nil]; |
79 self.gameModifierArray = mods; |
82 self.gameModifierArray = mods; |
80 [mods release]; |
83 [mods release]; |
81 |
84 |
82 NSArray *basicSettings = [[NSArray alloc] initWithObjects: |
85 NSArray *basicSettings = [[NSArray alloc] initWithObjects: |
83 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Damage Modifier",@""),@"title",@"Damage",@"image",nil], |
86 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Damage Modifier",@""),@"title",@"Damage",@"image", |
84 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Turn Time",@""),@"title",@"Time",@"image",nil], |
87 [NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:10],@"min",[NSNumber numberWithInt:300],@"max",nil], |
85 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Initial Health",@""),@"title",@"Health",@"image",nil], |
88 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Turn Time",@""),@"title",@"Time",@"image", |
86 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Sudden Death Timeout",@""),@"title",@"SuddenDeath",@"image",nil], |
89 [NSNumber numberWithInt:45],@"default",[NSNumber numberWithInt:1],@"min",[NSNumber numberWithInt:99],@"max",nil], |
87 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Crate Drops",@""),@"title",@"Box",@"image",nil], |
90 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Initial Health",@""),@"title",@"Health",@"image", |
88 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Time",@""),@"title",@"Time",@"image",nil], |
91 [NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:50],@"min",[NSNumber numberWithInt:200],@"max",nil], |
89 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Number",@""),@"title",@"Mine",@"image",nil], |
92 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Sudden Death Timeout",@""),@"title",@"SuddenDeath",@"image", |
90 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Dud Mines Probability",@""),@"title",@"Dud",@"image",nil], |
93 [NSNumber numberWithInt:15],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:50],@"max",nil], |
91 [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Explosives",@""),@"title",@"Damage",@"image",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], |
92 nil]; |
104 nil]; |
93 self.basicSettingList = basicSettings; |
105 self.basicSettingList = basicSettings; |
94 [basicSettings release]; |
106 [basicSettings release]; |
95 } |
107 } |
96 |
108 |
191 break; |
203 break; |
192 } |
204 } |
193 return 0; |
205 return 0; |
194 } |
206 } |
195 |
207 |
196 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
208 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
197 static NSString *CellIdentifier0 = @"Cell0"; |
209 static NSString *CellIdentifier0 = @"Cell0"; |
198 static NSString *CellIdentifier1 = @"Cell1"; |
210 static NSString *CellIdentifier1 = @"Cell1"; |
199 static NSString *CellIdentifier2 = @"Cell2"; |
211 static NSString *CellIdentifier2 = @"Cell2"; |
200 |
212 |
201 UITableViewCell *cell = nil; |
213 UITableViewCell *cell = nil; |
202 NSInteger row = [indexPath row]; |
214 NSInteger row = [indexPath row]; |
203 |
215 |
204 switch ([indexPath section]) { |
216 switch ([indexPath section]) { |
205 case 0: |
217 case 0: |
206 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
218 cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
207 if (cell == nil) { |
219 if (cell == nil) { |
208 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
220 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
209 reuseIdentifier:CellIdentifier0] autorelease]; |
221 reuseIdentifier:CellIdentifier0] autorelease]; |
210 // create a uitextfield for each row, expand it to take the maximum size |
222 // create a uitextfield for each row, expand it to take the maximum size |
211 UITextField *aTextField = [[UITextField alloc] |
223 UITextField *aTextField = [[UITextField alloc] |
231 } |
243 } |
232 cell.detailTextLabel.text = nil; |
244 cell.detailTextLabel.text = nil; |
233 cell.imageView.image = nil; |
245 cell.imageView.image = nil; |
234 break; |
246 break; |
235 case 1: |
247 case 1: |
236 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
248 cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
|
249 NSDictionary *detail = [self.basicSettingList objectAtIndex:row]; |
|
250 // need to offset this section (see format in CommodityFunctions.m and above) |
|
251 NSInteger gmSize = [self.gameModifierArray count]; |
237 if (cell == nil) { |
252 if (cell == nil) { |
238 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
253 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 |
239 reuseIdentifier:CellIdentifier1] autorelease]; |
254 reuseIdentifier:CellIdentifier1] autorelease]; |
|
255 UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(260, 12, 150, 23)]; |
|
256 slider.maximumValue = [[detail objectForKey:@"max"] floatValue]; |
|
257 slider.minimumValue = [[detail objectForKey:@"min"] floatValue]; |
|
258 slider.tag = row+gmSize; |
|
259 [slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged]; |
|
260 [cell.contentView addSubview:slider]; |
|
261 [slider release]; |
|
262 |
|
263 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 200, 30)]; |
|
264 label.tag = LABEL_TAG; |
|
265 label.backgroundColor = [UIColor clearColor]; |
|
266 label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
|
267 [cell.contentView addSubview:label]; |
|
268 [label release]; |
240 } |
269 } |
241 |
270 |
242 UIImage *img = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/icon%@.png",BTN_DIRECTORY(),[[self.basicSettingList objectAtIndex:row] objectForKey:@"image"]]]; |
271 UIImage *img = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/icon%@.png",BTN_DIRECTORY(),[[self.basicSettingList objectAtIndex:row] objectForKey:@"image"]]]; |
243 cell.imageView.image = [img scaleToSize:CGSizeMake(40, 40)]; |
272 cell.imageView.image = [img scaleToSize:CGSizeMake(40, 40)]; |
244 [img release]; |
273 [img release]; |
245 cell.textLabel.text = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"]; |
274 |
246 cell.detailTextLabel.text = nil; |
275 UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG]; |
|
276 cellLabel.text = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"]; |
|
277 |
|
278 UISlider *cellSlider = (UISlider *)[cell.contentView viewWithTag:row+gmSize]; |
|
279 cellSlider.value = [[self.schemeArray objectAtIndex:row+gmSize] floatValue]; |
|
280 |
|
281 // forced to use this weird format otherwise the label disappears when size of the text is bigger than the original |
|
282 cell.detailTextLabel.text = [NSString stringWithFormat:@"%0.3d",[[self.schemeArray objectAtIndex:row+gmSize] intValue]]; |
247 break; |
283 break; |
248 case 2: |
284 case 2: |
249 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2]; |
285 cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier2]; |
250 if (cell == nil) { |
286 if (cell == nil) { |
251 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
287 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
252 reuseIdentifier:CellIdentifier2] autorelease]; |
288 reuseIdentifier:CellIdentifier2] autorelease]; |
253 UISwitch *onOff = [[UISwitch alloc] init]; |
289 UISwitch *onOff = [[UISwitch alloc] init]; |
254 onOff.tag = row; |
290 onOff.tag = row; |
273 -(void) toggleSwitch:(id) sender { |
310 -(void) toggleSwitch:(id) sender { |
274 UISwitch *theSwitch = (UISwitch *)sender; |
311 UISwitch *theSwitch = (UISwitch *)sender; |
275 [self.schemeArray replaceObjectAtIndex:theSwitch.tag withObject:[NSNumber numberWithBool:theSwitch.on]]; |
312 [self.schemeArray replaceObjectAtIndex:theSwitch.tag withObject:[NSNumber numberWithBool:theSwitch.on]]; |
276 } |
313 } |
277 |
314 |
|
315 -(void) sliderChanged:(id) sender { |
|
316 // need to offset this section (see format in CommodityFunctions.m and above) |
|
317 NSInteger gmSize = [self.gameModifierArray count]; |
|
318 // the slider that changed is sent as object |
|
319 UISlider *theSlider = (UISlider *)sender; |
|
320 // create the indexPath of the row of the slider |
|
321 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:theSlider.tag-gmSize inSection:1]; |
|
322 // get its cell |
|
323 UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; |
|
324 // grab the associated label |
|
325 UILabel *label = (UILabel *)cell.detailTextLabel; |
|
326 // modify it |
|
327 label.text = [NSString stringWithFormat:@"%0.3d",(int)theSlider.value]; |
|
328 // save changes in the main array (remember that you need to offset it) |
|
329 [self.schemeArray replaceObjectAtIndex:theSlider.tag withObject:[NSNumber numberWithInt:(int)theSlider.value]]; |
|
330 NSLog(@"%@",self.schemeArray); |
|
331 } |
278 |
332 |
279 #pragma mark - |
333 #pragma mark - |
280 #pragma mark Table view delegate |
334 #pragma mark Table view delegate |
281 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
335 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
282 |
336 UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; |
283 if ([indexPath section] == 0) { |
337 UISwitch *sw = nil; |
284 UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; |
338 UISlider *cellSlider = nil; |
285 for (UIView *oneView in cell.contentView.subviews) { |
339 |
286 if ([oneView isMemberOfClass:[UITextField class]]) { |
340 switch ([indexPath section]) { |
287 textFieldBeingEdited = (UITextField *)oneView; |
341 case 0: |
288 [textFieldBeingEdited becomeFirstResponder]; |
342 for (UIView *oneView in cell.contentView.subviews) { |
289 } |
343 if ([oneView isMemberOfClass:[UITextField class]]) { |
290 } |
344 textFieldBeingEdited = (UITextField *)oneView; |
|
345 [textFieldBeingEdited becomeFirstResponder]; |
|
346 } |
|
347 } |
|
348 break; |
|
349 case 1: |
|
350 cellSlider = (UISlider *)[cell.contentView viewWithTag:[indexPath row]+[self.gameModifierArray count]]; |
|
351 [cellSlider setValue:[[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] floatValue] animated:YES]; |
|
352 [self sliderChanged:cellSlider]; |
|
353 //cell.detailTextLabel.text = [[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] stringValue]; |
|
354 break; |
|
355 case 2: |
|
356 sw = (UISwitch *)cell.accessoryView; |
|
357 [sw setOn:!sw.on animated:YES]; |
|
358 [self toggleSwitch:sw]; |
|
359 break; |
|
360 default: |
|
361 break; |
291 } |
362 } |
|
363 |
292 [aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
364 [aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
293 } |
365 } |
294 |
366 |
295 |
367 |
296 #pragma mark - |
368 #pragma mark - |