project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m
author koda
Fri, 13 Aug 2010 02:13:18 +0200
changeset 3737 2ba6ac8a114b
parent 3701 8c449776ebe6
child 3766 36b625111609
permissions -rw-r--r--
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch adjusted default zoom value polished lobby interface updated ammosets to new weapons
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     1
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     2
//  SingleWeaponViewController.m
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     3
//  Hedgewars
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     4
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     5
//  Created by Vittorio on 19/06/10.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     7
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     8
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     9
#import "SingleWeaponViewController.h"
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    10
#import "WeaponCellView.h"
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    11
#import "CommodityFunctions.h"
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    12
#import "UIImageExtra.h"
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    13
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    14
@implementation SingleWeaponViewController
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
    15
@synthesize weaponName, ammoStoreImage, ammoNames;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    16
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    17
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    18
    return rotationManager(interfaceOrientation);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    19
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    20
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
#pragma mark View lifecycle
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    23
-(void) viewDidLoad {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
    [super viewDidLoad];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    25
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
    26
    // also increment CURRENT_AMMOSIZE in CommodityFunctions.h
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    27
    NSArray *array = [[NSArray alloc] initWithObjects:
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    28
                      NSLocalizedString(@"Grenade",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    29
                      NSLocalizedString(@"Cluster Bomb",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    30
                      NSLocalizedString(@"Bazooka",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    31
                      NSLocalizedString(@"Homing Bee",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    32
                      NSLocalizedString(@"Shotgun",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    33
                      NSLocalizedString(@"Pick Hammer",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    34
                      NSLocalizedString(@"Skip",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    35
                      NSLocalizedString(@"Rope",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    36
                      NSLocalizedString(@"Mine",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    37
                      NSLocalizedString(@"Deagle",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    38
                      NSLocalizedString(@"Dynamite",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    39
                      NSLocalizedString(@"Fire Punch",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    40
                      NSLocalizedString(@"Slash",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    41
                      NSLocalizedString(@"Baseball bat",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    42
                      NSLocalizedString(@"Parachute",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    43
                      NSLocalizedString(@"Air Attack",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    44
                      NSLocalizedString(@"Mines Attack",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    45
                      NSLocalizedString(@"Blow Torch",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    46
                      NSLocalizedString(@"Construction",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    47
                      NSLocalizedString(@"Teleport",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    48
                      NSLocalizedString(@"Switch Hedgehog",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    49
                      NSLocalizedString(@"Mortar",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    50
                      NSLocalizedString(@"Kamikaze",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    51
                      NSLocalizedString(@"Cake",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    52
                      NSLocalizedString(@"Seduction",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    53
                      NSLocalizedString(@"Watermelon Bomb",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    54
                      NSLocalizedString(@"Hellish Hand Grenade",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    55
                      NSLocalizedString(@"Napalm Attack",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    56
                      NSLocalizedString(@"Drill Rocket",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    57
                      NSLocalizedString(@"Ballgun",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    58
                      NSLocalizedString(@"RC Plane",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    59
                      NSLocalizedString(@"Low Gravity",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    60
                      NSLocalizedString(@"Extra Damage",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    61
                      NSLocalizedString(@"Invulnerable",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    62
                      NSLocalizedString(@"Extra Time",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    63
                      NSLocalizedString(@"Laser Sight",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    64
                      NSLocalizedString(@"Vampirism",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    65
                      NSLocalizedString(@"Sniper Rifle",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    66
                      NSLocalizedString(@"Flying Saucer",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    67
                      NSLocalizedString(@"Molotov Cocktail",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    68
                      NSLocalizedString(@"Birdy",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    69
                      NSLocalizedString(@"Portable Portal Device",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    70
                      NSLocalizedString(@"Piano Attack",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    71
                      NSLocalizedString(@"Old Limburger",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    72
                      NSLocalizedString(@"Sine Gun",@""),
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    73
                      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
    74
                      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
    75
                      NSLocalizedString(@"Hammer",@""),
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    76
                      nil];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    77
    self.ammoNames = array;
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    78
    [array release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
3644
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
    80
    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
    81
    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
    82
    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
    83
    crateness = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1));
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    84
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    85
    NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    86
    UIImage *img = [[UIImage alloc] initWithContentsOfFile:str];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    87
    self.ammoStoreImage = img;
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    88
    [img release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    89
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
    90
    self.title = NSLocalizedString(@"Edit weapons preferences",@"");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    91
}
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    92
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    93
-(void) viewWillAppear:(BOOL) animated {
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    94
    [super viewWillAppear:animated];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    95
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
    96
    NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName];
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    97
    NSDictionary *weapon = [[NSDictionary alloc] initWithContentsOfFile:ammoFile];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    98
    [ammoFile release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    99
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   100
    const char *tmp1 = [[weapon objectForKey:@"ammostore_initialqt"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   101
    const char *tmp2 = [[weapon objectForKey:@"ammostore_probability"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   102
    const char *tmp3 = [[weapon objectForKey:@"ammostore_delay"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   103
    const char *tmp4 = [[weapon objectForKey:@"ammostore_crate"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   104
    [weapon release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   105
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   106
    // 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
   107
    // the missing ammos with 0 quantity
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   108
    int oldlen = strlen(tmp1);
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   109
    for (int i = 0; i < oldlen; i++) {
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   110
        quantity[i] = tmp1[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   111
        probability[i] = tmp2[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   112
        delay[i] = tmp3[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   113
        crateness[i] = tmp4[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   114
    }
3623
f14db208f2fa graphics applied and fixes here and there
koda
parents: 3621
diff changeset
   115
    for (int i = oldlen; i < CURRENT_AMMOSIZE; i++) {
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   116
        quantity[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   117
        probability[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   118
        delay[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   119
        crateness[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   120
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   121
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   122
    [self.tableView reloadData];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
}
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   124
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   125
-(void) viewWillDisappear:(BOOL) animated {
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   126
    [super viewWillDisappear:animated];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   127
    [self saveAmmos];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   128
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   129
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   130
-(void) saveAmmos {
3644
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   131
    quantity[CURRENT_AMMOSIZE] = '\0';
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   132
    probability[CURRENT_AMMOSIZE] = '\0';
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   133
    delay[CURRENT_AMMOSIZE] = '\0';
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   134
    crateness[CURRENT_AMMOSIZE] = '\0';
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   135
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   136
    NSString *quantityStr = [NSString stringWithUTF8String:quantity];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   137
    NSString *probabilityStr = [NSString stringWithUTF8String:probability];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   138
    NSString *delayStr = [NSString stringWithUTF8String:delay];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   139
    NSString *cratenessStr = [NSString stringWithUTF8String:crateness];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   140
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   141
    NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys:
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   142
                            [NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version",
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   143
                            quantityStr,@"ammostore_initialqt",
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   144
                            probabilityStr,@"ammostore_probability",
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   145
                            delayStr,@"ammostore_delay",
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   146
                            cratenessStr,@"ammostore_crate", nil];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   147
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   148
    NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName];
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   149
    [weapon writeToFile:ammoFile atomically:YES];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   150
    [ammoFile release];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   151
    [weapon release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   152
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   153
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   154
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   155
#pragma mark Table view data source
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   156
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   157
    return 2;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   158
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   159
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   160
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   161
    if (section == 0)
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   162
        return 1;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   163
    else
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   164
        return CURRENT_AMMOSIZE;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   165
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   166
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   167
// Customize the appearance of table view cells.
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   168
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   169
    static NSString *CellIdentifier0 = @"Cell0";
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   170
    static NSString *CellIdentifier1 = @"Cell1";
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   171
    NSInteger row = [indexPath row];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   172
    UITableViewCell *cell = nil;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   173
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   174
    if (0 == [indexPath section]) {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   175
        EditableCellView *customCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   176
        if (customCell == nil) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   177
            customCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   178
                                            reuseIdentifier:CellIdentifier0] autorelease];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   179
            customCell.delegate = self;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   180
        }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   181
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   182
        customCell.textField.text = self.weaponName;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   183
        customCell.detailTextLabel.text = nil;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   184
        customCell.imageView.image = nil;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   185
        customCell.selectionStyle = UITableViewCellSelectionStyleNone;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   186
        cell = customCell;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   187
    } else {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   188
        WeaponCellView *customCell = (WeaponCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier1];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   189
        if (customCell == nil) {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   190
            customCell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   191
            customCell.delegate = self;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   192
        }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   193
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   194
        int x = ((row*32)/1024)*32;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   195
        int y = (row*32)%1024;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   196
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   197
        UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   198
        customCell.weaponIcon.image = img;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   199
        customCell.weaponName.text = [ammoNames objectAtIndex:row];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   200
        customCell.tag = row;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   201
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   202
        [customCell.initialQt setValue:[[NSString stringWithFormat:@"%c",quantity[row]] intValue] animated:NO];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   203
        [customCell.probabilityQt setValue:[[NSString stringWithFormat:@"%c", probability[row]] intValue] animated:NO];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   204
        [customCell.delayQt setValue:[[NSString stringWithFormat:@"%c", delay[row]] intValue] animated:NO];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   205
        [customCell.crateQt setValue:[[NSString stringWithFormat:@"%c", crateness[row]] intValue] animated:NO];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   206
        cell = customCell;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   207
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   208
3643
858b20bafb6e reworked the ammunition configuration page (visually)
koda
parents: 3624
diff changeset
   209
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   210
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   211
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   212
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   213
-(CGFloat) tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   214
    if (0 == [indexPath section])
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   215
        return aTableView.rowHeight;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   216
    else
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   217
        return 120;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   218
}
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   219
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   220
-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section {
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   221
    NSString *sectionTitle = nil;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   222
    switch (section) {
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   223
        case 0:
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   224
            sectionTitle = NSLocalizedString(@"Weaponset Name", @"");
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   225
            break;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   226
        case 1:
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   227
            sectionTitle = NSLocalizedString(@"Weapon Ammuntions", @"");
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   228
            break;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   229
        default:
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   230
            DLog(@"nope");
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   231
            break;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   232
    }
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   233
    return sectionTitle;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   234
}
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   235
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   236
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   237
#pragma mark Table view delegate
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   238
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   239
    if (0 == [indexPath section]) {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   240
        EditableCellView *editableCell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   241
        [editableCell replyKeyboard];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   242
    }
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   243
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   244
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   245
#pragma mark -
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   246
#pragma mark editableCellView delegate
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   247
// set the new value
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   248
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   249
    // delete old file
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   250
    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName] error:NULL];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   251
    // update filename
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   252
    self.weaponName = textString;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   253
    // save new file
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   254
    [self saveAmmos];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   255
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   256
3624
304c6d32383a button to open ammomenu
koda
parents: 3623
diff changeset
   257
#pragma mark -
304c6d32383a button to open ammomenu
koda
parents: 3623
diff changeset
   258
#pragma mark WeaponButtonControllerDelegate
3644
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   259
-(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
   260
    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
   261
    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
   262
    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
   263
    crateness[index] = [[NSString stringWithFormat:@"%d",[[withArray objectAtIndex:3] intValue]] characterAtIndex:0];
3624
304c6d32383a button to open ammomenu
koda
parents: 3623
diff changeset
   264
}
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   265
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   266
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   267
#pragma mark Memory management
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   268
-(void) didReceiveMemoryWarning {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   269
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   270
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   271
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   272
-(void) viewDidUnload {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   273
    free(quantity); quantity = NULL;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   274
    free(probability); probability = NULL;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   275
    free(delay); delay = NULL;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   276
    free(crateness); crateness = NULL;
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   277
    [super viewDidUnload];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   278
    self.weaponName = nil;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   279
    self.ammoStoreImage = nil;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   280
    self.ammoNames = nil;
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   281
    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
   282
    [super viewDidUnload];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   283
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   284
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   285
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   286
-(void) dealloc {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   287
    [weaponName release];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   288
    [ammoStoreImage release];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   289
    [ammoNames release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   290
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   291
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   292
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   293
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   294
@end
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   295