author | koda |
Sun, 26 Sep 2010 23:48:03 +0200 | |
changeset 3910 | dd47efbdec46 |
parent 3829 | 81db3c85784b |
child 3911 | 46d7a5cf8ac6 |
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 22/04/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "MapConfigViewController.h" |
|
23 |
#import "PascalImports.h" |
|
24 |
#import "CommodityFunctions.h" |
|
25 |
#import "UIImageExtra.h" |
|
26 |
||
27 |
||
28 |
@implementation MapConfigViewController |
|
3642 | 29 |
@synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand, themeCommand, staticMapCommand, |
3705 | 30 |
tableView, maxLabel, sizeLabel, segmentedControl, slider, lastIndexPath, themeArray, mapArray, busy, delegate; |
3547 | 31 |
|
32 |
||
33 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
34 |
return rotationManager(interfaceOrientation); |
|
35 |
} |
|
36 |
||
3783 | 37 |
-(IBAction) mapButtonPressed { |
38 |
playSound(@"clickSound"); |
|
39 |
[self updatePreview]; |
|
40 |
} |
|
41 |
||
42 |
-(void) updatePreview { |
|
3547 | 43 |
// don't generate a new preview while it's already generating one |
44 |
if (busy) |
|
45 |
return; |
|
3697 | 46 |
|
3547 | 47 |
// generate a seed |
48 |
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault); |
|
49 |
NSString *seed = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid); |
|
50 |
CFRelease(uuid); |
|
51 |
NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed]; |
|
52 |
self.seedCommand = seedCmd; |
|
53 |
[seedCmd release]; |
|
3697 | 54 |
|
3547 | 55 |
NSIndexPath *theIndex; |
56 |
if (segmentedControl.selectedSegmentIndex != 1) { |
|
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
57 |
// prevent other events and add an activity while the preview is beign generated |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
58 |
[self turnOffWidgets]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
59 |
[self.previewButton updatePreviewWithSeed:seed]; |
3547 | 60 |
theIndex = [NSIndexPath indexPathForRow:(random()%[self.themeArray count]) inSection:0]; |
61 |
} else { |
|
62 |
theIndex = [NSIndexPath indexPathForRow:(random()%[self.mapArray count]) inSection:0]; |
|
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
63 |
// the preview for static maps is loaded in didSelectRowAtIndexPath |
3547 | 64 |
} |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
65 |
[seed release]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
66 |
|
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
67 |
// perform as if user clicked on an entry |
3547 | 68 |
[self tableView:self.tableView didSelectRowAtIndexPath:theIndex]; |
69 |
[self.tableView scrollToRowAtIndexPath:theIndex atScrollPosition:UITableViewScrollPositionNone animated:YES]; |
|
70 |
} |
|
71 |
||
72 |
-(void) turnOffWidgets { |
|
73 |
busy = YES; |
|
74 |
self.previewButton.alpha = 0.5f; |
|
75 |
self.previewButton.enabled = NO; |
|
76 |
self.maxLabel.text = @"..."; |
|
77 |
self.segmentedControl.enabled = NO; |
|
78 |
self.slider.enabled = NO; |
|
79 |
} |
|
80 |
||
81 |
-(void) turnOnWidgets { |
|
82 |
self.previewButton.alpha = 1.0f; |
|
83 |
self.previewButton.enabled = YES; |
|
84 |
self.segmentedControl.enabled = YES; |
|
85 |
self.slider.enabled = YES; |
|
86 |
busy = NO; |
|
87 |
} |
|
3697 | 88 |
|
3547 | 89 |
-(void) setLabelText:(NSString *)str { |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
90 |
self.maxHogs = [str intValue]; |
3547 | 91 |
self.maxLabel.text = str; |
92 |
} |
|
93 |
||
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
94 |
-(NSDictionary *)getDataForEngine { |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
95 |
NSDictionary *dictForEngine = [NSDictionary dictionaryWithObjectsAndKeys: |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
96 |
self.seedCommand,@"seedCommand", |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
97 |
self.templateFilterCommand,@"templateFilterCommand", |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
98 |
self.mapGenCommand,@"mapGenCommand", |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
99 |
self.mazeSizeCommand,@"mazeSizeCommand", |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
100 |
nil]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
101 |
return dictForEngine; |
3547 | 102 |
} |
103 |
||
104 |
#pragma mark - |
|
105 |
#pragma mark Table view data source |
|
106 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
107 |
return 1; |
|
108 |
} |
|
109 |
||
110 |
-(NSInteger) tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger) section { |
|
111 |
if (self.segmentedControl.selectedSegmentIndex != 1) |
|
112 |
return [themeArray count]; |
|
113 |
else |
|
114 |
return [mapArray count]; |
|
115 |
} |
|
116 |
||
117 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
118 |
static NSString *CellIdentifier = @"Cell"; |
|
119 |
NSInteger row = [indexPath row]; |
|
3697 | 120 |
|
3547 | 121 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
3697 | 122 |
if (cell == nil) |
3547 | 123 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
3697 | 124 |
|
3792 | 125 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
126 |
cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
3697 | 127 |
|
3547 | 128 |
if (self.segmentedControl.selectedSegmentIndex != 1) { |
129 |
// the % prevents a strange bug that occurs sporadically |
|
130 |
NSString *themeName = [self.themeArray objectAtIndex:row % [self.themeArray count]]; |
|
131 |
cell.textLabel.text = themeName; |
|
132 |
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/icon.png",THEMES_DIRECTORY(),themeName]]; |
|
133 |
cell.imageView.image = image; |
|
134 |
[image release]; |
|
135 |
} else { |
|
136 |
cell.textLabel.text = [self.mapArray objectAtIndex:row]; |
|
137 |
cell.imageView.image = nil; |
|
138 |
} |
|
3697 | 139 |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
140 |
if (row == [self.lastIndexPath row]) { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
141 |
UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
142 |
cell.accessoryView = checkbox; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
143 |
[checkbox release]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
144 |
} else |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
145 |
cell.accessoryView = nil; |
3547 | 146 |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
147 |
cell.backgroundColor = [UIColor blackColor]; |
3547 | 148 |
return cell; |
149 |
} |
|
150 |
||
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
151 |
// this set details for a static map (called by didSelectRowAtIndexPath) |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
152 |
-(void) setDetailsForStaticMap:(NSInteger) index { |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
153 |
// update label |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
154 |
maxHogs = 18; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
155 |
NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg", MAPS_DIRECTORY(),[self.mapArray objectAtIndex:index]]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
156 |
NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
157 |
[fileCfg release]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
158 |
NSArray *split = [contents componentsSeparatedByString:@"\n"]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
159 |
[contents release]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
160 |
|
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
161 |
// set the theme and map here |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
162 |
self.themeCommand = [NSString stringWithFormat:@"etheme %@", [split objectAtIndex:0]]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
163 |
self.staticMapCommand = [NSString stringWithFormat:@"emap %@", [self.mapArray objectAtIndex:index]]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
164 |
|
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
165 |
// if the number is not set we keep 18 standard; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
166 |
// sometimes it's not set but there are trailing characters, we get around them with the second equation |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
167 |
if ([split count] > 1 && [[split objectAtIndex:1] intValue] > 0) |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
168 |
maxHogs = [[split objectAtIndex:1] intValue]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
169 |
NSString *max = [[NSString alloc] initWithFormat:@"%d",maxHogs]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
170 |
self.maxLabel.text = max; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
171 |
[max release]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
172 |
} |
3547 | 173 |
|
174 |
#pragma mark - |
|
175 |
#pragma mark Table view delegate |
|
176 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
177 |
int newRow = [indexPath row]; |
|
178 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 179 |
|
3547 | 180 |
if (newRow != oldRow) { |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
181 |
[self.tableView reloadData]; |
3547 | 182 |
if (self.segmentedControl.selectedSegmentIndex != 1) { |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
183 |
// just change the theme, don't update preview |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
184 |
self.themeCommand = [NSString stringWithFormat:@"etheme %@", [self.themeArray objectAtIndex:newRow]]; |
3642 | 185 |
} else { |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
186 |
NSString *fileImage = [NSString stringWithFormat:@"%@/%@/preview.png",MAPS_DIRECTORY(),[self.mapArray objectAtIndex:newRow]]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
187 |
[self.previewButton updatePreviewWithFile:fileImage]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
188 |
[self setDetailsForStaticMap:newRow]; |
3642 | 189 |
} |
3697 | 190 |
|
191 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
192 |
UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
193 |
newCell.accessoryView = checkbox; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
194 |
[checkbox release]; |
3547 | 195 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:self.lastIndexPath]; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
196 |
oldCell.accessoryView = nil; |
3547 | 197 |
|
198 |
self.lastIndexPath = indexPath; |
|
199 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
200 |
} |
|
201 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
202 |
} |
|
203 |
||
204 |
#pragma mark - |
|
205 |
#pragma mark slider & segmentedControl |
|
206 |
// this updates the label and the command keys when the slider is moved, depending of the selection in segmentedControl |
|
207 |
// no methods are called by this routine and you can pass nil to it |
|
208 |
-(IBAction) sliderChanged:(id) sender { |
|
209 |
NSString *labelText; |
|
210 |
NSString *templateCommand; |
|
211 |
NSString *mazeCommand; |
|
3697 | 212 |
|
3547 | 213 |
switch ((int)(self.slider.value*100)) { |
214 |
case 0: |
|
215 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
216 |
labelText = NSLocalizedString(@"Wacky",@""); |
|
217 |
} else { |
|
218 |
labelText = NSLocalizedString(@"Large Floating Islands",@""); |
|
219 |
} |
|
220 |
templateCommand = @"e$template_filter 5"; |
|
221 |
mazeCommand = @"e$maze_size 5"; |
|
222 |
break; |
|
223 |
case 1: |
|
224 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
225 |
labelText = NSLocalizedString(@"Cavern",@""); |
|
226 |
} else { |
|
227 |
labelText = NSLocalizedString(@"Medium Floating Islands",@""); |
|
228 |
} |
|
229 |
templateCommand = @"e$template_filter 4"; |
|
230 |
mazeCommand = @"e$maze_size 4"; |
|
231 |
break; |
|
232 |
case 2: |
|
233 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
234 |
labelText = NSLocalizedString(@"Small",@""); |
|
235 |
} else { |
|
236 |
labelText = NSLocalizedString(@"Small Floating Islands",@""); |
|
237 |
} |
|
238 |
templateCommand = @"e$template_filter 1"; |
|
239 |
mazeCommand = @"e$maze_size 3"; |
|
240 |
break; |
|
241 |
case 3: |
|
242 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
243 |
labelText = NSLocalizedString(@"Medium",@""); |
|
244 |
} else { |
|
245 |
labelText = NSLocalizedString(@"Large Tunnels",@""); |
|
246 |
} |
|
247 |
templateCommand = @"e$template_filter 2"; |
|
248 |
mazeCommand = @"e$maze_size 2"; |
|
249 |
break; |
|
250 |
case 4: |
|
251 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
252 |
labelText = NSLocalizedString(@"Large",@""); |
|
253 |
} else { |
|
254 |
labelText = NSLocalizedString(@"Medium Tunnels",@""); |
|
255 |
} |
|
256 |
templateCommand = @"e$template_filter 3"; |
|
257 |
mazeCommand = @"e$maze_size 1"; |
|
258 |
break; |
|
259 |
case 5: |
|
260 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
261 |
labelText = NSLocalizedString(@"All",@""); |
|
262 |
} else { |
|
263 |
labelText = NSLocalizedString(@"Small Tunnels",@""); |
|
264 |
} |
|
265 |
templateCommand = @"e$template_filter 0"; |
|
266 |
mazeCommand = @"e$maze_size 0"; |
|
267 |
break; |
|
268 |
default: |
|
269 |
labelText = nil; |
|
270 |
templateCommand = nil; |
|
271 |
mazeCommand = nil; |
|
272 |
break; |
|
273 |
} |
|
3697 | 274 |
|
3547 | 275 |
self.sizeLabel.text = labelText; |
276 |
self.templateFilterCommand = templateCommand; |
|
277 |
self.mazeSizeCommand = mazeCommand; |
|
278 |
} |
|
279 |
||
280 |
// update preview (if not busy and if its value really changed) as soon as the user lifts its finger up |
|
281 |
-(IBAction) sliderEndedChanging:(id) sender { |
|
282 |
int num = (int) (self.slider.value * 100); |
|
283 |
if (oldValue != num) { |
|
284 |
[self updatePreview]; |
|
285 |
oldValue = num; |
|
286 |
} |
|
3783 | 287 |
playSound(@"clickSound"); |
3547 | 288 |
} |
289 |
||
3697 | 290 |
// perform actions based on the activated section, then call updatePreview to visually update the selection |
3547 | 291 |
// and if necessary update the table with a slide animation |
292 |
-(IBAction) segmentedControlChanged:(id) sender { |
|
3642 | 293 |
NSString *mapgen, *staticmap; |
3547 | 294 |
NSInteger newPage = self.segmentedControl.selectedSegmentIndex; |
3697 | 295 |
|
3783 | 296 |
playSound(@"selSound"); |
3547 | 297 |
switch (newPage) { |
298 |
case 0: // Random |
|
299 |
mapgen = @"e$mapgen 0"; |
|
3642 | 300 |
staticmap = @""; |
3547 | 301 |
[self sliderChanged:nil]; |
302 |
self.slider.enabled = YES; |
|
303 |
break; |
|
3697 | 304 |
|
3547 | 305 |
case 1: // Map |
306 |
mapgen = @"e$mapgen 0"; |
|
3642 | 307 |
// dummy value, everything is set by -updatePreview -> -didSelectRowAtIndexPath -> -updatePreviewWithMap |
308 |
staticmap = @"map Bamboo"; |
|
3547 | 309 |
self.slider.enabled = NO; |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
310 |
self.sizeLabel.text = NSLocalizedString(@"No filter",@""); |
3547 | 311 |
break; |
3697 | 312 |
|
3547 | 313 |
case 2: // Maze |
314 |
mapgen = @"e$mapgen 1"; |
|
3642 | 315 |
staticmap = @""; |
3547 | 316 |
[self sliderChanged:nil]; |
317 |
self.slider.enabled = YES; |
|
318 |
break; |
|
3697 | 319 |
|
3547 | 320 |
default: |
321 |
mapgen = nil; |
|
3642 | 322 |
staticmap = nil; |
3547 | 323 |
break; |
324 |
} |
|
325 |
self.mapGenCommand = mapgen; |
|
3642 | 326 |
self.staticMapCommand = staticmap; |
3547 | 327 |
[self updatePreview]; |
3697 | 328 |
|
3547 | 329 |
// nice animation for updating the table when appropriate (on iphone) |
330 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) |
|
331 |
if (((oldPage == 0 || oldPage == 2) && newPage == 1) || |
|
332 |
(oldPage == 1 && (newPage == 0 || newPage == 2))) { |
|
333 |
[UIView beginAnimations:@"moving out table" context:NULL]; |
|
334 |
self.tableView.frame = CGRectMake(480, 0, 185, 276); |
|
335 |
[UIView commitAnimations]; |
|
336 |
[self performSelector:@selector(moveTable) withObject:nil afterDelay:0.2]; |
|
337 |
} |
|
338 |
oldPage = newPage; |
|
339 |
} |
|
340 |
||
341 |
// update data when table is not visible and then show it |
|
342 |
-(void) moveTable { |
|
343 |
[self.tableView reloadData]; |
|
3697 | 344 |
|
3547 | 345 |
[UIView beginAnimations:@"moving in table" context:NULL]; |
346 |
self.tableView.frame = CGRectMake(295, 0, 185, 276); |
|
347 |
[UIView commitAnimations]; |
|
348 |
} |
|
349 |
||
350 |
#pragma mark - |
|
351 |
#pragma mark view management |
|
352 |
-(void) viewDidLoad { |
|
353 |
[super viewDidLoad]; |
|
3697 | 354 |
|
3547 | 355 |
srandom(time(NULL)); |
3697 | 356 |
|
3547 | 357 |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
358 |
self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
|
359 |
||
360 |
// themes.cfg contains all the user-selectable themes |
|
361 |
NSString *string = [[NSString alloc] initWithContentsOfFile:[THEMES_DIRECTORY() stringByAppendingString:@"/themes.cfg"] |
|
3697 | 362 |
encoding:NSUTF8StringEncoding |
3547 | 363 |
error:NULL]; |
364 |
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[string componentsSeparatedByString:@"\n"]]; |
|
365 |
[string release]; |
|
366 |
// remove a trailing "" element |
|
367 |
[array removeLastObject]; |
|
368 |
self.themeArray = array; |
|
369 |
[array release]; |
|
370 |
self.mapArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL]; |
|
371 |
||
372 |
// initialize some "default" values |
|
373 |
self.sizeLabel.text = NSLocalizedString(@"All",@""); |
|
374 |
self.slider.value = 0.05f; |
|
3697 | 375 |
|
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3783
diff
changeset
|
376 |
// select a map at first because it's faster - done in IB |
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3783
diff
changeset
|
377 |
//self.segmentedControl.selectedSegmentIndex = 1; |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
378 |
if (self.segmentedControl.selectedSegmentIndex == 1) { |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
379 |
self.slider.enabled = NO; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
380 |
self.sizeLabel.text = NSLocalizedString(@"No filter",@""); |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
381 |
} |
3547 | 382 |
|
383 |
self.templateFilterCommand = @"e$template_filter 0"; |
|
384 |
self.mazeSizeCommand = @"e$maze_size 0"; |
|
385 |
self.mapGenCommand = @"e$mapgen 0"; |
|
3642 | 386 |
self.staticMapCommand = @""; |
3697 | 387 |
|
3792 | 388 |
self.lastIndexPath = [NSIndexPath indexPathForRow:-1 inSection:0]; |
3697 | 389 |
|
3547 | 390 |
oldValue = 5; |
391 |
oldPage = 0; |
|
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
392 |
busy = NO; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
393 |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
394 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
395 |
[self.tableView setBackgroundView:nil]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
396 |
self.view.backgroundColor = [UIColor clearColor]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
397 |
self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
398 |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
399 |
self.tableView.rowHeight = 45; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
400 |
} |
3547 | 401 |
} |
402 |
||
403 |
-(void) viewDidAppear:(BOOL) animated { |
|
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
404 |
[self updatePreview]; |
3547 | 405 |
[super viewDidAppear:animated]; |
406 |
} |
|
407 |
||
408 |
#pragma mark - |
|
3705 | 409 |
#pragma mark delegate functions for iPad |
410 |
-(IBAction) buttonPressed:(id) sender { |
|
411 |
if (self.delegate != nil && [delegate respondsToSelector:@selector(buttonPressed:)]) |
|
412 |
[self.delegate buttonPressed:(UIButton *)sender]; |
|
413 |
} |
|
414 |
||
415 |
#pragma mark - |
|
3547 | 416 |
-(void) didReceiveMemoryWarning { |
417 |
[super didReceiveMemoryWarning]; |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
418 |
MSG_MEMCLEAN(); |
3547 | 419 |
} |
420 |
||
421 |
-(void) viewDidUnload { |
|
3705 | 422 |
self.delegate = nil; |
423 |
||
3547 | 424 |
self.previewButton = nil; |
425 |
self.seedCommand = nil; |
|
426 |
self.templateFilterCommand = nil; |
|
427 |
self.mapGenCommand = nil; |
|
428 |
self.mazeSizeCommand = nil; |
|
429 |
self.themeCommand = nil; |
|
3642 | 430 |
self.staticMapCommand = nil; |
3697 | 431 |
|
3547 | 432 |
self.previewButton = nil; |
433 |
self.tableView = nil; |
|
434 |
self.maxLabel = nil; |
|
435 |
self.sizeLabel = nil; |
|
436 |
self.segmentedControl = nil; |
|
437 |
self.slider = nil; |
|
3697 | 438 |
|
3547 | 439 |
self.lastIndexPath = nil; |
440 |
self.themeArray = nil; |
|
441 |
self.mapArray = nil; |
|
3697 | 442 |
|
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
|
443 |
MSG_DIDUNLOAD(); |
3547 | 444 |
[super viewDidUnload]; |
445 |
} |
|
446 |
||
447 |
-(void) dealloc { |
|
3705 | 448 |
self.delegate = nil; |
449 |
||
3547 | 450 |
[seedCommand release]; |
451 |
[templateFilterCommand release]; |
|
452 |
[mapGenCommand release]; |
|
453 |
[mazeSizeCommand release]; |
|
454 |
[themeCommand release]; |
|
3642 | 455 |
[staticMapCommand release]; |
3697 | 456 |
|
3547 | 457 |
[previewButton release]; |
458 |
[tableView release]; |
|
459 |
[maxLabel release]; |
|
460 |
[sizeLabel release]; |
|
461 |
[segmentedControl release]; |
|
462 |
[slider release]; |
|
3697 | 463 |
|
3547 | 464 |
[lastIndexPath release]; |
465 |
[themeArray release]; |
|
466 |
[mapArray release]; |
|
3697 | 467 |
|
3547 | 468 |
[super dealloc]; |
469 |
} |
|
470 |
||
471 |
@end |