cocoaTouch/MainMenuViewController.m
author koda
Wed, 10 Feb 2010 22:00:49 +0000
changeset 2799 558b29bf00c5
parent 2743 39d097ac2276
child 2803 1f446fc5c8ec
permissions -rw-r--r--
add a new way to fetch version info from pascal to c complete the stubs for the new lua section fixed a glitch in the ifrontend

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

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

@implementation MainMenuViewController

@synthesize versionLabel, settingsViewController, mainView;

/*
 // 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;
		[settingsViewController release];
	}
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
-(void) viewDidLoad {
	char *ver;
	HW_versionInfo(NULL, &ver);
	self.versionLabel.text = [[NSString stringWithUTF8String:ver] autorelease];
	[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.mainView.userInteractionEnabled = NO;
	[super viewWillDisappear:animated];
}

-(void) viewDidAppear:(BOOL)animated {
	self.mainView.userInteractionEnabled = YES;
	[super viewDidAppear: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, -320, 480, 320);
		self.settingsViewController.parentView = self.mainView;

		[UIView beginAnimations:@"View Switch" context:NULL];
		[UIView setAnimationDuration:1];
		//[UIView setAnimationDuration:UIViewAnimationCurveEaseOut];
		self.settingsViewController.view.frame = CGRectMake(0, 0, 480, 320);
		self.mainView.frame = CGRectMake(0, 320, 480, 320);
		
		[self.view addSubview:settingsViewController.view];
		[UIView commitAnimations];
	}

}

@end