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 --- Cartographic.xcodeproj/project.pbxproj | 40 +++++++++++--- Classes/CocosOverlayScrollView.h | 18 +++++++ Classes/CocosOverlayScrollView.m | 99 ++++++++++++++++++++++++++++++++++ Classes/GameModeSelection.h | 8 ++- Classes/GameModeSelection.m | 35 ++++++++---- Classes/GameModeSelectionDelegate.h | 17 ++++++ Classes/GameModeSelectionLayer.h | 9 +++- Classes/GameModeSelectionLayer.m | 66 +++++++++++++++++++---- Classes/NMPanelMenu.h | 14 +++++ Classes/NMPanelMenu.m | 37 +++++++++++++ Classes/TouchDelegatingView.h | 18 +++++++ Classes/TouchDelegatingView.m | 26 +++++++++ 12 files changed, 360 insertions(+), 27 deletions(-) create mode 100755 Classes/CocosOverlayScrollView.h create mode 100755 Classes/CocosOverlayScrollView.m create mode 100644 Classes/GameModeSelectionDelegate.h create mode 100755 Classes/NMPanelMenu.h create mode 100755 Classes/NMPanelMenu.m create mode 100755 Classes/TouchDelegatingView.h create mode 100755 Classes/TouchDelegatingView.m diff --git a/Cartographic.xcodeproj/project.pbxproj b/Cartographic.xcodeproj/project.pbxproj index cda609e..59cf7cd 100755 --- a/Cartographic.xcodeproj/project.pbxproj +++ b/Cartographic.xcodeproj/project.pbxproj @@ -102,6 +102,9 @@ 6C0C141113F2099B003A31B2 /* Cart.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C0C141013F2099B003A31B2 /* Cart.m */; }; 6C0C141413F20E98003A31B2 /* GameMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C0C141313F20E98003A31B2 /* GameMode.m */; }; 6C18C3CA1402AD9C0005AA4C /* UIImage+ColorMasking.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C18C3C91402AD9C0005AA4C /* UIImage+ColorMasking.m */; }; + 6C18C3D214033DC50005AA4C /* CocosOverlayScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C18C3CD14033DC10005AA4C /* CocosOverlayScrollView.m */; }; + 6C18C3D314033DC60005AA4C /* NMPanelMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C18C3CF14033DC30005AA4C /* NMPanelMenu.m */; }; + 6C18C3D414033DC60005AA4C /* TouchDelegatingView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C18C3D114033DC40005AA4C /* TouchDelegatingView.m */; }; 6C29041013EAEB590032DA0F /* TutorialBubble.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C29040F13EAEB590032DA0F /* TutorialBubble.m */; }; 6C29041213EAEC8A0032DA0F /* framestuff.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C29041113EAEC8A0032DA0F /* framestuff.png */; }; 6C39CFE013FC2708002B21AF /* tutorial.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C39CFDF13FC2708002B21AF /* tutorial.png */; }; @@ -414,6 +417,12 @@ 6C0C141313F20E98003A31B2 /* GameMode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameMode.m; sourceTree = ""; }; 6C18C3C81402AD9C0005AA4C /* UIImage+ColorMasking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+ColorMasking.h"; sourceTree = ""; }; 6C18C3C91402AD9C0005AA4C /* UIImage+ColorMasking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ColorMasking.m"; sourceTree = ""; }; + 6C18C3CC14033DBF0005AA4C /* CocosOverlayScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocosOverlayScrollView.h; sourceTree = ""; }; + 6C18C3CD14033DC10005AA4C /* CocosOverlayScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocosOverlayScrollView.m; sourceTree = ""; }; + 6C18C3CE14033DC20005AA4C /* NMPanelMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NMPanelMenu.h; sourceTree = ""; }; + 6C18C3CF14033DC30005AA4C /* NMPanelMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NMPanelMenu.m; sourceTree = ""; }; + 6C18C3D014033DC40005AA4C /* TouchDelegatingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TouchDelegatingView.h; sourceTree = ""; }; + 6C18C3D114033DC40005AA4C /* TouchDelegatingView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TouchDelegatingView.m; sourceTree = ""; }; 6C29040E13EAEB590032DA0F /* TutorialBubble.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TutorialBubble.h; sourceTree = ""; }; 6C29040F13EAEB590032DA0F /* TutorialBubble.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TutorialBubble.m; sourceTree = ""; }; 6C29041113EAEC8A0032DA0F /* framestuff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = framestuff.png; sourceTree = ""; }; @@ -427,6 +436,7 @@ 6C39D00713FD9037002B21AF /* florence.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = florence.png; sourceTree = ""; }; 6C39D01113FD9945002B21AF /* paris.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = paris.png; sourceTree = ""; }; 6C5179C513DF3839006F1F38 /* Morning1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Morning1.png; sourceTree = ""; }; + 6CB532581403BA4F00780A5E /* GameModeSelectionDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameModeSelectionDelegate.h; sourceTree = ""; }; 6CC89DD813F2F4E6003704F7 /* Entitlements.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Entitlements.plist; sourceTree = ""; }; 6CC89DDD13F31413003704F7 /* TutorialMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TutorialMode.h; sourceTree = ""; }; 6CC89DDE13F31413003704F7 /* TutorialMode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TutorialMode.m; sourceTree = ""; }; @@ -710,6 +720,7 @@ 2D500B1D0D5A766B00DBA0E3 /* Classes */ = { isa = PBXGroup; children = ( + 6CB532561403492E00780A5E /* Selection Screen */, 6C0C141513F211C7003A31B2 /* Game Modes */, 6C5887E313EE3ED900B5A80A /* Items */, E0F81035120A173C005866B8 /* GameConfig.h */, @@ -727,12 +738,6 @@ 3F03221813D7904E00E6A708 /* Highscore.m */, 6C29040E13EAEB590032DA0F /* TutorialBubble.h */, 6C29040F13EAEB590032DA0F /* TutorialBubble.m */, - 6C39CFF113FD4F87002B21AF /* GameModeSelection.h */, - 6C39CFF213FD4F89002B21AF /* GameModeSelection.m */, - 6C39CFF613FD7636002B21AF /* GameModeSelectionLayer.h */, - 6C39CFF713FD7637002B21AF /* GameModeSelectionLayer.m */, - 6C18C3C81402AD9C0005AA4C /* UIImage+ColorMasking.h */, - 6C18C3C91402AD9C0005AA4C /* UIImage+ColorMasking.m */, ); path = Classes; sourceTree = ""; @@ -929,6 +934,26 @@ name = Items; sourceTree = ""; }; + 6CB532561403492E00780A5E /* Selection Screen */ = { + isa = PBXGroup; + children = ( + 6C39CFF113FD4F87002B21AF /* GameModeSelection.h */, + 6C39CFF213FD4F89002B21AF /* GameModeSelection.m */, + 6C39CFF613FD7636002B21AF /* GameModeSelectionLayer.h */, + 6C39CFF713FD7637002B21AF /* GameModeSelectionLayer.m */, + 6C18C3C81402AD9C0005AA4C /* UIImage+ColorMasking.h */, + 6C18C3C91402AD9C0005AA4C /* UIImage+ColorMasking.m */, + 6C18C3CC14033DBF0005AA4C /* CocosOverlayScrollView.h */, + 6C18C3CD14033DC10005AA4C /* CocosOverlayScrollView.m */, + 6C18C3CE14033DC20005AA4C /* NMPanelMenu.h */, + 6C18C3CF14033DC30005AA4C /* NMPanelMenu.m */, + 6C18C3D014033DC40005AA4C /* TouchDelegatingView.h */, + 6C18C3D114033DC40005AA4C /* TouchDelegatingView.m */, + 6CB532581403BA4F00780A5E /* GameModeSelectionDelegate.h */, + ); + name = "Selection Screen"; + sourceTree = ""; + }; E02BBB19126CC2F5006E46A2 /* cocos2d */ = { isa = PBXGroup; children = ( @@ -1445,6 +1470,9 @@ 6C39CFF313FD4F8B002B21AF /* GameModeSelection.m in Sources */, 6C39CFF813FD7638002B21AF /* GameModeSelectionLayer.m in Sources */, 6C18C3CA1402AD9C0005AA4C /* UIImage+ColorMasking.m in Sources */, + 6C18C3D214033DC50005AA4C /* CocosOverlayScrollView.m in Sources */, + 6C18C3D314033DC60005AA4C /* NMPanelMenu.m in Sources */, + 6C18C3D414033DC60005AA4C /* TouchDelegatingView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Classes/CocosOverlayScrollView.h b/Classes/CocosOverlayScrollView.h new file mode 100755 index 0000000..29de1c7 --- /dev/null +++ b/Classes/CocosOverlayScrollView.h @@ -0,0 +1,18 @@ +// +// CocosOverlayScrollView.h +// shapes +// +// Created by Nate Murray on 8/23/10. +// Copyright 2010 LittleHiccup. All rights reserved. +// + +#import +#import "cocos2d.h" + +@interface CocosOverlayScrollView : UIScrollView +{ + CCNode* targetLayer; +} +@property(nonatomic, retain) CCNode* targetLayer; +-(id) initWithFrame: (CGRect) frameRect numPages: (int) numPages width: (float) width layer: (CCNode*) layer; +@end diff --git a/Classes/CocosOverlayScrollView.m b/Classes/CocosOverlayScrollView.m new file mode 100755 index 0000000..dcf5571 --- /dev/null +++ b/Classes/CocosOverlayScrollView.m @@ -0,0 +1,99 @@ +// +// CocosOverlayScrollView.m +// shapes +// +// Created by Nate Murray on 8/23/10. +// Copyright 2010 LittleHiccup. All rights reserved. +// + +#import "CocosOverlayScrollView.h" + +@implementation CocosOverlayScrollView +@synthesize targetLayer; + +// Configure your favorite UIScrollView options here +-(id) initWithFrame: (CGRect) frameRect numPages: (int) numPages width: (float) width layer: (CCNode*) layer { + if ((self = [super initWithFrame: frameRect])){ + self.contentSize = CGSizeMake(width*numPages, 320); + self.bounces = YES; + self.delaysContentTouches = NO; + self.delegate = self; + self.pagingEnabled = YES; + self.scrollsToTop = NO; + self.showsVerticalScrollIndicator = NO; + self.showsHorizontalScrollIndicator = NO; + [self setUserInteractionEnabled:TRUE]; + [self setScrollEnabled:TRUE]; + self.targetLayer = layer; + // self.canCancelContentTouches = YES; + } + return self; +} + +-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event +{ + if (!self.dragging) + { + // UITouch* touch = [[touches allObjects] objectAtIndex:0]; + // CGPoint location = [touch locationInView: [[touch view] superview]]; + // CCLOG(@"touch at l.x:%f l.y:%f", location.x, location.y); + + [self.nextResponder touchesBegan: touches withEvent:event]; + [[[CCDirector sharedDirector] openGLView] touchesBegan:touches withEvent:event]; + } + + [super touchesBegan: touches withEvent: event]; +} + +-(void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event +{ + if (!self.dragging) + { + [self.nextResponder touchesEnded: touches withEvent:event]; + [[[CCDirector sharedDirector] openGLView] touchesEnded:touches withEvent:event]; + } + + [super touchesEnded: touches withEvent: event]; +} + +-(void) touchesCancelled: (NSSet *) touches withEvent: (UIEvent *) event +{ + // if (!self.dragging) + // { + // CCLOG(@"CocosOverlayScrollView touchesEnded not dragging"); + [self.nextResponder touchesCancelled: touches withEvent:event]; + [[[CCDirector sharedDirector] openGLView] touchesCancelled:touches withEvent:event]; + // } + [super touchesCancelled: touches withEvent: event]; +} + + +- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView +{ + // TODO - Custom code for handling deceleration of the scroll view +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView +{ + CGPoint dragPt = [scrollView contentOffset]; + dragPt = [[CCDirector sharedDirector] convertToGL:dragPt]; + + dragPt.y = dragPt.y * -1; + dragPt.x = dragPt.x * -1; + + CGPoint newLayerPosition = CGPointMake(dragPt.x, dragPt.y); + + [targetLayer setPosition:newLayerPosition]; +} + +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView +{ + // CGPoint dragPt = [scrollView contentOffset]; + // etc. +} + +-(void) dealloc { + self.targetLayer = nil; + [super dealloc]; +} +@end \ No newline at end of file diff --git a/Classes/GameModeSelection.h b/Classes/GameModeSelection.h index f6aaeff..f69ea37 100644 --- a/Classes/GameModeSelection.h +++ b/Classes/GameModeSelection.h @@ -7,17 +7,23 @@ // #import "cocos2d.h" +#import "GameModeSelectionDelegate.h" -@interface GameModeSelection : CCNode { +@interface GameModeSelection : CCMenuItem { NSString* name; NSString* location; BOOL unlocked; NSString* unlockCondition; + id delegate; } @property (readonly) NSString* name; @property (readonly) NSString* location; @property (readonly) BOOL unlocked; +@property (nonatomic,retain) id delegate; ++ (id)selectionWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked; ++ (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename highscore:(int)highscore; ++ (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition; - (id)initWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked; - (id)initWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename highscore:(int)highscore; - (id)initWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition; 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]; diff --git a/Classes/GameModeSelectionDelegate.h b/Classes/GameModeSelectionDelegate.h new file mode 100644 index 0000000..854a980 --- /dev/null +++ b/Classes/GameModeSelectionDelegate.h @@ -0,0 +1,17 @@ +// +// GameModeSelectionDelegate.h +// Cartographic +// +// Created by Starla Insigna on 8/23/11. +// Copyright 2011 Four Island. All rights reserved. +// + +#import + +@class GameModeSelection; + +@protocol GameModeSelectionDelegate + +- (void)didSelectGameMode:(GameModeSelection*)gameMode; + +@end diff --git a/Classes/GameModeSelectionLayer.h b/Classes/GameModeSelectionLayer.h index 2f57bfb..451a5f8 100644 --- a/Classes/GameModeSelectionLayer.h +++ b/Classes/GameModeSelectionLayer.h @@ -7,8 +7,15 @@ // #import "cocos2d.h" +#import "TouchDelegatingView.h" +#import "CocosOverlayScrollView.h" +#import "GameModeSelectionDelegate.h" -@interface GameModeSelectionLayer : CCLayer +@interface GameModeSelectionLayer : CCLayer { + NSMutableArray* gameModes; + TouchDelegatingView* touchDelegatingView; + CocosOverlayScrollView* scrollView; +} + (CCScene*)scene; - (id)init; diff --git a/Classes/GameModeSelectionLayer.m b/Classes/GameModeSelectionLayer.m index a90606e..9875d41 100644 --- a/Classes/GameModeSelectionLayer.m +++ b/Classes/GameModeSelectionLayer.m @@ -11,6 +11,8 @@ #import #import "Cart_CollectAppDelegate.h" #import "MainMenuLayer.h" +#import "TutorialMode.h" +#import "ClassicGameMode.h" @implementation GameModeSelectionLayer @@ -36,12 +38,14 @@ if (nil != self) { - // Initialization code here. - GameModeSelection* tutorialSelection = [[[GameModeSelection alloc] initWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES] autorelease]; - tutorialSelection.position = ccp(160-32,160); - [self addChild:tutorialSelection]; - + gameModes = [[NSMutableArray alloc] init]; + CCMenu* menu = [CCMenu menuWithItems:nil]; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + float onePanelWide = 128; + + GameModeSelection* tutorialSelection = [GameModeSelection selectionWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES]; + [gameModes addObject:tutorialSelection]; + GameModeSelection* collectSelection; if ([defaults boolForKey:@"hasDoneTutorial"]) @@ -58,13 +62,37 @@ } } - collectSelection = [[[GameModeSelection alloc] initWithName:@"Collect" location:@"Paris" filename:@"paris" highscore:score] autorelease]; + collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" highscore:score]; } else { - collectSelection = [[[GameModeSelection alloc] initWithName:@"Collect" location:@"Paris" filename:@"paris" unlockCondition:@"Beat the tutorial!"] autorelease]; + collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlockCondition:@"Beat the tutorial!"]; + } + + [gameModes addObject:collectSelection]; + + float padding = 15; + float totalPanelWidth = onePanelWide + padding*2; + float numberOfPanels = [gameModes count]; + float totalWidth = numberOfPanels * totalPanelWidth; + int currentWorldOffset = [defaults integerForKey:@"lastSelectedMode"]; + CCLayer* panels = [CCLayer node]; + + for (GameModeSelection* gameMode in gameModes) + { + [gameMode setDelegate:self]; + [menu addChild:gameMode]; } - collectSelection.position = ccp(320+32,160); - [self addChild:collectSelection]; + [menu alignItemsHorizontallyWithPadding:padding*2]; + [panels addChild:menu]; + [self addChild:panels]; + + menu.position = ccpAdd(menu.position, ccp(totalWidth/2 - totalPanelWidth/2, 320)); + touchDelegatingView = [[TouchDelegatingView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)]; + scrollView = [[CocosOverlayScrollView alloc] initWithFrame:CGRectMake(0, 0, totalPanelWidth, 320) numPages:numberOfPanels width:totalPanelWidth layer:panels]; + touchDelegatingView.scrollView = scrollView; + [scrollView setContentOffset:CGPointMake(currentWorldOffset*totalPanelWidth+1,0) animated:NO]; + [[[CCDirector sharedDirector] openGLView] addSubview:touchDelegatingView]; + [[[CCDirector sharedDirector] openGLView] addSubview:scrollView]; CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)]; CCMenu* myMenu = [CCMenu menuWithItems:newgameMenuItem, nil]; @@ -75,9 +103,29 @@ return self; } +- (void)onExit +{ + [touchDelegatingView removeFromSuperview]; + [scrollView removeFromSuperview]; +} + - (void)mainmenu { [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; } +- (void)didSelectGameMode:(GameModeSelection *)gameMode +{ + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + [defaults setInteger:[gameModes indexOfObject:gameMode] forKey:@"lastSelectedMode"]; + + if ([gameMode.name isEqual:@"Tutorial"]) + { + [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]]; + } else if ([gameMode.name isEqual:@"Collect"]) + { + [[CCDirector sharedDirector] replaceScene:[ClassicGameMode scene]]; + } +} + @end diff --git a/Classes/NMPanelMenu.h b/Classes/NMPanelMenu.h new file mode 100755 index 0000000..3487849 --- /dev/null +++ b/Classes/NMPanelMenu.h @@ -0,0 +1,14 @@ +/* + * NMPanelMenu.h + * shapes + * + * Created by Nate Murray on 7/29/10. + * Copyright 2010 YetiApps. All rights reserved. + * + */ + +#import "cocos2d.h" +@interface NMPanelMenu : CCMenu { +} +-(CCMenuItem *) itemForTouch: (UITouch *) touch; +@end diff --git a/Classes/NMPanelMenu.m b/Classes/NMPanelMenu.m new file mode 100755 index 0000000..ee24279 --- /dev/null +++ b/Classes/NMPanelMenu.m @@ -0,0 +1,37 @@ +/* + * NMPanelMenu.m + * shapes + * + * Created by Nate Murray on 7/29/10. + * Copyright 2010 YetiApps. All rights reserved. + * + */ + +#import "NMPanelMenu.h" + +@implementation NMPanelMenu + +-(CCMenuItem *) itemForTouch: (UITouch *) touch +{ + CGPoint touchLocation = [touch locationInView: [[touch view] superview]]; + touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation]; + + CCMenuItem* item; + CCARRAY_FOREACH(children_, item){ + // ignore invisible and disabled items: issue #779, #866 + if ( [item visible] && [item isEnabled] ) { + + CGPoint local = [item convertToNodeSpace:touchLocation]; + + CGRect r = [item rect]; + r.origin = CGPointZero; + + if( CGRectContainsPoint( r, local ) ) { + return item; + } + } + } + return nil; +} + +@end diff --git a/Classes/TouchDelegatingView.h b/Classes/TouchDelegatingView.h new file mode 100755 index 0000000..5ed6884 --- /dev/null +++ b/Classes/TouchDelegatingView.h @@ -0,0 +1,18 @@ +// +// TouchDelegatingView.h +// shapes +// +// Created by Nate Murray on 8/23/10. +// Copyright 2010 LittleHiccup. All rights reserved. +// + +#import +#import "CocosOverLayScrollView.h" + +@interface TouchDelegatingView : UIView { + // UIPageControl* pageControl; + CocosOverlayScrollView* scrollView; +} +@property(nonatomic, retain) CocosOverlayScrollView* scrollView; + +@end diff --git a/Classes/TouchDelegatingView.m b/Classes/TouchDelegatingView.m new file mode 100755 index 0000000..83bda73 --- /dev/null +++ b/Classes/TouchDelegatingView.m @@ -0,0 +1,26 @@ +// +// TouchDelegatingView.m +// Jacob's Shapes +// +// Created by Nate Murray on 8/23/10. +// Copyright 2010 LittleHiccup. All rights reserved. +// + +#import "TouchDelegatingView.h" + +@implementation TouchDelegatingView +@synthesize scrollView; + +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { + if ([self pointInside:point withEvent:event]) { + return self.scrollView; + } + return nil; +} + +-(void) dealloc { + self.scrollView = nil; + [super dealloc]; +} + +@end -- cgit 1.4.1