All Data Structures Files Functions Variables Enumerations Enumerator Properties Defines
/Projects/Cogito/src/Layers/Menu/MainMenuLayer.m
Go to the documentation of this file.
00001 //
00002 //  MainMenuLayer.m
00003 //  Author: Thomas Taylor
00004 //
00005 //  The main menu layer
00006 //
00007 //  16/12/2011: Created class
00008 //
00009 
00010 #import "MainMenuLayer.h"
00011 
00012 #pragma mark -
00013 #pragma mark Interface
00014 
00015 @interface MainMenuLayer()
00016 
00017 -(void)playScene:(CCMenuItemFont*)menuItemToPlay;
00018 -(void)buildMainMenu;
00019 -(void)onNewGameButtonPressed;
00020 -(void)onHighScoresButtonPressed;
00021 -(void)onAboutButtonPressed;
00022 
00023 @end
00024 
00025 @implementation MainMenuLayer
00026 
00027 #pragma mark -
00028 #pragma mark Initialisation
00029 
00034 -(id)init
00035 {    
00036     self = [super init];
00037     
00038     if (self != nil) 
00039     {
00040         CGSize winSize = [CCDirector sharedDirector].winSize;
00041         
00042         CCSprite *background = [CCSprite spriteWithFile:@"MainMenuBackground.png"];
00043         [background setPosition:ccp(winSize.width/2, winSize.height/2)];
00044         [self addChild:background];
00045         [self buildMainMenu];
00046     }
00047     
00048     return self;
00049 }
00050 
00051 #pragma mark -
00052 
00057 -(void)playScene:(CCMenuItemFont*)menuItemToPlay
00058 {
00059     if([menuItemToPlay tag] == 1) [[GameManager sharedGameManager] runSceneWithID:kSettingsScene];
00060     else CCLOG(@"Tag %d passed", [menuItemToPlay tag]);
00061 }
00062 
00066 -(void)buildMainMenu
00067 {
00068     CGSize winSize = [CCDirector sharedDirector].winSize;
00069     
00070     //create the menu buttons
00071     CCMenuItemImage *newGameButton = [CCMenuItemImage itemFromNormalImage:@"NewGame.png" selectedImage:@"NewGame_down.png" disabledImage:nil target:self selector:@selector(onNewGameButtonPressed)];
00072     CCMenuItemImage *instructionsButton = [CCMenuItemImage itemFromNormalImage:@"Instructions.png" selectedImage:@"Instructions_down.png" disabledImage:nil target:self selector:@selector(onInstructionsButtonPressed)];
00073     //CCMenuItemImage *highScoresButton = [CCMenuItemImage itemFromNormalImage:@"Settings.png" selectedImage:@"Settings_down.png" disabledImage:nil target:self selector:@selector(onAboutButtonPressed)];
00074     CCMenuItemImage *statsButton = [CCMenuItemImage itemFromNormalImage:@"Stats.png" selectedImage:@"Stats_down.png" disabledImage:nil target:self selector:@selector(onStatsButtonPressed)];
00075     CCMenuItemImage *aboutButton = [CCMenuItemImage itemFromNormalImage:@"About.png" selectedImage:@"About_down.png" disabledImage:nil target:self selector:@selector(onAboutButtonPressed)];
00076         
00077     // create menu with the items
00078     //mainMenu = [CCMenu menuWithItems:newGameButton, highScoresButton, aboutButton, nil];
00079     mainMenu = [CCMenu menuWithItems:newGameButton, statsButton, instructionsButton, aboutButton, nil];
00080     
00081     // position the menu
00082     [mainMenu alignItemsVerticallyWithPadding:13.0f];
00083     [mainMenu setPosition: ccp(winSize.width*2, winSize.height*0.3)];
00084     
00085     // create the animations
00086     id animateInAction = [CCMoveTo actionWithDuration:1.5f position:ccp(winSize.width * 0.80f, winSize.height * 0.3)];
00087     id easeEffectAction = [CCEaseIn actionWithAction:animateInAction rate:1.5f];
00088     [mainMenu runAction:easeEffectAction];
00089     
00090     // add the menu
00091     [self addChild:mainMenu z:0 tag:kMainMenuTagValue];
00092 }
00093 
00094 #pragma mark -
00095 #pragma mark Button release handlers
00096 
00100 -(void)onNewGameButtonPressed
00101 {
00102     [[GameManager sharedGameManager] runSceneWithID:kNewGameScene];
00103 }
00104 
00108 -(void)onStatsButtonPressed
00109 {
00110     [[GameManager sharedGameManager] runSceneWithID:kStatsScene];
00111 }
00112 
00116 -(void)onInstructionsButtonPressed
00117 {
00118     [[GameManager sharedGameManager] runSceneWithID:kInstructionsScene];
00119 }
00120 
00124 -(void)onHighScoresButtonPressed
00125 {
00126     CCLOG(@"MainMenuLayer.onHighScoresButtonPressed");
00127 }
00128 
00132 -(void)onAboutButtonPressed
00133 {
00134     [[GameManager sharedGameManager] runSceneWithID:kAboutScene];
00135 }
00136 
00137 @end