project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m
author nemo
Sun, 20 Jun 2010 22:35:10 -0400
changeset 3526 a1d2180fef42
parent 3514 59dbd31e9953
child 3546 ccf4854df294
permissions -rw-r--r--
Replace SHA1 with adler32. For simple purposes of checking to see if players are playing the same map, this should be quite adequate and runs 15 times faster.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3479
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
     1
//
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
     2
//  SingleSchemeViewController.m
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
     3
//  Hedgewars
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
     4
//
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
     5
//  Created by Vittorio on 23/05/10.
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
     7
//
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
     8
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
     9
#import "SingleSchemeViewController.h"
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    10
#import <QuartzCore/QuartzCore.h>
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    11
#import "CommodityFunctions.h"
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    12
#import "UIImageExtra.h"
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    13
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    14
@implementation SingleSchemeViewController
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    15
@synthesize textFieldBeingEdited, schemeArray, basicSettingList, gameModifierArray;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    16
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    17
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    18
	return rotationManager(interfaceOrientation);
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    19
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    20
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    21
#pragma mark -
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    22
#pragma mark View lifecycle
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    23
-(void) viewDidLoad {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    24
    [super viewDidLoad];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    25
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    26
    NSArray *mods = [[NSArray alloc] initWithObjects:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    27
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Fort Mode",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    28
                      NSLocalizedString(@"Defend your fort and destroy the opponents (two team colours max)",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    29
                      @"Forts",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    30
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Divide Team",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    31
                      NSLocalizedString(@"Teams will start on opposite sides of the terrain (two team colours max)",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    32
                      @"TeamsDivide",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    33
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Solid Land",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    34
                      NSLocalizedString(@"Land can not be destroyed",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    35
                      @"Solid",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    36
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Add Border",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    37
                      NSLocalizedString(@"Add an indestructable border around the terrain",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    38
                      @"Border",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    39
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Low Gravity",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    40
                      NSLocalizedString(@"Lower gravity",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    41
                      @"LowGravity",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    42
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Laser Sight",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    43
                      NSLocalizedString(@"Assisted aiming with laser sight",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    44
                      @"LaserSight",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    45
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Invulnerable",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    46
                      NSLocalizedString(@"All hogs have a personal forcefield",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    47
                      @"Invulnerable",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    48
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Add Mines",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    49
                      NSLocalizedString(@"Enable random mines",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    50
                      @"Mines",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    51
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Vampirism Mode",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    52
                      NSLocalizedString(@"Gain 80% of the damage you do back in health",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    53
                      @"Vampiric",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    54
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Karma Mode",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    55
                      NSLocalizedString(@"Share your opponents pain, share their damage",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    56
                      @"Karma",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    57
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Artillery Mode",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    58
                      NSLocalizedString(@"Your hogs are unable to move, test your aim",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    59
                      @"Artillery",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    60
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Random Order",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    61
                      NSLocalizedString(@"Order of play is random instead of in room order",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    62
                      @"RandomOrder",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    63
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"King Mode",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    64
                      NSLocalizedString(@"Play with a King. If he dies, your side loses",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    65
                      @"King",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    66
                     [NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Place Hedgehogs",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    67
                      NSLocalizedString(@"Take turns placing your hedgehogs pre-game",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    68
                      @"PlaceHog",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    69
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Clan Shares Ammo",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    70
                      NSLocalizedString(@"Ammo is shared between all clan teams",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    71
                      @"SharedAmmo",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    72
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Disable Girders",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    73
                      NSLocalizedString(@"Disable girders when generating random maps",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    74
                      @"DisableGirders",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    75
                     [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Disable Land Objects",@""),@"title",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    76
                      NSLocalizedString(@"Disable land objects when generating maps",@""),@"description",
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    77
                      @"DisableLandObjects",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    78
                     nil];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    79
    self.gameModifierArray = mods;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    80
    [mods release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    81
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    82
    NSArray *basicSettings = [[NSArray alloc] initWithObjects:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    83
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Damage Modifier",@""),@"title",@"Damage",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    84
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Turn Time",@""),@"title",@"Time",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    85
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Initial Health",@""),@"title",@"Health",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    86
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Sudden Death Timeout",@""),@"title",@"SuddenDeath",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    87
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Crate Drops",@""),@"title",@"Box",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    88
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Time",@""),@"title",@"Time",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    89
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Number",@""),@"title",@"Mine",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    90
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Dud Mines Probability",@""),@"title",@"Dud",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    91
                              [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Explosives",@""),@"title",@"Damage",@"image",nil],
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    92
                              nil];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    93
    self.basicSettingList = basicSettings;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    94
    [basicSettings release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    95
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    96
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    97
// load from file
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    98
-(void) viewWillAppear:(BOOL) animated {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
    99
    [super viewWillAppear:animated];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   100
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   101
    NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   102
	NSMutableArray *scheme = [[NSMutableArray alloc] initWithContentsOfFile:schemeFile];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   103
    self.schemeArray = scheme;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   104
    [scheme release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   105
	[schemeFile release];
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
   106
    
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
   107
    [self.tableView reloadData];
3479
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   108
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   109
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   110
// save to file
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   111
-(void) viewWillDisappear:(BOOL) animated {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   112
    [super viewWillDisappear:animated];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   113
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   114
    NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   115
    [self.schemeArray writeToFile:schemeFile atomically:YES];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   116
    [schemeFile release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   117
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   118
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   119
#pragma mark -
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   120
#pragma mark textfield methods
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   121
-(void) cancel:(id) sender {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   122
    if (textFieldBeingEdited != nil)
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   123
        [self.textFieldBeingEdited resignFirstResponder];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   124
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   125
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   126
// set the new value
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   127
-(BOOL) save:(id) sender {    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   128
    if (textFieldBeingEdited != nil) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   129
        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title] error:NULL];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   130
        self.title = self.textFieldBeingEdited.text;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   131
        [self.schemeArray writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title] atomically:YES];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   132
        [self.textFieldBeingEdited resignFirstResponder];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   133
        return YES;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   134
    }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   135
    return NO;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   136
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   137
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   138
// the textfield is being modified, update the navigation controller
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   139
-(void) textFieldDidBeginEditing:(UITextField *)aTextField{   
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   140
    self.textFieldBeingEdited = aTextField;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   141
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   142
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"from schemes table")
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   143
                                                                     style:UIBarButtonItemStylePlain
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   144
                                                                    target:self
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   145
                                                                    action:@selector(cancel:)];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   146
    self.navigationItem.leftBarButtonItem = cancelButton;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   147
    [cancelButton release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   148
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   149
    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Save",@"from schemes table")
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   150
                                                                     style:UIBarButtonItemStyleDone
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   151
                                                                    target:self
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   152
                                                                    action:@selector(save:)];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   153
    self.navigationItem.rightBarButtonItem = saveButton;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   154
    [saveButton release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   155
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   156
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   157
// the textfield has been modified, check for empty strings and restore original navigation bar
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   158
-(void) textFieldDidEndEditing:(UITextField *)aTextField{
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   159
    if ([textFieldBeingEdited.text length] == 0) 
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   160
        textFieldBeingEdited.text = [NSString stringWithFormat:@"New Scheme"];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   161
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   162
    self.textFieldBeingEdited = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   163
    self.navigationItem.rightBarButtonItem = self.navigationItem.backBarButtonItem;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   164
    self.navigationItem.leftBarButtonItem = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   165
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   166
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   167
// limit the size of the field to 64 characters like in original frontend
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   168
-(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   169
    int limit = 64;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   170
    return !([textField.text length] > limit && [string length] > range.length);
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   171
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   172
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   173
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   174
#pragma mark -
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   175
#pragma mark Table view data source
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   176
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   177
    return 3;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   178
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   179
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   180
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   181
    switch (section) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   182
        case 0:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   183
            return 1;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   184
            break;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   185
        case 1:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   186
            return [self.basicSettingList count];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   187
            break;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   188
        case 2:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   189
            return [self.gameModifierArray count];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   190
        default:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   191
            break;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   192
    }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   193
    return 0;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   194
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   195
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   196
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   197
    static NSString *CellIdentifier0 = @"Cell0";
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   198
    static NSString *CellIdentifier1 = @"Cell1";
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   199
    static NSString *CellIdentifier2 = @"Cell2";
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   200
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   201
    UITableViewCell *cell = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   202
    NSInteger row = [indexPath row];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   203
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   204
    switch ([indexPath section]) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   205
        case 0:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   206
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   207
            if (cell == nil) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   208
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   209
                                               reuseIdentifier:CellIdentifier0] autorelease];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   210
                // create a uitextfield for each row, expand it to take the maximum size
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   211
                UITextField *aTextField = [[UITextField alloc] 
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   212
                                           initWithFrame:CGRectMake(5, 12, (cell.frame.size.width + cell.frame.size.width/3) - 42, 25)];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   213
                aTextField.clearsOnBeginEditing = NO;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   214
                aTextField.returnKeyType = UIReturnKeyDone;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   215
                aTextField.adjustsFontSizeToFitWidth = YES;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   216
                aTextField.delegate = self;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   217
                aTextField.tag = [indexPath row];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   218
                aTextField.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   219
                aTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   220
                [aTextField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   221
                [cell.contentView addSubview:aTextField];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   222
                [aTextField release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   223
            }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   224
            
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   225
            for (UIView *oneView in cell.contentView.subviews) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   226
                if ([oneView isMemberOfClass:[UITextField class]]) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   227
                    // we find the uitextfied and we'll use its tag to understand which one is being edited
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   228
                    UITextField *textFieldFound = (UITextField *)oneView;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   229
                    textFieldFound.text = self.title;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   230
                }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   231
            }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   232
            cell.detailTextLabel.text = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   233
            cell.imageView.image = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   234
            break;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   235
        case 1:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   236
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   237
            if (cell == nil) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   238
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   239
                                               reuseIdentifier:CellIdentifier1] autorelease];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   240
            }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   241
            
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   242
            UIImage *img = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/icon%@.png",BTN_DIRECTORY(),[[self.basicSettingList objectAtIndex:row] objectForKey:@"image"]]];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   243
            cell.imageView.image = [img scaleToSize:CGSizeMake(40, 40)];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   244
            [img release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   245
            cell.textLabel.text = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   246
            cell.detailTextLabel.text = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   247
            break;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   248
        case 2:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   249
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   250
            if (cell == nil) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   251
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   252
                                               reuseIdentifier:CellIdentifier2] autorelease];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   253
                UISwitch *onOff = [[UISwitch alloc] init];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   254
                onOff.tag = row;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   255
                [onOff addTarget:self action:@selector(toggleSwitch:) forControlEvents:UIControlEventValueChanged];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   256
                cell.accessoryView = onOff;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   257
                [onOff release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   258
            }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   259
            
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   260
            UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/btn%@.png",BTN_DIRECTORY(),[[self.gameModifierArray objectAtIndex:row] objectForKey:@"image"]]];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   261
            cell.imageView.image = image;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   262
            [image release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   263
            [cell.imageView.layer setCornerRadius:7.0f];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   264
            [cell.imageView.layer setMasksToBounds:YES];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   265
            cell.textLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   266
            cell.detailTextLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   267
            [(UISwitch *)cell.accessoryView setOn:[[self.schemeArray objectAtIndex:row] boolValue] animated:NO];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   268
        }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   269
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   270
    return cell;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   271
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   272
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   273
-(void) toggleSwitch:(id) sender {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   274
    UISwitch *theSwitch = (UISwitch *)sender;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   275
    [self.schemeArray replaceObjectAtIndex:theSwitch.tag withObject:[NSNumber numberWithBool:theSwitch.on]];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   276
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   277
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   278
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   279
#pragma mark -
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   280
#pragma mark Table view delegate
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   281
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   282
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   283
    if ([indexPath section] == 0) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   284
        UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   285
        for (UIView *oneView in cell.contentView.subviews) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   286
            if ([oneView isMemberOfClass:[UITextField class]]) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   287
                textFieldBeingEdited = (UITextField *)oneView;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   288
                [textFieldBeingEdited becomeFirstResponder];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   289
            }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   290
        }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   291
    }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   292
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   293
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   294
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   295
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   296
#pragma mark -
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   297
#pragma mark Memory management
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   298
-(void) didReceiveMemoryWarning {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   299
    [super didReceiveMemoryWarning];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   300
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   301
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   302
-(void) viewDidUnload {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   303
    self.textFieldBeingEdited = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   304
    self.schemeArray = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   305
    self.basicSettingList = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   306
    self.gameModifierArray = nil;
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
   307
    [super viewDidUnload];
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
   308
    MSG_DIDUNLOAD();
3479
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   309
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   310
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   311
-(void) dealloc {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   312
    [textFieldBeingEdited release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   313
    [schemeArray release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   314
    [basicSettingList release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   315
    [gameModifierArray release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   316
    [super dealloc];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   317
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   318
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   319
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   320
@end
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   321