Beispiel #1
0
void MenuScene::initButton() {
    auto startButton = _rootNode->getChildByName<Button *>(STARTBUTTON);
    startButton->addClickEventListener([](Ref *ref) {
        if (DATAOPERATOR->getEffectEnable())
            AUDIOENGINE->playEffect(CLICKEFFECT_NAME);
        //跳转关卡选择界面
        DIRECTOR->replaceScene(SelectScene::createScene());
    });

    auto musicButton = _rootNode->getChildByName<Button *>(MUSICBUTTON);
    musicButton->addClickEventListener([](Ref *ref) {
        if (DATAOPERATOR->getEffectEnable())
            AUDIOENGINE->playEffect(CLICKEFFECT_NAME);
        if (DATAOPERATOR->getMusicEnable()) {
            AUDIOENGINE->stopBackgroundMusic();
            DATAOPERATOR->setMusicEnable(false);
        }
        else {
            AUDIOENGINE->playBackgroundMusic(MENUSCENE_BGM_NAME, true);
            DATAOPERATOR->setMusicEnable(true);
        }

    });

    auto effectButton = _rootNode->getChildByName<Button *>(EFFECTBUTTON);
    effectButton->addClickEventListener([](Ref *ref) {
        if (DATAOPERATOR->getEffectEnable()) {
            DATAOPERATOR->setEffectEnable(false);
        }
        else {
            AUDIOENGINE->playEffect(CLICKEFFECT_NAME);
            DATAOPERATOR->setEffectEnable(true);
        }
    });
}
Beispiel #2
0
void Lobby_Layer::set_callbacks(Root_Node_Type * node)
{
  Widget* root = static_cast<Widget*>(node);
  {
    std::string node_name ="Button_Close";
    auto node = static_cast<Button*> (Helper::seekWidgetByName(root, node_name));
    if (node)
    {
      node->addClickEventListener(CC_CALLBACK_1(Self::on_btn_quit, this));
      
    }
  }
  {
    std::string node_name ="Button_Game";
    auto node = static_cast<Button*> (Helper::seekWidgetByName(root, node_name));
    if (node)
    {
      node->addClickEventListener(CC_CALLBACK_1(Self::on_btn_enter_game, this));
      
    }
  }
  
  {
    std::string node_name = "ListView_1";
    auto node = static_cast <ListView*> (Helper::seekWidgetByName(root, node_name));
    if (node)
    {
      room_list_view_ = node;
      room_list_view_->retain();
      room_list_view_->removeAllChildren();
    }
  }
}
Beispiel #3
0
bool LayerGroupMenu::init()
{
    if(!Layer::init()) {
        return false;
    }
    
    auto layout = Layout::create();
    layout->setContentSize(Director::getInstance()->getWinSize());
    layout->setTouchEnabled(true);
    layout->addClickEventListener([this](Ref*) {
        this->setVisible(false);
    });
    this->addChild(layout, -1);
    
    auto root = CSLoader::createNode("LayerGroupMenu.csb");
    this->addChild(root);
    
    void click_group_create(Ref* sender);
    void click_group_search(Ref* sender);
    
    auto btn_group_create = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_group_create"));
    btn_group_create->setTitleText("          " + tools::local_string("create_group", "创建群"));
    btn_group_create->addClickEventListener(std::bind(&LayerGroupMenu::click_group_create, this, std::placeholders::_1));

    auto btn_group_search = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_group_search"));
    btn_group_search->setTitleText("          " + tools::local_string("search_group", "搜索群"));
    btn_group_search->addClickEventListener(std::bind(&LayerGroupMenu::click_group_search, this, std::placeholders::_1));
    

    return true;
}
Beispiel #4
0
void CommonWidget::initInterface( void )
{
	_commonWidget = CSLoader::createNode( Ccs_GameWidgetLayer_FilePath );

	if ( !_commonWidget )
	{
		return;
	}
	addChild( _commonWidget );

	do 
	{
		auto butExit = (Button*)GameMainLayer::seekNodeByName(_commonWidget,"ButtonClose");
		CC_BREAK_IF( butExit == nullptr );
		butExit->setTag( Tag_ExitWidget );
		butExit->addClickEventListener(CC_CALLBACK_1(CommonWidget::callFuncButtonEvent, this));

		auto butBuy = (Button*)GameMainLayer::seekNodeByName(_commonWidget,"ButtonConfirm");
		CC_BREAK_IF( butBuy == nullptr );
		butBuy->setTag( Tag_Btn1 );
		butBuy->addClickEventListener(CC_CALLBACK_1(CommonWidget::callFuncButtonEvent, this));

		auto textContene1			= (Text*)GameMainLayer::seekNodeByName(_commonWidget, "TextWidgetTips" );
		textContene1->setString( "" );

		auto textContene2			= (Text*)GameMainLayer::seekNodeByName(_commonWidget, "TextWidgetTips2" );
		textContene2->setString( "" );

	} while (0);

}
Beispiel #5
0
bool MainScene::init() {
	if (!Layer::init())
		return false;

	auto director = Director::getInstance();
	auto pView = director->getOpenGLView();
	pView->setDesignResolutionSize(RESOLUTION_WIDTH, RESOLUTION_HEIGHT, ResolutionPolicy::SHOW_ALL);

	Size visibleSize = director->getVisibleSize();
	Vec2 origin = director->getVisibleOrigin();

	//Title 'Kid Sudoku'
	auto labelTitle = Label::createWithTTF("Kid Remember It", "fonts/Marker Felt.ttf", 188);
	labelTitle->setTextColor(Color4B(0xe3, 0x54, 0xf4, 0xff));
	labelTitle->setPosition(Vec2(origin.x + visibleSize.width / 2,
						 	origin.y + visibleSize.height - labelTitle->getContentSize().height/2 - 40)
						);
	this->addChild(labelTitle);

	//Cool Papa-Legend announcement
	auto labelAnn = Label::createWithTTF("Cool Papa-Legend :   Produce product for our kids.", "fonts/Marker Felt.ttf", 30);
	labelAnn->setTextColor(Color4B(0x00, 0xff, 0x00, 0xff));
	labelAnn->setPosition(Vec2(origin.x + visibleSize.width / 2,
						 	labelTitle->getPosition().y - labelTitle->getContentSize().height/2 - 60 - labelAnn->getContentSize().height / 2)
						);
	this->addChild(labelAnn);

	//Campaign Button
	auto btnPlay = ui::Button::create("btn-menu-0.png",
											  "btn-menu-1.png",
											  "btn-menu-2.png");
	btnPlay->setScale9Enabled(true);
	btnPlay->setCapInsets(Rect(15, 15, 4, 4));
	btnPlay->setTitleText("Play");
	btnPlay->setTitleFontSize(40);
	btnPlay->setContentSize(Size(300, 90));
	btnPlay->setPosition(Vec2(origin.x + visibleSize.width / 2,
			 	 	 	   	 	  labelAnn->getPosition().y - labelAnn->getContentSize().height / 2 - 140 - btnPlay->getContentSize().height/2)
							);
	btnPlay->addClickEventListener(CC_CALLBACK_1(MainScene::onMenuPlayClicked, this));
	this->addChild(btnPlay, 1);

	//Exit Button
	auto btnExit = ui::Button::create("btn-menu-0.png",
											  "btn-menu-1.png",
											  "btn-menu-2.png");
	btnExit->setScale9Enabled(true);
	btnExit->setCapInsets(Rect(15, 15, 4, 4));
	btnExit->setTitleText("Exit");
	btnExit->setTitleFontSize(40);
	btnExit->setContentSize(Size(300, 90));
	btnExit->setPosition(Vec2(origin.x + visibleSize.width / 2,
							btnPlay->getPosition().y - btnPlay->getContentSize().height / 2 - 40 - btnExit->getContentSize().height/2)
							);
	btnExit->addClickEventListener(CC_CALLBACK_1(MainScene::onMenuExitClicked, this));
	this->addChild(btnExit, 1);
	return true;
}
Beispiel #6
0
bool ActionSheet::init()
{
    if (!Layer::init()) {
        return false;
    }
    
    auto layerColor = LayerColor::create(Color4B(100, 100, 100, 80));
    this->addChild(layerColor, -1);
    
    auto layout = Layout::create();
    layout->setContentSize(this->getContentSize());
    layout->setTouchEnabled(true);
    layout->addClickEventListener([this](Ref*) {
        click_image_cancel(nullptr);
    });
    this->addChild(layout);
    
    origin_ = Point(0, -189);
    
    root_ = CSLoader::createNode("LayerActionSheet.csb");
    root_->setPosition(origin_);
    this->addChild(root_);
    
    auto image_camera = dynamic_cast<ImageView*>(CSLoader::seekNodeByName(root_, "image_camera"));
    auto image_album = dynamic_cast<ImageView*>(CSLoader::seekNodeByName(root_, "image_album"));
    auto image_cancel = dynamic_cast<ImageView*>(CSLoader::seekNodeByName(root_, "image_cancel"));
    
    image_camera->addClickEventListener(std::bind(&ActionSheet::click_image_camera, this, std::placeholders::_1));
    image_album->addClickEventListener(std::bind(&ActionSheet::click_image_album, this, std::placeholders::_1));
    image_cancel->addClickEventListener(std::bind(&ActionSheet::click_image_cancel, this, std::placeholders::_1));
    
    auto text_camera = dynamic_cast<Text*>(CSLoader::seekNodeByName(root_, "text_camera"));
    auto text_photo = dynamic_cast<Text*>(CSLoader::seekNodeByName(root_, "text_photo"));
    auto text_cancel = dynamic_cast<Text*>(CSLoader::seekNodeByName(root_, "text_cancel"));
    
    text_camera->setString(tools::local_string("take_photo", "拍照"));
    text_photo->setString(tools::local_string("select_from_album", "从手机相册选择"));
    text_cancel->setString(tools::local_string("cancel", "取消"));
    
    auto& size = Director::getInstance()->getWinSize();
    
    image_camera->setContentSize(Size(size.width, image_camera->getContentSize().height));
    image_album->setContentSize(Size(size.width, image_album->getContentSize().height));
    image_cancel->setContentSize(Size(size.width, image_cancel->getContentSize().height));
    
    image_camera->setPosition(Point(size.width/2, image_camera->getPosition().y));
    image_album->setPosition(Point(size.width/2, image_album->getPosition().y));
    image_cancel->setPosition(Point(size.width/2, image_cancel->getPosition().y));
    
    text_camera->setPosition(Point(size.width/2, text_camera->getPosition().y));
    text_photo->setPosition(Point(size.width/2, text_photo->getPosition().y));
    text_cancel->setPosition(Point(size.width/2, text_cancel->getPosition().y));
    return true;
}
Beispiel #7
0
void UIUtils::mapBuildingDialog(cocos2d::Node * rootNode, uint32_t tiledIdx, uint32_t buildId, const std::function<void()> & comfirmBack, const std::function<void()> & cancelBack, bool isShow)
{
    if (!rootNode) {
        return;
    }
    
    auto buildStatus = TiledMapUI::getInstance()->GetBuildStatus(tiledIdx);
    if (buildStatus == TiledMapUI::BuildStatus::Normal || isShow) {
        // 未占领 或者 个别建筑
        auto layout_BuildDialog = rootNode->getChildByName<Layout*>("Layout_BuildDialog");
        if(!layout_BuildDialog) return;
        layout_BuildDialog->setVisible(true);
        
        CfgDataRow dataRow(buildId);
        
        auto text_BuildName = layout_BuildDialog->getChildByName<Text*>("Text_BuildName");
        auto langId = dataRow.GetValue(CfgField::Name)->asInt();
        auto langText = MultiLanguage::getInstance()->GetText(langId);
        text_BuildName->setString(langText);
        
        auto text_Desc = layout_BuildDialog->getChildByName<Text*>("Text_Desc");
        langId = dataRow.GetValue(CfgField::BodescribeId)->asInt();
        langText = MultiLanguage::getInstance()->GetText(langId);
        text_Desc->setString(langText);
        
        auto btn_Enter = layout_BuildDialog->getChildByName<Button*>("Btn_Enter");
        langId = (int)LanguageIdEnum::EnterLangId;
        langText = MultiLanguage::getInstance()->GetText(langId);
        btn_Enter->setTitleText(langText);
        btn_Enter->addClickEventListener(
                                         [comfirmBack, layout_BuildDialog](Ref* sender)
                                         {
                                             layout_BuildDialog->setVisible(false);
                                             if(comfirmBack) comfirmBack();
                                         });
        
        auto btn_Exit = layout_BuildDialog->getChildByName<Button*>("Btn_ExitBuild");
        langId = (int)LanguageIdEnum::ExitLangId;
        langText = MultiLanguage::getInstance()->GetText(langId);
        btn_Exit->setTitleText(langText);
        btn_Exit->addClickEventListener([cancelBack, layout_BuildDialog](Ref* sender)
                                        {
                                            layout_BuildDialog->setVisible(false);
                                            if(cancelBack) cancelBack();
                                        });
        
    }
    else if(buildStatus == TiledMapUI::BuildStatus::Occupy) {
        // 已占领
        if(comfirmBack) comfirmBack();
    }
    
}
Beispiel #8
0
bool BuyChipLayer::init()
{
    if(!PokerChildLayer::init()) {
        return false;
    }
    LayerColor *layer = LayerColor::create(Color4B(100,100,100,100));
    this->addChild(layer);
    this->setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
    this->setTouchEnabled(true);
    this->setSwallowsTouches(true);
    
    auto& size = Director::getInstance()->getWinSize();
    auto layout = ui::Layout::create();
    layout->setContentSize(size);
    layout->setTouchEnabled(true);
    layout->setAnchorPoint(Point::ZERO);
    this->addChild(layout, -10);
    
    auto root = CSLoader::createNode("LayerBuyChip1.csb");
    this->addChild(root);
    Size winSize = Director::getInstance()->getWinSize();
    LayerColor *layerBlack = LayerColor::create(Color4B(0, 0, 0, 100),winSize.width,winSize.height * 2);
    layerBlack->setPositionY(-winSize.height);
    this->addChild(layerBlack,-1);
    auto text_max_add = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_max_add"));
    auto text_min_add = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_min_add"));
    text_max_add->setString(tools::local_string("max_buy", "最多可添加"));
    text_min_add->setString(tools::local_string("min_buy", "最少可添加"));
    
    text_min_number_ = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_min_number"));
    text_max_number_ = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_max_number"));
    text_buy_number_ = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_buy_number"));
    
    auto btn_cancel = dynamic_cast<Button *>(CSLoader::seekNodeByName(root, "btn_cancel"));
    auto btn_confirm = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_confirm"));
    btn_cancel->addClickEventListener(std::bind(&BuyChipLayer::click_btn_cancel, this, std::placeholders::_1));
    btn_confirm->addClickEventListener(std::bind(&BuyChipLayer::click_btn_confirm, this, std::placeholders::_1));
    btn_cancel->setTitleText(tools::local_string("cancel","取消"));
    btn_confirm->setTitleText(tools::local_string("confirm_change_password","确定"));
    
    auto btn_add = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_add"));
    auto btn_sub = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_sub"));
    
    btn_add->addClickEventListener(std::bind(&BuyChipLayer::click_btn_add, this, std::placeholders::_1));
    btn_sub->addClickEventListener(std::bind(&BuyChipLayer::click_btn_sub, this, std::placeholders::_1));
    
    slider_chip_ = dynamic_cast<Slider*>(CSLoader::seekNodeByName(root, "slider_chip"));
    slider_chip_->addEventListener(std::bind(&BuyChipLayer::slider_slider_chip, this, std::placeholders::_1, std::placeholders::_2));
    
    return true;
}
Beispiel #9
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;
}
Beispiel #10
0
Layout* UI::createLayout(int i){
    auto lo=Layout::create();
    lo->setBackGroundImage("HelloWorld.png");
    lo->setBackGroundImageScale9Enabled(true);
    lo->setContentSize(Size(480,320)*1.5);
    for (int i=0; i<5; i++) {
        for (int j=0; j<7; j++) {
            auto ub=Button::create();
            ub->loadTextureNormal("editBG.png");
            ub->loadTexturePressed("editBG.png");
            ub->loadTextureDisabled("editBg.png");
            ub->setScale9Enabled(true);
            ub->setContentSize(Size(100,50));
            ub->setPressedActionEnabled(true);
            ub->setZoomScale(0.5f);
            ub->setTitleFontName("fonts/Marker Felt.ttf");
            ub->setTitleFontSize(30);
            ub->setTitleColor(Color3B::GREEN);
            ub->setTitleText(StringUtils::format("%d--%d",i,j));
            ub->addClickEventListener(CC_CALLBACK_1(UI::buttonClick, this));
            ub->setTag(i);
            ub->setPosition(Vec2(70+120*i, 35+j*60));
            lo->addChild(ub);
        }
    }
    return lo;
}
Beispiel #11
0
bool Card::initCard(Vec2 pos, Node *parent) {
	this->setPosition(pos);

	auto rootNode = CSLoader::createNode(CARD_CSB_NAME);
	this->addChild(rootNode);
	auto action = CSLoader::createTimeline(CARD_CSB_NAME);
	rootNode->runAction(action);
	action->gotoFrameAndPlay(0);

	auto image = rootNode->getChildByName<Sprite *>(CARDIMAGE);
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile(CARD_PLIST_NAME);
	auto cardID = (int)(CCRANDOM_0_1() * 2);
	auto cardName = CsvUtil::getInstance()->getValueForCard(cardID, CARD_CSV_NAME).asString();
	image->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(StringUtils::format("%s.png", cardName.c_str())));

	auto button = rootNode->getChildByName<Button *>(CARDTOUCH_BUTTON);
	button->addClickEventListener([=](Ref *ref) {
		if (DATAOPERATOR->getEffectEnable())
			AUDIOENGINE->playEffect(CLICKEFFECT_NAME);
		this->removeFromParent();
		auto click = ParticleSystemQuad::create(CARD_PARTICLE_NAME);
		click->setPosition(pos);
		parent->addChild(click);

		NotificationCenter::getInstance()->postNotification(cardName);
	});

	return true;
}
Beispiel #12
0
bool ShopLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}

	this->initWithColor(Color4B(0, 0, 0, 100));

	_shopLayer = CSLoader::createNode("ShopLayer.csb");
	auto frameSize = Director::getInstance()->getVisibleSize();
	_shopLayer->setContentSize(frameSize);
	ui::Helper::doLayout(_shopLayer);
	addChild(_shopLayer);

	auto goldLabel = Label::createWithCharMap("white_font.png", 25, 29, '0');
	CCLOG("bestLabel %d", UserData::getInstance()->getBestScore());
	goldLabel->setString(StringUtils::format("%d", UserData::getInstance()->getGold()));
	this->addChild(goldLabel);
	goldLabel->setPosition(370.0f, 210.0f);

	buyGold();

	auto buttonReturn = (ui::Button*)((Sprite*)_shopLayer->getChildByTag(40))->getChildByTag(50);
	buttonReturn->addClickEventListener(CC_CALLBACK_1(ShopLayer::menuReturnCallBack, this));

	return true;
}
Beispiel #13
0
void OverLayer::addLayer()
{

	this->setDJ(DiscJockey::getInstance());

	Node *optionNode = CSLoader::createNode("overNode.csb");//传入Studio2.x的资源路径
	optionNode->setPosition(Point(originPoint.x + visibleSize.width / 2, (originPoint.y + visibleSize.height / 2)));
	this->addChild(optionNode);


	this->setAnchorPoint(Point(0.5, 0.5));
	this->ignoreAnchorPointForPosition(false);
	this->setPosition(Point(originPoint.x + visibleSize.width / 2, -(originPoint.y + visibleSize.height / 2)));


	auto eventListener = EventListenerTouchOneByOne::create();
	eventListener->setSwallowTouches(true);
	eventListener->onTouchBegan = CC_CALLBACK_2(OverLayer::onTouchBegan, this);
	eventListener->onTouchCancelled = CC_CALLBACK_2(OverLayer::onTouchCancelled, this);
	eventListener->onTouchEnded = CC_CALLBACK_2(OverLayer::onTouchEnded, this);
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(eventListener, this);

	auto buttonNode = dynamic_cast<Node*>(optionNode->getChildByName("overNode"));
	auto restartButton = dynamic_cast<ui::Button*> (buttonNode->getChildByName("restartButton"));
	if (restartButton)
	{
		restartButton->addClickEventListener(CC_CALLBACK_1(OverLayer::restart, this));
	}

}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    _coin = 0;

    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }

    FileUtils::getInstance()->addSearchPath("res");

    sdkbox::PluginAdColony::init();
    sdkbox::PluginAdColony::setListener(this);

    auto rootNode = CSLoader::createNode("MainScene.csb");
    addChild(rootNode);

    _btnVideo = rootNode->getChildByName<ui::Button*>("btnVideo");
    _btnVideo->addClickEventListener(CC_CALLBACK_1(HelloWorld::onPlayVideo, this));
    _btnVideo->setBright(false);

    _btnReward = rootNode->getChildByName<ui::Button*>("btnReward");
    _btnReward->addClickEventListener(CC_CALLBACK_1(HelloWorld::onPlayReward, this));
    _btnReward->setBright(false);

    _txtCoin = rootNode->getChildByName<ui::Text*>("txtCoins");

    auto btnClose = rootNode->getChildByName<ui::Button*>("btnClose");
    btnClose->addClickEventListener(CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));

    return true;
}
Beispiel #15
0
bool UIButtonTextOnly::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        // Add a label in which the button events will be displayed
        _displayValueLabel = Text::create("Text Only Button", "fonts/Marker Felt.ttf",32);
        _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
        _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
        _uiLayer->addChild(_displayValueLabel);
        
        
        // Create the button
        auto button = Button::create();
        button->setNormalizedPosition(Vec2(0.5f, 0.5f));
       
        button->setTitleText("PLAY GAME");
        CCLOG("content size should be greater than 0:  width = %f, height = %f", button->getContentSize().width,
              button->getContentSize().height);
        button->setZoomScale(0.3f);
        button->setPressedActionEnabled(true);
        button->addClickEventListener([this](Ref* sender) {
            CCLOG("clicked!");
        });
        _uiLayer->addChild(button);
        
        return true;
    }
    return false;
}
Beispiel #16
0
bool CMainScene::init()
{
	IBaseScene::init();
	Node* pRoot = CSLoader::getInstance()->createNodeWithFlatBuffersFile("res/playerData.csb");
	addChild(pRoot);
	auto cSize = pRoot->getContentSize();
	pRoot->setContentSize(Director::getInstance()->getWinSize()) ;
	ui::Helper::doLayout(pRoot);

	m_pName = (ui::Text*)pRoot->getChildByName("name");
	m_pCoin = dynamic_cast<ui::Text*>(pRoot->getChildByName("coin"));
	m_pID = (ui::Text*)pRoot->getChildByName("id");

	auto pBtn = (ui::Button*)pRoot->getChildByName("Button_1");
	pBtn->addClickEventListener([=](Ref*){
		//cocos2d::MessageBox("send enter room msg","tip");
		stMsgTaxasEnterRoom msgEnterRoom ;
		//msgEnterRoom.nLevel = 0 ;
		msgEnterRoom.nRoomID = 1 ;
		//msgEnterRoom.nType = 0 ;
		sendMsg(&msgEnterRoom,sizeof(msgEnterRoom)) ;
	});

	m_pCoin->setString(String::createWithFormat("%d",CClientApp::getInstance()->getPlayerData()->nCoin)->getCString()) ;
	m_pID->setString(String::createWithFormat("%d",CClientApp::getInstance()->getPlayerData()->nUserUID)->getCString()) ;
	//m_pCoin->setString(String::createWithFormat("%d",CClientApp::getInstance()->getPlayerData()->nCoin)->getCString()) ;
	m_pName->setString(CClientApp::getInstance()->getPlayerData()->cName);
	return true ;
}
Beispiel #17
0
void AchievementUI::LoadFinish()
{
    MsgListNode::getInstance()->LoadMsg(m_RootWidget);
    
    auto layout_title = m_RootWidget->getChildByName<Layout*>("Layout_Title");
    
    auto btn_Left = layout_title->getChildByName<Button*>("Btn_Left");
    
    btn_Left->addClickEventListener([this](Ref* sender)
    {
        this->UnLoad();
        auto scene = BattlePubScene::createScene();
        Director::getInstance()->replaceScene(CCTransitionMoveInL::create(0.18f, scene));
    });
    
    UIUtils::getInstance()->addSlideEvent(m_RootWidget,
                                          [this]()
                                          {
                                              this->UnLoad();
                                              auto scene = BattlePubScene::createScene();
                                              Director::getInstance()->replaceScene(CCTransitionMoveInL::create(0.18f, scene));
                                          },
                                          nullptr
                                          );
}
bool SimplePage::initWithIndex(int newIndex)
{
    if(!Node::init())
        return  false;

    setName("secondPage");
    
    auto visibleSize=Director::getInstance()->getVisibleSize();
    auto rootNode= CSLoader::createNode("simplePage.csb");
    rootNode->setPosition(visibleSize/2);
    addChild(rootNode);
    
    auto listView=rootNode->getChildByName<ui::ListView *>("listView");
    
    const auto& data=CSVGlobalConfig::getInstance()->data;
    for(const auto& lineData : data)
    {
        auto buttonTitle=lineData[0];
        
        auto button=ui::Button::create("button.png");
        button->setScale9Enabled(true);
        button->setTitleFontSize(25);
        button->setContentSize(Size( 300,30));
        button->setTitleText(buttonTitle);
        button->addClickEventListener(CC_CALLBACK_1(SimplePage::onButtonClickCallBack, this));
        listView->pushBackCustomItem(button);
    }
    
    return true;
}
Beispiel #19
0
// on "init" you need to initialize your instance
bool GameOver::init()
{

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

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

	//Ìí¼Ó±³¾°
	auto background = Sprite::create("map/end_bg.jpg");
	background->setPosition(visibleSize.width / 2, visibleSize.height / 2);
	addChild(background, 0);

	string a = Global::getWinner();
	a = a + " Win";
	auto field = Label::create(a, "fonts/pan.ttf", 70);
	field->setColor(ccc3(51, 63, 80));
	field->setPosition(Size(visibleSize.width / 2, visibleSize.height / 4 * 3 - 20));
	this->addChild(field, 2);

	//restart
	auto start_button = Button::create();
	start_button->setTitleText("Restart");
	start_button->setTitleFontSize(60);
	start_button->setTitleFontName("fonts/pan.ttf");
	start_button->setColor(ccc3(132, 60, 12));
	start_button->setPosition(Size(visibleSize.width / 2, visibleSize.height / 4 - 20));
	start_button->addClickEventListener(CC_CALLBACK_1(GameOver::menuChangeCallback, this));
	this->addChild(start_button, 2);
	
	return true;
}
Beispiel #20
0
bool UIButtonIgnoreContentSizeTest::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        // Add a label in which the button events will be displayed
        _displayValueLabel = Text::create("Button IgnoreContent Size Test", "fonts/Marker Felt.ttf",32);
        _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
        _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
        _uiLayer->addChild(_displayValueLabel);
        
        
        // Create the button
        auto button = Button::create("cocosui/animationbuttonnormal.png",
                                     "cocosui/animationbuttonpressed.png");
        button->ignoreContentAdaptWithSize(false);
        button->setContentSize(Size(200,100));
        button->setNormalizedPosition(Vec2(0.3f, 0.5f));
        button->setTitleText("PLAY GAME");
        button->setZoomScale(0.3f);
        button->setPressedActionEnabled(true);
        button->addClickEventListener([=](Ref* sender) {
            CCLOG("clicked!");
            button->setScale(1.2f);
        });
        _uiLayer->addChild(button);
        
        // Create the button
        auto button2 = Button::create("cocosui/animationbuttonnormal.png",
                                     "cocosui/animationbuttonpressed.png");
        button2->ignoreContentAdaptWithSize(false);
        button2->setContentSize(Size(200,100));
        button2->setNormalizedPosition(Vec2(0.8f, 0.5f));
        button2->setTitleText("PLAY GAME");
        button2->setZoomScale(0.3f);
        button2->setPressedActionEnabled(true);
        button2->addClickEventListener([=](Ref* sender) {
            button2->runAction(ScaleTo::create(1.0f, 1.2f));
            CCLOG("clicked!");
        });
        _uiLayer->addChild(button2);
        
        return true;
    }
    return false;
}
Beispiel #21
0
bool SelectScene::init() {
	if (!Layer::init()) return false;

	if (DATAOPERATOR->getMusicEnable())
		AUDIOENGINE->playBackgroundMusic(MENUSCENE_BGM_NAME, true);

	auto rootNode = CSLoader::createNode(SELECTSCENE_CSB_NAME);
	this->addChild(rootNode);

	_jewel = rootNode->getChildByName<Text *>(JEWELTEXT);
	_gold = rootNode->getChildByName<Text *>(GOLDTEXT);
	_jewel->setFontName(TEXTFONT_NAME);
	_gold->setFontName(TEXTFONT_NAME);
	this->updateLabel();

	_bowLayer = rootNode->getChildByName(BowSELECTLAYER);
	_levelLayer = rootNode->getChildByName(LEVELSELECTLAYER);
	_levelLayer->setPosition(Vec2(0, 800));
	this->initBowLayer();
	this->initLevelLayer();

	auto levelSelectButton = rootNode->getChildByName<Button *>(LEVELSELECTBUTTON);
	levelSelectButton->addClickEventListener([=](Ref *ref) {
		if (DATAOPERATOR->getEffectEnable())
			AUDIOENGINE->playEffect(CLICKEFFECT_NAME);
		_levelLayer->setPosition(Vec2(0, 0));
		_levelLayer->setVisible(true);
		_levelLayer->onEnter();
		_bowLayer->onExit();
	});

	auto closeButton = rootNode->getChildByName<Button *>(CLOSE);
	closeButton->addClickEventListener([](Ref *ref) {
		if (DATAOPERATOR->getEffectEnable())
			AUDIOENGINE->playEffect(CLICKEFFECT_NAME);
		DIRECTOR->replaceScene(MenuScene::createScene());
	});

	auto continueButton = rootNode->getChildByName<Button *>(CONTINUE);
	continueButton->addClickEventListener([](Ref *ref) {
		if (DATAOPERATOR->getEffectEnable())
			AUDIOENGINE->playEffect(CLICKEFFECT_NAME);
		//Çл»µ½×îйؿ¨
		DIRECTOR->replaceScene(GameScene::createScene(DATAOPERATOR->getUnlockLevel()));
	});
	return true;
}
Beispiel #22
0
bool TournamentBuyChipLayer::init()
{
    if(!Layer::init()) {
        return false;
    }
    
    auto root = CSLoader::createNode("LayerTourmentBuyChip.csb");
    this->addChild(root);
    auto btn_cancel = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_cancel"));
    auto btn_confirm = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_confirm"));
    btn_cancel->addClickEventListener(std::bind(&TournamentBuyChipLayer::click_btn_cancel, this, std::placeholders::_1));
    btn_confirm->addClickEventListener(std::bind(&TournamentBuyChipLayer::click_btn_confirm, this, std::placeholders::_1));
    
    text_buyin_ = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_buy_chip"));

    return true;
}
Beispiel #23
0
bool Game::init()
{
    if (!Layer::init()) {
        return false;
    }
    auto size = Director::getInstance()->getVisibleSize();
    
    auto layerColor = LayerColor::create(Color4B(200, 150, 100, 200));
    addChild(layerColor);
    
    //标题
    auto titleLabel = Label::createWithTTF("2048 Game","fonts/Marker Felt.ttf",70);
    titleLabel->setColor(Color3B(200, 250, 100));
    titleLabel->setPosition(Vec2(size.width/2,size.height/2+550));
    auto letter = titleLabel->getLetter(1);
    auto letter1 = titleLabel->getLetter(3);
    auto rote = RepeatForever::create(RotateBy::create(1, 180));
    auto rote1 = RepeatForever::create(RotateBy::create(1, 180));
    letter->runAction(rote);
    letter1->runAction(rote1);//设置字体旋转
    addChild(titleLabel);
    
    auto Label = Label::createWithTTF("score:", "fonts/arial.ttf", 50);
    Label->setColor(Color3B::BLUE);
    Label->setPosition(Vec2(80,size.height/2+450));
    addChild(Label);
    
    char t[10];
    score=0;
    sprintf(t,"%d",score);
    scoreLabel = Label::createWithTTF(t, "fonts/Marker Felt.ttf", 40);
    scoreLabel->setColor(Color3B::BLUE);
    scoreLabel->setPosition(Vec2(170,size.height/2+450));
    addChild(scoreLabel);
    
    auto newGame = Label::createWithTTF("new Game", "fonts/Marker Felt.ttf",50);
    newGame->setColor(Color3B::GRAY);
    newGame->setPosition(Vec2(110,size.height/2+380));
    addChild(newGame);
    
    auto bt = Button::create("buttonreplay.png");
    bt->setPosition(Vec2(260,size.height/2+380));
    bt->addClickEventListener(CC_CALLBACK_0(Game::restart, this));
    addChild(bt);
    
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan=CC_CALLBACK_2(Game::onTouchBegan, this)
    ;
    listener->onTouchEnded=CC_CALLBACK_2(Game::onTouchEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    
    createCard();
    createCardNumber();
    createCardNumber();
    return true;
}
Beispiel #24
0
void UIUtils::fillWithBatchesBuyLayout(UIBase* uiBase, int cfgId)
{
    auto rootNode = uiBase->m_RootWidget;
    
    auto addedLayout = rootNode->getChildByName<cocos2d::ui::Layout *>("Layout_Confirm");
    if (!addedLayout) {
        return;
    }
    addedLayout->setVisible(true);
    
    auto btn_buy10 = addedLayout->getChildByName<cocos2d::ui::Button *>("Btn_Buy1");
    auto btn_buy100 = addedLayout->getChildByName<cocos2d::ui::Button *>("Btn_Buy2");
    auto btn_buy1000 = addedLayout->getChildByName<cocos2d::ui::Button *>("Btn_Buy3");
    auto btn_close = addedLayout->getChildByName<cocos2d::ui::Button *>("Btn_Cancel");
    
    btn_buy10->addClickEventListener(
                                     [=](Ref* sender)
                                     {
                                         handleBuy(cfgId, 10, uiBase);
                                         addedLayout->setVisible(false);
                                     });

    btn_buy100->addClickEventListener(
                                     [=](Ref* sender)
                                     {
                                         handleBuy(cfgId, 100, uiBase);
                                         addedLayout->setVisible(false);
                                     });
    
    btn_buy1000->addClickEventListener(
                                     [=](Ref* sender)
                                     {
                                         handleBuy(cfgId, 1000, uiBase);
                                         addedLayout->setVisible(false);
                                     });
    
    btn_close->addClickEventListener(
                                    [=](Ref* sender)
                                     {
                                         addedLayout->setVisible(false);
                                     });
    
}
void FittingLayer::setOnBackButtonClickedCallback(const Callback& callback)
{
	auto backButton = dynamic_cast<cocos2d::ui::Button*>(this->getChildByName(BACK_BUTTON));
	assert(backButton != nullptr);
	backButton->addClickEventListener([callback](cocos2d::Ref* pRef)
	{
		if (callback != nullptr)
			callback();
	});
}
Button* OptionScene::createButton(std::string text, Size size, std::function<void(Ref*)> callback)
{
	auto button = Button::create("UI/ButtonNormal.png", "UI/ButtonSelected.png");
	button->setTitleText(text);
	button->setTitleFontName(MyCreator::normalFont);
	button->setTitleColor(Color3B::BLACK);
	button->setTitleFontSize(30);
	button->addClickEventListener(callback);
	button->setScale9Enabled(true);
	button->setContentSize(size);
	return button;
}
Beispiel #27
0
void OptionLayer::addOption()
{

	this->setDJ(DiscJockey::getInstance());

	Node *optionNode = CSLoader::createNode("optionNode.csb");//传入Studio2.x的资源路径
	optionNode->setPosition(Point(originPoint.x + visibleSize.width / 2, (originPoint.y + visibleSize.height / 2)));
	this->addChild(optionNode);
	optionNode->setName("optionNode");

	this->setAnchorPoint(Point(0.5, 0.5));
	this->ignoreAnchorPointForPosition(false);
	this->setPosition(Point(originPoint.x + visibleSize.width / 2, -(originPoint.y + visibleSize.height / 2)));


	auto eventListener = EventListenerTouchOneByOne::create();
	eventListener->setSwallowTouches(true);
	eventListener->onTouchBegan = CC_CALLBACK_2(OptionLayer::onTouchBegan, this);
	eventListener->onTouchCancelled = CC_CALLBACK_2(OptionLayer::onTouchCancelled, this);
	eventListener->onTouchEnded = CC_CALLBACK_2(OptionLayer::onTouchEnded, this);
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(eventListener, this);

	auto cancelButton = dynamic_cast<ui::Button*> (optionNode->getChildByName("cancelButton"));
	if (cancelButton)
	{
		cancelButton->addClickEventListener(CC_CALLBACK_1(OptionLayer::cancel, this));
	}

	//set font name again due to the cocos studio 2.0 bugs (Text load ttf error)
	for (auto node : optionNode->getChildren())
	{
		auto textNode = dynamic_cast<ui::Text*>(node);
		if (textNode)
		{
			textNode->enableOutline(Color4B(25, 26, 25, 155), 2);
		}
	}

	auto musicBox = dynamic_cast<ui::CheckBox*>(optionNode->getChildByName("soundCheck"));
	musicBox->addEventListenerCheckBox(this, checkboxselectedeventselector(OptionLayer::musicCheckBoxCallback));
	auto effectBox = dynamic_cast<ui::CheckBox*>(optionNode->getChildByName("effectCheck"));
	effectBox->addEventListenerCheckBox(this, checkboxselectedeventselector(OptionLayer::effectCheckBoxCallback));
	musicBox->setSelectedState(getDJ()->isMusicOn());
	effectBox->setSelectedState(getDJ()->isEffectOn());

	int curSpeed = CommandCenter::getInstance()->getSpeedLevel();
	auto textNode = dynamic_cast<ui::Text*>(optionNode->getChildByName("textCurSpeed"));
	textNode->setText(String::createWithFormat("%d", curSpeed)->getCString());
	auto speedSlider = dynamic_cast<ui::Slider*>(optionNode->getChildByName("speedSlider"));
	speedSlider->addEventListenerSlider(this, sliderpercentchangedselector(OptionLayer::speedSliderCallback));
	speedSlider->setPercent(curSpeed * 10);
}
Beispiel #28
0
bool Dialog::init() {
    if (not Super::init()) {
        return false;
    }

    transitionAction_ = cocos2d::Node::create();
    transitionAction_->setVisible(false);
    addProtectedChild(transitionAction_);

    setActive(false);
    addClickEventListener(CC_CALLBACK_0(Self::onPressed, this));
    return true;
}
void BackLayer::initUI()
{
	auto start_btn = ui::Button::create("back.png");
	if (start_btn)
	{
		m_popNode->addChild(start_btn);
		//start_btn->setTag(99);
		//start_btn->setPosition(CommonFunction::getVisibleAchor(Anchor::Center, Vec2(0, 0)));
		start_btn->addClickEventListener([=](Ref*){
		Director::getInstance()->replaceScene(TransitionFade::create(0.5, WelcomeScene::createScene()));
	});
	}
}
Beispiel #30
0
void Operator_Layer::set_callbacks(Root_Node_Type * node)
{
	 Widget* root = static_cast<Widget*>(node);
  {
    std::string node_name ="Button_Exit_App";
    auto node = static_cast<Button*> (Helper::seekWidgetByName(root, node_name));
    if (node)
    {
      node->addClickEventListener(CC_CALLBACK_1(Self::on_app_exit, this));
      
    }
  }
  {
    std::string node_name ="Button_Lobby";
    auto node = static_cast<Button*> (Helper::seekWidgetByName(root, node_name));
    if (node)
    {
      node->addClickEventListener(CC_CALLBACK_1(Self::on_lobby, this));
      
    }
  }
  
}