project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m
changeset 3926 668b71f31e51
parent 3924 2a9ace189288
child 3930 8b00b4f93242
equal deleted inserted replaced
3924:2a9ace189288 3926:668b71f31e51
    18  * File created on 19/06/2010.
    18  * File created on 19/06/2010.
    19  */
    19  */
    20 
    20 
    21 
    21 
    22 #import "SingleWeaponViewController.h"
    22 #import "SingleWeaponViewController.h"
    23 #import "WeaponCellView.h"
       
    24 #import "CommodityFunctions.h"
    23 #import "CommodityFunctions.h"
    25 #import "UIImageExtra.h"
    24 #import "UIImageExtra.h"
       
    25 #import "PascalImports.h"
    26 
    26 
    27 @implementation SingleWeaponViewController
    27 @implementation SingleWeaponViewController
    28 @synthesize weaponName, description, ammoStoreImage, ammoNames;
    28 @synthesize weaponName, description, ammoStoreImage;
    29 
    29 
    30 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    30 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    31     return rotationManager(interfaceOrientation);
    31     return rotationManager(interfaceOrientation);
    32 }
    32 }
    33 
    33 
    34 #pragma mark -
    34 #pragma mark -
    35 #pragma mark View lifecycle
    35 #pragma mark View lifecycle
    36 -(void) viewDidLoad {
    36 -(void) viewDidLoad {
    37     [super viewDidLoad];
    37     [super viewDidLoad];
    38     
    38     
    39     // also increment CURRENT_AMMOSIZE in CommodityFunctions.h
    39     NSString *trFilePath = [NSString stringWithFormat:@"%@/en.txt",LOCALE_DIRECTORY()];
    40     NSArray *array = [[NSArray alloc] initWithObjects:
    40     // fill the data structure that we are going to read
    41                       NSLocalizedString(@"Grenade",@""),
    41     LoadLocaleWrapper([trFilePath UTF8String]);
    42                       NSLocalizedString(@"Cluster Bomb",@""),
    42     
    43                       NSLocalizedString(@"Bazooka",@""),
    43     quantity = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1));
    44                       NSLocalizedString(@"Homing Bee",@""),
    44     probability = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1));
    45                       NSLocalizedString(@"Shotgun",@""),
    45     delay = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1));
    46                       NSLocalizedString(@"Pick Hammer",@""),
    46     crateness = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1));
    47                       NSLocalizedString(@"Skip",@""),
       
    48                       NSLocalizedString(@"Rope",@""),
       
    49                       NSLocalizedString(@"Mine",@""),
       
    50                       NSLocalizedString(@"Deagle",@""),
       
    51                       NSLocalizedString(@"Dynamite",@""),
       
    52                       NSLocalizedString(@"Fire Punch",@""),
       
    53                       NSLocalizedString(@"Slash",@""),
       
    54                       NSLocalizedString(@"Baseball bat",@""),
       
    55                       NSLocalizedString(@"Parachute",@""),
       
    56                       NSLocalizedString(@"Air Attack",@""),
       
    57                       NSLocalizedString(@"Mines Attack",@""),
       
    58                       NSLocalizedString(@"Blow Torch",@""),
       
    59                       NSLocalizedString(@"Construction",@""),
       
    60                       NSLocalizedString(@"Teleport",@""),
       
    61                       NSLocalizedString(@"Switch Hedgehog",@""),
       
    62                       NSLocalizedString(@"Mortar",@""),
       
    63                       NSLocalizedString(@"Kamikaze",@""),
       
    64                       NSLocalizedString(@"Cake",@""),
       
    65                       NSLocalizedString(@"Seduction",@""),
       
    66                       NSLocalizedString(@"Watermelon Bomb",@""),
       
    67                       NSLocalizedString(@"Hellish Hand Grenade",@""),
       
    68                       NSLocalizedString(@"Napalm Attack",@""),
       
    69                       NSLocalizedString(@"Drill Rocket",@""),
       
    70                       NSLocalizedString(@"Ballgun",@""),
       
    71                       NSLocalizedString(@"RC Plane",@""),
       
    72                       NSLocalizedString(@"Low Gravity",@""),
       
    73                       NSLocalizedString(@"Extra Damage",@""),
       
    74                       NSLocalizedString(@"Invulnerable",@""),
       
    75                       NSLocalizedString(@"Extra Time",@""),
       
    76                       NSLocalizedString(@"Laser Sight",@""),
       
    77                       NSLocalizedString(@"Vampirism",@""),
       
    78                       NSLocalizedString(@"Sniper Rifle",@""),
       
    79                       NSLocalizedString(@"Flying Saucer",@""),
       
    80                       NSLocalizedString(@"Molotov Cocktail",@""),
       
    81                       NSLocalizedString(@"Birdy",@""),
       
    82                       NSLocalizedString(@"Portable Portal Device",@""),
       
    83                       NSLocalizedString(@"Piano Attack",@""),
       
    84                       NSLocalizedString(@"Old Limburger",@""),
       
    85                       NSLocalizedString(@"Sine Gun",@""),
       
    86                       NSLocalizedString(@"Flamethrower",@""),
       
    87                       NSLocalizedString(@"Sticky Mine",@""),
       
    88                       NSLocalizedString(@"Hammer",@""),
       
    89                       nil];
       
    90     self.ammoNames = array;
       
    91     [array release];
       
    92     
       
    93     quantity = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1));
       
    94     probability = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1));
       
    95     delay = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1));
       
    96     crateness = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1));
       
    97     
    47     
    98     NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()];
    48     NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()];
    99     UIImage *img = [[UIImage alloc] initWithContentsOfFile:str];
    49     UIImage *img = [[UIImage alloc] initWithContentsOfFile:str];
   100     self.ammoStoreImage = img;
    50     self.ammoStoreImage = img;
   101     [img release];
    51     [img release];
   124         quantity[i] = tmp1[i];
    74         quantity[i] = tmp1[i];
   125         probability[i] = tmp2[i];
    75         probability[i] = tmp2[i];
   126         delay[i] = tmp3[i];
    76         delay[i] = tmp3[i];
   127         crateness[i] = tmp4[i];
    77         crateness[i] = tmp4[i];
   128     }
    78     }
   129     for (int i = oldlen; i < CURRENT_AMMOSIZE; i++) {
    79     for (int i = oldlen; i < HW_getNumberOfWeapons(); i++) {
   130         quantity[i] = '0';
    80         quantity[i] = '0';
   131         probability[i] = '0';
    81         probability[i] = '0';
   132         delay[i] = '0';
    82         delay[i] = '0';
   133         crateness[i] = '0';
    83         crateness[i] = '0';
   134     }
    84     }
   140     [super viewWillDisappear:animated];
    90     [super viewWillDisappear:animated];
   141     [self saveAmmos];
    91     [self saveAmmos];
   142 }
    92 }
   143 
    93 
   144 -(void) saveAmmos {
    94 -(void) saveAmmos {
   145     quantity[CURRENT_AMMOSIZE] = '\0';
    95     quantity[HW_getNumberOfWeapons()] = '\0';
   146     probability[CURRENT_AMMOSIZE] = '\0';
    96     probability[HW_getNumberOfWeapons()] = '\0';
   147     delay[CURRENT_AMMOSIZE] = '\0';
    97     delay[HW_getNumberOfWeapons()] = '\0';
   148     crateness[CURRENT_AMMOSIZE] = '\0';
    98     crateness[HW_getNumberOfWeapons()] = '\0';
   149     
    99     
   150     NSString *quantityStr = [NSString stringWithUTF8String:quantity];
   100     NSString *quantityStr = [NSString stringWithUTF8String:quantity];
   151     NSString *probabilityStr = [NSString stringWithUTF8String:probability];
   101     NSString *probabilityStr = [NSString stringWithUTF8String:probability];
   152     NSString *delayStr = [NSString stringWithUTF8String:delay];
   102     NSString *delayStr = [NSString stringWithUTF8String:delay];
   153     NSString *cratenessStr = [NSString stringWithUTF8String:crateness];
   103     NSString *cratenessStr = [NSString stringWithUTF8String:crateness];
   154     
   104     
   155     NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys:
   105     NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys:
   156                             [NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version",
   106                             [NSNumber numberWithInt:HW_getNumberOfWeapons()],@"version",
   157                             quantityStr,@"ammostore_initialqt",
   107                             quantityStr,@"ammostore_initialqt",
   158                             probabilityStr,@"ammostore_probability",
   108                             probabilityStr,@"ammostore_probability",
   159                             delayStr,@"ammostore_delay",
   109                             delayStr,@"ammostore_delay",
   160                             cratenessStr,@"ammostore_crate", 
   110                             cratenessStr,@"ammostore_crate", 
   161                             self.description,@"description",
   111                             self.description,@"description",
   175 
   125 
   176 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   126 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   177     if (section == 0)
   127     if (section == 0)
   178         return 2;
   128         return 2;
   179     else
   129     else
   180         return CURRENT_AMMOSIZE;
   130         return HW_getNumberOfWeapons();
   181 }
   131 }
   182 
   132 
   183 // Customize the appearance of table view cells.
   133 // Customize the appearance of table view cells.
   184 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   134 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   185     static NSString *CellIdentifier0 = @"Cell0";
   135     static NSString *CellIdentifier0 = @"Cell0";
   218         int x = ((row*32)/(int)self.ammoStoreImage.size.height)*32;
   168         int x = ((row*32)/(int)self.ammoStoreImage.size.height)*32;
   219         int y = (row*32)%(int)self.ammoStoreImage.size.height;
   169         int y = (row*32)%(int)self.ammoStoreImage.size.height;
   220 
   170 
   221         UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)];
   171         UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)];
   222         weaponCell.weaponIcon.image = img;
   172         weaponCell.weaponIcon.image = img;
   223         weaponCell.weaponName.text = [ammoNames objectAtIndex:row];
   173         weaponCell.weaponName.text = [NSString stringWithUTF8String:HW_getWeaponNameByIndex(row)];
   224         weaponCell.tag = row;
   174         weaponCell.tag = row;
   225 
   175 
   226         [weaponCell.initialSli setValue:[[NSString stringWithFormat:@"%c",quantity[row]] intValue] animated:NO];
   176         [weaponCell.initialSli setValue:[[NSString stringWithFormat:@"%c",quantity[row]] intValue] animated:NO];
   227         [weaponCell.probabilitySli setValue:[[NSString stringWithFormat:@"%c", probability[row]] intValue] animated:NO];
   177         [weaponCell.probabilitySli setValue:[[NSString stringWithFormat:@"%c", probability[row]] intValue] animated:NO];
   228         [weaponCell.delaySli setValue:[[NSString stringWithFormat:@"%c", delay[row]] intValue] animated:NO];
   178         [weaponCell.delaySli setValue:[[NSString stringWithFormat:@"%c", delay[row]] intValue] animated:NO];
   304     free(crateness); crateness = NULL;
   254     free(crateness); crateness = NULL;
   305     [super viewDidUnload];
   255     [super viewDidUnload];
   306     self.description = nil;
   256     self.description = nil;
   307     self.weaponName = nil;
   257     self.weaponName = nil;
   308     self.ammoStoreImage = nil;
   258     self.ammoStoreImage = nil;
   309     self.ammoNames = nil;
       
   310     MSG_DIDUNLOAD();
   259     MSG_DIDUNLOAD();
   311     [super viewDidUnload];
   260     [super viewDidUnload];
   312 }
   261 }
   313 
   262 
   314 
   263 
   315 -(void) dealloc {
   264 -(void) dealloc {
   316     [weaponName release];
   265     [weaponName release];
   317     [description release];
   266     [description release];
   318     [ammoStoreImage release];
   267     [ammoStoreImage release];
   319     [ammoNames release];
       
   320     [super dealloc];
   268     [super dealloc];
   321 }
   269 }
   322 
   270 
   323 
   271 
   324 @end
   272 @end