project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m
author koda
Thu, 21 Apr 2016 14:16:47 -0400
changeset 11661 7d483d400f8d
parent 11219 c51ecb9bcf05
child 11790 ac93cfc17365
permissions -rw-r--r--
Correctly set WEBGL macro during pas2c conversion
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
6700
e04da46ee43c the most important commit of the year
koda
parents: 6671
diff changeset
     3
 * Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com>
3829
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
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 8441
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
3829
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
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    19
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    20
#import "SingleWeaponViewController.h"
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents: 5976
diff changeset
    21
11141
01e8e5a6a8c1 - Fix for crash on loading SingleWeaponViewController in Settings
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
    22
@interface SingleWeaponViewController ()
01e8e5a6a8c1 - Fix for crash on loading SingleWeaponViewController in Settings
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
    23
@property (nonatomic, retain) NSString *trPath;
01e8e5a6a8c1 - Fix for crash on loading SingleWeaponViewController in Settings
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
    24
@property (nonatomic, retain) NSString *trFileName;
01e8e5a6a8c1 - Fix for crash on loading SingleWeaponViewController in Settings
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
    25
@end
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
@implementation SingleWeaponViewController
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    28
@synthesize weaponName, description, ammoStoreImage;
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];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
    38
11141
01e8e5a6a8c1 - Fix for crash on loading SingleWeaponViewController in Settings
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
    39
    self.trPath = [NSString stringWithFormat:@"%@", LOCALE_DIRECTORY()];
11219
c51ecb9bcf05 - Retrieving language ID moved to HWUtils
antonc27 <antonc27@mail.ru>
parents: 11200
diff changeset
    40
    self.trFileName = [NSString stringWithFormat:@"%@.txt", [HWUtils languageID]];
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    41
    // fill the data structure that we are going to read
