cocoaTouch/MainMenuViewController.m
author koda
Wed, 03 Feb 2010 03:01:44 +0000
changeset 2740 03df0573a9fd
parent 2738 bfccb2ec4334
child 2743 39d097ac2276
permissions -rw-r--r--
programmatically load main controller adapt settings to landscape transition between main controller and other views

//
//  MainMenuViewController.m
//  hwengine
//
//  Created by Vittorio on 08/01/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "MainMenuViewController.h"
#import "SDL_uikitappdelegate.h"

@implementation MainMenuViewController

@synthesize versionLabel, settingsViewController;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
	[super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
	if (nil == self.settingsViewController.view.superview) {
		self.settingsViewController = nil;
	}
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
-(void) viewDidLoad {
	self.versionLabel.text = @"0.9.13-dev";
	[super viewDidLoad];
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	self.versionLabel = nil;
}

- (void)dealloc {
	[versionLabel release];
	[settingsViewController release];
	[super dealloc];
}

// disable the buttons when to prevent launching twice the game
-(void) viewWillDisappear:(BOOL)animated {
	self.view.userInteractionEnabled = NO;
	[super viewWillDisappear:animated];
}

-(void) viewWillAppear:(BOOL)animated {
	self.view.userInteractionEnabled = YES;
	[super viewWillAppear:animated];
}

#pragma mark -
#pragma mark Action buttons
-(IBAction) startPlaying {
	[[SDLUIKitDelegate sharedAppDelegate] startSDLgame];
}

-(IBAction) notYetImplemented {
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented"
							message:@"Sorry, this feature is not yet implemented"
						       delegate:nil
					      cancelButtonTitle:@"Well, don't worry"
					      otherButtonTitles:nil];
	[alert show];
	[alert release];
}

-(IBAction) switchViews:(id)sender {

	// view not displayed or not created
	if (nil == self.settingsViewController.view.superview) {
		// view not created
		if (nil == self.settingsViewController) {
			SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController"
												      bundle:nil];
			self.settingsViewController = controller;
			[controller release];
		}
		self.settingsViewController.view.frame = CGRectMake(0, -480, 480, 320);

		[UIView beginAnimations:@"View Switch" context:NULL];
		[UIView setAnimationDuration:3];
		[UIView setAnimationDuration:UIViewAnimationCurveEaseOut];
		self.settingsViewController.view.frame = CGRectMake(0, 0, 480, 320);
		
		// we have the new controller, let's switch
		[self.view addSubview:settingsViewController.view];
		[UIView commitAnimations];
	}

}

@end