project_files/HedgewarsMobile/Classes/MapConfigViewController.m
author koda
Sun, 19 Sep 2010 22:56:53 +0200
changeset 3889 f7d6834a54fe
parent 3829 81db3c85784b
child 3910 dd47efbdec46
permissions -rw-r--r--
Added tag Hedgewars-iOS-1.0.1 for changeset 3620607258cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3829
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
     1
/*
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
     3
 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
     4
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
     8
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
    12
 * GNU General Public License for more details.
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
    13
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
    14
 * You should have received a copy of the GNU General Public License
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
    15
 * along with this program; if not, write to the Free Software
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
    17
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
    18
 * File created on 22/04/2010.
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
    19
 */
81db3c85784b headers ftw, also right project file
koda
parents: 3792
diff changeset
    20
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
#import "MapConfigViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
#import "PascalImports.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
#import "CommodityFunctions.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
#import "UIImageExtra.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
#import "SDL_net.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
#import <pthread.h>
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
#define INDICATOR_TAG 7654
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
@implementation MapConfigViewController
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
    32
@synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand, themeCommand, staticMapCommand,
3705
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
    33
            tableView, maxLabel, sizeLabel, segmentedControl, slider, lastIndexPath, themeArray, mapArray, busy, delegate;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
    return rotationManager(interfaceOrientation);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    40
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    41
#pragma mark Preview Handling
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    42
-(int) sendToEngine: (NSString *)string {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    43
    unsigned char length = [string length];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    44
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
    SDLNet_TCP_Send(csd, &length , 1);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
    return SDLNet_TCP_Send(csd, [string UTF8String], length);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
-(const uint8_t *)engineProtocol:(NSInteger) port {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
    IPaddress ip;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
    BOOL serverQuit = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
    static uint8_t map[128*32];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    53
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
    if (SDLNet_Init() < 0) {
3660
bc125bea5849 complete settings page rework
koda
parents: 3642
diff changeset
    55
        DLog(@"SDLNet_Init: %s", SDLNet_GetError());
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
        serverQuit = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    58
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
    // Resolving the host using NULL make network interface to listen
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
    if (SDLNet_ResolveHost(&ip, NULL, port) < 0) {
3660
bc125bea5849 complete settings page rework
koda
parents: 3642
diff changeset
    61
        DLog(@"SDLNet_ResolveHost: %s\n", SDLNet_GetError());
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
        serverQuit = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    64
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
    // Open a connection with the IP provided (listen on the host's port)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
    if (!(sd = SDLNet_TCP_Open(&ip))) {
3660
bc125bea5849 complete settings page rework
koda
parents: 3642
diff changeset
    67
        DLog(@"SDLNet_TCP_Open: %s %\n", SDLNet_GetError(), port);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
        serverQuit = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    70
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
    // launch the preview here so that we're sure the tcp channel is open
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
    pthread_t thread_id;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    73
    pthread_create(&thread_id, NULL, (void *)GenLandPreview, (void *)port);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    74
    pthread_detach(thread_id);
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    75
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
    DLog(@"Waiting for a client on port %d", port);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
    while (!serverQuit) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
        /* This check the sd if there is a pending connection.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
         * If there is one, accept that, and open a new socket for communicating */
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
        csd = SDLNet_TCP_Accept(sd);
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    81
        if (NULL != csd) {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
            DLog(@"Client found");
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    83
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
            [self sendToEngine:self.seedCommand];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    85
            [self sendToEngine:self.templateFilterCommand];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    86
            [self sendToEngine:self.mapGenCommand];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    87
            [self sendToEngine:self.mazeSizeCommand];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    88
            [self sendToEngine:@"!"];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    89
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    90
            memset(map, 0, 128*32);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    91
            SDLNet_TCP_Recv(csd, map, 128*32);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    92
            SDLNet_TCP_Recv(csd, &maxHogs, sizeof(uint8_t));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
            SDLNet_TCP_Close(csd);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
            serverQuit = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    96
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    97
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    98
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
    SDLNet_TCP_Close(sd);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   100
    SDLNet_Quit();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   101
    return map;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   102
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   103
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
-(void) drawingThread {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   105
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   106
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   107
    // select the port for IPC and launch the preview generation through engineProtocol:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   108
    int port = randomPort();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   109
    const uint8_t *map = [self engineProtocol:port];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
    uint8_t mapExp[128*32*8];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   111
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   112
    // draw the buffer (1 pixel per component, 0= transparent 1= color)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   113
    int k = 0;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   114
    for (int i = 0; i < 32*128; i++) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   115
        unsigned char byte = map[i];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   116
        for (int j = 0; j < 8; j++) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   117
            // select the color based on the leftmost bit
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   118
            if ((byte & 0x80) != 0)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   119
                mapExp[k] = 100;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   120
            else
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   121
                mapExp[k] = 255;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
            // shift to next bit
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
            byte <<= 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
            k++;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   125
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   126
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
    CGContextRef bitmapImage = CGBitmapContextCreate(mapExp, 256, 128, 8, 256, colorspace, kCGImageAlphaNone);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   129
    CGColorSpaceRelease(colorspace);
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   130
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   131
    CGImageRef previewCGImage = CGBitmapContextCreateImage(bitmapImage);
3598
a8aa06bae895 tiy new overlay graphics
koda
parents: 3547
diff changeset
   132
    CGContextRelease(bitmapImage);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   133
    UIImage *previewImage = [[UIImage alloc] initWithCGImage:previewCGImage];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   134
    CGImageRelease(previewCGImage);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   135
    previewCGImage = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   136
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
    // set the preview image (autoreleased) in the button and the maxhog label on the main thread to prevent a leak
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   138
    [self performSelectorOnMainThread:@selector(setButtonImage:) withObject:[previewImage makeRoundCornersOfSize:CGSizeMake(12, 12)] waitUntilDone:NO];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   139
    [previewImage release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   140
    [self performSelectorOnMainThread:@selector(setLabelText:) withObject:[NSString stringWithFormat:@"%d", maxHogs] waitUntilDone:NO];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   141
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   142
    // restore functionality of button and remove the spinning wheel on the main thread to prevent a leak
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   143
    [self performSelectorOnMainThread:@selector(turnOnWidgets) withObject:nil waitUntilDone:NO];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   144
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   145
    [pool release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   146
    //Invoking this method should be avoided as it does not give your thread a chance to clean up any resources it allocated during its execution.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   147
    //[NSThread exit];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   148
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   149
    /*
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   150
    // http://developer.apple.com/mac/library/qa/qa2001/qa1037.html
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   151
    UIGraphicsBeginImageContext(CGSizeMake(256,128));
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   152
    CGContextRef context = UIGraphicsGetCurrentContext();
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   153
    UIGraphicsPushContext(context);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   154
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   155
    CGContextSetRGBFillColor(context, 0.5, 0.5, 0.7, 1.0);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   156
    CGContextFillRect(context,CGRectMake(xc,yc,1,1));
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   157
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   158
    UIGraphicsPopContext();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   159
    UIImage *previewImage = UIGraphicsGetImageFromCurrentImageContext();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   160
    UIGraphicsEndImageContext();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   161
    */
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   162
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   163
3783
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3780
diff changeset
   164
-(IBAction) mapButtonPressed {
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3780
diff changeset
   165
    playSound(@"clickSound");
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3780
diff changeset
   166
    [self updatePreview];
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3780
diff changeset
   167
}
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3780
diff changeset
   168
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3780
diff changeset
   169
-(void) updatePreview {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   170
    // don't generate a new preview while it's already generating one
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   171
    if (busy)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   172
        return;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   173
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   174
    // generate a seed
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   175
    CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   176
    NSString *seed = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   177
    CFRelease(uuid);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   178
    NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   179
    [seed release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   180
    self.seedCommand = seedCmd;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   181
    [seedCmd release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   182
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   183
    NSIndexPath *theIndex;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   184
    if (segmentedControl.selectedSegmentIndex != 1) {
3670
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   185
        // remove the current preview and title
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   186
        [self.previewButton setImage:nil forState:UIControlStateNormal];
3670
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   187
        [self.previewButton setTitle:nil forState:UIControlStateNormal];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   188
3670
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   189
        // don't display preview on slower device, too slow and memory hog
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   190
        NSString *modelId = modelType();
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   191
        if ([modelId hasPrefix:@"iPhone1"] || [modelId hasPrefix:@"iPod1,1"] || [modelId hasPrefix:@"iPod2,1"]) {
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   192
            busy = NO;
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   193
            [self.previewButton setTitle:NSLocalizedString(@"Preview not available",@"") forState:UIControlStateNormal];
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   194
        } else {
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   195
            // prevent other events and add an activity while the preview is beign generated
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   196
            [self turnOffWidgets];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   197
3670
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   198
            // add a very nice spinning wheel
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   199
            UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]
3670
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   200
                                                  initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   201
            indicator.center = CGPointMake(previewButton.bounds.size.width / 2, previewButton.bounds.size.height / 2);
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   202
            indicator.tag = INDICATOR_TAG;
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   203
            [indicator startAnimating];
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   204
            [self.previewButton addSubview:indicator];
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   205
            [indicator release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   206
3670
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   207
            // let's draw in a separate thread so the gui can work; at the end it restore other widgets
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   208
            [NSThread detachNewThreadSelector:@selector(drawingThread) toTarget:self withObject:nil];
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3662
diff changeset
   209
        }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   210
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   211
        theIndex = [NSIndexPath indexPathForRow:(random()%[self.themeArray count]) inSection:0];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   212
    } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   213
        theIndex = [NSIndexPath indexPathForRow:(random()%[self.mapArray count]) inSection:0];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   214
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   215
    [self.tableView reloadData];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   216
    [self tableView:self.tableView didSelectRowAtIndexPath:theIndex];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   217
    [self.tableView scrollToRowAtIndexPath:theIndex atScrollPosition:UITableViewScrollPositionNone animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   218
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   219
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   220
// instead of drawing a random map we load an image; this function is called by didSelectRowAtIndexPath only
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   221
-(void) updatePreviewWithMap:(NSInteger) index {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   222
    // change the preview button
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   223
    NSString *fileImage = [[NSString alloc] initWithFormat:@"%@/%@/preview.png", MAPS_DIRECTORY(),[self.mapArray objectAtIndex:index]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   224
    UIImage *image = [[UIImage alloc] initWithContentsOfFile:fileImage];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   225
    [fileImage release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   226
    [self.previewButton setImage:[image makeRoundCornersOfSize:CGSizeMake(12, 12)] forState:UIControlStateNormal];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   227
    [image release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   228
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   229
    // update label
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   230
    maxHogs = 18;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   231
    NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg", MAPS_DIRECTORY(),[self.mapArray objectAtIndex:index]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   232
    NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   233
    [fileCfg release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   234
    NSArray *split = [contents componentsSeparatedByString:@"\n"];
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   235
    [contents release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   236
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   237
    // set the theme and map here
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   238
    self.themeCommand = [NSString stringWithFormat:@"etheme %@", [split objectAtIndex:0]];
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   239
    self.staticMapCommand = [NSString stringWithFormat:@"emap %@", [self.mapArray objectAtIndex:index]];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   240
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   241
    // if the number is not set we keep 18 standard;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   242
    // sometimes it's not set but there are trailing characters, we get around them with the second equation
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   243
    if ([split count] > 1 && [[split objectAtIndex:1] intValue] > 0)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   244
        maxHogs = [[split objectAtIndex:1] intValue];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   245
    NSString *max = [[NSString alloc] initWithFormat:@"%d",maxHogs];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   246
    self.maxLabel.text = max;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   247
    [max release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   248
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   249
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   250
-(void) turnOffWidgets {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   251
    busy = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   252
    self.previewButton.alpha = 0.5f;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   253
    self.previewButton.enabled = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   254
    self.maxLabel.text = @"...";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   255
    self.segmentedControl.enabled = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   256
    self.slider.enabled = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   257
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   258
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   259
-(void) turnOnWidgets {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   260
    self.previewButton.alpha = 1.0f;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   261
    self.previewButton.enabled = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   262
    self.segmentedControl.enabled = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   263
    self.slider.enabled = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   264
    busy = NO;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   265
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   266
    UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[self.previewButton viewWithTag:INDICATOR_TAG];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   267
    if (indicator) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   268
        [indicator stopAnimating];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   269
        [indicator removeFromSuperview];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   270
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   271
}
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   272
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   273
-(void) setLabelText:(NSString *)str {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   274
    self.maxLabel.text = str;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   275
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   276
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   277
-(void) setButtonImage:(UIImage *)img {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   278
    [self.previewButton setBackgroundImage:img forState:UIControlStateNormal];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   279
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   280
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   281
-(void) restoreBackgroundImage {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   282
    // white rounded rectangle as background image for previewButton
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   283
    UIGraphicsBeginImageContext(CGSizeMake(256,128));
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   284
    CGContextRef context = UIGraphicsGetCurrentContext();
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   285
    UIGraphicsPushContext(context);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   286
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   287
    CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   288
    CGContextFillRect(context,CGRectMake(0,0,256,128));
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   289
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   290
    UIGraphicsPopContext();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   291
    UIImage *bkgImg = UIGraphicsGetImageFromCurrentImageContext();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   292
    UIGraphicsEndImageContext();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   293
    [self.previewButton setBackgroundImage:[bkgImg makeRoundCornersOfSize:CGSizeMake(12, 12)] forState:UIControlStateNormal];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   294
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   295
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   296
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   297
#pragma mark Table view data source
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   298
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   299
    return 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   300
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   301
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   302
-(NSInteger) tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger) section {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   303
    if (self.segmentedControl.selectedSegmentIndex != 1)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   304
        return [themeArray count];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   305
    else
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   306
        return [mapArray count];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   307
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   308
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   309
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   310
    static NSString *CellIdentifier = @"Cell";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   311
    NSInteger row = [indexPath row];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   312
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   313
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   314
    if (cell == nil)
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   315
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   316
3792
dd9345e74b66 help page for lobby
koda
parents: 3791
diff changeset
   317
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
3703
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   318
        cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   319
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   320
    if (self.segmentedControl.selectedSegmentIndex != 1) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   321
        // the % prevents a strange bug that occurs sporadically
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   322
        NSString *themeName = [self.themeArray objectAtIndex:row % [self.themeArray count]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   323
        cell.textLabel.text = themeName;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   324
        UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/icon.png",THEMES_DIRECTORY(),themeName]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   325
        cell.imageView.image = image;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   326
        [image release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   327
    } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   328
        cell.textLabel.text = [self.mapArray objectAtIndex:row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   329
        cell.imageView.image = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   330
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   331
3703
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   332
    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
   333
        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
   334
        cell.accessoryView = checkbox;
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   335
        [checkbox release];
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   336
    } else
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   337
        cell.accessoryView = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   338
3703
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   339
    cell.backgroundColor = [UIColor blackColor];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   340
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   341
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   342
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   343
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   344
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   345
#pragma mark Table view delegate
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   346
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   347
    int newRow = [indexPath row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   348
    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   349
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   350
    if (newRow != oldRow) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   351
        if (self.segmentedControl.selectedSegmentIndex != 1) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   352
            NSString *theme = [self.themeArray objectAtIndex:newRow];
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   353
            self.themeCommand = [NSString stringWithFormat:@"etheme %@", theme];
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   354
        } else {
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   355
            // theme and map are set in the function below
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   356
            [self updatePreviewWithMap:newRow];
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   357
        }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   358
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   359
        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
   360
        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
   361
        newCell.accessoryView = checkbox;
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   362
        [checkbox release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   363
        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
   364
        oldCell.accessoryView = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   365
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   366
        self.lastIndexPath = indexPath;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   367
        [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   368
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   369
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   370
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   371
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   372
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   373
#pragma mark slider & segmentedControl
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   374
// this updates the label and the command keys when the slider is moved, depending of the selection in segmentedControl
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   375
// no methods are called by this routine and you can pass nil to it
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   376
-(IBAction) sliderChanged:(id) sender {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   377
    NSString *labelText;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   378
    NSString *templateCommand;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   379
    NSString *mazeCommand;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   380
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   381
    switch ((int)(self.slider.value*100)) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   382
        case 0:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   383
            if (self.segmentedControl.selectedSegmentIndex == 0) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   384
                labelText = NSLocalizedString(@"Wacky",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   385
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   386
                labelText = NSLocalizedString(@"Large Floating Islands",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   387
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   388
            templateCommand = @"e$template_filter 5";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   389
            mazeCommand = @"e$maze_size 5";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   390
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   391
        case 1:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   392
            if (self.segmentedControl.selectedSegmentIndex == 0) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   393
                labelText = NSLocalizedString(@"Cavern",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   394
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   395
                labelText = NSLocalizedString(@"Medium Floating Islands",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   396
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   397
            templateCommand = @"e$template_filter 4";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   398
            mazeCommand = @"e$maze_size 4";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   399
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   400
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   401
            if (self.segmentedControl.selectedSegmentIndex == 0) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   402
                labelText = NSLocalizedString(@"Small",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   403
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   404
                labelText = NSLocalizedString(@"Small Floating Islands",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   405
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   406
            templateCommand = @"e$template_filter 1";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   407
            mazeCommand = @"e$maze_size 3";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   408
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   409
        case 3:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   410
            if (self.segmentedControl.selectedSegmentIndex == 0) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   411
                labelText = NSLocalizedString(@"Medium",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   412
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   413
                labelText = NSLocalizedString(@"Large Tunnels",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   414
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   415
            templateCommand = @"e$template_filter 2";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   416
            mazeCommand = @"e$maze_size 2";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   417
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   418
        case 4:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   419
            if (self.segmentedControl.selectedSegmentIndex == 0) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   420
                labelText = NSLocalizedString(@"Large",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   421
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   422
                labelText = NSLocalizedString(@"Medium Tunnels",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   423
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   424
            templateCommand = @"e$template_filter 3";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   425
            mazeCommand = @"e$maze_size 1";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   426
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   427
        case 5:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   428
            if (self.segmentedControl.selectedSegmentIndex == 0) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   429
                labelText = NSLocalizedString(@"All",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   430
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   431
                labelText = NSLocalizedString(@"Small Tunnels",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   432
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   433
            templateCommand = @"e$template_filter 0";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   434
            mazeCommand = @"e$maze_size 0";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   435
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   436
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   437
            labelText = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   438
            templateCommand = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   439
            mazeCommand = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   440
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   441
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   442
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   443
    self.sizeLabel.text = labelText;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   444
    self.templateFilterCommand = templateCommand;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   445
    self.mazeSizeCommand = mazeCommand;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   446
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   447
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   448
// update preview (if not busy and if its value really changed) as soon as the user lifts its finger up
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   449
-(IBAction) sliderEndedChanging:(id) sender {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   450
    int num = (int) (self.slider.value * 100);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   451
    if (oldValue != num) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   452
        [self updatePreview];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   453
        oldValue = num;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   454
    }
3783
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3780
diff changeset
   455
    playSound(@"clickSound");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   456
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   457
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   458
// perform actions based on the activated section, then call updatePreview to visually update the selection
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   459
// updatePreview will call didSelectRowAtIndexPath which will call the right update routine)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   460
// and if necessary update the table with a slide animation
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   461
-(IBAction) segmentedControlChanged:(id) sender {
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   462
    NSString *mapgen, *staticmap;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   463
    NSInteger newPage = self.segmentedControl.selectedSegmentIndex;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   464
3783
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3780
diff changeset
   465
    playSound(@"selSound");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   466
    switch (newPage) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   467
        case 0: // Random
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   468
            mapgen = @"e$mapgen 0";
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   469
            staticmap = @"";
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   470
            [self sliderChanged:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   471
            self.slider.enabled = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   472
            break;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   473
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   474
        case 1: // Map
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   475
            mapgen = @"e$mapgen 0";
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   476
            // dummy value, everything is set by -updatePreview -> -didSelectRowAtIndexPath -> -updatePreviewWithMap
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   477
            staticmap = @"map Bamboo";
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   478
            self.slider.enabled = NO;
3791
98072b3871c1 help page for ingame, some other fixes here and there
koda
parents: 3789
diff changeset
   479
            self.sizeLabel.text = NSLocalizedString(@"No filter",@"");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   480
            [self restoreBackgroundImage];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   481
            break;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   482
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   483
        case 2: // Maze
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   484
            mapgen = @"e$mapgen 1";
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   485
            staticmap = @"";
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   486
            [self sliderChanged:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   487
            self.slider.enabled = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   488
            break;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   489
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   490
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   491
            mapgen = nil;
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   492
            staticmap = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   493
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   494
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   495
    self.mapGenCommand = mapgen;
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   496
    self.staticMapCommand = staticmap;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   497
    [self updatePreview];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   498
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   499
    // nice animation for updating the table when appropriate (on iphone)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   500
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   501
        if (((oldPage == 0 || oldPage == 2) && newPage == 1) ||
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   502
            (oldPage == 1 && (newPage == 0 || newPage == 2))) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   503
            [UIView beginAnimations:@"moving out table" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   504
            self.tableView.frame = CGRectMake(480, 0, 185, 276);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   505
            [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   506
            [self performSelector:@selector(moveTable) withObject:nil afterDelay:0.2];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   507
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   508
    oldPage = newPage;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   509
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   510
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   511
// update data when table is not visible and then show it
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   512
-(void) moveTable {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   513
    [self.tableView reloadData];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   514
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   515
    [UIView beginAnimations:@"moving in table" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   516
    self.tableView.frame = CGRectMake(295, 0, 185, 276);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   517
    [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   518
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   519
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   520
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   521
#pragma mark view management
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   522
-(void) viewDidLoad {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   523
    [super viewDidLoad];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   524
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   525
    srandom(time(NULL));
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   526
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   527
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   528
    self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   529
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   530
    // themes.cfg contains all the user-selectable themes
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   531
    NSString *string = [[NSString alloc] initWithContentsOfFile:[THEMES_DIRECTORY() stringByAppendingString:@"/themes.cfg"]
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   532
                                                       encoding:NSUTF8StringEncoding
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   533
                                                          error:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   534
    NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[string componentsSeparatedByString:@"\n"]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   535
    [string release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   536
    // remove a trailing "" element
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   537
    [array removeLastObject];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   538
    self.themeArray = array;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   539
    [array release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   540
    self.mapArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   541
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   542
    busy = NO;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   543
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   544
    // draw a white background
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   545
    [self restoreBackgroundImage];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   546
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   547
    // initialize some "default" values
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   548
    self.sizeLabel.text = NSLocalizedString(@"All",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   549
    self.slider.value = 0.05f;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   550
3789
c3eb56754e92 added a smaller version of forts, fixed a couple of regressions
koda
parents: 3783
diff changeset
   551
    // select a map at first because it's faster - done in IB
c3eb56754e92 added a smaller version of forts, fixed a couple of regressions
koda
parents: 3783
diff changeset
   552
    //self.segmentedControl.selectedSegmentIndex = 1;
3791
98072b3871c1 help page for ingame, some other fixes here and there
koda
parents: 3789
diff changeset
   553
    if (self.segmentedControl.selectedSegmentIndex == 1) {
98072b3871c1 help page for ingame, some other fixes here and there
koda
parents: 3789
diff changeset
   554
        self.slider.enabled = NO;
98072b3871c1 help page for ingame, some other fixes here and there
koda
parents: 3789
diff changeset
   555
        self.sizeLabel.text = NSLocalizedString(@"No filter",@"");
98072b3871c1 help page for ingame, some other fixes here and there
koda
parents: 3789
diff changeset
   556
    }
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   557
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   558
    self.templateFilterCommand = @"e$template_filter 0";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   559
    self.mazeSizeCommand = @"e$maze_size 0";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   560
    self.mapGenCommand = @"e$mapgen 0";
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   561
    self.staticMapCommand = @"";
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   562
3792
dd9345e74b66 help page for lobby
koda
parents: 3791
diff changeset
   563
    self.lastIndexPath = [NSIndexPath indexPathForRow:-1 inSection:0];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   564
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   565
    oldValue = 5;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   566
    oldPage = 0;
3703
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   567
    
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   568
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   569
        [self.tableView setBackgroundView:nil];
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   570
        self.view.backgroundColor = [UIColor clearColor];
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   571
        self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER;
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   572
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   573
        self.tableView.rowHeight = 45;
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   574
    }
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   575
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   576
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   577
-(void) viewDidAppear:(BOOL) animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   578
    [super viewDidAppear:animated];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   579
    [self updatePreview];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   580
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   581
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   582
#pragma mark -
3705
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   583
#pragma mark delegate functions for iPad
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   584
-(IBAction) buttonPressed:(id) sender {
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   585
    if (self.delegate != nil && [delegate respondsToSelector:@selector(buttonPressed:)])
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   586
        [self.delegate buttonPressed:(UIButton *)sender];
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   587
}
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   588
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   589
#pragma mark -
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   590
-(void) didReceiveMemoryWarning {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   591
    [super didReceiveMemoryWarning];
3705
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   592
    //[previewButton setImage:nil forState:UIControlStateNormal];
3791
98072b3871c1 help page for ingame, some other fixes here and there
koda
parents: 3789
diff changeset
   593
    MSG_MEMCLEAN();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   594
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   595
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   596
-(void) viewDidUnload {
3705
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   597
    self.delegate = nil;
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   598
    
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   599
    self.previewButton = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   600
    self.seedCommand = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   601
    self.templateFilterCommand = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   602
    self.mapGenCommand = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   603
    self.mazeSizeCommand = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   604
    self.themeCommand = nil;
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   605
    self.staticMapCommand = nil;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   606
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   607
    self.previewButton = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   608
    self.tableView = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   609
    self.maxLabel = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   610
    self.sizeLabel = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   611
    self.segmentedControl = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   612
    self.slider = nil;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   613
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   614
    self.lastIndexPath = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   615
    self.themeArray = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   616
    self.mapArray = nil;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   617
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
   618
    MSG_DIDUNLOAD();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   619
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   620
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   621
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   622
-(void) dealloc {
3705
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   623
    self.delegate = nil;
e1959819a542 completing the ifrontend interface...
koda
parents: 3703
diff changeset
   624
    
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   625
    [seedCommand release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   626
    [templateFilterCommand release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   627
    [mapGenCommand release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   628
    [mazeSizeCommand release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   629
    [themeCommand release];
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   630
    [staticMapCommand release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   631
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   632
    [previewButton release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   633
    [tableView release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   634
    [maxLabel release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   635
    [sizeLabel release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   636
    [segmentedControl release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   637
    [slider release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   638
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   639
    [lastIndexPath release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   640
    [themeArray release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   641
    [mapArray release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   642
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   643
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   644
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   645
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   646
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   647
@end