forked from otmb/cocoPuzzle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIDialog.cpp
More file actions
87 lines (68 loc) · 2.4 KB
/
UIDialog.cpp
File metadata and controls
87 lines (68 loc) · 2.4 KB
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
//
// Dialog.cpp
// Puzzle2
//
// Created by otmb on 2014/09/10.
//
//
#include "UIDialog.h"
#include "extensions/cocos-ext.h"
//#include "ui/CocosGUI.h"
using namespace ui;
UIDialog::UIDialog(Widget::ccWidgetTouchCallback& callback)
: _callback(callback) ,_uiLayer(nullptr)
{
}
UIDialog* UIDialog::create(Widget::ccWidgetTouchCallback& callback)
{
auto dialog = new UIDialog(callback);
dialog->init();
dialog->autorelease();
return dialog;
}
#define kModalLayerPriority -1
bool UIDialog::init()
{
if (!Layer::init())
return false;
_uiLayer = Layer::create();
addChild(_uiLayer);
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [](Touch *touch,Event*event)->bool{
return true;
};
auto dip = Director::getInstance()->getEventDispatcher();
dip->addEventListenerWithSceneGraphPriority(listener, this);
dip->setPriority(listener, kModalLayerPriority);
auto size = Director::getInstance()->getVisibleSize();
ui::ScrollView* sc = ui::ScrollView::create();
sc->setContentSize(size);
sc->setBackGroundColor(Color3B::GREEN);
sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
sc->setBounceEnabled(true);
sc->setDirection(ui::ScrollView::Direction::VERTICAL);
sc->setContentSize(Size(480,size.height));
sc->setInnerContainerSize(Size(480, sc->getContentSize().height + 300 ));
sc->setPosition(Vec2((size.width - sc->getContentSize().width) / 2, size.height - sc->getContentSize().height ));
Button* button = Button::create("Bullet.png");
button->setPosition(Vec2(240,320));
button->addTouchEventListener(_callback);
sc->addChild(button);
auto s = sc->getContentSize();
Text *alert = Text::create("What's New", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition( Vec2(s.width / 2.0f, s.height/2+50) );
addChild(alert);
alert = Text::create("Tap Start", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(sc->getContentSize().width / 2.0f, sc->getContentSize().height / 2.0f - alert->getContentSize().height * 3.125));
sc->addChild(alert);
_uiLayer->addChild(sc);
return true;
}
void UIDialog::close()
{
Action* action = RemoveSelf::create();
runAction(action);
}