1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
//
// GameModeSelectionLayer.m
// Cartographic
//
// Created by Starla Insigna on 8/18/11.
// Copyright 2011 Four Island. All rights reserved.
//
#import "GameModeSelectionLayer.h"
#import "GameModeSelection.h"
#import <sqlite3.h>
#import "Cart_CollectAppDelegate.h"
#import "MainMenuLayer.h"
#import "NMPanelMenu.h"
#import "ZoomFadeTransition.h"
#import "GameModeInfo.h"
#import "GameModeManager.h"
@implementation GameModeSelectionLayer
+ (CCScene*)scene
{
CCScene* scene = [CCScene node];
CCLayer* backgroundLayer = [[[CCLayer alloc] init] autorelease];
CCSprite* backgroundImage = [CCSprite spriteWithFile:@"paintdaubs.png"];
backgroundImage.position = ccp(240,160);
[backgroundLayer addChild:backgroundImage];
[scene addChild:backgroundLayer];
GameModeSelectionLayer* layer = [GameModeSelectionLayer node];
[scene addChild:layer];
return scene;
}
- (id)init
{
self = [super init];
if (nil != self)
{
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
gameModes = [[NSMutableArray alloc] init];
for (GameModeInfo* info in [[GameModeManager sharedInstance] gameModes])
{
if (info.unlocked)
{
GameModeSelection* selection = [GameModeSelection selectionWithGameModeInfo:info];
[gameModes addObject:selection];
}
}
CCMenu* menu = [CCMenu menuWithItems:nil];
float onePanelWide = 128;
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];
}
[menu alignItemsHorizontallyWithPadding:padding*2];
[panels addChild:menu];
[self addChild:panels];
pageControl = [[UIPageControl alloc] init];
pageControl.numberOfPages = numberOfPanels;
pageControl.currentPage = currentWorldOffset;
pageControl.frame = CGRectMake(0, 250, 480, 20);
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 pageControl:pageControl];
touchDelegatingView.scrollView = scrollView;
[scrollView setContentOffset:CGPointMake(currentWorldOffset*totalPanelWidth+1,0) animated:NO];
CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)];
NMPanelMenu* myMenu = [NMPanelMenu menuWithItems:newgameMenuItem, nil];
myMenu.position = ccp(240, 30);
[self addChild:myMenu];
}
return self;
}
- (void)onEnterTransitionDidFinish
{
[super onEnterTransitionDidFinish];
[[[CCDirector sharedDirector] openGLView] addSubview:pageControl];
[[[CCDirector sharedDirector] openGLView] addSubview:touchDelegatingView];
[[[CCDirector sharedDirector] openGLView] addSubview:scrollView];
}
- (void)onExit
{
[super onExit];
[touchDelegatingView removeFromSuperview];
[scrollView removeFromSuperview];
[pageControl removeFromSuperview];
}
- (void)mainmenu
{
[[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]];
}
- (void)didSelectGameMode:(GameModeSelection *)selection
{
[scrollView setScrollEnabled:NO];
[pageControl removeFromSuperview];
CGPoint opp = [scrollView convertPoint:selection.position toView:[[CCDirector sharedDirector] openGLView]];
CGPoint endPosition = ccp(0-(opp.x+158), opp.y);
[[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[selection.gameMode scene] position:endPosition]];
}
@end
|