void ImageViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
    {
        WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
        
        ImageView* imageView = static_cast<ImageView*>(widget);
        this->beginSetBasicProperties(widget);
        float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
        
        stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);

        for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
            std::string key = stChildArray[i].GetName(cocoLoader);
            std::string value = stChildArray[i].GetValue(cocoLoader);

            //read all basic properties of widget
            CC_BASIC_PROPERTY_BINARY_READER
            //read all color related properties of widget
            CC_COLOR_PROPERTY_BINARY_READER
            
            else if (key == P_Scale9Enable) {
                imageView->setScale9Enabled(valueToBool(value));
            }
            else if (key == P_FileNameData){
                stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
                std::string resType = backGroundChildren[2].GetValue(cocoLoader);;
                
                Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
                
                std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);

                imageView->loadTexture(backgroundValue, imageFileNameType);
                
            }
            else if(key == P_Scale9Width){
                imageView->setContentSize(Size(valueToFloat(value), imageView->getContentSize().height));
            }else if(key == P_Scale9Height){
                imageView->setContentSize(Size(imageView->getContentSize().width, valueToFloat(value)));
            }
            else if(key == P_CapInsetsX){
                capsx = valueToFloat(value);
            }else if(key == P_CapInsetsY){
                capsy = valueToFloat(value);
            }else if(key == P_CapInsetsWidth){
                capsWidth = valueToFloat(value);
            }else if(key == P_CapInsetsHeight){
                capsHeight = valueToFloat(value);
            }
            
        } //end of for loop
        
        if (imageView->isScale9Enabled()) {
            imageView->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
        }
        
        this->endSetBasicProperties(widget);

    }
