project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m
author koda
Wed, 06 Oct 2010 02:31:04 +0200
changeset 3926 668b71f31e51
parent 3916 e7d665a4ef42
child 3996 eb549fd864a5
permissions -rw-r--r--
use dynamic data from engine instead of using hardcoded values
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3829
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     1
/*
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     3
 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     4
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
81db3c85784b headers ftw, also right project file
koda
parents: 3825
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: 3825
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     8
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    12
 * GNU General Public License for more details.
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    13
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    14
 * You should have received a copy of the GNU General Public License
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    15
 * along with this program; if not, write to the Free Software
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    17
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    18
 * File created on 23/05/2010.
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    19
 */
81db3c85784b headers ftw, also right project file
koda
parents: 3825
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 "SingleSchemeViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
#import <QuartzCore/QuartzCore.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
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
    27
#define LABEL_TAG  12345
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
    28
#define SLIDER_TAG 54321
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
    29
#define SWITCH_TAG 67890
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
    30
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
@implementation SingleSchemeViewController
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
    32
@synthesize schemeName, schemeDictionary, basicSettingList, gameModifierArray;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
    return rotationManager(interfaceOrientation);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
#pragma mark View lifecycle
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    40
-(void) viewDidLoad {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    41
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    42
3753
bb5a0252fb56 small update for the about page
koda
parents: 3752
diff changeset
    43
    // title, description, image name (+btn)
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    44
    NSArray *mods = [[NSArray alloc] initWithObjects:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Fort Mode",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
                      NSLocalizedString(@"Defend your fort and destroy the opponents (two team colours max)",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
                      @"Forts",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Divide Team",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
                      NSLocalizedString(@"Teams will start on opposite sides of the terrain (two team colours max)",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
                      @"TeamsDivide",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Solid Land",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
                      NSLocalizedString(@"Land can not be destroyed",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
                      @"Solid",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Add Border",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    55
                      NSLocalizedString(@"Add an indestructable border around the terrain",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
                      @"Border",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Low Gravity",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
                      NSLocalizedString(@"Lower gravity",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
                      @"LowGravity",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Laser Sight",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
                      NSLocalizedString(@"Assisted aiming with laser sight",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
                      @"LaserSight",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Invulnerable",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
                      NSLocalizedString(@"All hogs have a personal forcefield",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
                      @"Invulnerable",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Add Mines",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    67
                      NSLocalizedString(@"Enable random mines",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
                      @"Mines",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Vampirism Mode",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
                      NSLocalizedString(@"Gain 80% of the damage you do back in health",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
                      @"Vampiric",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Karma Mode",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    73
                      NSLocalizedString(@"Share your opponents pain, share their damage",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    74
                      @"Karma",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Artillery Mode",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
                      NSLocalizedString(@"Your hogs are unable to move, test your aim",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
                      @"Artillery",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Random Order",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
                      NSLocalizedString(@"Order of play is random instead of in room order",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
                      @"RandomOrder",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"King Mode",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
                      NSLocalizedString(@"Play with a King. If he dies, your side loses",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    83
                      @"King",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
                     [NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Place Hedgehogs",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    85
                      NSLocalizedString(@"Take turns placing your hedgehogs pre-game",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    86
                      @"PlaceHog",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    87
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Clan Shares Ammo",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    88
                      NSLocalizedString(@"Ammo is shared between all clan teams",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    89
                      @"SharedAmmo",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    90
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Disable Girders",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    91
                      NSLocalizedString(@"Disable girders when generating random maps",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    92
                      @"DisableGirders",@"image",nil],
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Disable Land Objects",@""),@"title",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
                      NSLocalizedString(@"Disable land objects when generating maps",@""),@"description",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
                      @"DisableLandObjects",@"image",nil],
3752
73c2d7d5643b add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents: 3697
diff changeset
    96
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"AI Survival Mode",@""),@"title",
73c2d7d5643b add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents: 3697
diff changeset
    97
                      NSLocalizedString(@"AI-controlled hogs respawn on death",@""),@"description",
73c2d7d5643b add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents: 3697
diff changeset
    98
                      @"AISurvival",@"image",nil],
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
                     nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   100
    self.gameModifierArray = mods;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   101
    [mods release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   102
3753
bb5a0252fb56 small update for the about page
koda
parents: 3752
diff changeset
   103
    // title, image name (+icon), default value, max value, min value
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
    NSArray *basicSettings = [[NSArray alloc] initWithObjects:
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   105
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Damage Modifier",@""),@"title",@"Damage",@"image",
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   106
                               [NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:10],@"min",[NSNumber numberWithInt:300],@"max",nil],
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   107
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Turn Time",@""),@"title",@"Time",@"image",
3916
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   108
                               [NSNumber numberWithInt:45],@"default",[NSNumber numberWithInt:1],@"min",[NSNumber numberWithInt:100],@"max",nil],
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   109
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Initial Health",@""),@"title",@"Health",@"image",
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   110
                               [NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:50],@"min",[NSNumber numberWithInt:200],@"max",nil],
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   111
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Sudden Death Timeout",@""),@"title",@"SuddenDeath",@"image",
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   112
                               [NSNumber numberWithInt:15],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:50],@"max",nil],
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   113
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Crate Drops",@""),@"title",@"Box",@"image",
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   114
                               [NSNumber numberWithInt:5],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:9],@"max",nil],
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   115
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Time",@""),@"title",@"Time",@"image",
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   116
                               [NSNumber numberWithInt:3],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:3],@"max",nil],
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   117
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Number",@""),@"title",@"Mine",@"image",
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   118
                               [NSNumber numberWithInt:4],@"default",[NSNumber numberWithInt:1],@"min",[NSNumber numberWithInt:80],@"max",nil],
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   119
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Dud Mines Probability",@""),@"title",@"Dud",@"image",
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   120
                               [NSNumber numberWithInt:0],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:100],@"max",nil],
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   121
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Explosives",@""),@"title",@"Damage",@"image",
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   122
                               [NSNumber numberWithInt:2],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:40],@"max",nil],
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
                              nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
    self.basicSettingList = basicSettings;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   125
    [basicSettings release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   126
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   127
    self.title = NSLocalizedString(@"Edit scheme preferences",@"");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   129
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   130
// load from file
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   131
-(void) viewWillAppear:(BOOL) animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
    [super viewWillAppear:animated];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   133
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   134
    NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName];
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   135
    NSMutableDictionary *scheme = [[NSMutableDictionary alloc] initWithContentsOfFile:schemeFile];
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3574
diff changeset
   136
    [schemeFile release];
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   137
    self.schemeDictionary = scheme;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   138
    [scheme release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   139
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   140
    [self.tableView reloadData];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   141
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   142
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   143
// save to file
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   144
-(void) viewWillDisappear:(BOOL) animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   145
    [super viewWillDisappear:animated];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   146
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   147
    NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName];
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   148
    [self.schemeDictionary writeToFile:schemeFile atomically:YES];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   149
    [schemeFile release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   150
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   151
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   152
#pragma mark -
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   153
#pragma mark editableCellView delegate
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   154
// set the new value
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   155
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   156
    if (tagValue == 0) {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   157
        // delete old file
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   158
        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] error:NULL];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   159
        // update filename
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   160
        self.schemeName = textString;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   161
        // save new file
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   162
        [self.schemeDictionary writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] atomically:YES];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   163
    } else {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   164
        [self.schemeDictionary setObject:textString forKey:@"description"];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   165
    }
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   166
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   167
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   168
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   169
#pragma mark Table view data source
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   170
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   171
    return 3;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   172
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   173
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   174
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   175
    switch (section) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   176
        case 0:
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   177
            return 2;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   178
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   179
        case 1:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   180
            return [self.basicSettingList count];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   181
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   182
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   183
            return [self.gameModifierArray count];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   184
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   185
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   186
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   187
    return 0;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   188
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   189
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   190
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   191
    static NSString *CellIdentifier0 = @"Cell0";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   192
    static NSString *CellIdentifier1 = @"Cell1";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   193
    static NSString *CellIdentifier2 = @"Cell2";
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   194
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   195
    UITableViewCell *cell = nil;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   196
    EditableCellView *editableCell = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   197
    NSInteger row = [indexPath row];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   198
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   199
    switch ([indexPath section]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   200
        case 0:
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   201
            editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   202
            if (editableCell == nil) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   203
                editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   204
                                               reuseIdentifier:CellIdentifier0] autorelease];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   205
                editableCell.delegate = self;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   206
            }
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   207
            editableCell.tag = row;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   208
            editableCell.selectionStyle = UITableViewCellSelectionStyleNone;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   209
            editableCell.imageView.image = nil;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   210
            editableCell.detailTextLabel.text = nil;
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   211
         
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   212
            if (row == 0) {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   213
                editableCell.textField.text = self.schemeName;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   214
            } else {
3825
fd6c20cd90e3 typos, reduced sound size and last minute fixes
koda
parents: 3782
diff changeset
   215
                editableCell.minimumCharacters = 0;
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   216
                editableCell.textField.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   217
                editableCell.textField.text = [self.schemeDictionary objectForKey:@"description"];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   218
                editableCell.textField.placeholder = NSLocalizedString(@"You can add a description if you wish",@"");
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3781
diff changeset
   219
            }
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   220
            cell = editableCell;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   221
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   222
        case 1:
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   223
            cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   224
            NSDictionary *detail = [self.basicSettingList objectAtIndex:row];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   225
            // need to offset this section (see format in CommodityFunctions.m and above)
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   226
            if (cell == nil) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   227
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   228
                                               reuseIdentifier:CellIdentifier1] autorelease];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   229
