cocoaTouch/MasterViewController.m
author koda
Thu, 29 Apr 2010 17:20:42 +0000
changeset 3375 88bb88294e06
parent 3364 e5403e2bf02c
child 3405 8fdb08497bf1
permissions -rw-r--r--
this should fix the old project name that is present in the scm database
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     1
//
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     2
//  MasterViewController.m
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     3
//  HedgewarsMobile
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     4
//
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     5
//  Created by Vittorio on 27/03/10.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     7
//
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     8
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     9
#import "MasterViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    10
#import "DetailViewController.h"
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    11
#import "GeneralSettingsViewController.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    12
#import "TeamSettingsViewController.h"
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    13
#import "WeaponSettingsViewController.h"
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    14
#import "SchemeSettingsViewController.h"
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    15
#import "CommodityFunctions.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    16
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    17
@implementation MasterViewController
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    18
@synthesize detailViewController, controllerNames, lastIndexPath;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    19
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    20
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    21
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    22
	return rotationManager(interfaceOrientation);
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    23
}
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    24
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3316
diff changeset
    25
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    26
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    27
#pragma mark View lifecycle
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    28
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    29
    [super viewDidLoad];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    30
    
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    31
    // the list of selectable controllers
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    32
    controllerNames = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    33
                                                       NSLocalizedString(@"Teams",@""),
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    34
                                                       NSLocalizedString(@"Weapons",@""),
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    35
                                                       NSLocalizedString(@"Schemes",@""),
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    36
                                                       nil];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    37
    // the "Done" button on top left
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    38
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
3312
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    39
                                                                                          target:self
6d8f1c76756d restore and update the old general settings
koda
parents: 3305
diff changeset
    40
                                                                                          action:@selector(dismissSplitView)];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    41
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    42
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    43
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    44
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    45
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    46
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    47
    return 1;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    48
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    49
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    50
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    51
    return [controllerNames count];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    52
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    53
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
// Customize the appearance of table view cells.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    55
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    56
    static NSString *CellIdentifier = @"Cell";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    60
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    61
        cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    63
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
    return cell;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    66
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
// Override to support editing the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
    if (editingStyle == UITableViewCellEditingStyleDelete) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
        // Delete the row from the data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    73
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    74
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    78
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    82
// Override to support rearranging the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    83
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    84
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    85
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    87
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
// Override to support conditional rearranging of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    90
    // Return NO if you do not want the item to be re-orderable.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    91
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    92
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    96
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    97
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    98
    int newRow = [indexPath row];
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    99
    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
   100
    UIViewController *nextController = nil;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
    
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   102
    if (newRow != oldRow) {
3352
ac5d14a35482 complete previews on the team settings
koda
parents: 3335
diff changeset
   103
        [self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   104
        [detailViewController.navigationController popToRootViewControllerAnimated:NO];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   105
        
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   106
        switch (newRow) {
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   107
            case 0:
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   108
                if (nil == generalSettingsViewController)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   109
                    generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   110
                nextController = generalSettingsViewController;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   111
                break;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   112
            case 1:
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   113
                if (nil == teamSettingsViewController)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   114
                    teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   115
                nextController = teamSettingsViewController;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   116
                break;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   117
            case 2:
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   118
                if (nil == weaponSettingsViewController)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   119
                    weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   120
                nextController = weaponSettingsViewController;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   121
                break;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   122
            case 3:
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   123
                if (nil == schemeSettingsViewController)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   124
                    schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   125
                nextController = schemeSettingsViewController;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   126
                break;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   127
        }
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   128
        
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   129
        nextController.navigationItem.hidesBackButton = YES;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   130
        nextController.title = [controllerNames objectAtIndex:newRow];
3352
ac5d14a35482 complete previews on the team settings
koda
parents: 3335
diff changeset
   131
        [detailViewController.navigationController pushViewController:nextController animated:NO];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   132
        self.lastIndexPath = indexPath;
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   133
        [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   134
    }
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   138
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   139
#pragma mark Memory management
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   140
-(void) didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   144
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   145
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   146
-(void) viewDidUnload {
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   147
    self.detailViewController = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   148
    self.controllerNames = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   149
    self.lastIndexPath = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   150
    generalSettingsViewController = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   151
    teamSettingsViewController = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   152
    weaponSettingsViewController = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   153
    schemeSettingsViewController = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   154
    [super viewDidUnload];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   155
}
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   156
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   157
-(void) dealloc {
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   158
    [controllerNames release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   159
    [detailViewController release];
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   160
    [lastIndexPath release];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   161
    [generalSettingsViewController release];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   162
    [teamSettingsViewController release];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   163
    [weaponSettingsViewController release];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   164
    [schemeSettingsViewController release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   165
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   166
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   167
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   168
-(IBAction) dismissSplitView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   169
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   170
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   171
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   172
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   173