Exemple #2
0
bool UIImageViewFlipTest::init()
{
    if (UIScene::init())
    {
        SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/blocks9ss.plist");
        Size widgetSize = _widget->getContentSize();
        
        Text* alert = Text::create("ImageView flip test", "fonts/Marker Felt.ttf", 26);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f,
                                widgetSize.height / 2.0f - alert->getContentSize().height * 2.125f));
        
        _uiLayer->addChild(alert);
        
        // Create the imageview
        ImageView* imageView = ImageView::create("blocks9r.png", Widget::TextureResType::PLIST);
        imageView->setScale9Enabled(true);
        imageView->setContentSize(Size(250, 115));
        imageView->setFlippedX(true);
        imageView->setScale(0.5);
        imageView->ignoreContentAdaptWithSize(false);
        imageView->setPosition(Vec2(widgetSize.width / 2.0f,
                                    widgetSize.height / 2.0f));
        
        _uiLayer->addChild(imageView);
        
        auto toggleButton = Button::create();
        toggleButton->setTitleText("Toggle FlipX");
        toggleButton->setPosition(imageView->getPosition() + Vec2(-50, - imageView->getContentSize().height/2 - 20));
        this->addChild(toggleButton);
        toggleButton->addClickEventListener([=](Ref*){
            imageView->setFlippedX(!imageView->isFlippedX());
        });
        
        auto toggleScale9 = Button::create();
        toggleScale9->setTitleText("Toggle Scale9");
        toggleScale9->setPosition(imageView->getPosition() + Vec2(+50, - imageView->getContentSize().height/2- 20));
        this->addChild(toggleScale9);
        toggleScale9->addClickEventListener([=](Ref*){
            imageView->setScale9Enabled(!imageView->isScale9Enabled());
            //after switching scale9, you must call setContentSize to keep the size not change
             imageView->setContentSize(Size(250, 115));
        });
        
        return true;
    }
    return false;
}
bool UIScrollViewTest_Both::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();;
        
        // Add a label in which the dragpanel events will be displayed
        _displayValueLabel = Text::create("Move by any direction","fonts/Marker Felt.ttf",32);
        _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
        _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
        _uiLayer->addChild(_displayValueLabel);
        
        // Add the alert
        Text* alert = Text::create("ScrollView both","fonts/Marker Felt.ttf",30);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
        _uiLayer->addChild(alert);
        
        Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
        
        Layout* background = static_cast<Layout*>(root->getChildByName("background_Panel"));
        
        // Create the dragpanel
        ui::ScrollView* scrollView = ui::ScrollView::create();
        scrollView->setDirection(ui::ScrollView::Direction::BOTH);
        scrollView->setTouchEnabled(true);
        scrollView->setBounceEnabled(true);
        scrollView->setBackGroundImageScale9Enabled(true);
        scrollView->setBackGroundImage("cocosui/green_edit.png");
        scrollView->setContentSize(Size(210, 122.5));
		scrollView->setScrollBarWidth(4);
		scrollView->setScrollBarPositionFromCorner(Vec2(6, 6));
        Size backgroundSize = background->getContentSize();
        scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
                                    (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
                                    (widgetSize.height - backgroundSize.height) / 2.0f +
                                    (backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
        ImageView* imageView = ImageView::create("Hello.png");
        scrollView->addChild(imageView);
        
        scrollView->setInnerContainerSize(imageView->getContentSize());
        Size innerSize = scrollView->getInnerContainerSize();
        imageView->setPosition(Vec2(innerSize.width / 2.0f, innerSize.height / 2.0f));
        
        _uiLayer->addChild(scrollView);

        // Jump to right bottom
        scrollView->jumpToBottomRight();

        return true;
    }
    
    return false;
}
bool TalkDetailHelpLayer::init()
{
    if(!Layer::init()) return false;

    zPos = 0;
    visibleSize = Director::getInstance()->getVisibleSize();
    visibleSize.height -= 100;
    ImageView* bgImage = ImageView::create("res/common/dlgback.png");
    bgImage->setAnchorPoint(Vec2(0, 0));
    bgImage->setPosition(Vec2(0, 0));
    this->addChild(bgImage);
    
    ImageView* helpTop = ImageView::create("res/talk/f_help_t.png");
    helpTop->setAnchorPoint(Vec2(0, 0));
    helpTop->setPosition(Vec2(0, visibleSize.height - 360));
    this->addChild(helpTop);
    
    ImageView* helpBottom = ImageView::create("res/talk/f_help_b.png");
    helpBottom->setAnchorPoint(Vec2(0, 0));
    helpBottom->setPosition(Vec2(0, 90));
    this->addChild(helpBottom);
    float profileX = (visibleSize.width - helpBottom->getContentSize().width)/2;

    string str = "相手の好みに合った返信をすると好感度が貯まっていきます。\n♡色がピンクに染まったら相手はあなたに首ったけですよ。";
    _topMessage = CCLabelTTF::create(str, kDEFAULT_BOLD_FONT, 26);
    _topMessage->setColor(Color3B::BLACK);
    _topMessage->setHorizontalAlignment(TextHAlignment::LEFT);
    _topMessage->setAnchorPoint(Vec2(0, 0));
    _topMessage->setPosition(Vec2(profileX + 40, helpTop->getPosition().y + 45));
    _topMessage->setDimensions(Size(Vec2(visibleSize.width - 80, 0)));
    this->addChild(_topMessage, zPos++);

    str = "ここをタップで返信内容の選択肢が表示されます。\n相手に好印象を与える返信を選びましょう。\nあなたのテクニックの見せ所ですね。";
    _bottomMessage = CCLabelTTF::create(str, kDEFAULT_BOLD_FONT, 26);
    _bottomMessage->setColor(Color3B::BLACK);
    _bottomMessage->setHorizontalAlignment(TextHAlignment::LEFT);
    _bottomMessage->setAnchorPoint(Vec2(0, 0));
    _bottomMessage->setPosition(Vec2(profileX + 40, helpBottom->getPosition().y + 70));
    _bottomMessage->setDimensions(Size(Vec2(visibleSize.width - 80, 0)));
    this->addChild(_bottomMessage, zPos++);
    
    return true;
};
bool UIScrollViewTest_Horizontal::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        // Add a label in which the scrollview alert will be displayed
        _displayValueLabel = Text::create("Move by horizontal direction","fonts/Marker Felt.ttf",32);
        _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
        _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
        _uiLayer->addChild(_displayValueLabel);            
        
        Text* alert = Text::create("ScrollView horizontal","fonts/Marker Felt.ttf",30);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
        _uiLayer->addChild(alert);
        
        Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
        
        Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
        
        // Create the scrollview by horizontal
        ui::ScrollView* scrollView = ui::ScrollView::create();
        scrollView->setBounceEnabled(true);
        scrollView->setDirection(ui::ScrollView::Direction::HORIZONTAL);
        scrollView->setContentSize(Size(280.0f, 150.0f));
        scrollView->setInnerContainerSize(scrollView->getContentSize());
        Size backgroundSize = background->getContentSize();
        scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
                                    (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
                                    (widgetSize.height - backgroundSize.height) / 2.0f +
                                    (backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
        _uiLayer->addChild(scrollView);
        
        ImageView* imageView = ImageView::create("cocosui/ccicon.png");
        
        float innerWidth = scrollView->getContentSize().width + imageView->getContentSize().width;
        float innerHeight = scrollView->getContentSize().height;
        
        scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
        
        Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
        button->setPosition(Vec2(button->getContentSize().width / 2.0f,
                                scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
        scrollView->addChild(button);
        
        Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(Vec2(button->getRightBoundary() + button->getContentSize().width / 2.0f,
                                    button->getBottomBoundary() - button->getContentSize().height / 2.0f));
        scrollView->addChild(titleButton);
        
        Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
        button_scale9->setScale9Enabled(true);
        button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
        button_scale9->setPosition(Vec2(titleButton->getRightBoundary() + titleButton->getContentSize().width / 2.0f,
                                       titleButton->getBottomBoundary() - titleButton->getContentSize().height / 2.0f));
        scrollView->addChild(button_scale9);                
                
        imageView->setPosition(Vec2(innerWidth - imageView->getContentSize().width / 2.0f,
                                   button_scale9->getBottomBoundary() - button_scale9->getContentSize().height / 2.0f));
        scrollView->addChild(imageView);                
        
        return true;
    }
    
    return false;
}
Exemple #6
0
bool GamesScence::init()
{
    if ( !Layer::init() )
    {
        return false;
    }

	m_blockSize      = 20.0f;
	m_isGgameRunning = false;
	m_next3Tetrominos.clear();
	
	Widget* pRootWidget = cocostudio::GUIReader::getInstance()->widgetFromJsonFile("TetrisUi/TetrisUi.ExportJson");
	this->addChild(pRootWidget,0);
	
	//最高分显示
	m_highestLabel = (TextAtlas*)Helper::seekWidgetByName(pRootWidget,"atlHighest");
	int highest    = UserDefault::getInstance()->getIntegerForKey("TheHighestScore",0);
	char strHighest[20];
	sprintf(strHighest,"%d",highest);
	m_highestLabel->setString(strHighest);
	
	//分数显示
	m_scoreCount.setNumberLabel((TextAtlas*)Helper::seekWidgetByName(pRootWidget,"atlScore"));

	//提示消除了多少行
	m_clearCount.setNumberLabel((TextAtlas*)Helper::seekWidgetByName(pRootWidget,"atlNumClear"));

	//菜单按钮
	m_btMenu = (Button*)Helper::seekWidgetByName(pRootWidget,"btMenu");
	m_btMenu->addTouchEventListener(CC_CALLBACK_2(GamesScence::btMenuCallback,this));

	//底板的纵横线
	m_imgFrame = (ImageView*)Helper::seekWidgetByName(pRootWidget,"imgFrame");

	//下一个方块的提示
	ImageView* nextTip = (ImageView*)Helper::seekWidgetByName(pRootWidget,"imgTipBoard");
	m_nextTipPos  = nextTip->getPosition();
	m_nextTipSize = nextTip->getContentSize();

	//游戏菜单
	m_panelManager.setMenuPanel((Layout*)Helper::seekWidgetByName(pRootWidget,"layMenu"));
	m_panelManager.setMenuPanelVisible(false,true);
	((Button*)Helper::seekWidgetByName(pRootWidget,"btStart"))->addTouchEventListener(CC_CALLBACK_2(GamesScence::btStartCallback,this));
	((Button*)Helper::seekWidgetByName(pRootWidget,"btContinue"))->addTouchEventListener(CC_CALLBACK_2(GamesScence::btContinueCallback,this));
	((Button*)Helper::seekWidgetByName(pRootWidget,"btRankList"))->addTouchEventListener(CC_CALLBACK_2(GamesScence::btRankListCallback,this));
	((Button*)Helper::seekWidgetByName(pRootWidget,"btHelp"))->addTouchEventListener(CC_CALLBACK_2(GamesScence::btHelpCallback,this));
	((Button*)Helper::seekWidgetByName(pRootWidget,"btLeave"))->addTouchEventListener(CC_CALLBACK_2(GamesScence::btLeaveCallback,this));
	
	//GameOver菜单
	m_panelManager.setGameOverPanel((Layout*)Helper::seekWidgetByName(pRootWidget,"layGameOver"));
	m_panelManager.setGameOverPanelVisible(false);
	((Button*)Helper::seekWidgetByName(pRootWidget,"btRestart"))->addTouchEventListener(CC_CALLBACK_2(GamesScence::btRestartCallback,this));
	
	//上传分数面板
	m_panelManager.setUploadScorePanel((Layout*)Helper::seekWidgetByName(pRootWidget,"layUploadScore"));
	m_panelManager.setUploadScorePanelVisible(0,false);
	m_nickNameInput = (TextField*)Helper::seekWidgetByName(pRootWidget,"tfNickName");
	((Button*)Helper::seekWidgetByName(pRootWidget,"btConfirmation"))->addTouchEventListener(CC_CALLBACK_2(GamesScence::btConfirmationCallback,this));
	((Button*)Helper::seekWidgetByName(pRootWidget,"btCancel"))->addTouchEventListener(CC_CALLBACK_2(GamesScence::btCancelCallback,this));
	
	//排行榜(只是显示用,与服务器的交互放m_list里实现)
	ListView* uilist = (ListView*)Helper::seekWidgetByName(pRootWidget,"listRankList");
	m_panelManager.setRankList(uilist);
	m_panelManager.setRankListVisible(false);

	////真正与服务器交互的排行榜功能类
	m_list = RankList::create(uilist);
	this->addChild(m_list);
	

	//游戏底板
	Node* pFrame = Helper::seekWidgetByName(pRootWidget,"imgFrame");
	Size frameSize = pFrame->getContentSize();

	m_bgBpard = BackgroundBoard::create(m_blockSize);
	m_bgBpard->setPosition(pFrame->getPosition());
	m_bgBpard->setScaleX(frameSize.width/BACKGROUND_COL/m_blockSize);
	m_bgBpard->setScaleY(frameSize.height/BACKGROUND_ROW/m_blockSize);
	
	m_bgBpard->setDropDelayTime(0.5f);
	m_bgBpard->setClearLineListener(this,clearLine_selector(GamesScence::onAddScore));
	m_bgBpard->setNextBlockListener(this,nextBlock_selector(GamesScence::onNextBlock));
	m_bgBpard->setGameOverListener(this,gameOver_selector(GamesScence::onGameOver));
	Helper::seekWidgetByName(pRootWidget,"root")->addChild(m_bgBpard,0);
	
    return true;
}
bool UIScrollViewNestTest::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        // Add a label in which the scrollview alert will be displayed
        _displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
        _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
        _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
                                             widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
        _uiLayer->addChild(_displayValueLabel);
        
        // Add the alert
        Text* alert = Text::create("ScrollView vertical", "fonts/Marker Felt.ttf", 30);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
        _uiLayer->addChild(alert);
        
        Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
        
        Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
        
        // Create the scrollview by vertical
        ui::ScrollView* scrollView = ui::ScrollView::create();
        scrollView->setContentSize(Size(280.0f, 150.0f));
        scrollView->setDirection(ui::ScrollView::Direction::VERTICAL);
		scrollView->setScrollBarPositionFromCorner(Vec2(4, 4));
        Size backgroundSize = background->getContentSize();
        scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
                                     (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
                                     (widgetSize.height - backgroundSize.height) / 2.0f +
                                     (backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
		scrollView->setScrollBarPositionFromCornerForVertical(Vec2(scrollView->getContentSize().width - 4, 4));
		scrollView->setScrollBarColor(Color3B::BLUE);
        _uiLayer->addChild(scrollView);
        
        ImageView* imageView = ImageView::create("cocosui/ccicon.png");
        
        float innerWidth = scrollView->getContentSize().width;
        float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
        
        scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
        
        Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
        button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
        scrollView->addChild(button);
        
        Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
        scrollView->addChild(titleButton);
        
        Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
        button_scale9->setScale9Enabled(true);
        button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
        button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
        scrollView->addChild(button_scale9);
        
        imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
        scrollView->addChild(imageView);
        
        
        
        // Create the scrollview by both
        ui::ScrollView* sc = ui::ScrollView::create();
        sc->setBackGroundColor(Color3B::GREEN);
        sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
        sc->setBounceEnabled(true);
        sc->setDirection(ui::ScrollView::Direction::BOTH);
        sc->setInnerContainerSize(Size(480, 320));
        sc->setContentSize(Size(100,100));
        sc->setPropagateTouchEvents(false);
        sc->setPosition(Vec2(180,100));
        sc->scrollToPercentBothDirection(Vec2(50, 50), 1, true);
		sc->setScrollBarPositionFromCorner(Vec2(4, 4));
        ImageView* iv = ImageView::create("cocosui/Hello.png");
        iv->setPosition(Vec2(240, 160));
        sc->addChild(iv);

        
        scrollView->addChild(sc);
        
        return true;
    }
    
    return false;
}
bool ProfileScreen::init() {
    if (!Layer::init()) {
        return false;
    }
    
    loginReward = soomla::CCVirtualItemReward::create(__String::create("login_reward"),
                                                      __String::create("Login Reward"),
                                                      __Bool::create(false), __Integer::create(100), __String::create(MUFFIN_CURRENCY_ITEM_ID));
    loginReward->retain();
    
    shareReward = soomla::CCVirtualItemReward::create(__String::create("share_reward"),
                                                      __String::create("Share Reward"),
                                                      __Bool::create(false), __Integer::create(150), __String::create(MUFFIN_CURRENCY_ITEM_ID));
    shareReward->retain();
    
    uploadReward = soomla::CCVirtualItemReward::create(__String::create("upload_reward"),
                                                      __String::create("Upload Reward"),
                                                      __Bool::create(false), __Integer::create(200), __String::create(MUFFIN_CURRENCY_ITEM_ID));
    uploadReward->retain();
    
    likePageReward = soomla::CCVirtualItemReward::create(__String::create("like_page_reward"),
                                                       __String::create("Like Page Reward"),
                                                       __Bool::create(false), __Integer::create(300), __String::create(MUFFIN_CURRENCY_ITEM_ID));
    likePageReward->retain();

    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

    Layout *layout = Layout::create();

    float vShift = visibleSize.height;
    
    ImageView *background = ui::ImageView::create("profile/BG.png");
    background->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height / 2.0f));
    layout->addChild(background);
    
    float scaleX = visibleSize.width / background->getContentSize().width;
    float scaleY = visibleSize.height / background->getContentSize().height;
    
    background->setScale(scaleX, scaleY);
    
    ImageView *header = ui::ImageView::create("profile/Headline.png");
    header->setAnchorPoint(Vec2(0.0f, 1.0f));
    header->setScale(scaleX, scaleY);
    header->setPosition(Vec2(0.0f, vShift));
    layout->addChild(header);
    vShift -= header->getContentSize().height * scaleY;
    
    vShift -= relativeY(70.0f, visibleSize.height);
    
    shareButton = createActionButton(layout,
                                     "profile/BTN-Share-Normal.png", "profile/BTN-Share-Press.png", "profile/BTN-Share-Disable.png", "I Love SOOMLA!",
                                vShift, STATUS_BUTTON_TAG, scaleX, scaleY, visibleSize);
    shareButton->retain();
    
    vShift -= shareButton->getContentSize().height * scaleY;
    vShift -= relativeY(60.0f, visibleSize.height);
    
    storyButton = createActionButton(layout,
                                     "profile/BTN-ShareStory-Normal.png", "profile/BTN-ShareStory-Press.png", "profile/BTN-ShareStory-Disable.png", "Full story of The SOOMBOT!",
                                vShift, STORY_BUTTON_TAG, scaleX, scaleY, visibleSize);
    storyButton->retain();
    
    vShift -= storyButton->getContentSize().height * scaleY;
    vShift -= relativeY(60.0f, visibleSize.height);
    
    uploadButton = createActionButton(layout,
                                      "profile/BTN-Upload-Normal.png", "profile/BTN-Upload-Press.png", "profile/BTN-Upload-Disable.png", "Screenshot",
                                vShift, UPLOAD_BUTTON_TAG, scaleX, scaleY, visibleSize);
    uploadButton->retain();
    
    vShift -= uploadButton->getContentSize().height * scaleY;
    vShift -= relativeY(150.0f, visibleSize.height);
    
    loginButton = ui::Button::create("profile/BTN-Connect.png", "profile/BTN-Connect-Press.png", "profile/BTN-Connect.png");
    loginButton->retain();
    loginButton->setActionTag(LOGIN_BUTTON_TAG);
    loginButton->setAnchorPoint(Vec2(0.0f, 1.0f));
    loginButton->setScale(scaleX, scaleY);
    loginButton->setPosition(Vec2(relativeX(30.0f, visibleSize.width), vShift));
    
    loginButton->setTouchEnabled(true);
    loginButton->addTouchEventListener(CC_CALLBACK_2(ProfileScreen::onClicked, this));
    layout->addChild(loginButton);
    
    logoutButton = ui::Button::create("profile/BTN-LogOut.png", "profile/BTN-LogOut-Press.png", "profile/BTN-LogOut.png");
    logoutButton->retain();
    logoutButton->setActionTag(LOGOUT_BUTTON_TAG);
    logoutButton->setAnchorPoint(Vec2(0.0f, 1.0f));
    logoutButton->setScale(scaleX, scaleY);
    logoutButton->setPosition(Vec2(relativeX(30.0f, visibleSize.width), vShift));
    
    logoutButton->setVisible(false);
    logoutButton->setTouchEnabled(true);
    logoutButton->setEnabled(false);
    logoutButton->addTouchEventListener(CC_CALLBACK_2(ProfileScreen::onClicked, this));
    layout->addChild(logoutButton);

    this->addChild(layout);

    std::function<void(EventCustom *)> handleLoginFinished = [this](EventCustom *event) {
        this->setLoggedInState();
        
        soomla::CCError *profileError = nullptr;
        soomla::CCSoomlaProfile::getInstance()->like(soomla::FACEBOOK, "The.SOOMLA.Project", likePageReward, &profileError);
        soomla::CCSoomlaProfile::getInstance()->getFeed(soomla::FACEBOOK, nullptr, &profileError);
        soomla::CCSoomlaProfile::getInstance()->getContacts(soomla::FACEBOOK, nullptr, &profileError);
    };
    
    std::function<void(EventCustom *)> handleLogoutFinished = [this](EventCustom *event) {
        logoutButton->setVisible(false);
        logoutButton->setEnabled(false);
        loginButton->setVisible(true);
        loginButton->setEnabled(true);
        
        shareButton->setEnabled(false);
        shareButton->setBright(false);
        
        storyButton->setEnabled(false);
        storyButton->setBright(false);
        
        uploadButton->setEnabled(false);
        uploadButton->setBright(false);
    };
    
    std::function<void(EventCustom *)> handleProfileUpdatedFinished = [this](EventCustom *event) {
        soomla::CCUserProfile *userProfile = (soomla::CCUserProfile *)(event->getUserData());
        
        log("%s %s has logged in", userProfile->getFirstName()->getCString(), userProfile->getLastName()->getCString());
    };
    
    getEventDispatcher()->addEventListenerWithSceneGraphPriority(EventListenerCustom::create(soomla::CCProfileConsts::EVENT_LOGIN_FINISHED, handleLoginFinished),
                                                                 this);
    
    getEventDispatcher()->addEventListenerWithSceneGraphPriority(EventListenerCustom::create(soomla::CCProfileConsts::EVENT_USER_PROFILE_UPDATED, handleProfileUpdatedFinished),
                                                                 this);
    
    getEventDispatcher()->addEventListenerWithSceneGraphPriority(EventListenerCustom::create(soomla::CCProfileConsts::EVENT_LOGOUT_FINISHED, handleLogoutFinished),
                                                                 this);
    
    soomla::CCError *profileError = nullptr;
    bool isLoggedIn =  soomla::CCSoomlaProfile::getInstance()->isLoggedIn(soomla::FACEBOOK, &profileError);
    if (profileError) {
        MessageBox(profileError->getInfo(), "Error");
    }
    else {
        if (isLoggedIn) {
            setLoggedInState();
        }
    }

    return true;
}