3643
858b20bafb6e reworked the ammunition configuration page (visually)
koda
parents: 3623
diff changeset
   230
                int offset = 0;
858b20bafb6e reworked the ammunition configuration page (visually)
koda
parents: 3623
diff changeset
   231
                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   232
                    offset = 50;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   233
3643
858b20bafb6e reworked the ammunition configuration page (visually)
koda
parents: 3623
diff changeset
   234
                UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(offset+260, 12, offset+150, 23)];
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   235
                slider.maximumValue = [[detail objectForKey:@"max"] floatValue];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   236
                slider.minimumValue = [[detail objectForKey:@"min"] floatValue];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   237
                [slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   238
                [cell.contentView addSubview:slider];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   239
                [slider release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   240
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   241
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 200, 30)];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   242
                label.tag = LABEL_TAG;
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   243
                label.backgroundColor = [UIColor clearColor];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   244
                label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   245
                [cell.contentView addSubview:label];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   246
                [label release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   247
            }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   248
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   249
            UIImage *img = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/icon%@.png",BTN_DIRECTORY(),[[self.basicSettingList objectAtIndex:row] objectForKey:@"image"]]];
3623
f14db208f2fa graphics applied and fixes here and there
koda
parents: 3621
diff changeset
   250
            cell.imageView.image = img;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   251
            [img release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   252
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   253
            UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   254
            cellLabel.text = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   255
3916
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   256
            // can't use the viewWithTag method because row is dynamic
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   257
            UISlider *cellSlider = nil;
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   258
            for (UIView *oneView in cell.contentView.subviews) {
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   259
                if ([oneView isMemberOfClass:[UISlider class]]) {
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   260
                    cellSlider = (UISlider *)oneView;
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   261
                    break;
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   262
                }
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   263
            }
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   264
            cellSlider.tag = SLIDER_TAG + row;
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   265
            cellSlider.value = [[[self.schemeDictionary objectForKey:@"basic"] objectAtIndex:row] floatValue];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   266
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   267
            // forced to use this weird format otherwise the label disappears when size of the text is bigger than the original
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   268
            NSString *prestring = [NSString stringWithFormat:@"%d",(NSInteger) cellSlider.value];
3916
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   269
            // turntime 100 means unlimited time turns (set in GameSetup)
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   270
            if (row == 1 && (NSInteger) cellSlider.value == 100)
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   271
                prestring = @"∞";
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   272
            
3574
78fc6e61570b insert a default name when a void string is used
koda
parents: 3573
diff changeset
   273
            while ([prestring length] <= 4)
78fc6e61570b insert a default name when a void string is used
koda
parents: 3573
diff changeset
   274
                prestring = [NSString stringWithFormat:@" %@",prestring];
78fc6e61570b insert a default name when a void string is used
koda
parents: 3573
diff changeset
   275
            cell.detailTextLabel.text = prestring;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   276
3574
78fc6e61570b insert a default name when a void string is used
koda
parents: 3573
diff changeset
   277
            cell.selectionStyle = UITableViewCellSelectionStyleBlue;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   278
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   279
        case 2:
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   280
            cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier2];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   281
            if (cell == nil) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   282
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   283
                                               reuseIdentifier:CellIdentifier2] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   284
                UISwitch *onOff = [[UISwitch alloc] init];
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   285
                onOff.tag = SWITCH_TAG+row;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   286
                [onOff addTarget:self action:@selector(toggleSwitch:) forControlEvents:UIControlEventValueChanged];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   287
                cell.accessoryView = onOff;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   288
                [onOff release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   289
            }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   290
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   291
            UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/btn%@.png",BTN_DIRECTORY(),[[self.gameModifierArray objectAtIndex:row] objectForKey:@"image"]]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   292
            cell.imageView.image = image;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   293
            [image release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   294
            [cell.imageView.layer setCornerRadius:7.0f];
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   295
            [cell.imageView.layer setBorderWidth:1];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   296
            [cell.imageView.layer setMasksToBounds:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   297
            cell.textLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   298
            cell.detailTextLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"];
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   299
            [(UISwitch *)cell.accessoryView setOn:[[[self.schemeDictionary objectForKey:@"gamemod"] objectAtIndex:row] boolValue] animated:NO];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   300
3574
78fc6e61570b insert a default name when a void string is used
koda
parents: 3573
diff changeset
   301
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   302
        }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   303
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   304
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   305
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   306
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   307
-(void) toggleSwitch:(id) sender {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   308
    UISwitch *theSwitch = (UISwitch *)sender;
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   309
    NSMutableArray *array = [self.schemeDictionary objectForKey:@"gamemod"];
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   310
    [array replaceObjectAtIndex:theSwitch.tag-SWITCH_TAG withObject:[NSNumber numberWithBool:theSwitch.on]];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   311
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   312
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   313
-(void) sliderChanged:(id) sender {
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   314
    // the slider that changed is sent as object
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   315
    UISlider *theSlider = (UISlider *)sender;
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   316
    // create the indexPath of the row of the slider
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   317
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:theSlider.tag-SLIDER_TAG inSection:1];
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   318
    // get its cell
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   319
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   320
    // grab the associated label
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   321
    UILabel *label = (UILabel *)cell.detailTextLabel;
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   322
    // modify it
3916
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   323
    if ([indexPath row] == 1 && [indexPath section] == 1 && (NSInteger) theSlider.value == 100)
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   324
        label.text = @"∞";
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   325
    else
e7d665a4ef42 implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents: 3829
diff changeset
   326
        label.text = [NSString stringWithFormat:@"%d",(NSInteger) theSlider.value];
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   327
    // save changes in the main array
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   328
    NSMutableArray *array = [self.schemeDictionary objectForKey:@"basic"];
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   329
    [array replaceObjectAtIndex:theSlider.tag-SLIDER_TAG withObject:[NSNumber numberWithInt:(NSInteger) theSlider.value]];
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   330
}
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   331
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   332
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   333
#pragma mark Table view delegate
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   334
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   335
    UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   336
    EditableCellView *editableCell = nil;
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   337
    UISlider *cellSlider = nil;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   338
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   339
    switch ([indexPath section]) {
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   340
        case 0:
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   341
            editableCell = (EditableCellView *)cell;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   342
            [editableCell replyKeyboard];
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   343
            break;
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   344
        case 1:
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   345
            cellSlider = (UISlider *)[cell.contentView viewWithTag:[indexPath row]+SLIDER_TAG];
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   346
            [cellSlider setValue:[[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] floatValue] animated:YES];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   347
            [self sliderChanged:cellSlider];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   348
            //cell.detailTextLabel.text = [[[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"default"] stringValue];
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   349
            break;
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   350
        case 2:
3574
78fc6e61570b insert a default name when a void string is used
koda
parents: 3573
diff changeset
   351
            /*sw = (UISwitch *)cell.accessoryView;
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   352
            [sw setOn:!sw.on animated:YES];
3574
78fc6e61570b insert a default name when a void string is used
koda
parents: 3573
diff changeset
   353
            [self toggleSwitch:sw];*/
3573
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   354
            break;
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   355
        default:
c84067629035 complete configuration for schemes
koda
parents: 3547
diff changeset
   356
            break;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   357
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   358
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   359
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   360
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   361
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   362
-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   363
    NSString *sectionTitle = nil;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   364
    switch (section) {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   365
        case 0:
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   366
            sectionTitle = NSLocalizedString(@"Scheme Name", @"");
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   367
            break;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   368
        case 1:
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   369
            sectionTitle = NSLocalizedString(@"Game Settings", @"");
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   370
            break;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   371
        case 2:
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   372
            sectionTitle = NSLocalizedString(@"Game Modifiers", @"");
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   373
            break;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   374
        default:
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   375
            DLog(@"nope");
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   376
            break;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   377
    }
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   378
    return sectionTitle;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   379
}
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   380
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   381
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   382
#pragma mark Memory management
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   383
-(void) didReceiveMemoryWarning {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   384
    [super didReceiveMemoryWarning];
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   385
    self.basicSettingList = nil;
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   386
    self.gameModifierArray = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   387
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   388
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   389
-(void) viewDidUnload {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   390
    self.schemeName = nil;
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   391
    self.schemeDictionary = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   392
    self.basicSettingList = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   393
    self.gameModifierArray = nil;
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
   394
    MSG_DIDUNLOAD();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   395
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   396
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   397
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   398
-(void) dealloc {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3643
diff changeset
   399
    [schemeName release];
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3753
diff changeset
   400
    [schemeDictionary release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   401
    [basicSettingList release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   402
    [gameModifierArray release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   403
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   404
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   405
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   406
@end