author | koda |
Thu, 29 Apr 2010 17:20:42 +0000 | |
changeset 3375 | 88bb88294e06 |
parent 3374 | 0d522416d97f |
child 3385 | 361bd29293f4 |
permissions | -rw-r--r-- |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
1 |
// |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
2 |
// MapConfigViewController.m |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
3 |
// HedgewarsMobile |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
4 |
// |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
5 |
// Created by Vittorio on 22/04/10. |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
7 |
// |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
8 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
9 |
#import "MapConfigViewController.h" |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
10 |
#import "PascalImports.h" |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
11 |
#import "CommodityFunctions.h" |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
12 |
#import "UIImageExtra.h" |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
13 |
#import "SDL_net.h" |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
14 |
#import <pthread.h> |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
15 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
16 |
#define INDICATOR_TAG 7654 |
3373 | 17 |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
18 |
@implementation MapConfigViewController |
3373 | 19 |
@synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand, themeCommand, |
20 |
tableView, maxLabel, sizeLabel, segmentedControl, slider, lastIndexPath, themeArray, mapArray; |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
21 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
22 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
23 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
24 |
return rotationManager(interfaceOrientation); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
25 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
26 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
27 |
#pragma mark - |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
28 |
#pragma mark Preview Handling |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
29 |
-(int) sendToEngine: (NSString *)string { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
30 |
unsigned char length = [string length]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
31 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
32 |
SDLNet_TCP_Send(csd, &length , 1); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
33 |
return SDLNet_TCP_Send(csd, [string UTF8String], length); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
34 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
35 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
36 |
-(void) engineProtocol:(NSInteger) port { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
37 |
IPaddress ip; |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
38 |
BOOL serverQuit = NO; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
39 |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
40 |
if (SDLNet_Init() < 0) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
41 |
NSLog(@"SDLNet_Init: %s", SDLNet_GetError()); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
42 |
serverQuit = YES; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
43 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
44 |
|
3373 | 45 |
// Resolving the host using NULL make network interface to listen |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
46 |
if (SDLNet_ResolveHost(&ip, NULL, port) < 0) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
47 |
NSLog(@"SDLNet_ResolveHost: %s\n", SDLNet_GetError()); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
48 |
serverQuit = YES; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
49 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
50 |
|
3373 | 51 |
// Open a connection with the IP provided (listen on the host's port) |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
52 |
if (!(sd = SDLNet_TCP_Open(&ip))) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
53 |
NSLog(@"SDLNet_TCP_Open: %s %\n", SDLNet_GetError(), port); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
54 |
serverQuit = YES; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
55 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
56 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
57 |
NSLog(@"engineProtocol - Waiting for a client on port %d", port); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
58 |
while (!serverQuit) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
59 |
/* This check the sd if there is a pending connection. |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
60 |
* If there is one, accept that, and open a new socket for communicating */ |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
61 |
csd = SDLNet_TCP_Accept(sd); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
62 |
if (NULL != csd) { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
63 |
NSLog(@"engineProtocol - Client found"); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
64 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
65 |
[self sendToEngine:self.seedCommand]; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
66 |
[self sendToEngine:self.templateFilterCommand]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
67 |
[self sendToEngine:self.mapGenCommand]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
68 |
[self sendToEngine:self.mazeSizeCommand]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
69 |
[self sendToEngine:@"!"]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
70 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
71 |
memset(map, 0, 128*32); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
72 |
SDLNet_TCP_Recv(csd, map, 128*32); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
73 |
SDLNet_TCP_Recv(csd, &maxHogs, sizeof(Uint8)); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
74 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
75 |
SDLNet_TCP_Close(csd); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
76 |
serverQuit = YES; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
77 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
78 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
79 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
80 |
SDLNet_TCP_Close(sd); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
81 |
SDLNet_Quit(); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
82 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
83 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
84 |
-(void) drawingThread { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
85 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
86 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
87 |
// select the port for IPC and launch the preview generation |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
88 |
int port = randomPort(); |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
89 |
pthread_t thread_id; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
90 |
pthread_create(&thread_id, NULL, (void *)GenLandPreview, (void *)port); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
91 |
[self engineProtocol:port]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
92 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
93 |
// draw the buffer (1 pixel per component, 0= transparent 1= color) |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
94 |
int xc = 0; |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
95 |
int yc = -1; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
96 |
UIGraphicsBeginImageContext(CGSizeMake(256,128)); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
97 |
CGContextRef context = UIGraphicsGetCurrentContext(); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
98 |
UIGraphicsPushContext(context); |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
99 |
for (int i = 0; i < 32*128; i++) { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
100 |
unsigned char byte = map[i]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
101 |
for (int j = 0; j < 8; j++) { |
3373 | 102 |
// select the color based on the leftmost bit |
103 |
if ((byte & 0x80) != 0) |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
104 |
CGContextSetRGBFillColor(context, 0.5, 0.5, 0.7, 1.0); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
105 |
else |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
106 |
CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
107 |
// draw pixel |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
108 |
CGContextFillRect(context,CGRectMake(xc,yc,1,1)); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
109 |
// move coordinates |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
110 |
xc = (xc + 1) % 256; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
111 |
if (xc == 0) yc++; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
112 |
// shift to next bit |
3373 | 113 |
byte <<= 1; |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
114 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
115 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
116 |
UIGraphicsPopContext(); |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
117 |
UIImage *previewImage = UIGraphicsGetImageFromCurrentImageContext(); |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
118 |
UIGraphicsEndImageContext(); |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
119 |
|
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
120 |
// set the preview image (autoreleased) in the button and the maxhog label |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
121 |
[self.previewButton setBackgroundImage:previewImage forState:UIControlStateNormal]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
122 |
self.maxLabel.text = [NSString stringWithFormat:@"%d", maxHogs]; |
3366 | 123 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
124 |
// restore functionality of button and remove the spinning wheel |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
125 |
[self turnOnWidgets]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
126 |
UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[self.previewButton viewWithTag:INDICATOR_TAG]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
127 |
[indicator stopAnimating]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
128 |
[indicator removeFromSuperview]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
129 |
|
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
130 |
[pool release]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
131 |
[NSThread exit]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
132 |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
133 |
/* |
3366 | 134 |
// http://developer.apple.com/mac/library/qa/qa2001/qa1037.html |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
135 |
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray(); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
136 |
CGContextRef bitmapImage = CGBitmapContextCreate(mapExp, 128, 32, 8, 128, colorspace, kCGImageAlphaNone); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
137 |
CGColorSpaceRelease(colorspace); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
138 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
139 |
CGImageRef previewCGImage = CGBitmapContextCreateImage(bitmapImage); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
140 |
UIImage *previewImage = [[UIImage alloc] initWithCGImage:previewCGImage]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
141 |
CGImageRelease(previewCGImage); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
142 |
*/ |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
143 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
144 |
|
3373 | 145 |
-(IBAction) updatePreview { |
146 |
// don't generate a new preview while it's already generating one |
|
147 |
if (busy) |
|
148 |
return; |
|
149 |
||
150 |
// generate a seed |
|
151 |
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault); |
|
152 |
NSString *seed = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid); |
|
153 |
CFRelease(uuid); |
|
154 |
NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed]; |
|
155 |
[seed release]; |
|
156 |
self.seedCommand = seedCmd; |
|
157 |
[seedCmd release]; |
|
158 |
||
159 |
NSIndexPath *theIndex; |
|
160 |
if (segmentedControl.selectedSegmentIndex != 1) { |
|
161 |
// prevent other events and add an activity while the preview is beign generated |
|
162 |
[self turnOffWidgets]; |
|
163 |
||
164 |
// remove the current preview |
|
165 |
[self.previewButton setImage:nil forState:UIControlStateNormal]; |
|
166 |
||
167 |
// add a very nice spinning wheel |
|
168 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] |
|
169 |
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
|
170 |
indicator.center = CGPointMake(previewButton.bounds.size.width / 2, previewButton.bounds.size.height / 2); |
|
171 |
indicator.tag = INDICATOR_TAG; |
|
172 |
[indicator startAnimating]; |
|
173 |
[self.previewButton addSubview:indicator]; |
|
174 |
[indicator release]; |
|
175 |
||
176 |
// let's draw in a separate thread so the gui can work; at the end it restore other widgets |
|
177 |
[NSThread detachNewThreadSelector:@selector(drawingThread) toTarget:self withObject:nil]; |
|
178 |
||
179 |
theIndex = [NSIndexPath indexPathForRow:(random()%[self.themeArray count]) inSection:0]; |
|
180 |
} else { |
|
181 |
theIndex = [NSIndexPath indexPathForRow:(random()%[self.mapArray count]) inSection:0]; |
|
182 |
} |
|
183 |
[self.tableView reloadData]; |
|
184 |
[self tableView:self.tableView didSelectRowAtIndexPath:theIndex]; |
|
185 |
[self.tableView scrollToRowAtIndexPath:theIndex atScrollPosition:UITableViewScrollPositionNone animated:YES]; |
|
186 |
} |
|
187 |
||
188 |
-(void) updatePreviewWithMap:(NSInteger) index { |
|
189 |
// change the preview button |
|
190 |
NSString *fileImage = [[NSString alloc] initWithFormat:@"%@/%@/preview.png", MAPS_DIRECTORY(),[self.mapArray objectAtIndex:index]]; |
|
191 |
UIImage *image = [[UIImage alloc] initWithContentsOfFile:fileImage]; |
|
192 |
[fileImage release]; |
|
193 |
[self.previewButton setBackgroundImage:image forState:UIControlStateNormal]; |
|
194 |
[image release]; |
|
195 |
||
196 |
// update label |
|
197 |
maxHogs = 18; |
|
198 |
NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg", MAPS_DIRECTORY(),[self.mapArray objectAtIndex:index]]; |
|
199 |
NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL]; |
|
200 |
[fileCfg release]; |
|
201 |
NSArray *split = [contents componentsSeparatedByString:@"\n"]; |
|
202 |
||
203 |
// if the number is not set we keep 18 standard; |
|
204 |
// sometimes it's not set but there are trailing characters, we get around them with the second equation |
|
205 |
if ([split count] > 1 && [[split objectAtIndex:1] intValue] > 0) |
|
206 |
maxHogs = [[split objectAtIndex:1] intValue]; |
|
207 |
[contents release]; |
|
208 |
NSString *max = [[NSString alloc] initWithFormat:@"%d",maxHogs]; |
|
209 |
self.maxLabel.text = max; |
|
210 |
[max release]; |
|
211 |
} |
|
212 |
||
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
213 |
-(void) turnOffWidgets { |
3373 | 214 |
busy = YES; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
215 |
self.previewButton.alpha = 0.5f; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
216 |
self.previewButton.enabled = NO; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
217 |
self.maxLabel.text = @"..."; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
218 |
self.segmentedControl.enabled = NO; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
219 |
self.tableView.allowsSelection = NO; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
220 |
self.slider.enabled = NO; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
221 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
222 |
|
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
223 |
-(void) turnOnWidgets { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
224 |
self.previewButton.alpha = 1.0f; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
225 |
self.previewButton.enabled = YES; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
226 |
self.segmentedControl.enabled = YES; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
227 |
self.tableView.allowsSelection = YES; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
228 |
self.slider.enabled = YES; |
3373 | 229 |
busy = NO; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
230 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
231 |
|
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
232 |
#pragma mark - |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
233 |
#pragma mark Table view data source |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
234 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
235 |
return 1; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
236 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
237 |
|
3373 | 238 |
-(NSInteger) tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger) section { |
239 |
if (self.segmentedControl.selectedSegmentIndex != 1) |
|
240 |
return [themeArray count]; |
|
241 |
else |
|
242 |
return [mapArray count]; |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
243 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
244 |
|
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
245 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
246 |
static NSString *CellIdentifier = @"Cell"; |
3373 | 247 |
NSInteger row = [indexPath row]; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
248 |
|
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
249 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
250 |
if (cell == nil) |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
251 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
252 |
|
3373 | 253 |
if (self.segmentedControl.selectedSegmentIndex != 1) { |
254 |
// the % prevents a strange bug that occurs sporadically |
|
255 |
NSString *themeName = [self.themeArray objectAtIndex:row % [self.themeArray count]]; |
|
256 |
cell.textLabel.text = themeName; |
|
257 |
UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/Icon.png",THEMES_DIRECTORY(),themeName]]; |
|
258 |
cell.imageView.image = [image scaleToSize:CGSizeMake(40, 40)]; |
|
259 |
} else { |
|
260 |
cell.textLabel.text = [self.mapArray objectAtIndex:row]; |
|
261 |
cell.imageView.image = nil; |
|
262 |
} |
|
263 |
||
264 |
if (row == [self.lastIndexPath row]) |
|
265 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
266 |
else |
|
267 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
268 |
||
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
269 |
return cell; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
270 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
271 |
|
3373 | 272 |
|
273 |
#pragma mark - |
|
274 |
#pragma mark Table view delegate |
|
275 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
276 |
int newRow = [indexPath row]; |
|
277 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
278 |
||
279 |
if (newRow != oldRow) { |
|
280 |
if (self.segmentedControl.selectedSegmentIndex != 1) { |
|
281 |
NSString *theme = [self.themeArray objectAtIndex:newRow]; |
|
282 |
self.themeCommand = [NSString stringWithFormat:@"etheme %@", theme]; |
|
283 |
} else |
|
284 |
[self updatePreviewWithMap:newRow]; |
|
285 |
||
286 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
287 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
288 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:self.lastIndexPath]; |
|
289 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
290 |
||
291 |
self.lastIndexPath = indexPath; |
|
292 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
293 |
} |
|
294 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
295 |
} |
|
296 |
||
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
297 |
#pragma mark - |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
298 |
#pragma mark slider & segmentedControl |
3373 | 299 |
// this updates the label and the command keys when the slider is moved, depending of the selection in segmentedControl |
300 |
// no methods are called by this routine and you can pass nil to it |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
301 |
-(IBAction) sliderChanged:(id) sender { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
302 |
NSString *labelText; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
303 |
NSString *templateCommand; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
304 |
NSString *mazeCommand; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
305 |
|
3373 | 306 |
switch ((int)(self.slider.value*100)) { |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
307 |
case 0: |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
308 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
309 |
labelText = NSLocalizedString(@"Wacky",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
310 |
} else { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
311 |
labelText = NSLocalizedString(@"Large Floating Islands",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
312 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
313 |
templateCommand = @"e$template_filter 5"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
314 |
mazeCommand = @"e$maze_size 5"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
315 |
break; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
316 |
case 1: |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
317 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
318 |
labelText = NSLocalizedString(@"Cavern",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
319 |
} else { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
320 |
labelText = NSLocalizedString(@"Medium Floating Islands",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
321 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
322 |
templateCommand = @"e$template_filter 4"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
323 |
mazeCommand = @"e$maze_size 4"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
324 |
break; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
325 |
case 2: |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
326 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
327 |
labelText = NSLocalizedString(@"Small",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
328 |
} else { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
329 |
labelText = NSLocalizedString(@"Small Floating Islands",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
330 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
331 |
templateCommand = @"e$template_filter 1"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
332 |
mazeCommand = @"e$maze_size 3"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
333 |
break; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
334 |
case 3: |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
335 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
336 |
labelText = NSLocalizedString(@"Medium",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
337 |
} else { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
338 |
labelText = NSLocalizedString(@"Large Tunnels",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
339 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
340 |
templateCommand = @"e$template_filter 2"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
341 |
mazeCommand = @"e$maze_size 2"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
342 |
break; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
343 |
case 4: |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
344 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
345 |
labelText = NSLocalizedString(@"Large",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
346 |
} else { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
347 |
labelText = NSLocalizedString(@"Medium Tunnels",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
348 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
349 |
templateCommand = @"e$template_filter 3"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
350 |
mazeCommand = @"e$maze_size 1"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
351 |
break; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
352 |
case 5: |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
353 |
if (self.segmentedControl.selectedSegmentIndex == 0) { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
354 |
labelText = NSLocalizedString(@"All",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
355 |
} else { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
356 |
labelText = NSLocalizedString(@"Small Tunnels",@""); |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
357 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
358 |
templateCommand = @"e$template_filter 0"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
359 |
mazeCommand = @"e$maze_size 0"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
360 |
break; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
361 |
default: |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
362 |
break; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
363 |
} |
3373 | 364 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
365 |
self.sizeLabel.text = labelText; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
366 |
self.templateFilterCommand = templateCommand; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
367 |
self.mazeSizeCommand = mazeCommand; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
368 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
369 |
|
3373 | 370 |
// update preview (if not busy and if its value really changed) as soon as the user lifts its finger up |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
371 |
-(IBAction) sliderEndedChanging:(id) sender { |
3373 | 372 |
int num = (int) (self.slider.value * 100); |
373 |
if (oldValue != num) { |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
374 |
[self updatePreview]; |
3373 | 375 |
oldValue = num; |
376 |
} |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
377 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
378 |
|
3373 | 379 |
// perform actions based on the activated section, then call updatePreview to visually update the selection |
380 |
// updatePreview will call didSelectRowAtIndexPath which will call the right update routine) |
|
381 |
// and if necessary update the table with a slide animation |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
382 |
-(IBAction) segmentedControlChanged:(id) sender { |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
383 |
NSString *mapgen; |
3373 | 384 |
NSInteger newPage = self.segmentedControl.selectedSegmentIndex; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
385 |
|
3373 | 386 |
switch (newPage) { |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
387 |
case 0: // Random |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
388 |
mapgen = @"e$mapgen 0"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
389 |
[self sliderChanged:nil]; |
3373 | 390 |
self.slider.enabled = YES; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
391 |
break; |
3373 | 392 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
393 |
case 1: // Map |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
394 |
mapgen = @"e$mapgen 0"; |
3373 | 395 |
self.slider.enabled = NO; |
396 |
self.sizeLabel.text = @"."; |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
397 |
break; |
3373 | 398 |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
399 |
case 2: // Maze |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
400 |
mapgen = @"e$mapgen 1"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
401 |
[self sliderChanged:nil]; |
3373 | 402 |
self.slider.enabled = YES; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
403 |
break; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
404 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
405 |
self.mapGenCommand = mapgen; |
3373 | 406 |
[self updatePreview]; |
407 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
408 |
// nice animation for updating the table when appropriate (on iphone) |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
409 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
410 |
if (((oldPage == 0 || oldPage == 2) && newPage == 1) || |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
411 |
(oldPage == 1 && (newPage == 0 || newPage == 2))) { |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
412 |
[UIView beginAnimations:@"moving out table" context:NULL]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
413 |
self.tableView.frame = CGRectMake(480, 0, 185, 276); |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
414 |
[UIView commitAnimations]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
415 |
[self performSelector:@selector(moveTable) withObject:nil afterDelay:0.2]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
416 |
} |
3373 | 417 |
oldPage = newPage; |
418 |
} |
|
419 |
||
420 |
// update data when table is not visible and then show it |
|
421 |
-(void) moveTable { |
|
422 |
[self.tableView reloadData]; |
|
423 |
||
424 |
[UIView beginAnimations:@"moving in table" context:NULL]; |
|
425 |
self.tableView.frame = CGRectMake(295, 0, 185, 276); |
|
426 |
[UIView commitAnimations]; |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
427 |
} |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
428 |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
429 |
#pragma mark - |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
430 |
#pragma mark view management |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
431 |
-(void) viewDidLoad { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
432 |
[super viewDidLoad]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
433 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
434 |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
435 |
self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
436 |
|
3373 | 437 |
// themes.cfg contains all the user-selectable themes |
438 |
NSString *string = [[NSString alloc] initWithContentsOfFile:[THEMES_DIRECTORY() stringByAppendingString:@"/themes.cfg"] |
|
439 |
encoding:NSUTF8StringEncoding |
|
440 |
error:NULL]; |
|
441 |
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[string componentsSeparatedByString:@"\n"]]; |
|
442 |
[string release]; |
|
443 |
// remove a trailing "" element |
|
444 |
[array removeLastObject]; |
|
445 |
self.themeArray = array; |
|
446 |
[array release]; |
|
447 |
self.mapArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL]; |
|
448 |
||
449 |
self.tableView.rowHeight = 42; |
|
450 |
busy = NO; |
|
451 |
// initialize some "default" values |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
452 |
self.sizeLabel.text = NSLocalizedString(@"All",@""); |
3373 | 453 |
self.slider.value = 0.05f; |
454 |
self.segmentedControl.selectedSegmentIndex = 0; |
|
455 |
||
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
456 |
self.templateFilterCommand = @"e$template_filter 0"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
457 |
self.mazeSizeCommand = @"e$maze_size 0"; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
458 |
self.mapGenCommand = @"e$mapgen 0"; |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
459 |
self.lastIndexPath = [NSIndexPath indexPathForRow:0 inSection:0]; |
3373 | 460 |
|
461 |
oldValue = 5; |
|
462 |
oldPage = 0; |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
463 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
464 |
|
3373 | 465 |
-(void) viewDidAppear:(BOOL) animated { |
466 |
[super viewDidAppear:animated]; |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
467 |
[self updatePreview]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
468 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
469 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
470 |
#pragma mark - |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
471 |
#pragma mark memory |
3373 | 472 |
-(void) didReceiveMemoryWarning { |
473 |
[super didReceiveMemoryWarning]; |
|
474 |
} |
|
475 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
476 |
-(void) viewDidUnload { |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
477 |
self.previewButton = nil; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
478 |
self.seedCommand = nil; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
479 |
self.templateFilterCommand = nil; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
480 |
self.mapGenCommand = nil; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
481 |
self.mazeSizeCommand = nil; |
3373 | 482 |
self.themeCommand = nil; |
483 |
||
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
484 |
self.previewButton = nil; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
485 |
self.tableView = nil; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
486 |
self.maxLabel = nil; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
487 |
self.sizeLabel = nil; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
488 |
self.segmentedControl = nil; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
489 |
self.slider = nil; |
3373 | 490 |
|
491 |
self.lastIndexPath = nil; |
|
492 |
self.themeArray = nil; |
|
493 |
self.mapArray = nil; |
|
494 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
495 |
[super viewDidUnload]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
496 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
497 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
498 |
-(void) dealloc { |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
499 |
[seedCommand release]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
500 |
[templateFilterCommand release]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
501 |
[mapGenCommand release]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
502 |
[mazeSizeCommand release]; |
3373 | 503 |
[themeCommand release]; |
504 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
505 |
[previewButton release]; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
506 |
[tableView release]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
507 |
[maxLabel release]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
508 |
[sizeLabel release]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
509 |
[segmentedControl release]; |
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3366
diff
changeset
|
510 |
[slider release]; |
3373 | 511 |
|
512 |
[lastIndexPath release]; |
|
513 |
[themeArray release]; |
|
514 |
[mapArray release]; |
|
515 |
||
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
516 |
[super dealloc]; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
517 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
518 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
519 |
|
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
diff
changeset
|
520 |
@end |