project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m
author koda
Sat, 02 Oct 2010 04:23:32 +0200
changeset 3922 44804043b691
parent 3829 81db3c85784b
child 3924 2a9ace189288
permissions -rw-r--r--
iPad Video Out support (+less warnings +code update for latest SDL)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3829
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     1
/*
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     3
 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     4
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     8
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    12
 * GNU General Public License for more details.
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    13
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    14
 * You should have received a copy of the GNU General Public License
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    15
 * along with this program; if not, write to the Free Software
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    17
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    18
 * File created on 19/06/2010.
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    19
 */
81db3c85784b headers ftw, also right project file
koda
parents: 3825
diff changeset
    20
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
#import "SingleWeaponViewController.h"
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    23
#import "WeaponCellView.h"
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    24
#import "CommodityFunctions.h"
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    25
#import "UIImageExtra.h"
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
@implementation SingleWeaponViewController
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
    28
@synthesize weaponName, description, ammoStoreImage, ammoNames;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    30
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    31
    return rotationManager(interfaceOrientation);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    32
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
#pragma mark View lifecycle
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    36
-(void) viewDidLoad {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
    [super viewDidLoad];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
    38
    
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3701
diff changeset
    39
    // also increment CURRENT_AMMOSIZE in CommodityFunctions.h
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    40
    NSArray *array = [[NSArray alloc] initWithObjects:
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    41
                      NSLocalizedString(@"Grenade",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    42
                      NSLocalizedString(@"Cluster Bomb",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    43
                      NSLocalizedString(@"Bazooka",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    44
                      NSLocalizedString(@"Homing Bee",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    45
                      NSLocalizedString(@"Shotgun",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    46
                      NSLocalizedString(@"Pick Hammer",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    47
                      NSLocalizedString(@"Skip",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    48
                      NSLocalizedString(@"Rope",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    49
                      NSLocalizedString(@"Mine",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    50
                      NSLocalizedString(@"Deagle",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    51
                      NSLocalizedString(@"Dynamite",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    52
                      NSLocalizedString(@"Fire Punch",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    53
                      NSLocalizedString(@"Slash",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    54
                      NSLocalizedString(@"Baseball bat",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    55
                      NSLocalizedString(@"Parachute",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    56
                      NSLocalizedString(@"Air Attack",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    57
                      NSLocalizedString(@"Mines Attack",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    58
                      NSLocalizedString(@"Blow Torch",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    59
                      NSLocalizedString(@"Construction",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    60
                      NSLocalizedString(@"Teleport",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    61
                      NSLocalizedString(@"Switch Hedgehog",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    62
                      NSLocalizedString(@"Mortar",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    63
                      NSLocalizedString(@"Kamikaze",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    64
                      NSLocalizedString(@"Cake",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    65
                      NSLocalizedString(@"Seduction",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    66
                      NSLocalizedString(@"Watermelon Bomb",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    67
                      NSLocalizedString(@"Hellish Hand Grenade",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    68
                      NSLocalizedString(@"Napalm Attack",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    69
                      NSLocalizedString(@"Drill Rocket",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    70
                      NSLocalizedString(@"Ballgun",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    71
                      NSLocalizedString(@"RC Plane",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    72
                      NSLocalizedString(@"Low Gravity",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    73
                      NSLocalizedString(@"Extra Damage",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    74
                      NSLocalizedString(@"Invulnerable",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    75
                      NSLocalizedString(@"Extra Time",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    76
                      NSLocalizedString(@"Laser Sight",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    77
                      NSLocalizedString(@"Vampirism",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    78
                      NSLocalizedString(@"Sniper Rifle",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    79
                      NSLocalizedString(@"Flying Saucer",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    80
                      NSLocalizedString(@"Molotov Cocktail",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    81
                      NSLocalizedString(@"Birdy",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    82
                      NSLocalizedString(@"Portable Portal Device",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    83
                      NSLocalizedString(@"Piano Attack",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    84
                      NSLocalizedString(@"Old Limburger",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    85
                      NSLocalizedString(@"Sine Gun",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    86
                      NSLocalizedString(@"Flamethrower",@""),
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3701
diff changeset
    87
                      NSLocalizedString(@"Sticky Mine",@""),
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3701
diff changeset
    88
                      NSLocalizedString(@"Hammer",@""),
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    89
                      nil];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    90
    self.ammoNames = array;
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    91
    [array release];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
    92
    
3644
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
    93
    quantity = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1));
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
    94
    probability = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1));
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
    95
    delay = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1));
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
    96
    crateness = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1));
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
    97
    
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    98
    NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    99
    UIImage *img = [[UIImage alloc] initWithContentsOfFile:str];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   100
    self.ammoStoreImage = img;
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   101
    [img release];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   102
    
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   103
    self.title = NSLocalizedString(@"Edit weapons preferences",@"");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
}
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   105
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   106
-(void) viewWillAppear:(BOOL) animated {
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   107
    [super viewWillAppear:animated];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   108
    
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   109
    NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName];
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   110
    NSDictionary *weapon = [[NSDictionary alloc] initWithContentsOfFile:ammoFile];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   111
    [ammoFile release];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   112
    
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   113
    self.description = [weapon objectForKey:@"description"];
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   114
    const char *tmp1 = [[weapon objectForKey:@"ammostore_initialqt"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   115
    const char *tmp2 = [[weapon objectForKey:@"ammostore_probability"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   116
    const char *tmp3 = [[weapon objectForKey:@"ammostore_delay"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   117
    const char *tmp4 = [[weapon objectForKey:@"ammostore_crate"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   118
    [weapon release];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   119
    
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   120
    // if the new weaponset is diffrent from the older we need to update it replacing
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   121
    // the missing ammos with 0 quantity
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   122
    int oldlen = strlen(tmp1);
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   123
    for (int i = 0; i < oldlen; i++) {
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   124
        quantity[i] = tmp1[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   125
        probability[i] = tmp2[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   126
        delay[i] = tmp3[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   127
        crateness[i] = tmp4[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   128
    }
3623
f14db208f2fa graphics applied and fixes here and there
koda
parents: 3621
diff changeset
   129
    for (int i = oldlen; i < CURRENT_AMMOSIZE; i++) {
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   130
        quantity[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   131
        probability[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   132
        delay[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   133
        crateness[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   134
    }
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   135
    
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   136
    [self.tableView reloadData];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
}
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   138
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   139
-(void) viewWillDisappear:(BOOL) animated {
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   140
    [super viewWillDisappear:animated];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   141
    [self saveAmmos];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   142
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   143
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   144
-(void) saveAmmos {
3644
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   145
    quantity[CURRENT_AMMOSIZE] = '\0';
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   146
    probability[CURRENT_AMMOSIZE] = '\0';
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   147
    delay[CURRENT_AMMOSIZE] = '\0';
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   148
    crateness[CURRENT_AMMOSIZE] = '\0';
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   149
    
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   150
    NSString *quantityStr = [NSString stringWithUTF8String:quantity];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   151
    NSString *probabilityStr = [NSString stringWithUTF8String:probability];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   152
    NSString *delayStr = [NSString stringWithUTF8String:delay];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   153
    NSString *cratenessStr = [NSString stringWithUTF8String:crateness];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   154
    
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   155
    NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys:
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   156
                            [NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version",
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   157
                            quantityStr,@"ammostore_initialqt",
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   158
                            probabilityStr,@"ammostore_probability",
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   159
                            delayStr,@"ammostore_delay",
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   160
                            cratenessStr,@"ammostore_crate", 
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   161
                            self.description,@"description",
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   162
                            nil];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   163
    
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   164
    NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName];
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   165
    [weapon writeToFile:ammoFile atomically:YES];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   166
    [ammoFile release];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   167
    [weapon release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   168
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   169
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   170
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   171
#pragma mark Table view data source
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   172
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   173
    return 2;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   174
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   175
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   176
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   177
    if (section == 0)
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   178
        return 2;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   179
    else
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   180
        return CURRENT_AMMOSIZE;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   181
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   182
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   183
// Customize the appearance of table view cells.
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   184
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   185
    static NSString *CellIdentifier0 = @"Cell0";
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   186
    static NSString *CellIdentifier1 = @"Cell1";
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   187
    NSInteger row = [indexPath row];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   188
    UITableViewCell *cell = nil;
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   189
    
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   190
    if (0 == [indexPath section]) {
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   191
        EditableCellView *editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   192
        if (editableCell == nil) {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   193
            editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   194
                                                    reuseIdentifier:CellIdentifier0] autorelease];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   195
            editableCell.delegate = self;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   196
        }
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   197
        editableCell.tag = row;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   198
        editableCell.selectionStyle = UITableViewCellSelectionStyleNone;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   199
        editableCell.imageView.image = nil;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   200
        editableCell.detailTextLabel.text = nil;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   201
        
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   202
        if (row == 0) {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   203
            editableCell.textField.text = self.weaponName;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   204
        } else {
3825
fd6c20cd90e3 typos, reduced sound size and last minute fixes
koda
parents: 3782
diff changeset
   205
            editableCell.minimumCharacters = 0;
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   206
            editableCell.textField.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   207
            editableCell.textField.text = self.description;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   208
            editableCell.textField.placeholder = NSLocalizedString(@"You can add a description if you wish",@"");
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   209
        }
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   210
        cell = editableCell;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   211
    } else {
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   212
        WeaponCellView *weaponCell = (WeaponCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier1];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   213
        if (weaponCell == nil) {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   214
            weaponCell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   215
            weaponCell.delegate = self;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   216
        }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   217
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   218
        int x = ((row*32)/1024)*32;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   219
        int y = (row*32)%1024;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   220
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   221
        UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   222
        weaponCell.weaponIcon.image = img;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   223
        weaponCell.weaponName.text = [ammoNames objectAtIndex:row];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   224
        weaponCell.tag = row;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   225
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   226
        [weaponCell.initialSli setValue:[[NSString stringWithFormat:@"%c",quantity[row]] intValue] animated:NO];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   227
        [weaponCell.probabilitySli setValue:[[NSString stringWithFormat:@"%c", probability[row]] intValue] animated:NO];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   228
        [weaponCell.delaySli setValue:[[NSString stringWithFormat:@"%c", delay[row]] intValue] animated:NO];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   229
        [weaponCell.crateSli setValue:[[NSString stringWithFormat:@"%c", crateness[row]] intValue] animated:NO];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   230
        cell = weaponCell;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   231
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   232
3643
858b20bafb6e reworked the ammunition configuration page (visually)
koda
parents: 3624
diff changeset
   233
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   234
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   235
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   236
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   237
-(CGFloat) tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   238
    if (0 == [indexPath section])
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   239
        return aTableView.rowHeight;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   240
    else
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   241
        return 120;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   242
}
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   243
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   244
-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section {
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   245
    NSString *sectionTitle = nil;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   246
    switch (section) {
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   247
        case 0:
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   248
            sectionTitle = NSLocalizedString(@"Weaponset Name", @"");
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   249
            break;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   250
        case 1:
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   251
            sectionTitle = NSLocalizedString(@"Weapon Ammuntions", @"");
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   252
            break;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   253
        default:
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   254
            DLog(@"nope");
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   255
            break;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   256
    }
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   257
    return sectionTitle;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   258
}
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   259
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   260
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   261
#pragma mark Table view delegate
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   262
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   263
    if (0 == [indexPath section]) {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   264
        EditableCellView *editableCell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   265
        [editableCell replyKeyboard];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   266
    }
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   267
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   268
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   269
#pragma mark -
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   270
#pragma mark editableCellView delegate
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   271
// set the new value
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   272
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   273
    if (tagValue == 0) {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   274
        // delete old file
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   275
        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName] error:NULL];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   276
        // update filename
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   277
        self.weaponName = textString;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   278
        // save new file
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   279
        [self saveAmmos];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   280
    } else {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   281
        self.description = textString;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   282
    }
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   283
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   284
3624
304c6d32383a button to open ammomenu
koda
parents: 3623
diff changeset
   285
#pragma mark -
304c6d32383a button to open ammomenu
koda
parents: 3623
diff changeset
   286
#pragma mark WeaponButtonControllerDelegate
3644
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   287
-(void) updateValues:(NSArray *)withArray atIndex:(NSInteger) index {
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   288
    quantity[index] = [[NSString stringWithFormat:@"%d",[[withArray objectAtIndex:0] intValue]] characterAtIndex:0];
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   289
    probability[index] = [[NSString stringWithFormat:@"%d",[[withArray objectAtIndex:1] intValue]] characterAtIndex:0];
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   290
    delay[index] = [[NSString stringWithFormat:@"%d",[[withArray objectAtIndex:2] intValue]] characterAtIndex:0];
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   291
    crateness[index] = [[NSString stringWithFormat:@"%d",[[withArray objectAtIndex:3] intValue]] characterAtIndex:0];
3624
304c6d32383a button to open ammomenu
koda
parents: 3623
diff changeset
   292
}
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   293
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   294
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   295
#pragma mark Memory management
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   296
-(void) didReceiveMemoryWarning {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   297
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   298
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   299
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   300
-(void) viewDidUnload {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   301
    free(quantity); quantity = NULL;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   302
    free(probability); probability = NULL;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   303
    free(delay); delay = NULL;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   304
    free(crateness); crateness = NULL;
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   305
    [super viewDidUnload];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   306
    self.description = nil;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   307
    self.weaponName = nil;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   308
    self.ammoStoreImage = nil;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   309
    self.ammoNames = nil;
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   310
    MSG_DIDUNLOAD();
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   311
    [super viewDidUnload];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   312
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   313
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   314
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   315
-(void) dealloc {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   316
    [weaponName release];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   317
    [description release];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   318
    [ammoStoreImage release];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   319
    [ammoNames release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   320
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   321
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   322
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   323
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   324
@end
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   325