project_files/HedgewarsMobile/Classes/MapConfigViewController.m
author Grigory Ustinov <grenka@altlinux.org>
Tue, 27 Nov 2018 20:39:39 +0300
changeset 14348 85cd1aff2f04
parent 12872 00215a7ec5f5
permissions -rw-r--r--
sed -i -E "s/еж([аиу][^а-я])/ёжик\1/g" *ru* grep -E "еж[аиу][^а-я]" *ru* Comment: [^а-я] includes all spaces and punctuation and also finish of string
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
6700
e04da46ee43c the most important commit of the year
koda
parents: 6669
diff changeset
     3
 * Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com>
3829
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
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 8441
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
3829
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
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    19
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    20
#import "MapConfigViewController.h"
6108
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6107
diff changeset
    21
#import <QuartzCore/QuartzCore.h>
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
6832
fae8fd118da9 dates are no more!
koda
parents: 6829
diff changeset
    23
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
    24
#define scIndex         self.segmentedControl.selectedSegmentIndex
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
    25
#define isRandomness()  (segmentedControl.selectedSegmentIndex == 0 || segmentedControl.selectedSegmentIndex == 2)
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
@implementation MapConfigViewController
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
    28
@synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand, themeCommand, staticMapCommand,
6634
e00762923086 ios game configuration page supports rotation, with some enhancements (like the new slider); some glitches here and there
koda
parents: 6115
diff changeset
    29
            missionCommand, tableView, maxLabel, segmentedControl, slider, lastIndexPath, dataSourceArray, busy,
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
    30
            oldPage, oldValue;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    32
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
    33
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
3547
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
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
    37
