From c9337218ef1660360097928c753bde1c79775618 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Tue, 23 Aug 2011 07:52:24 -0400 Subject: Added scrolling to level selection screen Using http://www.xcombinator.com/2010/09/08/a-paging-uiscrollview-in-cocos2d-with-previews/ as a base, I was able to implement a paging scroller for the level selection screen so players can swipe through available levels and choose one to play. At this point, the level selection screen is practically done--the only other thing I want to add is a UIPageControl to interact with the scrolling and give the player an indication of how many levels there are. Refs #207 --- Classes/GameModeSelection.m | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'Classes/GameModeSelection.m') diff --git a/Classes/GameModeSelection.m b/Classes/GameModeSelection.m index fc6797a..582c9dd 100644 --- a/Classes/GameModeSelection.m +++ b/Classes/GameModeSelection.m @@ -7,17 +7,31 @@ // #import "GameModeSelection.h" -#import "TutorialMode.h" -#import "ClassicGameMode.h" #import "UIImage+ColorMasking.h" +#import "NMPanelMenu.h" @implementation GameModeSelection -@synthesize name, location, unlocked; +@synthesize name, location, unlocked, delegate; + ++ (id)selectionWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked +{ + return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlocked:unlocked] autorelease]; +} + ++ (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename highscore:(int)highscore +{ + return [[[GameModeSelection alloc] initWithName:name location:location filename:filename highscore:highscore] autorelease]; +} + ++ (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition +{ + return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlockCondition:unlockCondition] autorelease]; +} - (id)initWithName:(NSString*)m_name location:(NSString*)m_location filename:(NSString*)filename unlocked:(BOOL)m_unlocked; { - self = [super init]; + self = [super initWithTarget:nil selector:nil]; if (nil != self) { @@ -27,6 +41,8 @@ location = m_location; unlocked = m_unlocked; + contentSize_ = CGSizeMake(128, 320); + NSString* filenameMod; if (unlocked) @@ -124,7 +140,7 @@ CCSprite* selectedButton = [CCSprite spriteWithCGImage:selectedButtonRef key:[NSString stringWithFormat:@"gms-%@-selected", filenameMod]]; CCMenuItemSprite* pictureMenuItem = [CCMenuItemSprite itemFromNormalSprite:picture selectedSprite:selectedButton target:self selector:@selector(buttonTapped)]; - CCMenu* theMenu = [CCMenu menuWithItems:pictureMenuItem, nil]; + NMPanelMenu* theMenu = [NMPanelMenu menuWithItems:pictureMenuItem, nil]; theMenu.position = ccp(-5, 0); [self addChild:theMenu]; @@ -196,12 +212,11 @@ { if (unlocked) { - if ([name isEqual:@"Tutorial"]) - { - [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]]; - } else if ([name isEqual:@"Collect"]) + if (delegate != nil) { - [[CCDirector sharedDirector] replaceScene:[ClassicGameMode scene]]; + [delegate didSelectGameMode:self]; + } else { + NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); } } else { UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"To unlock this game mode:" message:unlockCondition delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; -- cgit 1.4.1