project_files/HedgewarsMobile/Classes/GravesViewController.m
author Wuzzy <Wuzzy2@mail.ru>
Sun, 02 Jun 2019 18:22:06 +0200
changeset 15102 260e96addf92
parent 12877 00215a7ec5f5
permissions -rw-r--r--
Allow vgtBigExplosion in low quality mode Rationale: We already allow vgtExplosion, which is a smaller version. Without vgtBigExplosion, there is not *any* explosion effect.
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
6700
e04da46ee43c the most important commit of the year
koda
parents: 6078
diff changeset
     3
 * Copyright (c) 2009-2012 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
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: 6832
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: 3697
diff changeset
    17
 */
81db3c85784b headers ftw, also right project file
koda
parents: 3697
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 "GravesViewController.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: 5208
diff changeset
    21
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
@implementation GravesViewController
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
@synthesize teamDictionary, graveArray, lastIndexPath;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
12877
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11148
diff changeset
    26
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
    return rotationManager(interfaceOrientation);
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
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
#pragma mark View lifecycle
12877
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11148
diff changeset
    32
- (void)viewDidLoad {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
    // load all the grave names and store them into graveArray
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
    self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    37
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
    38
    self.title = NSLocalizedString(@"Choose hedgehog graves",@"");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    40
12877
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11148
diff changeset
    41
- (void)viewWillAppear:(BOOL)animated {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    42
    [super viewWillAppear:animated];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    43
    [self.tableView reloadData];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    44
    // this moves the tableview to the top
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
    [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
#pragma mark Table view data source
12877
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11148
diff changeset
    51
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
    return 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
12877
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11148
diff changeset
    55
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
    return [self.graveArray count];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
// Customize the appearance of table view cells.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
    static NSString *CellIdentifier = @"Cell";
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    62
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
    if (cell == nil)
12877
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11148
diff changeset
    65
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    66
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    67
    NSString *grave = [self.graveArray objectAtIndex:[indexPath row]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
    cell.textLabel.text = [grave stringByDeletingPathExtension];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    69
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
    if ([grave isEqualToString:[self.teamDictionary objectForKey:@"grave"]]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
        self.lastIndexPath = indexPath;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    73
    } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    74
        cell.accessoryType = UITableViewCellAccessoryNone;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
    NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
    // because we also have multi frame graves, let's take the first one only
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
    UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
    cell.imageView.image = graveSprite;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    81
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    83
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    85
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    86
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    87
#pragma mark Table view delegate
12877
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11148
diff changeset
    88
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
11148
064a53861759 - Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
    89
    NSInteger newRow = [indexPath row];
064a53861759 - Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents: 10108
diff changeset
    90
    NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    91
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    92
    if (newRow != oldRow) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
        [teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    94
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
        // tell our boss to write this new stuff on disk
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    96
        [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    97
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    98
        UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   100
        UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   101
        oldCell.accessoryType = UITableViewCellAccessoryNone;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   102
        self.lastIndexPath = indexPath;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   103
        [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   105
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   106
    [self.navigationController popViewControllerAnimated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   107
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   108
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   109
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   111
#pragma mark Memory management
12877
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11148
diff changeset
   112
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11148
diff changeset
   113
- (void)didReceiveMemoryWarning {
3971
5c82ee165ed5 minor stuff
koda
parents: 3829
diff changeset
   114
    self.lastIndexPath = nil;
5c82ee165ed5 minor stuff
koda
parents: 3829
diff changeset
   115
    MSG_MEMCLEAN();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   116
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   117
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   118
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   119
@end
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   120