author | koda |
Sun, 09 Oct 2011 01:45:12 +0200 | |
changeset 6108 | 7a8da11a6144 |
parent 6107 | 0741c0f0203e |
child 6109 | f6726ec81e64 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
4976 | 3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
3829 | 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" |
|
6108 | 23 |
#import <QuartzCore/QuartzCore.h> |
4349 | 24 |
#import "SchemeWeaponConfigViewController.h" |
4362
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4356
diff
changeset
|
25 |
#import "GameConfigViewController.h" |
3547 | 26 |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6000
diff
changeset
|
27 |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
28 |
#define scIndex self.segmentedControl.selectedSegmentIndex |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
29 |
#define isRandomness() (segmentedControl.selectedSegmentIndex == 0 || segmentedControl.selectedSegmentIndex == 2) |
3547 | 30 |
|
31 |
@implementation MapConfigViewController |
|
3642 | 32 |
@synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand, themeCommand, staticMapCommand, |
4362
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4356
diff
changeset
|
33 |
missionCommand, tableView, maxLabel, sizeLabel, segmentedControl, slider, lastIndexPath, dataSourceArray, busy, |
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4356
diff
changeset
|
34 |
externalController, parentController; |
3547 | 35 |
|
36 |
||
37 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
38 |
return rotationManager(interfaceOrientation); |
|
39 |
} |
|
40 |
||
3783 | 41 |
-(IBAction) mapButtonPressed { |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
5483
diff
changeset
|
42 |
[AudioManagerController playClickSound]; |
3783 | 43 |
[self updatePreview]; |
44 |
} |
|
45 |
||
46 |
-(void) updatePreview { |
|
3547 | 47 |
// don't generate a new preview while it's already generating one |
48 |
if (busy) |
|
49 |
return; |
|
3697 | 50 |
|
3547 | 51 |
// generate a seed |
52 |
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault); |
|
53 |
NSString *seed = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid); |
|
54 |
CFRelease(uuid); |
|
55 |
NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed]; |
|
56 |
self.seedCommand = seedCmd; |
|
57 |
[seedCmd release]; |
|
3697 | 58 |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
59 |
NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
3547 | 60 |
NSIndexPath *theIndex; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
61 |
if (isRandomness()) { |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
62 |
// 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
|
63 |
[self turnOffWidgets]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
64 |
[self.previewButton updatePreviewWithSeed:seed]; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
65 |
theIndex = [NSIndexPath indexPathForRow:(random()%[source count]) inSection:0]; |
3547 | 66 |
} else { |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
67 |
theIndex = [NSIndexPath indexPathForRow:(random()%[source 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
|
68 |
// the preview for static maps is loaded in didSelectRowAtIndexPath |
3547 | 69 |
} |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
70 |
[seed release]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
71 |
|
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
72 |
// perform as if user clicked on an entry |
3547 | 73 |
[self tableView:self.tableView didSelectRowAtIndexPath:theIndex]; |
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6000
diff
changeset
|
74 |
if (IS_NOT_POWERFUL([HWUtils modelType]) == NO) |
4287 | 75 |
[self.tableView scrollToRowAtIndexPath:theIndex atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; |
3547 | 76 |
} |
77 |
||
78 |
-(void) turnOffWidgets { |
|
79 |
busy = YES; |
|
80 |
self.previewButton.alpha = 0.5f; |
|
81 |
self.previewButton.enabled = NO; |
|
82 |
self.maxLabel.text = @"..."; |
|
83 |
self.segmentedControl.enabled = NO; |
|
84 |
self.slider.enabled = NO; |
|
85 |
} |
|
86 |
||
87 |
-(void) turnOnWidgets { |
|
88 |
self.previewButton.alpha = 1.0f; |
|
89 |
self.previewButton.enabled = YES; |
|
90 |
self.segmentedControl.enabled = YES; |
|
91 |
self.slider.enabled = YES; |
|
92 |
busy = NO; |
|
93 |
} |
|
3697 | 94 |
|
3547 | 95 |
-(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
|
96 |
self.maxHogs = [str intValue]; |
3547 | 97 |
self.maxLabel.text = str; |
98 |
} |
|
99 |
||
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
100 |
-(NSDictionary *)getDataForEngine { |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
nil]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
107 |
return dictForEngine; |
3547 | 108 |
} |
109 |
||
110 |
#pragma mark - |
|
111 |
#pragma mark Table view data source |
|
112 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
113 |
return 1; |
|
114 |
} |
|
115 |
||
116 |
-(NSInteger) tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger) section { |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
117 |
return [[self.dataSourceArray objectAtIndex:scIndex] count]; |
3547 | 118 |
} |
119 |
||
120 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
121 |
static NSString *CellIdentifier = @"Cell"; |
|
122 |
NSInteger row = [indexPath row]; |
|
3697 | 123 |
|
3547 | 124 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
3697 | 125 |
if (cell == nil) |
3547 | 126 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
3697 | 127 |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
128 |
NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
129 |
|
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
130 |
NSString *labelString = [source objectAtIndex:row]; |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
131 |
cell.textLabel.text = labelString; |
3996 | 132 |
cell.textLabel.adjustsFontSizeToFitWidth = YES; |
133 |
cell.textLabel.minimumFontSize = 7; |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6000
diff
changeset
|
134 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4362
diff
changeset
|
135 |
cell.textLabel.backgroundColor = [UIColor clearColor]; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
136 |
|
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
137 |
if (isRandomness()) { |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
138 |
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/icon.png",THEMES_DIRECTORY(),labelString]]; |
3547 | 139 |
cell.imageView.image = image; |
140 |
[image release]; |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
141 |
} else |
3547 | 142 |
cell.imageView.image = nil; |
3697 | 143 |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
cell.accessoryView = checkbox; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
147 |
[checkbox release]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
148 |
} else |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
149 |
cell.accessoryView = nil; |
3547 | 150 |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6000
diff
changeset
|
151 |
cell.backgroundColor = [UIColor blackColorTransparent]; |
3547 | 152 |
return cell; |
153 |
} |
|
154 |
||
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
155 |
// 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
|
156 |
-(void) setDetailsForStaticMap:(NSInteger) index { |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
157 |
NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
158 |
|
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
159 |
NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg", |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
160 |
(scIndex == 1) ? MAPS_DIRECTORY() : MISSIONS_DIRECTORY(),[source objectAtIndex:index]]; |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
161 |
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
|
162 |
[fileCfg release]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
163 |
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
|
164 |
[contents release]; |
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
165 |
|
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
166 |
// 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
|
167 |
// 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
|
168 |
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
|
169 |
maxHogs = [[split objectAtIndex:1] intValue]; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
170 |
else |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
171 |
maxHogs = 18; |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
172 |
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
|
173 |
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
|
174 |
[max release]; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
175 |
|
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
176 |
self.themeCommand = [NSString stringWithFormat:@"etheme %@", [split objectAtIndex:0]]; |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
177 |
self.staticMapCommand = [NSString stringWithFormat:@"emap %@", [source objectAtIndex:index]]; |
3912
e11df2de6af2
have engine try for a second position when map loading fails (in this way it's possible to move Missions data to any path)
koda
parents:
3911
diff
changeset
|
178 |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
179 |
if (scIndex != 3) |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
180 |
self.missionCommand = @""; |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
181 |
else |
3920
a54ca6185307
updated lua loading in the ifrontend and also fixed masked maps
koda
parents:
3912
diff
changeset
|
182 |
self.missionCommand = [NSString stringWithFormat:@"escript Missions/Maps/%@/map.lua",[source objectAtIndex:index]]; |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
183 |
} |
3547 | 184 |
|
185 |
#pragma mark - |
|
186 |
#pragma mark Table view delegate |
|
187 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
188 |
int newRow = [indexPath row]; |
|
189 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 190 |
|
3547 | 191 |
if (newRow != oldRow) { |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
192 |
NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
193 |
if (isRandomness()) { |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
194 |
// just change the theme, don't update preview |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
195 |
self.themeCommand = [NSString stringWithFormat:@"etheme %@", [source objectAtIndex:newRow]]; |
3642 | 196 |
} else { |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
197 |
NSString *fileImage = [NSString stringWithFormat:@"%@/%@/preview.png", |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
198 |
(scIndex == 1) ? MAPS_DIRECTORY() : MISSIONS_DIRECTORY(),[source objectAtIndex:newRow]]; |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
199 |
[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
|
200 |
[self setDetailsForStaticMap:newRow]; |
3642 | 201 |
} |
3697 | 202 |
|
203 |
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
|
204 |
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
|
205 |
newCell.accessoryView = checkbox; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
206 |
[checkbox release]; |
3547 | 207 |
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
|
208 |
oldCell.accessoryView = nil; |
3547 | 209 |
|
210 |
self.lastIndexPath = indexPath; |
|
211 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
212 |
} |
|
213 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
214 |
} |
|
215 |
||
216 |
#pragma mark - |
|
4082 | 217 |
#pragma mark slider & segmentedControl & button |
3547 | 218 |
// this updates the label and the command keys when the slider is moved, depending of the selection in segmentedControl |
219 |
// no methods are called by this routine and you can pass nil to it |
|
220 |
-(IBAction) sliderChanged:(id) sender { |
|
221 |
NSString *labelText; |
|
222 |
NSString *templateCommand; |
|
223 |
NSString *mazeCommand; |
|
3697 | 224 |
|
3547 | 225 |
switch ((int)(self.slider.value*100)) { |
226 |
case 0: |
|
227 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
228 |
labelText = NSLocalizedString(@"Wacky",@""); |
|
229 |
} else { |
|
230 |
labelText = NSLocalizedString(@"Large Floating Islands",@""); |
|
231 |
} |
|
232 |
templateCommand = @"e$template_filter 5"; |
|
233 |
mazeCommand = @"e$maze_size 5"; |
|
234 |
break; |
|
235 |
case 1: |
|
236 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
237 |
labelText = NSLocalizedString(@"Cavern",@""); |
|
238 |
} else { |
|
239 |
labelText = NSLocalizedString(@"Medium Floating Islands",@""); |
|
240 |
} |
|
241 |
templateCommand = @"e$template_filter 4"; |
|
242 |
mazeCommand = @"e$maze_size 4"; |
|
243 |
break; |
|
244 |
case 2: |
|
245 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
246 |
labelText = NSLocalizedString(@"Small",@""); |
|
247 |
} else { |
|
248 |
labelText = NSLocalizedString(@"Small Floating Islands",@""); |
|
249 |
} |
|
250 |
templateCommand = @"e$template_filter 1"; |
|
251 |
mazeCommand = @"e$maze_size 3"; |
|
252 |
break; |
|
253 |
case 3: |
|
254 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
255 |
labelText = NSLocalizedString(@"Medium",@""); |
|
256 |
} else { |
|
257 |
labelText = NSLocalizedString(@"Large Tunnels",@""); |
|
258 |
} |
|
259 |
templateCommand = @"e$template_filter 2"; |
|
260 |
mazeCommand = @"e$maze_size 2"; |
|
261 |
break; |
|
262 |
case 4: |
|
263 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
264 |
labelText = NSLocalizedString(@"Large",@""); |
|
265 |
} else { |
|
266 |
labelText = NSLocalizedString(@"Medium Tunnels",@""); |
|
267 |
} |
|
268 |
templateCommand = @"e$template_filter 3"; |
|
269 |
mazeCommand = @"e$maze_size 1"; |
|
270 |
break; |
|
271 |
case 5: |
|
272 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
|
273 |
labelText = NSLocalizedString(@"All",@""); |
|
274 |
} else { |
|
275 |
labelText = NSLocalizedString(@"Small Tunnels",@""); |
|
276 |
} |
|
277 |
templateCommand = @"e$template_filter 0"; |
|
278 |
mazeCommand = @"e$maze_size 0"; |
|
279 |
break; |
|
280 |
default: |
|
281 |
labelText = nil; |
|
282 |
templateCommand = nil; |
|
283 |
mazeCommand = nil; |
|
284 |
break; |
|
285 |
} |
|
3697 | 286 |
|
3547 | 287 |
self.sizeLabel.text = labelText; |
288 |
self.templateFilterCommand = templateCommand; |
|
289 |
self.mazeSizeCommand = mazeCommand; |
|
290 |
} |
|
291 |
||
292 |
// update preview (if not busy and if its value really changed) as soon as the user lifts its finger up |
|
293 |
-(IBAction) sliderEndedChanging:(id) sender { |
|
294 |
int num = (int) (self.slider.value * 100); |
|
295 |
if (oldValue != num) { |
|
296 |
[self updatePreview]; |
|
297 |
oldValue = num; |
|
298 |
} |
|
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
5483
diff
changeset
|
299 |
[AudioManagerController playClickSound]; |
3547 | 300 |
} |
301 |
||
3697 | 302 |
// perform actions based on the activated section, then call updatePreview to visually update the selection |
3547 | 303 |
// and if necessary update the table with a slide animation |
304 |
-(IBAction) segmentedControlChanged:(id) sender { |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
305 |
NSString *mapgen, *staticmap, *mission; |
3547 | 306 |
NSInteger newPage = self.segmentedControl.selectedSegmentIndex; |
3697 | 307 |
|
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
5483
diff
changeset
|
308 |
[AudioManagerController playSelectSound]; |
3547 | 309 |
switch (newPage) { |
310 |
case 0: // Random |
|
311 |
mapgen = @"e$mapgen 0"; |
|
3642 | 312 |
staticmap = @""; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
313 |
mission = @""; |
3547 | 314 |
[self sliderChanged:nil]; |
315 |
self.slider.enabled = YES; |
|
4349 | 316 |
[externalController fillSections]; |
3547 | 317 |
break; |
3697 | 318 |
|
3547 | 319 |
case 1: // Map |
320 |
mapgen = @"e$mapgen 0"; |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
321 |
// dummy values, these are set by -updatePreview -> -didSelectRowAtIndexPath -> -setDetailsForStaticMap |
3642 | 322 |
staticmap = @"map Bamboo"; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
323 |
mission = @""; |
3547 | 324 |
self.slider.enabled = NO; |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
325 |
self.sizeLabel.text = NSLocalizedString(@"No filter",@""); |
4349 | 326 |
[externalController fillSections]; |
3547 | 327 |
break; |
3697 | 328 |
|
3547 | 329 |
case 2: // Maze |
330 |
mapgen = @"e$mapgen 1"; |
|
3642 | 331 |
staticmap = @""; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
332 |
mission = @""; |
3547 | 333 |
[self sliderChanged:nil]; |
334 |
self.slider.enabled = YES; |
|
4349 | 335 |
[externalController fillSections]; |
336 |
break; |
|
337 |
||
338 |
case 3: // Mission |
|
339 |
mapgen = @"e$mapgen 0"; |
|
340 |
// dummy values, these are set by -updatePreview -> -didSelectRowAtIndexPath -> -setDetailsForStaticMap |
|
341 |
staticmap = @"map Bamboo"; |
|
342 |
mission = @""; |
|
343 |
self.slider.enabled = NO; |
|
344 |
self.sizeLabel.text = NSLocalizedString(@"No filter",@""); |
|
345 |
[externalController emptySections]; |
|
3547 | 346 |
break; |
3697 | 347 |
|
3547 | 348 |
default: |
349 |
mapgen = nil; |
|
3642 | 350 |
staticmap = nil; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
351 |
mission = nil; |
3547 | 352 |
break; |
353 |
} |
|
354 |
self.mapGenCommand = mapgen; |
|
3642 | 355 |
self.staticMapCommand = staticmap; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
356 |
self.missionCommand = mission; |
3697 | 357 |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
358 |
[self.tableView reloadData]; |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
359 |
[self updatePreview]; |
3547 | 360 |
oldPage = newPage; |
361 |
} |
|
362 |
||
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
363 |
-(IBAction) buttonPressed:(id) sender { |
4362
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4356
diff
changeset
|
364 |
[self.parentController buttonPressed:sender]; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
365 |
} |
3697 | 366 |
|
4082 | 367 |
#pragma mark - |
368 |
#pragma mark view management |
|
6107 | 369 |
-(NSArray *) dataSourceArray { |
370 |
if (dataSourceArray == nil) { |
|
371 |
NSString *model = [HWUtils modelType]; |
|
372 |
||
373 |
// only folders containing icon.png are a valid theme |
|
374 |
NSArray *themeArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:THEMES_DIRECTORY() error:NULL]; |
|
375 |
NSMutableArray *themeArray = [[NSMutableArray alloc] init]; |
|
376 |
for (NSString *themeName in themeArrayFull) { |
|
377 |
NSString *checkPath = [[NSString alloc] initWithFormat:@"%@/%@/icon.png",THEMES_DIRECTORY(),themeName]; |
|
378 |
if ([[NSFileManager defaultManager] fileExistsAtPath:checkPath]) |
|
379 |
[themeArray addObject:themeName]; |
|
380 |
[checkPath release]; |
|
381 |
} |
|
382 |
||
383 |
// remove images that are too big for certain devices without loading the whole image |
|
384 |
NSArray *mapArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL]; |
|
385 |
NSMutableArray *mapArray = [[NSMutableArray alloc] init]; |
|
386 |
for (NSString *str in mapArrayFull) { |
|
387 |
CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MAPS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]]; |
|
388 |
if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f) |
|
389 |
continue; |
|
390 |
if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f) |
|
391 |
continue; |
|
392 |
[mapArray addObject:str]; |
|
393 |
} |
|
394 |
||
395 |
NSArray *missionArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MISSIONS_DIRECTORY() error:NULL]; |
|
396 |
NSMutableArray *missionArray = [[NSMutableArray alloc] init]; |
|
397 |
for (NSString *str in missionArrayFull) { |
|
398 |
CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MISSIONS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]]; |
|
399 |
if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f) |
|
400 |
continue; |
|
401 |
if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f) |
|
402 |
continue; |
|
403 |
[missionArray addObject:str]; |
|
404 |
} |
|
405 |
NSArray *array = [[NSArray alloc] initWithObjects:themeArray,mapArray,themeArray,missionArray,nil]; |
|
406 |
[missionArray release]; |
|
407 |
[themeArray release]; |
|
408 |
[mapArray release]; |
|
409 |
||
410 |
self.dataSourceArray = array; |
|
411 |
[array release]; |
|
5281 | 412 |
} |
6107 | 413 |
return dataSourceArray; |
3547 | 414 |
} |
415 |
||
416 |
-(void) viewDidLoad { |
|
417 |
[super viewDidLoad]; |
|
3697 | 418 |
|
3547 | 419 |
srandom(time(NULL)); |
3697 | 420 |
|
3547 | 421 |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
422 |
self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
423 |
|
3547 | 424 |
// initialize some "default" values |
425 |
self.sizeLabel.text = NSLocalizedString(@"All",@""); |
|
426 |
self.slider.value = 0.05f; |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
427 |
oldValue = 5; |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
428 |
|
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
429 |
busy = NO; |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
430 |
self.lastIndexPath = [NSIndexPath indexPathForRow:-1 inSection:0]; |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
431 |
|
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3783
diff
changeset
|
432 |
// select a map at first because it's faster - done in IB |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
433 |
oldPage = 1; |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
434 |
if (self.segmentedControl.selectedSegmentIndex == 1) { |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
435 |
self.slider.enabled = NO; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
436 |
self.sizeLabel.text = NSLocalizedString(@"No filter",@""); |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
437 |
} |
3547 | 438 |
|
439 |
self.templateFilterCommand = @"e$template_filter 0"; |
|
440 |
self.mazeSizeCommand = @"e$maze_size 0"; |
|
441 |
self.mapGenCommand = @"e$mapgen 0"; |
|
3642 | 442 |
self.staticMapCommand = @""; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
443 |
self.missionCommand = @""; |
3910
dd47efbdec46
move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents:
3829
diff
changeset
|
444 |
|
6108 | 445 |
if (IS_IPAD()) { |
446 |
[self.tableView setBackgroundColorForAnyTable:[UIColor darkBlueColorTransparent]]; |
|
447 |
self.tableView.layer.borderColor = [[UIColor darkYellowColor] CGColor]; |
|
448 |
self.tableView.layer.borderWidth = 2.7f; |
|
449 |
self.tableView.layer.cornerRadius = 8; |
|
450 |
self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 10, 0); |
|
451 |
} |
|
452 |
self.tableView.separatorColor = [UIColor whiteColor]; |
|
4244 | 453 |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
3547 | 454 |
} |
455 |
||
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
456 |
-(void) viewWillAppear:(BOOL)animated { |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
457 |
[super viewWillAppear:animated]; |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
458 |
} |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
459 |
|
3547 | 460 |
-(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
|
461 |
[self updatePreview]; |
3547 | 462 |
[super viewDidAppear:animated]; |
463 |
} |
|
464 |
||
465 |
-(void) viewDidUnload { |
|
466 |
self.previewButton = nil; |
|
467 |
self.seedCommand = nil; |
|
468 |
self.templateFilterCommand = nil; |
|
469 |
self.mapGenCommand = nil; |
|
470 |
self.mazeSizeCommand = nil; |
|
471 |
self.themeCommand = nil; |
|
3642 | 472 |
self.staticMapCommand = nil; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
473 |
self.missionCommand = nil; |
3697 | 474 |
|
3547 | 475 |
self.previewButton = nil; |
476 |
self.tableView = nil; |
|
477 |
self.maxLabel = nil; |
|
478 |
self.sizeLabel = nil; |
|
479 |
self.segmentedControl = nil; |
|
480 |
self.slider = nil; |
|
3697 | 481 |
|
3547 | 482 |
self.lastIndexPath = nil; |
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
483 |
self.dataSourceArray = nil; |
3697 | 484 |
|
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
|
485 |
MSG_DIDUNLOAD(); |
3547 | 486 |
[super viewDidUnload]; |
487 |
} |
|
488 |
||
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
489 |
-(void) didReceiveMemoryWarning { |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
490 |
self.dataSourceArray = nil; |
4356 | 491 |
[super didReceiveMemoryWarning]; |
3984 | 492 |
|
4356 | 493 |
if (self.view.superview == nil) { |
494 |
self.tableView = nil; |
|
495 |
self.maxLabel = nil; |
|
496 |
self.sizeLabel = nil; |
|
497 |
self.slider = nil; |
|
498 |
} |
|
3971 | 499 |
|
3911
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
500 |
MSG_MEMCLEAN(); |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
501 |
} |
46d7a5cf8ac6
further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents:
3910
diff
changeset
|
502 |
|
3547 | 503 |
-(void) dealloc { |
5208 | 504 |
releaseAndNil(seedCommand); |
505 |
releaseAndNil(templateFilterCommand); |
|
506 |
releaseAndNil(mapGenCommand); |
|
507 |
releaseAndNil(mazeSizeCommand); |
|
508 |
releaseAndNil(themeCommand); |
|
509 |
releaseAndNil(staticMapCommand); |
|
510 |
releaseAndNil(missionCommand); |
|
3697 | 511 |
|
5208 | 512 |
releaseAndNil(previewButton); |
513 |
releaseAndNil(tableView); |
|
514 |
releaseAndNil(maxLabel); |
|
515 |
releaseAndNil(sizeLabel); |
|
516 |
releaseAndNil(segmentedControl); |
|
517 |
releaseAndNil(slider); |
|
3697 | 518 |
|
5208 | 519 |
releaseAndNil(lastIndexPath); |
520 |
releaseAndNil(dataSourceArray); |
|
3697 | 521 |
|
3547 | 522 |
[super dealloc]; |
523 |
} |
|
524 |
||
525 |
@end |