project_files/HedgewarsMobile/Classes/SingleTeamViewController.m
author koda
Mon, 30 Aug 2010 01:38:46 +0200
changeset 3789 c3eb56754e92
parent 3783 8e9daf967406
child 3816 7b74aa003f52
permissions -rw-r--r--
added a smaller version of forts, fixed a couple of regressions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     1
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     2
//  SingleTeamViewController.m
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     3
//  HedgewarsMobile
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     4
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     5
//  Created by Vittorio on 02/04/10.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     7
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     8
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     9
#import "SingleTeamViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    10
#import "HogHatViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    11
#import "GravesViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    12
#import "VoicesViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    13
#import "FortsViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    14
#import "FlagsViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    15
#import "LevelViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    16
#import "CommodityFunctions.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    17
#import "UIImageExtra.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    18
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    19
#define TEAMNAME_TAG 78789
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    20
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
@implementation SingleTeamViewController
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    22
@synthesize teamDictionary, normalHogSprite, secondaryItems, teamName;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
    return rotationManager(interfaceOrientation);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
#pragma mark -
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    29
#pragma mark editableCellViewDelegate methods
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
// set the new value
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    31
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    32
    if (TEAMNAME_TAG == tagValue) {
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    33
        // delete old file
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    34
        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),self.teamName] error:NULL];
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    35
        // update filename
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    36
        self.teamName = textString;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    37
        // save new file
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    38
        [self writeFile];
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    39
    } else {
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    40
        // replace the old value with the new one
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    41
        NSMutableDictionary *hog = [[teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:tagValue];
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    42
        [hog setObject:textString forKey:@"hogname"];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    43
        isWriteNeeded = YES;
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
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
#pragma mark View lifecycle
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
-(void) viewDidLoad {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
    [super viewDidLoad];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    51
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
    // labels for the entries
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
    NSArray *array = [[NSArray alloc] initWithObjects:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
                      NSLocalizedString(@"Grave",@""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    55
                      NSLocalizedString(@"Voice",@""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
                      NSLocalizedString(@"Fort",@""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
                      NSLocalizedString(@"Flag",@""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
                      NSLocalizedString(@"Level",@""),nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
    self.secondaryItems = array;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
    [array release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
    // load the base hog image, drawing will occure in cellForRow...
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
    NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
    UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
    [normalHogFile release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
    self.normalHogSprite = hogSprite;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    67
    [hogSprite release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    68
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
    // listen if any childController modifies the plist and write it if needed
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setWriteNeeded) name:@"setWriteNeedTeams" object:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
    isWriteNeeded = NO;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    72
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    73
    self.title = NSLocalizedString(@"Edit team settings",@"");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    74
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
-(void) viewWillAppear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
    [super viewWillAppear:animated];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    78
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    79
    // load data about the team and write if there has been a change from other childControllers
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    80
    if (isWriteNeeded)
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
        [self writeFile];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    82
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    83
    NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),self.teamName];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
    NSMutableDictionary *teamDict = [[NSMutableDictionary alloc] initWithContentsOfFile:teamFile];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    85
    self.teamDictionary = teamDict;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    86
    [teamDict release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    87
    [teamFile 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
    [self.tableView reloadData];
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
// write on file if there has been a change
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
-(void) viewWillDisappear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
    [super viewWillDisappear:animated];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
    96
    if (isWriteNeeded)
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    97
        [self writeFile];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    98
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   100
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   101
// needed by other classes to warn about a user change
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   102
-(void) setWriteNeeded {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   103
    isWriteNeeded = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   105
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   106
-(void) writeFile {
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   107
    NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),self.teamName];
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   108
    [self.teamDictionary writeToFile:teamFile atomically:YES];
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   109
    [teamFile release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
3789
c3eb56754e92 added a smaller version of forts, fixed a couple of regressions
koda
parents: 3783
diff changeset
   111
    //DLog(@"%@",teamDictionary);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   112
    isWriteNeeded = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   113
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   114
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   115
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   116
#pragma mark Table view data source
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   117
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   118
    return 3;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   119
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   120
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   121
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
    NSInteger rows = 0;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
    switch (section) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
        case 0: // team name
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   125
            rows = 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   126
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
        case 1: // team members
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
            rows = MAX_HOGS;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   129
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   130
        case 2: // team details
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   131
            rows = [self.secondaryItems count];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   133
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   134
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   135
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   136
    return rows;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   138
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   139
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   140
    NSString *sectionTitle = nil;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   141
    switch (section) {
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   142
        case 0:
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   143
            sectionTitle = NSLocalizedString(@"Team Name", @"");
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   144
            break;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   145
        case 1:
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   146
            sectionTitle = NSLocalizedString(@"Names and Hats", @"");
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   147
            break;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   148
        case 2:
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   149
            sectionTitle = NSLocalizedString(@"Team Preferences", @"");
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   150
            break;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   151
        default:
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   152
            DLog(@"Nope");
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   153
            break;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   154
    }
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   155
    return sectionTitle;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   156
}
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   157
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   158
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   159
    static NSString *CellIdentifier0 = @"Cell0";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   160
    static NSString *CellIdentifier1 = @"Cell1";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   161
    static NSString *CellIdentifier2 = @"Cell2";
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   162
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   163
    NSArray *hogArray;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   164
    UITableViewCell *cell = nil;
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   165
    EditableCellView *editableCell = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   166
    NSInteger row = [indexPath row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   167
    UIImage *accessoryImage;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   168
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   169
    switch ([indexPath section]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   170
        case 0:
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   171
            editableCell = (EditableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   172
            if (editableCell == nil) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   173
                editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   174
                                               reuseIdentifier:CellIdentifier0] autorelease];
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   175
                editableCell.delegate = self;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   176
                editableCell.tag = TEAMNAME_TAG;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   177
            }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   178
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   179
            editableCell.imageView.image = nil;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   180
            editableCell.accessoryType = UITableViewCellAccessoryNone;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   181
            editableCell.textField.text = self.teamName;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   182
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   183
            cell = editableCell;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   184
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   185
        case 1:
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   186
            editableCell = (EditableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   187
            if (editableCell == nil) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   188
                editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   189
                                               reuseIdentifier:CellIdentifier1] autorelease];
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   190
                editableCell.delegate = self;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   191
                editableCell.tag = [indexPath row];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   192
            }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   193
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   194
            hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   195
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   196
            // draw the hat on top of the hog
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   197
            NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@.png", HATS_DIRECTORY(), [[hogArray objectAtIndex:row] objectForKey:@"hat"]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   198
            UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile: hatFile andCutAt:CGRectMake(0, 0, 32, 32)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   199
            [hatFile release];
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   200
            editableCell.imageView.image = [self.normalHogSprite mergeWith:hatSprite atPoint:CGPointMake(0, -5)];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   201
            [hatSprite release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   202
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   203
            editableCell.textField.text = [[hogArray objectAtIndex:row] objectForKey:@"hogname"];
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   204
            editableCell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   205
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   206
            cell = editableCell;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   207
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   208
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   209
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   210
            if (cell == nil) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   211
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   212
                                               reuseIdentifier:CellIdentifier2] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   213
            }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   214
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   215
            cell.textLabel.text = [self.secondaryItems objectAtIndex:row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   216
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   217
            switch (row) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   218
                case 0: // grave
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   219
                    accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   220
                                                                              GRAVES_DIRECTORY(),[teamDictionary objectForKey:@"grave"]]
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   221
                                                                    andCutAt:CGRectMake(0,0,32,32)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   222
                    cell.imageView.image = accessoryImage;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   223
                    [accessoryImage release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   224
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   225
                case 2: // fort
3789
c3eb56754e92 added a smaller version of forts, fixed a couple of regressions
koda
parents: 3783
diff changeset
   226
                    accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@-preview.png",
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   227
                                                                              FORTS_DIRECTORY(),[teamDictionary objectForKey:@"fort"]]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   228
                    cell.imageView.image = [accessoryImage scaleToSize:CGSizeMake(42, 42)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   229
                    [accessoryImage release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   230
                    break;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   231
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   232
                case 3: // flags
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   233
                    accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   234
                                                                              FLAGS_DIRECTORY(),[teamDictionary objectForKey:@"flag"]]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   235
                    cell.imageView.image = accessoryImage;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   236
                    [accessoryImage release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   237
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   238
                case 4: // level
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   239
                    accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%d.png",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   240
                                                                              BOTLEVELS_DIRECTORY(),[[[[teamDictionary objectForKey:@"hedgehogs"]
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   241
                                                                                                      objectAtIndex:0] objectForKey:@"level"]
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   242
                                                                                                     intValue]]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   243
                    cell.imageView.image = accessoryImage;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   244
                    [accessoryImage release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   245
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   246
                default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   247
                    cell.imageView.image = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   248
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   249
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   250
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   251
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   252
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   253
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   254
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   255
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   256
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   257
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   258
#pragma mark Table view delegate
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   259
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   260
    NSInteger row = [indexPath row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   261
    NSInteger section = [indexPath section];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   262
    UITableViewController *nextController = nil;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   263
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   264
    if (2 == section) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   265
        switch (row) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   266
            case 0: // grave
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   267
                if (nil == gravesViewController)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   268
                    gravesViewController = [[GravesViewController alloc] initWithStyle:UITableViewStyleGrouped];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   269
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   270
                nextController = gravesViewController;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   271
                break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   272
            case 1: // voice
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   273
                if (nil == voicesViewController)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   274
                    voicesViewController = [[VoicesViewController alloc] initWithStyle:UITableViewStyleGrouped];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   275
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   276
                nextController = voicesViewController;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   277
                break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   278
            case 2: // fort
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   279
                if (nil == fortsViewController)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   280
                    fortsViewController = [[FortsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   281
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   282
                nextController = fortsViewController;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   283
                break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   284
            case 3: // flag
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   285
                if (nil == flagsViewController)
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   286
                    flagsViewController = [[FlagsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   287
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   288
                nextController = flagsViewController;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   289
                break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   290
            case 4: // level
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   291
                if (nil == levelViewController)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   292
                    levelViewController = [[LevelViewController alloc] initWithStyle:UITableViewStyleGrouped];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   293
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   294
                nextController = levelViewController;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   295
                break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   296
        }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   297
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   298
        if ([nextController respondsToSelector:@selector(setTeamDictionary:)])
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   299
            [nextController setTeamDictionary:teamDictionary];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   300
        [self.navigationController pushViewController:nextController animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   301
    } else {
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   302
        EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   303
        [cell replyKeyboard];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   304
        [aTableView deselectRowAtIndexPath:indexPath animated:NO];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   305
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   306
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   307
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   308
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   309
// action to perform when you want to change a hog hat
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   310
-(void) tableView:(UITableView *)aTableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   311
    if (nil == hogHatViewController)
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   312
        hogHatViewController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   313
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   314
    // cache the dictionary file of the team, so that other controllers can modify it
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   315
    hogHatViewController.teamDictionary = self.teamDictionary;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   316
    hogHatViewController.selectedHog = [indexPath row];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   317
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   318
    // if we are editing the field undo any change before proceeding
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   319
    EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   320
    [cell cancel:nil];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3662
diff changeset
   321
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   322
    [self.navigationController pushViewController:hogHatViewController animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   323
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   324
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   325
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   326
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   327
#pragma mark Memory management
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   328
-(void) didReceiveMemoryWarning {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   329
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   330
    if (hogHatViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   331
        hogHatViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   332
    if (gravesViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   333
        gravesViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   334
    if (voicesViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   335
        voicesViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   336
    if (fortsViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   337
        fortsViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   338
    if (flagsViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   339
        flagsViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   340
    if (levelViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   341
        levelViewController = nil;
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   342
    MSG_MEMCLEAN();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   343
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   344
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   345
-(void) viewDidUnload {
3783
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3697
diff changeset
   346
    [[NSNotificationCenter defaultCenter] removeObserver:self];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   347
    self.teamDictionary = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   348
    self.teamName = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   349
    self.normalHogSprite = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   350
    self.secondaryItems = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   351
    hogHatViewController = nil;
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   352
    gravesViewController = nil;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   353
    voicesViewController = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   354
    flagsViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   355
    fortsViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   356
    levelViewController = nil;
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   357
    MSG_DIDUNLOAD();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   358
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   359
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   360
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   361
-(void) dealloc {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   362
    [teamDictionary release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   363
    [teamName release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   364
    [normalHogSprite release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   365
    [secondaryItems release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   366
    [hogHatViewController release];
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   367
    [gravesViewController release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   368
    [fortsViewController release];
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   369
    [voicesViewController release];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   370
    [flagsViewController release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   371
    [levelViewController release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   372
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   373
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   374
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   375
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   376
@end
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   377