equal
deleted
inserted
replaced
93 if (section == 0) { |
93 if (section == 0) { |
94 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
94 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
95 if (cell == nil) { |
95 if (cell == nil) { |
96 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
96 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
97 UISwitch *theSwitch = [[UISwitch alloc] init]; |
97 UISwitch *theSwitch = [[UISwitch alloc] init]; |
98 if (numberOfSections == 1) |
|
99 theSwitch.on = NO; |
|
100 else |
|
101 theSwitch.on = YES; |
|
102 [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged]; |
98 [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged]; |
103 cell.accessoryView = theSwitch; |
99 cell.accessoryView = theSwitch; |
104 [theSwitch release]; |
100 [theSwitch release]; |
105 } |
101 } |
|
102 UISwitch *theSwitch = (UISwitch *)cell.accessoryView; |
|
103 if (numberOfSections == 1) |
|
104 theSwitch.on = NO; |
|
105 else |
|
106 theSwitch.on = YES; |
106 cell.textLabel.text = NSLocalizedString(@"Hogs controlled by AI",@""); |
107 cell.textLabel.text = NSLocalizedString(@"Hogs controlled by AI",@""); |
107 } else { |
108 } else { |
108 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
109 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
109 if (cell == nil) |
110 if (cell == nil) |
110 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; |
111 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; |
135 NSInteger level; |
136 NSInteger level; |
136 |
137 |
137 if (theSwitch.on) { |
138 if (theSwitch.on) { |
138 numberOfSections = 2; |
139 numberOfSections = 2; |
139 [self.tableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
140 [self.tableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
140 level = random() % [levelArray count]; |
141 level = 1 + (random() % ([levelArray count] - 1)); |
141 } else { |
142 } else { |
142 numberOfSections = 1; |
143 numberOfSections = 1; |
143 [self.tableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
144 [self.tableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
144 level = 0; |
145 level = 0; |
145 } |
146 } |
146 |
147 |
147 DLog(@"New level is %d",level); |
148 DLog(@"New level is %d",level); |
148 for (NSMutableDictionary *hog in hogs) |
149 for (NSMutableDictionary *hog in hogs) |
149 [hog setObject:[NSNumber numberWithInt:0] forKey:@"level"]; |
150 [hog setObject:[NSNumber numberWithInt:level] forKey:@"level"]; |
150 |
151 |
151 [self.tableView reloadData]; |
152 [self.tableView reloadData]; |
152 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
153 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
153 |
154 |
154 [sections release]; |
155 [sections release]; |