project_files/HedgewarsMobile/Classes/GravesViewController.m
author nemo
Fri, 09 Sep 2011 18:30:40 -0400
changeset 5832 f730c8a9777b
parent 5208 878e551f0b4a
child 6078 8c0cc07731e5
permissions -rw-r--r--
Remove some unused variables and options.inc which uFloat doesn't use, probably should never use, and was getting in the way of my testcase - but most importantly, remove the inline on hwSqrt which was causing very bad math on my compiler/machine. We may have to remove more inlining. A pity.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3829
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
     1
/*
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 3971
diff changeset
     3
 * Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com>
3829
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
     4
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
81db3c85784b headers ftw, also right project file
koda
parents: 3697
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: 3697
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
     8
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
    12
 * GNU General Public License for more details.
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
    13
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
    14
 * You should have received a copy of the GNU General Public License
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
    15
 * along with this program; if not, write to the Free Software
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
    17
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
    18
 * File created on 02/04/2010.
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
    19
 */
81db3c85784b headers ftw, also right project file
koda
parents: 3697
diff changeset
    20
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
#import "GravesViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
#import "CommodityFunctions.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
#import "UIImageExtra.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
@implementation GravesViewController
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
@synthesize teamDictionary, graveArray, lastIndexPath;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
    return rotationManager(interfaceOrientation);
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
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
#pragma mark View lifecycle
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
-(void) viewDidLoad {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    40
    // load all the grave names and store them into graveArray
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    41
    self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    42
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3547
diff changeset
    43
    self.title = NSLocalizedString(@"Choose hedgehog graves",@"");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    44
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
-(void) viewWillAppear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
    [super viewWillAppear:animated];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
    [self.tableView reloadData];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
    // this moves the tableview to the top
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
    [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    55
#pragma mark Table view data source
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
    return 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
    return [self.graveArray count];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
// Customize the appearance of table view cells.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
    static NSString *CellIdentifier = @"Cell";
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    67
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
    if (cell == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    71
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
    NSString *grave = [self.graveArray objectAtIndex:[indexPath row]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    73
    cell.textLabel.text = [grave stringByDeletingPathExtension];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    74
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
    if ([grave isEqualToString:[self.teamDictionary objectForKey:@"grave"]]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
        self.lastIndexPath = indexPath;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
    } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
        cell.accessoryType = UITableViewCellAccessoryNone;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
    NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    83
    // because we also have multi frame graves, let's take the first one only
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
    UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    85
    [graveFilePath release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    86
    cell.imageView.image = graveSprite;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    87
    [graveSprite release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    88
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    89
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    90
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    91
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    92
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
#pragma mark Table view delegate
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    96
    int newRow = [indexPath row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    97
    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    98
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
    if (newRow != oldRow) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   100
        [teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   101
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   102
        // tell our boss to write this new stuff on disk
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   103
        [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   104
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   105
        UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   106
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   107
        UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   108
        oldCell.accessoryType = UITableViewCellAccessoryNone;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   109
        self.lastIndexPath = indexPath;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
        [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   111
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   112
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   113
    [self.navigationController popViewControllerAnimated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   114
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   115
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   116
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   117
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   118
#pragma mark Memory management
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3547
diff changeset
   119
-(void) didReceiveMemoryWarning {
3971
5c82ee165ed5 minor stuff
koda
parents: 3829
diff changeset
   120
    self.lastIndexPath = nil;
5c82ee165ed5 minor stuff
koda
parents: 3829
diff changeset
   121
    MSG_MEMCLEAN();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3547
diff changeset
   125
-(void) viewDidUnload {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   126
    self.lastIndexPath = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
    self.teamDictionary = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
    self.graveArray = nil;
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3547
diff changeset
   129
    MSG_DIDUNLOAD();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   130
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   131
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3547
diff changeset
   133
-(void) dealloc {
5208
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 4976
diff changeset
   134
    releaseAndNil(graveArray);
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 4976
diff changeset
   135
    releaseAndNil(teamDictionary);
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 4976
diff changeset
   136
    releaseAndNil(lastIndexPath);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   138
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   139
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   140
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   141
@end
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   142