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