- (IBAction)mapButtonPressed:(id)sender {
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    38
    [[AudioManagerController mainManager] playClickSound];
3783
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
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
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
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
    44
    if (self.busy)
3547
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
11554
73e6a3d2f768 - Small refactoring for seed generation on iOS side
antonc27 <antonc27@mail.ru>
parents: 11226
diff changeset
    48
    NSString *seed = [HWUtils seed];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
    NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
    self.seedCommand = seedCmd;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    51
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
    52
    NSArray *source = [self.dataSourceArray objectAtIndex:scIndex];
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
    53
    if (isRandomness()) {
3910
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
    54
        // 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
    55
        [self turnOffWidgets];
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
    56
        [self.previewButton updatePreviewWithSeed:seed];
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
    57
        // the preview for static maps is loaded in didSelectRowAtIndexPath
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
    }
3910
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
    59
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
    60
    // perform as if user clicked on an entry
11206
2e80c9861818 - Better random number generation for front-end: random() replaced with arc4random_uniform()
antonc27 <antonc27@mail.ru>
parents: 11148
diff changeset
    61
    NSIndexPath *theIndex = [NSIndexPath indexPathForRow:arc4random_uniform((int)[source count]) inSection:0];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
    [self tableView:self.tableView didSelectRowAtIndexPath:theIndex];
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents: 6000
diff changeset
    63
    if (IS_NOT_POWERFUL([HWUtils modelType]) == NO)
4287
7dbdc862097c some interface tricks for iphone as well
koda
parents: 4244
diff changeset
    64
        [self.tableView scrollToRowAtIndexPath:theIndex atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
    67
- (void)turnOffWidgets {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
    busy = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
    self.previewButton.alpha = 0.5f;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
    self.previewButton.enabled = NO;
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
    71
    self.maxLabel.text = NSLocalizedString(@"Loading...",@"");;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
    self.segmentedControl.enabled = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    73
    self.slider.enabled = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    74
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
    76
#pragma mark -
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
    77
#pragma mark MapPreviewButtonView delegate methods
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
    78
- (void)turnOnWidgets {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
    self.previewButton.alpha = 1.0f;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
    self.previewButton.enabled = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
    self.segmentedControl.enabled = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
    self.slider.enabled = YES;
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
    83
    self.busy = NO;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
}
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    85
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
    86
- (void)setMaxLabelText:(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
    87
    self.maxHogs = [str intValue];
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
    88
    self.maxLabel.text = [NSString stringWithFormat:@"%@ %@",NSLocalizedString(@"Max Hogs:",@""),str];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    89
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    90
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
    91
- (NSDictionary *)getDataForEngine {
3910
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
    92
    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
    93
                                   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
    94
                                   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
    95
                                   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
    96
                                   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
    97
                                   nil];
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
    98
    return dictForEngine;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   100
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   101
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   102
#pragma mark Table view data source
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   103
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
    return 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   105
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   106
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   107
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   108
    return [[self.dataSourceArray objectAtIndex:scIndex] count];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   109
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   111
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   112
    static NSString *CellIdentifier = @"Cell";
6908
896ed2afcfb8 ios: turn on more warning messages and start correcting them
koda
parents: 6869
diff changeset
   113
    NSUInteger row = [indexPath row];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   114
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   115
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   116
    if (cell == nil)
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   117
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   118
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   119
    NSArray *source = [self.dataSourceArray objectAtIndex:scIndex];
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   120
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   121
    NSString *labelString = [source objectAtIndex:row];
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   122
    cell.textLabel.text = labelString;
3996
eb549fd864a5 the ios port is also iphone compatible
koda
parents: 3984
diff changeset
   123
    cell.textLabel.adjustsFontSizeToFitWidth = YES;
eb549fd864a5 the ios port is also iphone compatible
koda
parents: 3984
diff changeset
   124
    cell.textLabel.minimumFontSize = 7;
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents: 6000
diff changeset
   125
    cell.textLabel.textColor = [UIColor lightYellowColor];
4476
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents: 4362
diff changeset
   126
    cell.textLabel.backgroundColor = [UIColor clearColor];
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   127
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   128
    if (isRandomness()) {
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   129
        UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/icon.png",THEMES_DIRECTORY(),labelString]];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   130
        cell.imageView.image = image;
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   131
    } else
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
        cell.imageView.image = nil;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   133
3703
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   134
    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
   135
        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
   136
        cell.accessoryView = checkbox;
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   137
    } else
12d17c6e8855 halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents: 3697
diff changeset
   138
        cell.accessoryView = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   139
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents: 6000
diff changeset
   140
    cell.backgroundColor = [UIColor blackColorTransparent];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   141
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   142
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   143
3910
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
   144
// this set details for a static map (called by didSelectRowAtIndexPath)
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   145
- (void)setDetailsForStaticMap:(NSInteger)index {
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   146
    NSArray *source = [self.dataSourceArray objectAtIndex:scIndex];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   147
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   148
    NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg",
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   149
                         (scIndex == 1) ? MAPS_DIRECTORY() : MISSIONS_DIRECTORY(),[source objectAtIndex:index]];
3910
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
   150
    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
   151
    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
   152
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
   153
    // 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
   154
    // sometimes it's not set but there are trailing characters, we get around them with the second equation
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
   155
    NSString *max;
3910
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
   156
    if ([split count] > 1 && [[split objectAtIndex:1] intValue] > 0)
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
   157
        max = [split objectAtIndex:1];
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   158
    else
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
   159
        max = @"18";
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
   160
    [self setMaxLabelText:max];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   161
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   162
    self.themeCommand = [NSString stringWithFormat:@"etheme %@", [split objectAtIndex:0]];
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   163
    self.staticMapCommand = [NSString stringWithFormat:@"emap %@", [source objectAtIndex:index]];
3912
e11df2de6af2 have engine try for a second position when map loading fails (in this way it's possible to move Missions data to any path)
koda
parents: 3911
diff changeset
   164
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   165
    if (scIndex != 3)
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   166
        self.missionCommand = @"";
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   167
    else
3920
a54ca6185307 updated lua loading in the ifrontend and also fixed masked maps
koda
parents: 3912
diff changeset
   168
        self.missionCommand = [NSString stringWithFormat:@"escript Missions/Maps/%@/map.lua",[source objectAtIndex:index]];
3910
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
   169
}
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   170
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   171
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   172
#pragma mark Table view delegate
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   173
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
11148
064a53861759 - Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
   174
    NSInteger newRow = [indexPath row];
064a53861759 - Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
   175
    NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   176
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   177
    if (newRow != oldRow) {
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   178
        NSArray *source = [self.dataSourceArray objectAtIndex:scIndex];
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   179
        if (isRandomness()) {
3910
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
   180
            // just change the theme, don't update preview
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   181
            self.themeCommand = [NSString stringWithFormat:@"etheme %@", [source objectAtIndex:newRow]];
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   182
        } else {
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   183
            NSString *fileImage = [NSString stringWithFormat:@"%@/%@/preview.png",
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   184
                                   (scIndex == 1) ? MAPS_DIRECTORY() : MISSIONS_DIRECTORY(),[source objectAtIndex:newRow]];
3910
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
   185
            [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
   186
            [self setDetailsForStaticMap:newRow];
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   187
        }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   188
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   189
        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
   190
        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
   191
        newCell.accessoryView = checkbox;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   192
        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
   193
        oldCell.accessoryView = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   194
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   195
        self.lastIndexPath = indexPath;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   196
        [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   197
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   198
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   199
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   200
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   201
#pragma mark -
4082
bfe14b38dad1 better support for wimpier i-devices
koda
parents: 3996
diff changeset
   202
#pragma mark slider & segmentedControl & button
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   203
// 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
   204
// no methods are called by this routine and you can pass nil to it
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   205
- (IBAction)sliderChanged:(id)sender {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   206
    NSString *labelText;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   207
    NSString *templateCommand;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   208
    NSString *mazeCommand;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   209
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   210
    switch ((int)(self.slider.value*100)) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   211
        case 0:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   212
            if (self.segmentedControl.selectedSegmentIndex == 0) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   213
                labelText = NSLocalizedString(@"Wacky",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   214
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   215
                labelText = NSLocalizedString(@"Large Floating Islands",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   216
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   217
            templateCommand = @"e$template_filter 5";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   218
            mazeCommand = @"e$maze_size 5";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   219
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   220
        case 1:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   221
            if (self.segmentedControl.selectedSegmentIndex == 0) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   222
                labelText = NSLocalizedString(@"Cavern",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   223
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   224
                labelText = NSLocalizedString(@"Medium Floating Islands",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   225
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   226
            templateCommand = @"e$template_filter 4";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   227
            mazeCommand = @"e$maze_size 4";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   228
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   229
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   230
            if (self.segmentedControl.selectedSegmentIndex == 0) {
6669
3933198e2b28 i don't know how this is possible
koda
parents: 6634
diff changeset
   231
                labelText = NSLocalizedString(@"Large",@"");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   232
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   233
                labelText = NSLocalizedString(@"Small Floating Islands",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   234
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   235
            templateCommand = @"e$template_filter 1";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   236
            mazeCommand = @"e$maze_size 3";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   237
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   238
        case 3:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   239
            if (self.segmentedControl.selectedSegmentIndex == 0) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   240
                labelText = NSLocalizedString(@"Medium",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   241
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   242
                labelText = NSLocalizedString(@"Large Tunnels",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   243
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   244
            templateCommand = @"e$template_filter 2";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   245
            mazeCommand = @"e$maze_size 2";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   246
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   247
        case 4:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   248
            if (self.segmentedControl.selectedSegmentIndex == 0) {
6669
3933198e2b28 i don't know how this is possible
koda
parents: 6634
diff changeset
   249
                labelText = NSLocalizedString(@"Small",@"");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   250
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   251
                labelText = NSLocalizedString(@"Medium Tunnels",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   252
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   253
            templateCommand = @"e$template_filter 3";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   254
            mazeCommand = @"e$maze_size 1";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   255
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   256
        case 5:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   257
            if (self.segmentedControl.selectedSegmentIndex == 0) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   258
                labelText = NSLocalizedString(@"All",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   259
            } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   260
                labelText = NSLocalizedString(@"Small Tunnels",@"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   261
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   262
            templateCommand = @"e$template_filter 0";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   263
            mazeCommand = @"e$maze_size 0";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   264
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   265
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   266
            labelText = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   267
            templateCommand = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   268
            mazeCommand = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   269
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   270
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   271
6634
e00762923086 ios game configuration page supports rotation, with some enhancements (like the new slider); some glitches here and there
koda
parents: 6115
diff changeset
   272
    self.slider.textValue = labelText;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   273
    self.templateFilterCommand = templateCommand;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   274
    self.mazeSizeCommand = mazeCommand;
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
// update preview (if not busy and if its value really changed) as soon as the user lifts its finger up
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   278
- (IBAction)sliderEndedChanging:(id)sender {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   279
    int num = (int) (self.slider.value * 100);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   280
    if (oldValue != num) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   281
        [self updatePreview];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   282
        oldValue = num;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   283
    }
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   284
    [[AudioManagerController mainManager] playClickSound];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   285
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   286
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   287
// 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
   288
// and if necessary update the table with a slide animation
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   289
- (IBAction)segmentedControlChanged:(id)sender {
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   290
    NSString *mapgen, *staticmap, *mission;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   291
    NSInteger newPage = self.segmentedControl.selectedSegmentIndex;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   292
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
   293
    [[AudioManagerController mainManager] playSelectSound];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   294
    switch (newPage) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   295
        case 0: // Random
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   296
            mapgen = @"e$mapgen 0";
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   297
            staticmap = @"";
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   298
            mission = @"";
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   299
            [self sliderChanged:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   300
            self.slider.enabled = YES;
6829
60b039d88dab ios: use notifications instead of class methods (maybe tidier)
koda
parents: 6823
diff changeset
   301
            [[NSNotificationCenter defaultCenter] postNotificationName:@"fillsections" object:nil];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   302
            break;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   303
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   304
        case 1: // Map
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   305
            mapgen = @"e$mapgen 0";
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   306
            // dummy values, these are set by -updatePreview -> -didSelectRowAtIndexPath -> -setDetailsForStaticMap
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   307
            staticmap = @"map Bamboo";
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   308
            mission = @"";
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   309
            self.slider.enabled = NO;
6829
60b039d88dab ios: use notifications instead of class methods (maybe tidier)
koda
parents: 6823
diff changeset
   310
            [[NSNotificationCenter defaultCenter] postNotificationName:@"fillsections" object:nil];
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 = @"";
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   316
            mission = @"";
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   317
            [self sliderChanged:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   318
            self.slider.enabled = YES;
6829
60b039d88dab ios: use notifications instead of class methods (maybe tidier)
koda
parents: 6823
diff changeset
   319
            [[NSNotificationCenter defaultCenter] postNotificationName:@"fillsections" object:nil];
4349
8efa91f98274 display an empty table for missions
koda
parents: 4290
diff changeset
   320
            break;
8efa91f98274 display an empty table for missions
koda
parents: 4290
diff changeset
   321
8efa91f98274 display an empty table for missions
koda
parents: 4290
diff changeset
   322
        case 3: // Mission
8efa91f98274 display an empty table for missions
koda
parents: 4290
diff changeset
   323
            mapgen = @"e$mapgen 0";
8efa91f98274 display an empty table for missions
koda
parents: 4290
diff changeset
   324
            // dummy values, these are set by -updatePreview -> -didSelectRowAtIndexPath -> -setDetailsForStaticMap
8efa91f98274 display an empty table for missions
koda
parents: 4290
diff changeset
   325
            staticmap = @"map Bamboo";
8efa91f98274 display an empty table for missions
koda
parents: 4290
diff changeset
   326
            mission = @"";
8efa91f98274 display an empty table for missions
koda
parents: 4290
diff changeset
   327
            self.slider.enabled = NO;
6829
60b039d88dab ios: use notifications instead of class methods (maybe tidier)
koda
parents: 6823
diff changeset
   328
            [[NSNotificationCenter defaultCenter] postNotificationName:@"emptysections" object:nil];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   329
            break;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   330
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   331
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   332
            mapgen = nil;
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   333
            staticmap = nil;
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   334
            mission = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   335
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   336
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   337
    self.mapGenCommand = mapgen;
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   338
    self.staticMapCommand = staticmap;
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   339
    self.missionCommand = mission;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   340
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   341
    [self.tableView reloadData];
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   342
    [self updatePreview];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   343
    oldPage = newPage;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   344
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   345
11226
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   346
- (void)localizeSegmentedControl
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   347
{
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   348
    for (NSUInteger i = 0; i < self.segmentedControl.numberOfSegments; i++)
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   349
    {
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   350
        NSString *oldTitle = [self.segmentedControl titleForSegmentAtIndex:i];
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   351
        [self.segmentedControl setTitle:NSLocalizedString(oldTitle, nil) forSegmentAtIndex:i];
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   352
    }
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   353
}
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   354
4082
bfe14b38dad1 better support for wimpier i-devices
koda
parents: 3996
diff changeset
   355
#pragma mark -
bfe14b38dad1 better support for wimpier i-devices
koda
parents: 3996
diff changeset
   356
#pragma mark view management
6107
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   357
-(NSArray *) dataSourceArray {
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   358
    if (dataSourceArray == nil) {
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   359
        NSString *model = [HWUtils modelType];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   360
6107
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   361
        // only folders containing icon.png are a valid theme
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   362
        NSArray *themeArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:THEMES_DIRECTORY() error:NULL];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   363
        NSMutableArray *themeArray = [[NSMutableArray alloc] init];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   364
        for (NSString *themeName in themeArrayFull) {
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   365
            NSString *checkPath = [[NSString alloc] initWithFormat:@"%@/%@/icon.png",THEMES_DIRECTORY(),themeName];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   366
            if ([[NSFileManager defaultManager] fileExistsAtPath:checkPath])
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   367
                [themeArray addObject:themeName];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   368
        }
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   369
6107
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   370
        // remove images that are too big for certain devices without loading the whole image
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   371
        NSArray *mapArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   372
        NSMutableArray *mapArray = [[NSMutableArray alloc] init];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   373
        for (NSString *str in mapArrayFull) {
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   374
            CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MAPS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   375
            if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f)
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   376
                continue;
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   377
            if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f)
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   378
                continue;
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   379
            [mapArray addObject:str];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   380
        }
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   381
6107
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   382
        NSArray *missionArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MISSIONS_DIRECTORY() error:NULL];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   383
        NSMutableArray *missionArray = [[NSMutableArray alloc] init];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   384
        for (NSString *str in missionArrayFull) {
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   385
            CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MISSIONS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   386
            if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f)
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   387
                continue;
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   388
            if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f)
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   389
                continue;
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   390
            [missionArray addObject:str];
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   391
        }
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   392
        NSArray *array = [[NSArray alloc] initWithObjects:themeArray,mapArray,themeArray,missionArray,nil];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6908
diff changeset
   393
6107
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   394
        self.dataSourceArray = array;
5281
3324e9897ea7 update theme listing for ios
koda
parents: 5208
diff changeset
   395
    }
6107
0741c0f0203e some code refactoring of the ios game config
koda
parents: 6079
diff changeset
   396
    return dataSourceArray;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   397
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   398
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   399
- (void)viewDidLoad {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   400
    [super viewDidLoad];
11226
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   401
    
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   402
    [self localizeSegmentedControl];
628ac6f8a41e - SegmentedControl is localizable now in MapConfig
antonc27 <antonc27@mail.ru>
parents: 11206
diff changeset
   403
    
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   404
    // initialize some "default" values
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   405
    self.slider.value = 0.05f;
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
   406
    self.slider.enabled = NO;
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
   407
    self.oldValue = 5;
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
   408
    self.busy = NO;
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
   409
    self.oldPage = self.segmentedControl.selectedSegmentIndex;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   410
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   411
    self.templateFilterCommand = @"e$template_filter 0";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   412
    self.mazeSizeCommand = @"e$maze_size 0";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   413
    self.mapGenCommand = @"e$mapgen 0";
3642
fb39fecca350 support for static map added to iFrontend
koda
parents: 3625
diff changeset
   414
    self.staticMapCommand = @"";
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   415
    self.missionCommand = @"";
3910
dd47efbdec46 move all preview drawing code into its own class (for a simplified and more readable MapConfigViewController)
koda
parents: 3829
diff changeset
   416
6108
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6107
diff changeset
   417
    if (IS_IPAD()) {
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6107
diff changeset
   418
        [self.tableView setBackgroundColorForAnyTable:[UIColor darkBlueColorTransparent]];
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6107
diff changeset
   419
        self.tableView.layer.borderColor = [[UIColor darkYellowColor] CGColor];
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6107
diff changeset
   420
        self.tableView.layer.borderWidth = 2.7f;
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6107
diff changeset
   421
        self.tableView.layer.cornerRadius = 8;
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6107
diff changeset
   422
        self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
   423
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
   424
        UILabel *backLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 14, 300, 190) andTitle:nil withBorderWidth:2.3f];
6634
e00762923086 ios game configuration page supports rotation, with some enhancements (like the new slider); some glitches here and there
koda
parents: 6115
diff changeset
   425
        backLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 6109
diff changeset
   426
        [self.view insertSubview:backLabel belowSubview:self.segmentedControl];
6108
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6107
diff changeset
   427
    }
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6107
diff changeset
   428
    self.tableView.separatorColor = [UIColor whiteColor];
4244
bf46b4bdf27d iphone interface
koda
parents: 4115
diff changeset
   429
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   430
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   431
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   432
- (void)viewWillAppear:(BOOL)animated {
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   433
    [super viewWillAppear:animated];
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   434
}
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   435
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   436
- (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
   437
    [self updatePreview];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   438
    [super viewDidAppear:animated];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   439
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   440
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11554
diff changeset
   441
- (void)didReceiveMemoryWarning {
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   442
    self.dataSourceArray = nil;
4356
d1d26f8963a3 update some files for new graphics and new ios4.2
koda
parents: 4349
diff changeset
   443
    [super didReceiveMemoryWarning];
3984
d92509c2f255 some more memory opt
koda
parents: 3978
diff changeset
   444
4356
d1d26f8963a3 update some files for new graphics and new ios4.2
koda
parents: 4349
diff changeset
   445
    if (self.view.superview == nil) {
6823
e54a68b9b844 ios: fix blocked preview button
koda
parents: 6822
diff changeset
   446
        self.previewButton = nil;
4356
d1d26f8963a3 update some files for new graphics and new ios4.2
koda
parents: 4349
diff changeset
   447
        self.tableView = nil;
d1d26f8963a3 update some files for new graphics and new ios4.2
koda
parents: 4349
diff changeset
   448
        self.maxLabel = nil;
d1d26f8963a3 update some files for new graphics and new ios4.2
koda
parents: 4349
diff changeset
   449
        self.slider = nil;
d1d26f8963a3 update some files for new graphics and new ios4.2
koda
parents: 4349
diff changeset
   450
    }
3971
5c82ee165ed5 minor stuff
koda
parents: 3930
diff changeset
   451
3911
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   452
    MSG_MEMCLEAN();
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   453
}
46d7a5cf8ac6 further rework of MapConfigViewController, lists missions correctly (they don't load fine yet)
koda
parents: 3910
diff changeset
   454
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   455
@end