diff options
Diffstat (limited to 'Classes/GameModeSelectionLayer.m')
| -rw-r--r-- | Classes/GameModeSelectionLayer.m | 132 |
1 files changed, 132 insertions, 0 deletions
| diff --git a/Classes/GameModeSelectionLayer.m b/Classes/GameModeSelectionLayer.m new file mode 100644 index 0000000..db08146 --- /dev/null +++ b/Classes/GameModeSelectionLayer.m | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | // | ||
| 2 | // GameModeSelectionLayer.m | ||
| 3 | // Cartographic | ||
| 4 | // | ||
| 5 | // Created by Starla Insigna on 8/18/11. | ||
| 6 | // Copyright 2011 Four Island. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "GameModeSelectionLayer.h" | ||
| 10 | #import "GameModeSelection.h" | ||
| 11 | #import <sqlite3.h> | ||
| 12 | #import "Cart_CollectAppDelegate.h" | ||
| 13 | #import "MainMenuLayer.h" | ||
| 14 | #import "TutorialMode.h" | ||
| 15 | #import "ClassicGameMode.h" | ||
| 16 | #import "NMPanelMenu.h" | ||
| 17 | |||
| 18 | @implementation GameModeSelectionLayer | ||
| 19 | |||
| 20 | + (CCScene*)scene | ||
| 21 | { | ||
| 22 | CCScene* scene = [CCScene node]; | ||
| 23 | |||
| 24 | CCLayer* backgroundLayer = [[[CCLayer alloc] init] autorelease]; | ||
| 25 | CCSprite* backgroundImage = [CCSprite spriteWithFile:@"paintdaubs.png"]; | ||
| 26 | backgroundImage.position = ccp(240,160); | ||
| 27 | [backgroundLayer addChild:backgroundImage]; | ||
| 28 | [scene addChild:backgroundLayer]; | ||
| 29 | |||
| 30 | GameModeSelectionLayer* layer = [GameModeSelectionLayer node]; | ||
| 31 | [scene addChild:layer]; | ||
| 32 | |||
| 33 | return scene; | ||
| 34 | } | ||
| 35 | |||
| 36 | - (id)init | ||
| 37 | { | ||
| 38 | self = [super init]; | ||
| 39 | |||
| 40 | if (nil != self) | ||
| 41 | { | ||
| 42 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
| 43 | gameModes = [[NSMutableArray alloc] init]; | ||
| 44 | |||
| 45 | GameModeSelection* tutorialSelection = [GameModeSelection selectionWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES]; | ||
| 46 | [gameModes addObject:tutorialSelection]; | ||
| 47 | |||
| 48 | GameModeSelection* collectSelection; | ||
| 49 | |||
| 50 | if ([defaults boolForKey:@"hasDoneTutorial"]) | ||
| 51 | { | ||
| 52 | collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlocked:YES]; | ||
| 53 | } else { | ||
| 54 | collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlockCondition:@"Beat the tutorial!"]; | ||
| 55 | } | ||
| 56 | |||
| 57 | [gameModes addObject:collectSelection]; | ||
| 58 | |||
| 59 | CCMenu* menu = [CCMenu menuWithItems:nil]; | ||
| 60 | float onePanelWide = 128; | ||
| 61 | float padding = 15; | ||
| 62 | float totalPanelWidth = onePanelWide + padding*2; | ||
| 63 | float numberOfPanels = [gameModes count]; | ||
| 64 | float totalWidth = numberOfPanels * totalPanelWidth; | ||
| 65 | int currentWorldOffset = [defaults integerForKey:@"lastSelectedMode"]; | ||
| 66 | CCLayer* panels = [CCLayer node]; | ||
| 67 | |||
| 68 | for (GameModeSelection* gameMode in gameModes) | ||
| 69 | { | ||
| 70 | [gameMode setDelegate:self]; | ||
| 71 | [menu addChild:gameMode]; | ||
| 72 | } | ||
| 73 | |||
| 74 | [menu alignItemsHorizontallyWithPadding:padding*2]; | ||
| 75 | [panels addChild:menu]; | ||
| 76 | [self addChild:panels]; | ||
| 77 | |||
| 78 | pageControl = [[UIPageControl alloc] init]; | ||
| 79 | pageControl.numberOfPages = numberOfPanels; | ||
| 80 | pageControl.currentPage = currentWorldOffset; | ||
| 81 | pageControl.frame = CGRectMake(0, 250, 480, 20); | ||
| 82 | |||
| 83 | menu.position = ccpAdd(menu.position, ccp(totalWidth/2 - totalPanelWidth/2, 320)); | ||
| 84 | touchDelegatingView = [[TouchDelegatingView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)]; | ||
| 85 | scrollView = [[CocosOverlayScrollView alloc] initWithFrame:CGRectMake(0, 0, totalPanelWidth, 320) numPages:numberOfPanels width:totalPanelWidth layer:panels pageControl:pageControl]; | ||
| 86 | touchDelegatingView.scrollView = scrollView; | ||
| 87 | [scrollView setContentOffset:CGPointMake(currentWorldOffset*totalPanelWidth+1,0) animated:NO]; | ||
| 88 | |||
| 89 | CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)]; | ||
| 90 | NMPanelMenu* myMenu = [NMPanelMenu menuWithItems:newgameMenuItem, nil]; | ||
| 91 | myMenu.position = ccp(240, 30); | ||
| 92 | [self addChild:myMenu]; | ||
| 93 | } | ||
| 94 | |||
| 95 | return self; | ||
| 96 | } | ||
| 97 | |||
| 98 | - (void)onEnterTransitionDidFinish | ||
| 99 | { | ||
| 100 | [super onEnterTransitionDidFinish]; | ||
| 101 | |||
| 102 | [[[CCDirector sharedDirector] openGLView] addSubview:pageControl]; | ||
| 103 | [[[CCDirector sharedDirector] openGLView] addSubview:touchDelegatingView]; | ||
| 104 | [[[CCDirector sharedDirector] openGLView] addSubview:scrollView]; | ||
| 105 | } | ||
| 106 | |||
| 107 | - (void)onExit | ||
| 108 | { | ||
| 109 | [super onExit]; | ||
| 110 | |||
| 111 | [touchDelegatingView removeFromSuperview]; | ||
| 112 | [scrollView removeFromSuperview]; | ||
| 113 | [pageControl removeFromSuperview]; | ||
| 114 | } | ||
| 115 | |||
| 116 | - (void)mainmenu | ||
| 117 | { | ||
| 118 | [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; | ||
| 119 | } | ||
| 120 | |||
| 121 | - (void)didSelectGameMode:(GameModeSelection *)gameMode | ||
| 122 | { | ||
| 123 | if ([gameMode.name isEqual:@"Tutorial"]) | ||
| 124 | { | ||
| 125 | [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]]; | ||
| 126 | } else if ([gameMode.name isEqual:@"Collect"]) | ||
| 127 | { | ||
| 128 | [[CCDirector sharedDirector] replaceScene:[ClassicGameMode scene]]; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | @end | ||
