cocoaTouch/SingleSchemeViewController.m
author smxx
Sat, 05 Jun 2010 19:50:02 +0000
changeset 3498 1c74e277069c
parent 3490 016b3172b645
child 3513 f589230fa21b
permissions -rw-r--r--
Frontend: * Fixed main menu tips not showing up
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];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   106
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   107
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   108
// save to file
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   109
-(void) viewWillDisappear:(BOOL) animated {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   110
    [super viewWillDisappear:animated];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   111
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   112
    NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   113
    [self.schemeArray writeToFile:schemeFile atomically:YES];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   114
    [schemeFile release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   115
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   116
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   117
#pragma mark -
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   118
#pragma mark textfield methods
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   119
-(void) cancel:(id) sender {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   120
    if (textFieldBeingEdited != nil)
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   121
        [self.textFieldBeingEdited resignFirstResponder];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   122
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   123
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   124
// set the new value
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   125
-(BOOL) save:(id) sender {    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   126
    if (textFieldBeingEdited != nil) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   127
        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title] error:NULL];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   128
        self.title = self.textFieldBeingEdited.text;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   129
        [self.schemeArray writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title] atomically:YES];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   130
        [self.textFieldBeingEdited resignFirstResponder];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   131
        return YES;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   132
    }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   133
    return NO;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   134
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   135
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   136
// the textfield is being modified, update the navigation controller
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   137
-(void) textFieldDidBeginEditing:(UITextField *)aTextField{   
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   138
    self.textFieldBeingEdited = aTextField;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   139
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   140
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"from schemes table")
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   141
                                                                     style:UIBarButtonItemStylePlain
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   142
                                                                    target:self
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   143
                                                                    action:@selector(cancel:)];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   144
    self.navigationItem.leftBarButtonItem = cancelButton;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   145
    [cancelButton release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   146
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   147
    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Save",@"from schemes table")
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   148
                                                                     style:UIBarButtonItemStyleDone
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   149
                                                                    target:self
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   150
                                                                    action:@selector(save:)];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   151
    self.navigationItem.rightBarButtonItem = saveButton;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   152
    [saveButton release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   153
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   154
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   155
// 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
   156
-(void) textFieldDidEndEditing:(UITextField *)aTextField{
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   157
    if ([textFieldBeingEdited.text length] == 0) 
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   158
        textFieldBeingEdited.text = [NSString stringWithFormat:@"New Scheme"];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   159
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   160
    self.textFieldBeingEdited = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   161
    self.navigationItem.rightBarButtonItem = self.navigationItem.backBarButtonItem;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   162
    self.navigationItem.leftBarButtonItem = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   163
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   164
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   165
// limit the size of the field to 64 characters like in original frontend
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   166
-(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   167
    int limit = 64;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   168
    return !([textField.text length] > limit && [string length] > range.length);
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   169
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   170
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   171
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   172
#pragma mark -
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   173
#pragma mark Table view data source
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   174
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   175
    return 3;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   176
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   177
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   178
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   179
    switch (section) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   180
        case 0:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   181
            return 1;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   182
            break;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   183
        case 1:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   184
            return [self.basicSettingList count];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   185
            break;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   186
        case 2:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   187
            return [self.gameModifierArray count];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   188
        default:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   189
            break;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   190
    }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   191
    return 0;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   192
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   193
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   194
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   195
    static NSString *CellIdentifier0 = @"Cell0";
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   196
    static NSString *CellIdentifier1 = @"Cell1";
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   197
    static NSString *CellIdentifier2 = @"Cell2";
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   198
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   199
    UITableViewCell *cell = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   200
    NSInteger row = [indexPath row];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   201
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   202
    switch ([indexPath section]) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   203
        case 0:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   204
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   205
            if (cell == nil) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   206
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   207
                                               reuseIdentifier:CellIdentifier0] autorelease];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   208
                // create a uitextfield for each row, expand it to take the maximum size
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   209
                UITextField *aTextField = [[UITextField alloc] 
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   210
                                           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
   211
                aTextField.clearsOnBeginEditing = NO;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   212
                aTextField.returnKeyType = UIReturnKeyDone;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   213
                aTextField.adjustsFontSizeToFitWidth = YES;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   214
                aTextField.delegate = self;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   215
                aTextField.tag = [indexPath row];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   216
                aTextField.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   217
                aTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   218
                [aTextField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   219
                [cell.contentView addSubview:aTextField];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   220
                [aTextField release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   221
            }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   222
            
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   223
            for (UIView *oneView in cell.contentView.subviews) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   224
                if ([oneView isMemberOfClass:[UITextField class]]) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   225
                    // 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
   226
                    UITextField *textFieldFound = (UITextField *)oneView;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   227
                    textFieldFound.text = self.title;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   228
                }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   229
            }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   230
            cell.detailTextLabel.text = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   231
            cell.imageView.image = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   232
            break;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   233
        case 1:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   234
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   235
            if (cell == nil) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   236
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   237
                                               reuseIdentifier:CellIdentifier1] autorelease];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   238
            }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   239
            
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   240
            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
   241
            cell.imageView.image = [img scaleToSize:CGSizeMake(40, 40)];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   242
            [img release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   243
            cell.textLabel.text = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   244
            cell.detailTextLabel.text = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   245
            break;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   246
        case 2:
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   247
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   248
            if (cell == nil) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   249
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   250
                                               reuseIdentifier:CellIdentifier2] autorelease];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   251
                UISwitch *onOff = [[UISwitch alloc] init];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   252
                onOff.tag = row;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   253
                [onOff addTarget:self action:@selector(toggleSwitch:) forControlEvents:UIControlEventValueChanged];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   254
                cell.accessoryView = onOff;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   255
                [onOff release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   256
            }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   257
            
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   258
            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
   259
            cell.imageView.image = image;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   260
            [image release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   261
            [cell.imageView.layer setCornerRadius:7.0f];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   262
            [cell.imageView.layer setMasksToBounds:YES];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   263
            cell.textLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   264
            cell.detailTextLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   265
            [(UISwitch *)cell.accessoryView setOn:[[self.schemeArray objectAtIndex:row] boolValue] animated:NO];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   266
        }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   267
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   268
    return cell;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   269
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   270
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   271
-(void) toggleSwitch:(id) sender {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   272
    UISwitch *theSwitch = (UISwitch *)sender;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   273
    [self.schemeArray replaceObjectAtIndex:theSwitch.tag withObject:[NSNumber numberWithBool:theSwitch.on]];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   274
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   275
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   276
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   277
#pragma mark -
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   278
#pragma mark Table view delegate
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   279
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   280
    
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   281
    if ([indexPath section] == 0) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   282
        UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   283
        for (UIView *oneView in cell.contentView.subviews) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   284
            if ([oneView isMemberOfClass:[UITextField class]]) {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   285
                textFieldBeingEdited = (UITextField *)oneView;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   286
                [textFieldBeingEdited becomeFirstResponder];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   287
            }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   288
        }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   289
    }
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   290
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   291
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   292
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   293
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   294
#pragma mark -
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   295
#pragma mark Memory management
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   296
-(void) didReceiveMemoryWarning {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   297
    [super didReceiveMemoryWarning];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   298
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   299
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   300
-(void) viewDidUnload {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   301
    self.textFieldBeingEdited = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   302
    self.schemeArray = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   303
    self.basicSettingList = nil;
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   304
    self.gameModifierArray = nil;
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
   305
    [super viewDidUnload];
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
   306
    MSG_DIDUNLOAD();
3479
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   307
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   308
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   309
-(void) dealloc {
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   310
    [textFieldBeingEdited release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   311
    [schemeArray release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   312
    [basicSettingList release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   313
    [gameModifierArray release];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   314
    [super dealloc];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   315
}
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   316
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   317
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   318
@end
972ae3ec178a initial support for game modifiers (schemes)
koda
parents:
diff changeset
   319