cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
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
|
//
// SettingsLayer.cpp
// Steve and Maggie Halloween
//
// Created by Katarzyna Kalinowska-Górska on 06/10/2019.
//
#include <stdio.h>
#include "SettingsLayer.h"
#include "MiscUtils.h"
#include "ScalingUtils.h"
#include "Strings.h"
#include "SimpleButton.h"
SettingsLayer* SettingsLayer::create(float width, float height, std::function<void(int)> onLevelPickedCallback){
SettingsLayer * view = new (std::nothrow) SettingsLayer();
if(view && view->init(width, height, onLevelPickedCallback))
{
view->autorelease();
return view;
}
CC_SAFE_DELETE(view);
return nullptr;
}
bool SettingsLayer::init(float width, float height, std::function<void(int)> onLevelPickedCallback){
if(!cocos2d::LayerColor::initWithColor(cocos2d::Color4B(0,0,0,230), width, height)){
return false;
}
_isPresentingParentalGate = false;
_onLevelPicked = onLevelPickedCallback;
auto wholeContainer = cocos2d::Node::create();
addChild(wholeContainer);
auto upperStuffContainer = cocos2d::Node::create();
wholeContainer->addChild(upperStuffContainer);
auto paddingTop = 50*ScalingUtils::scaleAspectFillToDesignIpadProSize();
std::vector<std::string> levelImagePaths = { "graphics/levels/level_1.png", "graphics/levels/level_2.png", "graphics/levels/level_3.png" };
_levelPickerView = LevelPickerView::create(levelImagePaths, std::vector<std::string>());
upperStuffContainer->addChild(_levelPickerView);
_levelPickerView->addOnLevelChangedCallback([&](int pickedLevel){
MiscUtils::saveLastLevel(pickedLevel);
_onLevelPicked(pickedLevel);
});
_levelPickerView->selectLevelIndex((int)MiscUtils::lastLevel(), false);
upperStuffContainer->setAnchorPoint(cocos2d::Vec2(0.5, 0.5));
upperStuffContainer->setContentSize(_levelPickerView->getContentSize());
// upperStuffContainer->setContentSize(cocos2d::Size(instructionLabel->getBoundingBox().size.width + lpPaddingLeft + _levelPickerView->getBoundingBox().size.width, _levelPickerView->getBoundingBox().size.height));
upperStuffContainer->setPosition(width/2, height/2 + paddingTop);
_levelPickerView->setAnchorPoint(cocos2d::Vec2(1, 0.5));
_levelPickerView->setPosition(upperStuffContainer->getContentSize().width, upperStuffContainer->getContentSize().height/2);
// instructionLabel->setAnchorPoint(cocos2d::Vec2(0, 0.5));
// instructionLabel->setPosition(0, _levelPickerView->getBoundingBox().getMidY());
auto lowerStuffContainer = cocos2d::Node::create();
wholeContainer->addChild(lowerStuffContainer);
auto menuItemColor = cocos2d::Color3B(140, 140, 140);
cocos2d::MenuItemFont::setFontSize(120*ScalingUtils::getScaleForFont()); //TODO MAGIC NUMBER
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
auto paddingBottom = 20*ScalingUtils::scaleAspectFillToDesignIpadProSize(); //TODO padding is a magicnumber scaling!
cocos2d::MenuItemFont::setFontName("ComicSansMS-Bold");
#else
auto paddingBottom = 70*ScalingUtils::scaleAspectFillToDesignIpadProSize(); //TODO padding is a magicnumber scaling!
cocos2d::MenuItemFont::setFontName("fonts/ComicSansMSBold.ttf");
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
68a4c50a
xiaoyu
Merge remote-trac...
|
76
77
78
79
80
81
82
83
84
85
|
// setupAppLinksView(cocos2d::Point(getContentSize().width/2, upperStuffContainer->getBoundingBox().getMinY() - paddingBottom - paddingTop));
// wholeContainer->addChild(m_appLinksView); //TODO messy messy
// auto leftAppLinkSprite = cocos2d::Sprite::create("app_links/witch_halloween_app.png");
// leftAppLinkSprite->setAnchorPoint(cocos2d::Vec2(1,1));
// leftAppLinkSprite->setPosition(cocos2d::Vec2(m_appLinksView->getBoundingBox().getMinX(), m_appLinksView->getBoundingBox().getMaxY()));
// auto rightAppLinkSprite = cocos2d::Sprite::create("app_links/doll_toy_app.png");
// rightAppLinkSprite->setAnchorPoint(cocos2d::Vec2(0,0));
// rightAppLinkSprite->setPosition(cocos2d::Vec2(m_appLinksView->getBoundingBox().getMaxX(), m_appLinksView->getBoundingBox().getMinY()));
// wholeContainer->addChild(leftAppLinkSprite);
// wholeContainer->addChild(rightAppLinkSprite);
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
86
|
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
68a4c50a
xiaoyu
Merge remote-trac...
|
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
|
// auto webLinkButton = SimpleButton::create();
// wholeContainer->addChild(webLinkButton);
// auto buttonTexturePath = "app_links/steve_maggie.png";
// webLinkButton->loadTextures(buttonTexturePath, buttonTexturePath, buttonTexturePath);
// webLinkButton->setPosition(cocos2d::Point(getContentSize().width/2, upperStuffContainer->getBoundingBox().getMinY() - paddingTop*3 - webLinkButton->getBoundingBox().size.height/2));
// webLinkButton->setOnTouchEndedCallback([&, webLinkButton](std::string name, cocos2d::ui::Widget::TouchEventType eventType){
// presentParentalGate([&](){
// hideParentalGate();
// cocos2d::Application::getInstance()->openURL("https://www.steveandmaggie.com"); //TODO hardcoded
// }, [&](){
// hideParentalGate();
// });
// });
#endif
auto paddingExitButton = 20*ScalingUtils::scaleAspectFillToDesignIpadProSize();
auto scaleExitButton = 1.0f;
if(ScalingUtils::isSmallDevice()){
paddingExitButton *= ScalingUtils::getScaleForSmallDevice();
scaleExitButton = 1.6f;
}
auto appExitButton = SimpleButton::create();
addChild(appExitButton);
auto exitButtonTexturePath = "buttons/graphics/button_x.png";
appExitButton->loadTextures(exitButtonTexturePath, exitButtonTexturePath, exitButtonTexturePath);
appExitButton->setScale(scaleExitButton);
appExitButton->setOriginalScale(scaleExitButton);
appExitButton->setPosition(cocos2d::Point(getContentSize().width - appExitButton->getBoundingBox().size.width/2 - paddingExitButton, getContentSize().height - appExitButton->getBoundingBox().size.height/2 - paddingExitButton));
appExitButton->setOnTouchEndedCallback([&, appExitButton](std::string name, cocos2d::ui::Widget::TouchEventType eventType){
MiscUtils::showAppCloseConfirmDialog([&](){
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
117
118
|
});
});
|
68a4c50a
xiaoyu
Merge remote-trac...
|
119
120
121
122
123
|
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
auto menuPadding = 30*ScalingUtils::scaleAspectFillToDesignIpadProSize();//TODO magic number
auto menuItemAbout = cocos2d::MenuItemFont::create("Terms of Use", CC_CALLBACK_1(SettingsLayer::aboutMenuButtonTapped, this));
auto menuItemPrivacyPolicy = cocos2d::MenuItemFont::create("Privacy Policy", CC_CALLBACK_1(SettingsLayer::privacyPolicyMenuButtonTapped, this));
auto menuCenter = cocos2d::Menu::create(menuItemAbout,menuItemPrivacyPolicy, NULL);
menuCenter->setContentSize(cocos2d::Size(MAX(menuItemAbout->getBoundingBox().size.width, menuItemPrivacyPolicy->getBoundingBox().size.width), menuItemAbout->getBoundingBox().size.height + menuItemPrivacyPolicy->getBoundingBox().size.height + 3*menuPadding));
menuCenter->setColor(menuItemColor);
menuCenter->alignItemsVerticallyWithPadding(menuPadding);
lowerStuffContainer->addChild(menuCenter);//addChild(menuContainer, 3);
lowerStuffContainer->setContentSize(cocos2d::Size(menuCenter->getContentSize().width, menuCenter->getBoundingBox().size.height));
lowerStuffContainer->setAnchorPoint(cocos2d::Vec2(0.5, 1));
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
68a4c50a
xiaoyu
Merge remote-trac...
|
140
|
lowerStuffContainer->setPosition(getContentSize().width/2, upperStuffContainer->getBoundingBox().getMinY() - paddingBottom);
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
141
|
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
68a4c50a
xiaoyu
Merge remote-trac...
|
142
|
lowerStuffContainer->setPosition(getContentSize().width/2, upperStuffContainer->getBoundingBox().getMinY() - paddingBottom);
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
143
144
145
146
|
#endif
menuCenter->setPosition(lowerStuffContainer->getContentSize().width/2, lowerStuffContainer->getContentSize().height/2);
|
22495953
xiaoyu
打开多点触控,开启游戏时使用hud遮罩
|
147
148
|
menuCenter->setVisible(false);
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
wholeContainer->setContentSize(cocos2d::Size(getContentSize().width, upperStuffContainer->getContentSize().height + lowerStuffContainer->getContentSize().height + paddingBottom + paddingTop));
wholeContainer->setAnchorPoint(cocos2d::Vec2(0.5, 0.5));
wholeContainer->setPosition(width/2, height/2);
wholeContainer->setCascadeOpacityEnabled(true);
upperStuffContainer->setCascadeOpacityEnabled(true);
lowerStuffContainer->setCascadeOpacityEnabled(true);
return true;
}
void SettingsLayer::prepareForShowing(){
_levelPickerView->selectLevelIndex((int)(MiscUtils::lastLevel()), false);
}
void SettingsLayer::aboutMenuButtonTapped(cocos2d::Ref* pSender){
presentParentalGate([&](){
hideParentalGate();
// cocos2d::Application::getInstance()->openURL(Strings::LINK_TERMS_OF_SERVICE);
cocos2d::Application::getInstance()->openURL("https://www.wattsenglish.com/steve-and-maggie-halloween/terms-of-use.html");
}, [&](){
hideParentalGate();
});
}
void SettingsLayer::privacyPolicyMenuButtonTapped(cocos2d::Ref* pSender){
presentParentalGate([&](){
hideParentalGate();
// cocos2d::Application::getInstance()->openURL(Strings::LINK_PRIVACY_POLICY);
cocos2d::Application::getInstance()->openURL("https://www.wattsenglish.com/steve-and-maggie-halloween/principles-of-personal-data-processing.html");
}, [&](){
hideParentalGate();
});
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
void SettingsLayer::setupAppLinksView(const cocos2d::Point& position){
// TODO remove hard-code and add loading from a settings json file maybe
auto contentScaleF = ScalingUtils::getAdjustedContentScaleFactor();
//#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// static std::vector<AppLinksView::AppLinkData> apps {
// {"app_links/app_link_halloween.png", "com.wattsenglish.halloweengameapp"},
// {"app_links/app_link_toy.png", "com.wattsenglish.toyapp"}
// };
static std::vector<AppLinksView::AppLinkData> apps {
{"app_links/app_link_halloween.png", "id1482385753"},
{"app_links/app_link_toy.png", "id1496563219"}
};
m_appLinksView = AppLinksView::create(apps, this);
m_appLinksView->setAnchorPoint(cocos2d::Vec2(0.5, 1));
m_appLinksView->setPosition(position);
}
#endif
|