cocoaTouch/GameConfigViewController.m
author koda
Thu, 22 Apr 2010 17:43:12 +0000
changeset 3364 e5403e2bf02c
parent 3361 cfc6cd502f85
child 3365 37ac593e9027
permissions -rw-r--r--
no more hardcoded teams, team selection is real \o/ custom buttons rock removed difficult errlib from openalbridge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3356
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
     1
    //
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
     2
//  GameConfigViewController.m
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
     3
//  HedgewarsMobile
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
     4
//
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
     5
//  Created by Vittorio on 18/04/10.
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
     7
//
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
     8
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
     9
#import "GameConfigViewController.h"
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    10
#import "SDL_uikitappdelegate.h"
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    11
#import "CommodityFunctions.h"
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    12
#import "TeamConfigViewController.h"
3356
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    13
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    14
@implementation GameConfigViewController
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    15
@synthesize availableTeamsTableView, weaponsButton, schemesButton, mapButton, randomButton, startButton;
3356
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    16
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    17
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    18
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    19
    return rotationManager(interfaceOrientation);
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    20
}
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    21
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    22
-(IBAction) buttonPressed:(id) sender {
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    23
    // works even if it's not actually a button
3356
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    24
    UIButton *theButton = (UIButton *)sender;
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    25
    switch (theButton.tag) {
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    26
        case 0:
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    27
            [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    28
            break;
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    29
        case 1:
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    30
            [self performSelector:@selector(startGame)
3356
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    31
                       withObject:nil
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    32
                       afterDelay:0.25];
3356
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    33
            break;
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    34
    }
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    35
}
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    36
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    37
-(void) startGame {
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    38
    if ([teamConfigViewController.listOfSelectedTeams count] < 2) {
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    39
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"")
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    40
                                                        message:NSLocalizedString(@"You need to select at least two teams to play a Game",@"")
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    41
                                                       delegate:nil
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    42
                                              cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    43
                                              otherButtonTitles:nil];
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    44
        [alert show];
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    45
        [alert release];
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    46
    } else {
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    47
        [teamConfigViewController.listOfSelectedTeams writeToFile:GAMECONFIG_FILE() atomically:YES];
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    48
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    49
        [[SDLUIKitDelegate sharedAppDelegate] startSDLgame];
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    50
    }
3356
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    51
}
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    52
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    53
-(void) viewDidLoad {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    54
    teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    55
    activeController = teamConfigViewController;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    56
    
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    57
    [self.view insertSubview:teamConfigViewController.view atIndex:0];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    58
    
3356
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    59
    [super viewDidLoad];
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    60
}
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    61
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    62
-(void) didReceiveMemoryWarning {
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    63
    // Releases the view if it doesn't have a superview.
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    64
    [super didReceiveMemoryWarning];
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    65
    // Release any cached data, images, etc that aren't in use.
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    66
}
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    67
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    68
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    69
-(void) viewDidUnload {
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    70
    activeController = nil;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    71
    teamConfigViewController = nil;
3356
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    72
    self.availableTeamsTableView = nil;
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    73
    self.weaponsButton = nil;
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    74
    self.schemesButton = nil;
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    75
    self.mapButton = nil;
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    76
    self.randomButton = nil;
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    77
    self.startButton = nil;
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    78
    [super viewDidUnload];
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    79
}
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    80
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    81
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    82
-(void) dealloc {
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    83
    [activeController release];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    84
    [teamConfigViewController release];
3356
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    85
    [availableTeamsTableView release];
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    86
    [weaponsButton release];
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    87
    [schemesButton release];
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    88
    [mapButton release];
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    89
    [randomButton release];
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    90
    [startButton release];
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    91
    [super dealloc];
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    92
}
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
    93
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    94
-(void) viewWillAppear:(BOOL)animated {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    95
    [super viewWillAppear:animated];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    96
    [activeController viewWillAppear:animated];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    97
}
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    98
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
    99
-(void) viewWillDisappear:(BOOL)animated {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   100
    [super viewWillDisappear:animated];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   101
    [activeController viewWillDisappear:animated];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   102
}
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   103
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   104
-(void) viewDidAppear:(BOOL)animated {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   105
    [super viewDidLoad];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   106
    [activeController viewDidAppear:animated];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   107
}
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   108
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   109
-(void) viewDidDisappear:(BOOL)animated {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   110
    [super viewDidUnload];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   111
    [activeController viewDidDisappear:animated];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents: 3356
diff changeset
   112
}
3356
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
   113
3ae3fccb439e add missing controller stubs
koda
parents:
diff changeset
   114
@end