11141
01e8e5a6a8c1 - Fix for crash on loading SingleWeaponViewController in Settings
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
    42
    LoadLocaleWrapper([self.trPath UTF8String], [self.trFileName UTF8String]);
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
    43
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    44
    quantity = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1));
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    45
    probability = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1));
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    46
    delay = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1));
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    47
    crateness = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1));
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
    48
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    49
    NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    50
    UIImage *img = [[UIImage alloc] initWithContentsOfFile:str];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    51
    self.ammoStoreImage = img;
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    52
    [img release];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
    53
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
    54
    self.title = NSLocalizedString(@"Edit weapons preferences",@"");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    55
}
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    56
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    57
-(void) viewWillAppear:(BOOL) animated {
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    58
    [super viewWillAppear:animated];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
    59
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
    60
    NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName];
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    61
    NSDictionary *weapon = [[NSDictionary alloc] initWithContentsOfFile:ammoFile];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    62
    [ammoFile release];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
    63
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
    64
    self.description = [weapon objectForKey:@"description"];
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    65
    const char *tmp1 = [[weapon objectForKey:@"ammostore_initialqt"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    66
    const char *tmp2 = [[weapon objectForKey:@"ammostore_probability"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    67
    const char *tmp3 = [[weapon objectForKey:@"ammostore_delay"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    68
    const char *tmp4 = [[weapon objectForKey:@"ammostore_crate"] UTF8String];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    69
    [weapon release];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
    70
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    71
    // 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
    72
    // the missing ammos with 0 quantity
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    73
    int oldlen = strlen(tmp1);
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    74
    for (int i = 0; i < oldlen; i++) {
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    75
        quantity[i] = tmp1[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    76
        probability[i] = tmp2[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    77
        delay[i] = tmp3[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    78
        crateness[i] = tmp4[i];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    79
    }
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    80
    for (int i = oldlen; i < HW_getNumberOfWeapons(); i++) {
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    81
        quantity[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    82
        probability[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    83
        delay[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    84
        crateness[i] = '0';
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    85
    }
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
    86
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    87
    [self.tableView reloadData];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    88
}
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    89
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    90
-(void) viewWillDisappear:(BOOL) animated {
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
    91
    [super viewWillDisappear:animated];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
    92
    [self saveAmmos];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
    93
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
    94
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
    95
-(void) saveAmmos {
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    96
    quantity[HW_getNumberOfWeapons()] = '\0';
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    97
    probability[HW_getNumberOfWeapons()] = '\0';
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    98
    delay[HW_getNumberOfWeapons()] = '\0';
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    99
    crateness[HW_getNumberOfWeapons()] = '\0';
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
   100
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   101
    NSString *quantityStr = [NSString stringWithUTF8String:quantity];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   102
    NSString *probabilityStr = [NSString stringWithUTF8String:probability];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   103
    NSString *delayStr = [NSString stringWithUTF8String:delay];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   104
    NSString *cratenessStr = [NSString stringWithUTF8String:crateness];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
   105
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   106
    NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys:
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   107
                            quantityStr,@"ammostore_initialqt",
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   108
                            probabilityStr,@"ammostore_probability",
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   109
                            delayStr,@"ammostore_delay",
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
   110
                            cratenessStr,@"ammostore_crate",
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   111
                            self.description,@"description",
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   112
                            nil];
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
   113
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   114
    NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName];
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   115
    [weapon writeToFile:ammoFile atomically:YES];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   116
    [ammoFile release];
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   117
    [weapon release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   118
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   119
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   120
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   121
#pragma mark Table view data source
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   122
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   123
    return 2;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   125
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   126
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   127
    if (section == 0)
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   128
        return 2;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   129
    else
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
   130
        return HW_getNumberOfWeapons();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   131
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   133
// Customize the appearance of table view cells.
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   134
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   135
    static NSString *CellIdentifier0 = @"Cell0";
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   136
    static NSString *CellIdentifier1 = @"Cell1";
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   137
    NSInteger row = [indexPath row];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   138
    UITableViewCell *cell = nil;
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
   139
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   140
    if (0 == [indexPath section]) {
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   141
        EditableCellView *editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   142
        if (editableCell == nil) {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   143
            editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   144
                                                    reuseIdentifier:CellIdentifier0] autorelease];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   145
            editableCell.delegate = self;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   146
        }
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   147
        editableCell.tag = row;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   148
        editableCell.selectionStyle = UITableViewCellSelectionStyleNone;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   149
        editableCell.imageView.image = nil;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   150
        editableCell.detailTextLabel.text = nil;
8441
a00b0fa0dbd7 some whitespaces from ios files
koda
parents: 6832
diff changeset
   151
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   152
        if (row == 0) {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   153
            editableCell.textField.text = self.weaponName;
4284
57a501a69e5f update iFrontend with new schemes and weaps, fix up smaller glitches
koda
parents: 3930
diff changeset
   154
            editableCell.textField.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   155
        } else {
3825
fd6c20cd90e3 typos, reduced sound size and last minute fixes
koda
parents: 3782
diff changeset
   156
            editableCell.minimumCharacters = 0;
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   157
            editableCell.textField.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   158
            editableCell.textField.text = self.description;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   159
            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
   160
        }
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   161
        cell = editableCell;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   162
    } else {
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   163
        WeaponCellView *weaponCell = (WeaponCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier1];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   164
        if (weaponCell == nil) {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   165
            weaponCell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   166
            weaponCell.delegate = self;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   167
        }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   168
6209
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6078
diff changeset
   169
        CGFloat theScale = [[UIScreen mainScreen] safeScale];
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6078
diff changeset
   170
        int size = 32 * theScale;
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6078
diff changeset
   171
        int corners = 8 * theScale;
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6078
diff changeset
   172
        int x = ((row*size)/(int)(self.ammoStoreImage.size.height * theScale))*size;
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6078
diff changeset
   173
        int y = (row*size)%(int)(self.ammoStoreImage.size.height * theScale);
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   174
5976
306cedbeb213 fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents: 5208
diff changeset
   175
        UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, size, size)] makeRoundCornersOfSize:CGSizeMake(corners, corners)];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   176
        weaponCell.weaponIcon.image = img;
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
   177
        weaponCell.weaponName.text = [NSString stringWithUTF8String:HW_getWeaponNameByIndex(row)];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   178
        weaponCell.tag = row;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   179
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   180
        [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
   181
        [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
   182
        [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
   183
        [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
   184
        cell = weaponCell;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   185
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   186
3643
858b20bafb6e reworked the ammunition configuration page (visually)
koda
parents: 3624
diff changeset
   187
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   188
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   189
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   190
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   191
-(CGFloat) tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   192
    if (0 == [indexPath section])
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   193
        return aTableView.rowHeight;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   194
    else
6671
5532d5f6285c shorten the portait orientation check
koda
parents: 6670
diff changeset
   195
        return IS_ON_PORTRAIT() ? 208 : 120;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   196
}
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   197
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   198
-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section {
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   199
    NSString *sectionTitle = nil;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   200
    switch (section) {
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   201
        case 0:
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   202
            sectionTitle = NSLocalizedString(@"Weaponset Name", @"");
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   203
            break;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   204
        case 1:
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   205
            sectionTitle = NSLocalizedString(@"Weapon Ammuntions", @"");
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   206
            break;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   207
        default:
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   208
            DLog(@"nope");
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   209
            break;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   210
    }
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   211
    return sectionTitle;
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   212
}
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
   213
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   214
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   215
#pragma mark Table view delegate
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   216
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   217
    if (0 == [indexPath section]) {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   218
        EditableCellView *editableCell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   219
        [editableCell replyKeyboard];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   220
    }
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   221
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   222
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   223
#pragma mark -
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   224
#pragma mark editableCellView delegate
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   225
// set the new value
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   226
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   227
    if (tagValue == 0) {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   228
        // delete old file
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   229
        [[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
   230
        // update filename
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   231
        self.weaponName = textString;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   232
        // save new file
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   233
        [self saveAmmos];
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   234
    } else {
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   235
        self.description = textString;
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   236
    }
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   237
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   238
3624
304c6d32383a button to open ammomenu
koda
parents: 3623
diff changeset
   239
#pragma mark -
304c6d32383a button to open ammomenu
koda
parents: 3623
diff changeset
   240
#pragma mark WeaponButtonControllerDelegate
3644
42c5684289ae finished ammo configuration (which is the last page missing in config \o/)
koda
parents: 3643
diff changeset
   241
-(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
   242
    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
   243
    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
   244
    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
   245
    crateness[index] = [[NSString stringWithFormat:@"%d",[[withArray objectAtIndex:3] intValue]] characterAtIndex:0];
3624
304c6d32383a button to open ammomenu
koda
parents: 3623
diff changeset
   246
}
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   247
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   248
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   249
#pragma mark Memory management
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   250
-(void) didReceiveMemoryWarning {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   251
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   252
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   253
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   254
-(void) viewDidUnload {
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   255
    free(quantity); quantity = NULL;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   256
    free(probability); probability = NULL;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   257
    free(delay); delay = NULL;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   258
    free(crateness); crateness = NULL;
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   259
    [super viewDidUnload];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3766
diff changeset
   260
    self.description = nil;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   261
    self.weaponName = nil;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents: 3644
diff changeset
   262
    self.ammoStoreImage = nil;
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   263
    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
   264
    [super viewDidUnload];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   265
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   266
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   267
3621
a8ddf681ba7d initial support for customizing weaponset
koda
parents: 3547
diff changeset
   268
-(void) dealloc {
11141
01e8e5a6a8c1 - Fix for crash on loading SingleWeaponViewController in Settings
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
   269
    releaseAndNil(_trPath);
01e8e5a6a8c1 - Fix for crash on loading SingleWeaponViewController in Settings
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
   270
    releaseAndNil(_trFileName);
01e8e5a6a8c1 - Fix for crash on loading SingleWeaponViewController in Settings
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
   271
    
5208
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 4976
diff changeset
   272
    releaseAndNil(weaponName);
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 4976
diff changeset
   273
    releaseAndNil(description);
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 4976
diff changeset
   274
    releaseAndNil(ammoStoreImage);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   275
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   276
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   277
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   278
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   279
@end
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   280