--- a/project_files/HedgewarsMobile/Classes/SingleTeamViewController.m Fri Dec 29 22:37:31 2017 +0100
+++ b/project_files/HedgewarsMobile/Classes/SingleTeamViewController.m Sat Dec 30 01:22:11 2017 +0100
@@ -32,14 +32,14 @@
@implementation SingleTeamViewController
@synthesize teamDictionary, normalHogSprite, secondaryItems, moreSecondaryItems, teamName;
--(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return rotationManager(interfaceOrientation);
}
#pragma mark -
#pragma mark editableCellViewDelegate methods
// set the new value
--(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
+- (void)saveTextFieldValue:(NSString *)textString withTag:(NSInteger)tagValue {
if (TEAMNAME_TAG == tagValue) {
// delete old file
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),self.teamName] error:NULL];
@@ -57,7 +57,7 @@
#pragma mark -
#pragma mark View lifecycle
--(void) viewDidLoad {
+- (void)viewDidLoad {
[super viewDidLoad];
// labels for the entries
@@ -68,7 +68,6 @@
NSLocalizedString(@"Flag",@""),
NSLocalizedString(@"Level",@""),nil];
self.secondaryItems = array;
- [array release];
// labels for the subtitles
NSArray *moreArray = [[NSArray alloc] initWithObjects:
@@ -78,14 +77,11 @@
NSLocalizedString(@"Choose a charismatic symbol for your team",@""),
NSLocalizedString(@"Opt for controlling the team or let the AI lead",@""),nil];
self.moreSecondaryItems = moreArray;
- [moreArray release];
// load the base hog image, drawing will occure in cellForRow...
NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/basehat-hedgehog.png",[[NSBundle mainBundle] resourcePath]];
UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile];
- [normalHogFile release];
self.normalHogSprite = hogSprite;
- [hogSprite release];
// listen if any childController modifies the plist and write it if needed
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setWriteNeeded) name:@"setWriteNeedTeams" object:nil];
@@ -94,7 +90,7 @@
self.title = NSLocalizedString(@"Edit team settings",@"");
}
--(void) viewWillAppear:(BOOL)animated {
+- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// load data about the team and write if there has been a change from other childControllers
@@ -104,14 +100,12 @@
NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),self.teamName];
NSMutableDictionary *teamDict = [[NSMutableDictionary alloc] initWithContentsOfFile:teamFile];
self.teamDictionary = teamDict;
- [teamDict release];
- [teamFile release];
[self.tableView reloadData];
}
// write on file if there has been a change
--(void) viewWillDisappear:(BOOL)animated {
+- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (isWriteNeeded)
@@ -120,14 +114,13 @@
#pragma mark -
// needed by other classes to warn about a user change
--(void) setWriteNeeded {
+- (void)setWriteNeeded {
isWriteNeeded = YES;
}
--(void) writeFile {
+- (void)writeFile {
NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),self.teamName];
[self.teamDictionary writeToFile:teamFile atomically:YES];
- [teamFile release];
//DLog(@"%@",teamDictionary);
isWriteNeeded = NO;
@@ -135,11 +128,11 @@
#pragma mark -
#pragma mark Table view data source
--(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
--(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger rows = 0;
switch (section) {
case 0: // team name
@@ -189,11 +182,11 @@
UIImage *accessoryImage;
switch ([indexPath section]) {
- case 0:
+ case 0: {
editableCell = (EditableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
if (editableCell == nil) {
- editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
- reuseIdentifier:CellIdentifier0] autorelease];
+ editableCell = [[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
+ reuseIdentifier:CellIdentifier0];
editableCell.delegate = self;
editableCell.tag = TEAMNAME_TAG;
}
@@ -204,14 +197,15 @@
cell = editableCell;
break;
- case 1:
+ }
+ case 1: {
if ([indexPath row] == HW_getMaxNumberOfHogs())
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierDefault];
if (cell == nil)
{
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
- reuseIdentifier:CellIdentifierDefault] autorelease];
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
+ reuseIdentifier:CellIdentifierDefault];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
@@ -222,8 +216,8 @@
editableCell = (EditableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (editableCell == nil) {
- editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
- reuseIdentifier:CellIdentifier1] autorelease];
+ editableCell = [[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
+ reuseIdentifier:CellIdentifier1];
editableCell.delegate = self;
}
editableCell.tag = [indexPath row];
@@ -233,20 +227,19 @@
// draw the hat on top of the hog
NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@.png", HATS_DIRECTORY(), [[hogArray objectAtIndex:row] objectForKey:@"hat"]];
UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile: hatFile andCutAt:CGRectMake(0, 0, 32, 32)];
- [hatFile release];
editableCell.imageView.image = [self.normalHogSprite mergeWith:hatSprite atPoint:CGPointMake(0, 5)];
- [hatSprite release];
editableCell.textField.text = [[hogArray objectAtIndex:row] objectForKey:@"hogname"];
editableCell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell = editableCell;
break;
- case 2:
+ }
+ case 2: {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
- reuseIdentifier:CellIdentifier2] autorelease];
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
+ reuseIdentifier:CellIdentifier2];
}
cell.textLabel.text = [self.secondaryItems objectAtIndex:row];
@@ -258,25 +251,21 @@
GRAVES_DIRECTORY(),[teamDictionary objectForKey:@"grave"]]
andCutAt:CGRectMake(0,0,32,32)];
cell.imageView.image = accessoryImage;
- [accessoryImage release];
break;
case 1: // voice
accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/HellishBomb.png",
GRAPHICS_DIRECTORY()]];
cell.imageView.image = accessoryImage;
- [accessoryImage release];
break;
case 2: // fort
accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@-icon.png",
FORTS_DIRECTORY(),[teamDictionary objectForKey:@"fort"]]];
cell.imageView.image = accessoryImage;
- [accessoryImage release];
break;
case 3: // flags
accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png",
FLAGS_DIRECTORY(),[teamDictionary objectForKey:@"flag"]]];
cell.imageView.image = [accessoryImage scaleToSize:CGSizeMake(26, 18)];
- [accessoryImage release];
cell.imageView.layer.borderWidth = 1;
cell.imageView.layer.borderColor = [[UIColor blackColor] CGColor];
break;
@@ -287,13 +276,13 @@
objectAtIndex:0] objectForKey:@"level"]
intValue]]];
cell.imageView.image = accessoryImage;
- [accessoryImage release];
break;
default:
cell.imageView.image = nil;
break;
}
break;
+ }
}
return cell;
@@ -302,7 +291,7 @@
#pragma mark -
#pragma mark Table view delegate
--(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
NSInteger section = [indexPath section];
@@ -316,7 +305,6 @@
[gravesViewController setTeamDictionary:teamDictionary];
[self.navigationController pushViewController:gravesViewController animated:YES];
- [gravesViewController release];
break;
}
case 1: // voice
@@ -325,7 +313,6 @@
[voicesViewController setTeamDictionary:teamDictionary];
[self.navigationController pushViewController:voicesViewController animated:YES];
- [voicesViewController release];
break;
}
case 2: // fort
@@ -334,7 +321,6 @@
[fortsViewController setTeamDictionary:teamDictionary];
[self.navigationController pushViewController:fortsViewController animated:YES];
- [fortsViewController release];
break;
}
case 3: // flag
@@ -343,7 +329,6 @@
[flagsViewController setTeamDictionary:teamDictionary];
[self.navigationController pushViewController:flagsViewController animated:YES];
- [flagsViewController release];
break;
}
case 4: // level
@@ -352,7 +337,6 @@
[levelViewController setTeamDictionary:teamDictionary];
[self.navigationController pushViewController:levelViewController animated:YES];
- [levelViewController release];
break;
}
default:
@@ -373,7 +357,7 @@
}
// action to perform when you want to change a hog hat
--(void) tableView:(UITableView *)aTableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
+- (void)tableView:(UITableView *)aTableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
// if we are editing the field undo any change before proceeding
EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
[cell cancel:nil];
@@ -390,37 +374,15 @@
hogHatViewController.selectedHog = hogIndex;
[self.navigationController pushViewController:hogHatViewController animated:YES];
- [hogHatViewController release];
}
#pragma mark -
#pragma mark Memory management
--(void) didReceiveMemoryWarning {
+
+- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
MSG_MEMCLEAN();
}
--(void) viewDidUnload {
- self.teamDictionary = nil;
- self.teamName = nil;
- self.normalHogSprite = nil;
- self.secondaryItems = nil;
- self.moreSecondaryItems = nil;
- MSG_DIDUNLOAD();
- [super viewDidUnload];
-}
-
--(void) dealloc
-{
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- releaseAndNil(teamDictionary);
- releaseAndNil(teamName);
- releaseAndNil(normalHogSprite);
- releaseAndNil(secondaryItems);
- releaseAndNil(moreSecondaryItems);
- [super dealloc];
-}
-
-
@end