cocoaTouch/MasterViewController.m
author sheepluva
Fri, 07 May 2010 09:57:12 +0000
changeset 3444 9d501dc22f71
parent 3405 8fdb08497bf1
child 3490 016b3172b645
permissions -rw-r--r--
* no zooming when game is paused * don't do visual gear steps while paused
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
3405
8fdb08497bf1 js' patch that restores Vsync on snow leopard
koda
parents: 3364
diff changeset
    28
-(void) viewDidLoad {
3305
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    70
    int newRow = [indexPath row];
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    71
    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
    72
    UIViewController *nextController = nil;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    73
    
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    74
    if (newRow != oldRow) {
3352
ac5d14a35482 complete previews on the team settings
koda
parents: 3335
diff changeset
    75
        [self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    76
        [detailViewController.navigationController popToRootViewControllerAnimated:NO];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
    77
        
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    78
        switch (newRow) {
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    79
            case 0:
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    80
                if (nil == generalSettingsViewController)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    81
                    generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    82
                nextController = generalSettingsViewController;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    83
                break;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    84
            case 1:
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    85
                if (nil == teamSettingsViewController)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    86
                    teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    87
                nextController = teamSettingsViewController;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    88
                break;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    89
            case 2:
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    90
                if (nil == weaponSettingsViewController)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    91
                    weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    92
                nextController = weaponSettingsViewController;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    93
                break;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    94
            case 3:
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    95
                if (nil == schemeSettingsViewController)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    96
                    schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    97
                nextController = schemeSettingsViewController;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    98
                break;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
    99
        }
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   100
        
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   101
        nextController.navigationItem.hidesBackButton = YES;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   102
        nextController.title = [controllerNames objectAtIndex:newRow];
3352
ac5d14a35482 complete previews on the team settings
koda
parents: 3335
diff changeset
   103
        [detailViewController.navigationController pushViewController:nextController animated:NO];
3316
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   104
        self.lastIndexPath = indexPath;
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   105
        [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
52f0482b043f fix a couple of leaks in hte ifrontend
koda
parents: 3312
diff changeset
   106
    }
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   107
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   110
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   111
#pragma mark Memory management
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   112
-(void) didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   113
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   118
-(void) viewDidUnload {
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   119
    self.detailViewController = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   120
    self.controllerNames = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   121
    self.lastIndexPath = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   122
    generalSettingsViewController = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   123
    teamSettingsViewController = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   124
    weaponSettingsViewController = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   125
    schemeSettingsViewController = nil;
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   126
    [super viewDidUnload];
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
-(void) dealloc {
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   130
    [controllerNames release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
    [detailViewController release];
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   132
    [lastIndexPath release];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   133
    [generalSettingsViewController release];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   134
    [teamSettingsViewController release];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   135
    [weaponSettingsViewController release];
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3352
diff changeset
   136
    [schemeSettingsViewController release];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   138
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   139
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   140
-(IBAction) dismissSplitView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   144
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   145