# HG changeset patch # User koda # Date 1282966502 -7200 # Node ID dc3531e49e4cc6a9422e1e3de93428efd0a47a90 # Parent 2bfda544ae48f7c7b35eb22211181960b76d962f add a description field for schemes and weapons diff -r 2bfda544ae48 -r dc3531e49e4c project_files/HedgewarsMobile/Classes/EditableCellView.m --- a/project_files/HedgewarsMobile/Classes/EditableCellView.m Sat Aug 28 05:03:26 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/EditableCellView.m Sat Aug 28 05:35:02 2010 +0200 @@ -62,7 +62,7 @@ skew +=2; } - textField.frame = CGRectMake(boundsX+offset+10, skew+10, 250, [UIFont labelFontSize] + 4); + textField.frame = CGRectMake(boundsX+offset+10, skew+10, 300, [UIFont labelFontSize] + 4); } -(void) setSelected:(BOOL)selected animated:(BOOL)animated { diff -r 2bfda544ae48 -r dc3531e49e4c project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m --- a/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m Sat Aug 28 05:03:26 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m Sat Aug 28 05:35:02 2010 +0200 @@ -80,7 +80,10 @@ cell.accessoryView = nil; if ([indexPath section] == 0) { cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension]; - cell.detailTextLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension]; + NSString *str = [NSString stringWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),[self.listOfSchemes objectAtIndex:row]]; + NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str]; + cell.detailTextLabel.text = [dict objectForKey:@"description"]; + [dict release]; if ([[self.listOfSchemes objectAtIndex:row] isEqualToString:self.selectedScheme]) { UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; cell.accessoryView = checkbox; @@ -89,7 +92,10 @@ } } else { cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension]; - cell.detailTextLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension]; + NSString *str = [NSString stringWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),[self.listOfWeapons objectAtIndex:row]]; + NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str]; + cell.detailTextLabel.text = [dict objectForKey:@"description"]; + [dict release]; if ([[self.listOfWeapons objectAtIndex:row] isEqualToString:self.selectedWeapon]) { UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; cell.accessoryView = checkbox; diff -r 2bfda544ae48 -r dc3531e49e4c project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m --- a/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m Sat Aug 28 05:03:26 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m Sat Aug 28 05:35:02 2010 +0200 @@ -140,12 +140,16 @@ #pragma mark editableCellView delegate // set the new value -(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue { - // delete old file - [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] error:NULL]; - // update filename - self.schemeName = textString; - // save new file - [self.schemeDictionary writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] atomically:YES]; + if (tagValue == 0) { + // delete old file + [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] error:NULL]; + // update filename + self.schemeName = textString; + // save new file + [self.schemeDictionary writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] atomically:YES]; + } else { + [self.schemeDictionary setObject:textString forKey:@"description"]; + } } #pragma mark - @@ -157,7 +161,7 @@ -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { switch (section) { case 0: - return 1; + return 2; break; case 1: return [self.basicSettingList count]; @@ -187,11 +191,18 @@ reuseIdentifier:CellIdentifier0] autorelease]; editableCell.delegate = self; } - - editableCell.textField.text = self.schemeName; + editableCell.tag = row; + editableCell.selectionStyle = UITableViewCellSelectionStyleNone; + editableCell.imageView.image = nil; editableCell.detailTextLabel.text = nil; - editableCell.imageView.image = nil; - editableCell.selectionStyle = UITableViewCellSelectionStyleNone; + + if (row == 0) { + editableCell.textField.text = self.schemeName; + } else { + editableCell.textField.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; + editableCell.textField.text = [self.schemeDictionary objectForKey:@"description"]; + editableCell.textField.placeholder = NSLocalizedString(@"You can add a description if you wish",@""); + } cell = editableCell; break; case 1: diff -r 2bfda544ae48 -r dc3531e49e4c project_files/HedgewarsMobile/Classes/SingleWeaponViewController.h --- a/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.h Sat Aug 28 05:03:26 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.h Sat Aug 28 05:35:02 2010 +0200 @@ -12,6 +12,7 @@ @interface SingleWeaponViewController : UITableViewController { NSString *weaponName; + NSString *description; UIImage *ammoStoreImage; NSArray *ammoNames; @@ -23,6 +24,7 @@ } @property (nonatomic,retain) NSString *weaponName; +@property (nonatomic,retain) NSString *description; @property (nonatomic,retain) UIImage *ammoStoreImage; @property (nonatomic,retain) NSArray *ammoNames; diff -r 2bfda544ae48 -r dc3531e49e4c project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m --- a/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m Sat Aug 28 05:03:26 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m Sat Aug 28 05:35:02 2010 +0200 @@ -12,7 +12,7 @@ #import "UIImageExtra.h" @implementation SingleWeaponViewController -@synthesize weaponName, ammoStoreImage, ammoNames; +@synthesize weaponName, description, ammoStoreImage, ammoNames; -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { return rotationManager(interfaceOrientation); @@ -22,7 +22,7 @@ #pragma mark View lifecycle -(void) viewDidLoad { [super viewDidLoad]; - + // also increment CURRENT_AMMOSIZE in CommodityFunctions.h NSArray *array = [[NSArray alloc] initWithObjects: NSLocalizedString(@"Grenade",@""), @@ -76,33 +76,34 @@ nil]; self.ammoNames = array; [array release]; - + quantity = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1)); probability = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1)); delay = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1)); crateness = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1)); - + NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; UIImage *img = [[UIImage alloc] initWithContentsOfFile:str]; self.ammoStoreImage = img; [img release]; - + self.title = NSLocalizedString(@"Edit weapons preferences",@""); } -(void) viewWillAppear:(BOOL) animated { [super viewWillAppear:animated]; - + NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName]; NSDictionary *weapon = [[NSDictionary alloc] initWithContentsOfFile:ammoFile]; [ammoFile release]; - + + self.description = [weapon objectForKey:@"description"]; const char *tmp1 = [[weapon objectForKey:@"ammostore_initialqt"] UTF8String]; const char *tmp2 = [[weapon objectForKey:@"ammostore_probability"] UTF8String]; const char *tmp3 = [[weapon objectForKey:@"ammostore_delay"] UTF8String]; const char *tmp4 = [[weapon objectForKey:@"ammostore_crate"] UTF8String]; [weapon release]; - + // if the new weaponset is diffrent from the older we need to update it replacing // the missing ammos with 0 quantity int oldlen = strlen(tmp1); @@ -118,7 +119,7 @@ delay[i] = '0'; crateness[i] = '0'; } - + [self.tableView reloadData]; } @@ -132,19 +133,21 @@ probability[CURRENT_AMMOSIZE] = '\0'; delay[CURRENT_AMMOSIZE] = '\0'; crateness[CURRENT_AMMOSIZE] = '\0'; - + NSString *quantityStr = [NSString stringWithUTF8String:quantity]; NSString *probabilityStr = [NSString stringWithUTF8String:probability]; NSString *delayStr = [NSString stringWithUTF8String:delay]; NSString *cratenessStr = [NSString stringWithUTF8String:crateness]; - + NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version", quantityStr,@"ammostore_initialqt", probabilityStr,@"ammostore_probability", delayStr,@"ammostore_delay", - cratenessStr,@"ammostore_crate", nil]; - + cratenessStr,@"ammostore_crate", + self.description,@"description", + nil]; + NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName]; [weapon writeToFile:ammoFile atomically:YES]; [ammoFile release]; @@ -159,7 +162,7 @@ -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 0) - return 1; + return 2; else return CURRENT_AMMOSIZE; } @@ -170,40 +173,47 @@ static NSString *CellIdentifier1 = @"Cell1"; NSInteger row = [indexPath row]; UITableViewCell *cell = nil; - + if (0 == [indexPath section]) { - EditableCellView *customCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; - if (customCell == nil) { - customCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault - reuseIdentifier:CellIdentifier0] autorelease]; - customCell.delegate = self; + EditableCellView *editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; + if (editableCell == nil) { + editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault + reuseIdentifier:CellIdentifier0] autorelease]; + editableCell.delegate = self; } - - customCell.textField.text = self.weaponName; - customCell.detailTextLabel.text = nil; - customCell.imageView.image = nil; - customCell.selectionStyle = UITableViewCellSelectionStyleNone; - cell = customCell; + editableCell.tag = row; + editableCell.selectionStyle = UITableViewCellSelectionStyleNone; + editableCell.imageView.image = nil; + editableCell.detailTextLabel.text = nil; + + if (row == 0) { + editableCell.textField.text = self.weaponName; + } else { + editableCell.textField.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; + editableCell.textField.text = self.description; + editableCell.textField.placeholder = NSLocalizedString(@"You can add a description if you wish",@""); + } + cell = editableCell; } else { - WeaponCellView *customCell = (WeaponCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; - if (customCell == nil) { - customCell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; - customCell.delegate = self; + WeaponCellView *weaponCell = (WeaponCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; + if (weaponCell == nil) { + weaponCell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; + weaponCell.delegate = self; } int x = ((row*32)/1024)*32; int y = (row*32)%1024; UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)]; - customCell.weaponIcon.image = img; - customCell.weaponName.text = [ammoNames objectAtIndex:row]; - customCell.tag = row; + weaponCell.weaponIcon.image = img; + weaponCell.weaponName.text = [ammoNames objectAtIndex:row]; + weaponCell.tag = row; - [customCell.initialSli setValue:[[NSString stringWithFormat:@"%c",quantity[row]] intValue] animated:NO]; - [customCell.probabilitySli setValue:[[NSString stringWithFormat:@"%c", probability[row]] intValue] animated:NO]; - [customCell.delaySli setValue:[[NSString stringWithFormat:@"%c", delay[row]] intValue] animated:NO]; - [customCell.crateSli setValue:[[NSString stringWithFormat:@"%c", crateness[row]] intValue] animated:NO]; - cell = customCell; + [weaponCell.initialSli setValue:[[NSString stringWithFormat:@"%c",quantity[row]] intValue] animated:NO]; + [weaponCell.probabilitySli setValue:[[NSString stringWithFormat:@"%c", probability[row]] intValue] animated:NO]; + [weaponCell.delaySli setValue:[[NSString stringWithFormat:@"%c", delay[row]] intValue] animated:NO]; + [weaponCell.crateSli setValue:[[NSString stringWithFormat:@"%c", crateness[row]] intValue] animated:NO]; + cell = weaponCell; } cell.selectionStyle = UITableViewCellSelectionStyleNone; @@ -246,12 +256,16 @@ #pragma mark editableCellView delegate // set the new value -(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue { - // delete old file - [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName] error:NULL]; - // update filename - self.weaponName = textString; - // save new file - [self saveAmmos]; + if (tagValue == 0) { + // delete old file + [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName] error:NULL]; + // update filename + self.weaponName = textString; + // save new file + [self saveAmmos]; + } else { + self.description = textString; + } } #pragma mark - @@ -275,6 +289,7 @@ free(delay); delay = NULL; free(crateness); crateness = NULL; [super viewDidUnload]; + self.description = nil; self.weaponName = nil; self.ammoStoreImage = nil; self.ammoNames = nil; @@ -285,6 +300,7 @@ -(void) dealloc { [weaponName release]; + [description release]; [ammoStoreImage release]; [ammoNames release]; [super dealloc];