Beispiel #1
0
bool MainMenu::init(void)
{
    if ( !Layer::init() )
    {
        return false;
    }

	_uiLayer = Layer::create();
	_uiLayer->setPosition(Point(D_display.getLeftBottom()));
	addChild(_uiLayer);

	auto spBg = Sprite::create("images/mainmenu_bg.jpg");
	spBg->setPosition(D_display.getCenterPoint());
	_uiLayer->addChild(spBg);


	auto btnStart = Button::create();
    btnStart->setTouchEnabled(true);
    btnStart->loadTextures("images/btn_start.png", "", "");
	btnStart->setPosition(Point(D_display.cx, D_display.cy+43));
	btnStart->setTag(1);
    btnStart->addTouchEventListener(this, toucheventselector(MainMenu::touchEvent));
    _uiLayer->addChild(btnStart);

	auto btnExit = Button::create();
    btnExit->setTouchEnabled(true);
    btnExit->loadTextures("images/btn_exit.png", "", "");
	btnExit->setPosition(Point(D_display.cx, D_display.cy-43));
    btnExit->addTouchEventListener(this, toucheventselector(MainMenu::touchEvent));
	btnExit->setTag(2);
    _uiLayer->addChild(btnExit); 

	return true;
}
void MenuScene::addUI()
{
	auto bg = cocostudio::GUIReader::getInstance()->widgetFromJsonFile("MenuUI/MenuUI.ExportJson");
	this->addChild(bg);

	// play button
	auto btnPlay = (Button*)Helper::seekWidgetByName(bg, "BtnPlay");
	btnPlay->addTouchEventListener(CC_CALLBACK_2(MenuScene::turnToGameScene, this));

	// options button
	auto btnOptions = (Button*)Helper::seekWidgetByName(bg, "BtnOptions");
	btnOptions->addTouchEventListener(CC_CALLBACK_2(MenuScene::turnToOptionsScene, this));

	// about button
	auto btnAbout = (Button*)Helper::seekWidgetByName(bg, "BtnAbout");
	btnAbout->addTouchEventListener(CC_CALLBACK_2(MenuScene::turnToAboutScene, this));

	// quit button
	auto btnQuit = (Button*)Helper::seekWidgetByName(bg, "BtnQuit");
	btnQuit->addTouchEventListener(CC_CALLBACK_2(MenuScene::quit, this));

	// record
	auto textScore = (TextBMFont*)Helper::seekWidgetByName(bg, "Score");
	double score = UserDefault::getInstance()->getDoubleForKey("Record", 0.000);
	char s[50];
	sprintf(s, "%.3f", score);
	textScore->setString(s);
}
Beispiel #3
0
void Transmigration::onEnter()
{
    Layer::onEnter();
    
    Size size = Director::getInstance()->getVisibleSize();
    setContentSize(size);
    ui::Helper::doLayout(this);
    
    _updateLocalization();

    auto menu = getChildByName("menu");
    auto yes = menu->getChildByName<ui::Button*>("yesButton");
    yes->addTouchEventListener(CC_CALLBACK_2(Transmigration::_pushYesButton, this));
    auto no = menu->getChildByName<ui::Button*>("noButton");
    no->addTouchEventListener(CC_CALLBACK_2(Transmigration::_pushNoButton, this));

    _getDiamondNum = menu->getChildByName<ui::TextBMFont*>("getDiamondNum");
    _getDiamondNum->setString(StringUtils::format("x %d", WorldManager::getInstance()->getDiamondNumInTransmigration()));
    
    // タッチイベントの設定
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    listener->onTouchBegan = CC_CALLBACK_2(Transmigration::onTouchBegan, this);
    dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
// 加载UI
void GameOverScene::addUI()
{
	this->bg = (Layout*)cocostudio::GUIReader::getInstance()->widgetFromJsonFile("GameOverUI/GameOverUI.ExportJson");
	this->addChild(this->bg);

	// again button
	auto btnAgain = (Button*)Helper::seekWidgetByName(bg, "BtnAgain");
	btnAgain->addTouchEventListener(CC_CALLBACK_2(GameOverScene::turnToGameScene, this));

	// back button
	auto btnBack = (Button*)Helper::seekWidgetByName(bg, "BtnBack");
	btnBack->addTouchEventListener(CC_CALLBACK_2(GameOverScene::turnToMenuScene, this));

	// 新分数
	this->text =(TextBMFont*) ui::Helper::seekWidgetByName(this->bg, "NewScore");
	char str[50];
	sprintf(str, "%.3f", this->score);
	this->text->setString(str);

	// 历史记录
	auto rd = (TextBMFont*)ui::Helper::seekWidgetByName(this->bg, "Score");
	char s[50];
	sprintf(s, "%.3f", this->record);
	rd->setString(s);

	// New Logo --> New_IMG
	this->image = (ImageView*)ui::Helper::seekWidgetByName(this->bg, "New_IMG");
	this->image->setVisible(false);
	this->image->setScale(0.0);
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
//    auto bg = Sprite::createWithSpriteFrameName("bg.png");
//    bg->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
//    this->addChild(bg);
    
//    auto panel = Sprite::create("panel.png");
//    panel->setPosition(bg->getPosition());
//    panel->setScaleX(1.5);
//    panel->setScaleY(2);
//    this->addChild(panel);
    
    float margin = 40.0f;
    
    auto appname = cocos2d::ui::Text::create(LHLocalizedCString("appname"), Common_Font, 50);
    appname->setColor(Color3B::BLACK);
    appname->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + appname->getContentSize().height/2 + margin + origin.y));
    this->addChild(appname);
    
    auto play = ui::Button::create("play.png");
    play->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 - play->getContentSize().height/2 - margin + origin.y));
    play->addTouchEventListener([](Ref *ps,ui::Widget::TouchEventType type){
        if (type == ui::Widget::TouchEventType::ENDED) {
            Director::getInstance()->replaceScene(PlayScene::createScene(nullptr));
        }
    });
    this->addChild(play);
    
    auto debt = DeveloperInfo::DevInfoButton("devinfo.png");
    debt->setPosition(Vec2(appname->getPositionX() + appname->getContentSize().width/2 + 40, appname->getPositionY() + appname->getContentSize().height/2 + 20));
    this->addChild(debt);
    
    auto leader = LHLeaderBoard::defaultButton("lb.png");
    leader->setPosition(Vec2(visibleSize.width/3*2 + origin.x, visibleSize.height/4 + origin.y));
    this->addChild(leader);
    
    auto goReview = ui::Button::create("goreview.png");
    goReview->setPosition(Vec2(visibleSize.width/3 + origin.x, visibleSize.height/4 + origin.y));
    goReview->addTouchEventListener([](Ref *ps,ui::Widget::TouchEventType type){
        if (type == ui::Widget::TouchEventType::ENDED) {
            ThirdPartyHelper::goReview();
        }
    });
    this->addChild(goReview);
    
    return true;
}
Beispiel #6
0
void InfoLikeBox::setUI()
{
    if(_bIsLike)
    {
        auto button = ui::Button::create("Info_LikeButtonUp_Selected-hd.png", "Info_LikeButtonDown-hd.png");
        button->setPosition(ratioPosition(50, 51.5f));
        button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type) {
            switch (type)
            {
            case ui::Widget::TouchEventType::BEGAN:
                break;
            case ui::Widget::TouchEventType::ENDED:
                likeButtonCallBack(sender);
                break;
            default:
                break;
            }
        });

        auto buttonState = setLabelSystemTTFUnAdd("LIKE", 30, Vec2(button->getContentSize()/2));
        buttonState->setColor(Color3B::WHITE);
        buttonState->setTag(TAG_BUTTON_STATE);
        button->addChild(buttonState);

        addChild(button);
    }
    else
    {
        auto button = ui::Button::create("Info_LikeButtonUp_Normal-hd.png", "Info_LikeButtonDown-hd.png", "Info_LikeButtonDown-hd.png");
        button->setPosition(ratioPosition(50, 51.5f));
        button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type) {
            switch (type)
            {
            case ui::Widget::TouchEventType::BEGAN:
                break;
            case ui::Widget::TouchEventType::ENDED:
                likeButtonCallBack(sender);
                break;
            default:
                break;
            }
        });

        auto buttonState = setLabelSystemTTFUnAdd("LIKE IT!!", 30, Vec2(button->getContentSize()/2));
        buttonState->setColor(Color3B::BLACK);
        buttonState->setTag(TAG_BUTTON_STATE);
        button->addChild(buttonState);

        addChild(button);
    }
}
void BattleHudLayer::showUI()
{
    auto ui = GUIReader::getInstance()->widgetFromJsonFile(UI_DIALOG_BATTLEHUD);
    this->addChild(ui, 0, "UI");
    
    // select
    auto btn0 = (Button*)Helper::seekWidgetByName(ui, "Button0");
    auto btn1 = (Button*)Helper::seekWidgetByName(ui, "Button1");
    auto btn2 = (Button*)Helper::seekWidgetByName(ui, "Button2");
    auto btn3 = (Button*)Helper::seekWidgetByName(ui, "Button3");
    auto btn4 = (Button*)Helper::seekWidgetByName(ui, "Button4");
    btn0->addTouchEventListener(CC_CALLBACK_2(BattleHudLayer::selectCallback, this));
    btn1->addTouchEventListener(CC_CALLBACK_2(BattleHudLayer::selectCallback, this));
    btn2->addTouchEventListener(CC_CALLBACK_2(BattleHudLayer::selectCallback, this));
    btn3->addTouchEventListener(CC_CALLBACK_2(BattleHudLayer::selectCallback, this));
    btn4->addTouchEventListener(CC_CALLBACK_2(BattleHudLayer::selectCallback, this));
    btn0->setBright(true);
    btn1->setBright(false);
    btn2->setBright(false);
    btn3->setBright(false);
    btn4->setBright(false);
    _select = 0;
    
    // skill
    auto skill1 = (Button*)Helper::seekWidgetByName(ui, "Skill1");
    auto skill2 = (Button*)Helper::seekWidgetByName(ui, "Skill2");
    skill1->addTouchEventListener(CC_CALLBACK_2(BattleHudLayer::skillCallback, this));
    skill2->addTouchEventListener(CC_CALLBACK_2(BattleHudLayer::skillCallback, this));
    
    // retreat
    auto retreat = (Button*)Helper::seekWidgetByName(ui, "RetreatButton");
    retreat->addTouchEventListener(CC_CALLBACK_2(BattleHudLayer::retreatCallback, this));

    showInfo();
}
Beispiel #8
0
void EstimatePlace::setSecondSelect()
{
    Vector<__String*> vInfo = setSecondSelectListInfo();
    if(_vSecondButton.size() > 0) _vSecondButton.clear();
    
    for(int i = 0 ; i < vInfo.size(); i++)
    {
        auto button = ui::Button::create("UI_TopMenuBG-hd.png");
        button->setBright(true);
        button->setZoomScale(0.1f);
        button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type){
            switch (type)
            {
                case ui::Widget::TouchEventType::BEGAN:
                    break;
                case ui::Widget::TouchEventType::ENDED:
                    
                    SecondbuttonCallBack(sender);
                    break;
                default:
                    break;
            }
        });
        
        _vSecondButton.pushBack(button);
        
        setTypeLabel(1, vInfo.at(i)->getCString());
    }
}
Beispiel #9
0
void EstimatePlace::setFirstSelect()
{
    for(int i=0;i<3;i++)
    {
        auto button = ui::Button::create("UI_TopMenuBG-hd.png");
        button->setBright(true);
        button->setZoomScale(0.1f);
        button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type){
            switch (type)
            {
                case ui::Widget::TouchEventType::BEGAN:
                    break;
                case ui::Widget::TouchEventType::ENDED:
                    
                    buttonCallBack(sender);
                    break;
                default:
                    break;
            }
        });
        
        _vFirstButton.pushBack(button);
        
        setTypeLabel(0, i==0 ? "주거공간": i==1? "상업공간": "사무공간");
    }
}
Beispiel #10
0
void UIStorageScene::setTrashCan(Point position)
{
    auto button = ui::Button::create("Storage_TrashUp-hd.png", "Storage_TrashDown-hd.png", "Storage_TrashDown-hd.png");
    button->setPosition(position);
//    button->setScale(0.8f);
    button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type){
        switch (type)
        {
            case ui::Widget::TouchEventType::BEGAN:
                break;
            case ui::Widget::TouchEventType::ENDED:
                
                if(!_bReadyToRemove)
                {
                    setTrashImage();
                }
                else if(_bReadyToRemove)
                {
                    removeTrashImage();
                }
                break;
            default:
                break;
        }
    });
    this->addChild(button);
}
bool TrialPanel::init()
{
    for(auto node:_buttons->getChildren())
    {
        auto button = static_cast<Button*>(node);
        button->addTouchEventListener(CC_CALLBACK_2(TrialPanel::onButtonClicked, this));
    }
    _container->setTouchEnabled(true);
    _container->setAnchorPoint(Vec2(0,0));
    _listView = static_cast<ListView*>(Helper::seekWidgetByName(_root, "ListView_content"));

    _achieveUnit = static_cast<Layout*>(Helper::seekWidgetByName(_root, "Panel_achieveUnit"));
    _achieveUnit->retain();
    _achieveUnit->removeFromParent();

    _listView->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(TrialPanel::selectedItemEvent, this));
    _listView->addEventListener((ui::ListView::ccScrollViewCallback)CC_CALLBACK_2(TrialPanel::selectedItemEventScrollView,this));

    _container->setScale(0.85f);
    _container->setOpacity(200);
    _container->runAction(FadeIn::create(0.2));
    _container->runAction(ScaleTo::create(0.2,1.0f,1.0f,1.0f));

    _root->setTouchEnabled(true);
    _container->setTouchEnabled(false);
    _root->addTouchEventListener(CC_CALLBACK_2(TrialPanel::onButtonClicked, this));
    setKeyboardEnabled(true);
    return true;
}
Beispiel #12
0
void SelectRoundLayer::createRoundButton(int round, bool isUnlock, const Point& pos) {
	auto roundButton = ui::Button::create();

	std::string normalButton;
	std::string selectedButton = s_roundButtonBackgroundSelected;
	if (isUnlock) {
		normalButton = s_roundButtonBackgroundNormal;
		roundButton->setTouchEnabled(true);
	}
	else {
		normalButton = selectedButton;
		roundButton->setTouchEnabled(false);
	}
	roundButton->loadTextures(normalButton, selectedButton, "", ui::Button::TextureResType::PLIST);
	Vec2 visibleOrigin = Director::getInstance()->getVisibleOrigin();
	const int step = 100;
	roundButton->setPosition(ccpAdd(visibleOrigin, pos));
	roundButton->setUserData((void*)round);
	addChild(roundButton);
	roundButton->addTouchEventListener(this, ui::SEL_TouchEvent(&SelectRoundLayer::onRoundButtonTouched));

	auto labelRound = LabelBMFont::create(StringUtils::toString(round+1), "fonts/boundsTestFont.fnt");
	labelRound->setPosition(ccpAdd(visibleOrigin, pos));
	addChild(labelRound);
}
Beispiel #13
0
void MenuBoxManager::setBoxWithImgInfo(ImageInfoParser* imgInfo)
{
    auto button = ui::Button::create("Main_BoxUp-hd.png", "Main_BoxDown-hd.png", "Main_BoxDown-hd.png");
    //        button->setTitleText("text");
    button->setTag(TAG_MAIN_BOX + imgInfo->getidx()->intValue());
    button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type) {
        switch (type)
        {
        case ui::Widget::TouchEventType::BEGAN:

            break;
        case ui::Widget::TouchEventType::ENDED:

            buttonCallBack(sender);
            break;
        default:
            break;
        }
    });
    button->setTouchEnabled(true);
    setTypeTitle(button, imgInfo->gettitle()->getCString());
    setTypeInfo(button, __String::createWithFormat("%s / %s",imgInfo->getspace()->getCString(),imgInfo->getair()->getCString())->getCString());
    setPrice(button, __String::createWithFormat("%s", imgInfo->getprice()->getCString())->intValue());
    setImageWithName(button, __String::createWithFormat("%s", imgInfo->getimgName()->getCString())->getCString());

    _vButton.pushBack(button);
}
Beispiel #14
0
bool Sensors::init() {
    if (!Node::init()) {
        return false;
    }

    // load sensors layout
    this->_p_contents = CSLoader::getInstance()->createNode(
        "res/MenuSensorList.csb");  // .csbを読み込んだディレクトリを保持してリソースを探す指定

    // 戻るボタンの設定
    // Topic
    auto panel =
        this->_p_contents->getChildByName<ui::Layout*>("panelBackground");
    auto label_back = panel->getChildByName<ui::Text*>("txtBack");
    label_back->addTouchEventListener(
        [this](Ref* sender, ui::Widget::TouchEventType type) {
            if (type == ui::Widget::TouchEventType::ENDED) {
                this->touchBack();
            }
        });

    this->_p_contents->setTag(Tag_Id_Sensor_Main);
    this->addChild(this->_p_contents);

    this->showSensorList();

    return true;
}
Beispiel #15
0
void CGridIcon::updateByContent()
{
    if(m_GridsType == emGrids_BagBook)
    {
        ShowQuality();
        ShowIcon();
        ShowMask();
        ShowNum();
        ShowPrecent();
        ShowPrecentBar();
        ShowLevel();
    }
    else
    {
        ShowQuality();
        ShowIcon();
        ShowMask();
        ShowNum();
        ShowCd();
    }
    setTouchEnabled(true);
    if (m_bCanMove&&m_pItem)
    {
        CDragCtrol* pDrag = CDragCtrol::create(this,m_pItem->getId(),DragSlotType_Item,this,toucheventselector(CGridIcon::clickGridIcon),NULL);
        addChild(pDrag);
    }
    else
    {
        addTouchEventListener(this,toucheventselector(CGridIcon::clickGridIcon));
    }
}
void CompleteMissionScene::initButton()
{
	Size visibleSize = Director::getInstance()->getVisibleSize();
	int MemberNum = 10;
	int MissionNum = MissionManager::getInstance()->getMissionSize(MissionCondition::COMPLETION);
	int revision = 0;

	for (int i = 0; i < MissionNum; i++)
	{
		Mission mission = MissionManager::getInstance()->getMission(MissionCondition::COMPLETION,i);

		auto menuitem = ui::Button::create("res/MissionButton.png");
		menuitem->addTouchEventListener(CC_CALLBACK_2(CompleteMissionScene::MissionButtonCallback, this));
		menuitem->setAnchorPoint(Point(0, 0));
		menuitem->setTag(MissionButtonList.size());
		menuitem->setName("MISSION_FUNCTION");
		this->getChildByName("MISSION_SCROLLVIEW")->addChild(menuitem);

		if (8 > MissionNum)
		{
			revision = 7 - MissionNum;
		}

		menuitem->setPositionY(MissionNum
			* 40 - 40 * i - 40 + revision * 40);
		MissionButtonList.push_back(menuitem);

		auto missionName = Label::createWithSystemFont(mission.name, "Thonburi", 24, Size::ZERO,
			TextHAlignment::LEFT);
		missionName->setColor(Color3B(0, 0, 0));
		missionName->setPosition(110, 20);
		menuitem->addChild(missionName);
		
	}
}
Beispiel #17
0
Node* LHGameChat::waitView(){
    Size vs = Director::getInstance()->getVisibleSize();
    Vec2 vo = Director::getInstance()->getVisibleOrigin();
    
    auto lo = ui::Layout::create();
    Size sz = Size(vs.width/2,vs.height/4);
    lo->setSize(sz);
    lo->setPosition(Vec2(vs.width/2 - sz.width/2, vs.height/2 - sz.height/2));
    lo->setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID);
    lo->setBackGroundColor(Color3B::GRAY);
    lo->setBackGroundColorOpacity(200);
    
    auto load = ui::Text::create("Loading...", Common_Font, 30);
    load->setColor(Color3B::GREEN);
    load->setPosition(Vec2(sz.width/2, lo->getSize().height/2));
    auto cancel = ui::Button::create("close.png");
    cancel->setPosition(Vec2(sz.width/2, lo->getSize().height/2 - load->getContentSize().height - 20));
    cancel->addTouchEventListener([](Ref *ps,ui::Widget::TouchEventType type){
        if (type == ui::Widget::TouchEventType::ENDED) {
            if (_chatManager) {
                _chatManager->disconnect();
                delete _chatManager;
                _chatManager = nullptr;
                
                LHDialog::disMissDialog();
            }
        }
    });
    
    lo->addChild(load);
    lo->addChild(cancel);
    return lo;
}
Beispiel #18
0
void ButtonEx::setTouchEndedCallback(const TouchCallback& callback) {
    addTouchEventListener([callback, this](cocos2d::Ref*, TouchEventType type) {
        if (type == TouchEventType::ENDED) {
            callback(currentTouch_, currentEvent_);
        }
    });
}
Beispiel #19
0
void WorldHudLayer::showUI()
{
    auto ui = GUIReader::getInstance()->widgetFromJsonFile(UI_LAYER_WORLDHUD);
    this->addChild(ui, 0, "UI");
    
    // HomeButton
    auto btnEnter = (Button*)Helper::seekWidgetByName(ui, "HomeButton");
    btnEnter->addTouchEventListener(CC_CALLBACK_2(WorldHudLayer::btnCallback, this));

    // player
    auto playerName = (Text*)Helper::seekWidgetByName(ui, "PlayerName");
    auto playerLevel = (Text*)Helper::seekWidgetByName(ui, "PlayerLevel");
    auto playerBar = (LoadingBar*)Helper::seekWidgetByName(ui, "PlayerBar");
    playerName->setString(_name);
    playerLevel->setString(GM()->getIntToStr(_level));
    playerBar->setPercent(100.0 * _exp / _expRequire);
    // gold
    auto goldCount = (Text*)Helper::seekWidgetByName(ui, "GoldCount");
    auto goldCapacity = (Text*)Helper::seekWidgetByName(ui, "GoldCapacity");
    auto goldBar = (LoadingBar*)Helper::seekWidgetByName(ui, "GoldBar");
    goldCount->setString(GM()->getIntToStr(_goldCount));
    goldCapacity->setString(GM()->getIntToStr(_goldCapacity));
    goldBar->setPercent(100.0 * _goldCount / _goldCapacity);
    // wood
    auto woodCount = (Text*)Helper::seekWidgetByName(ui, "WoodCount");
    auto woodCapacity = (Text*)Helper::seekWidgetByName(ui, "WoodCapacity");
    auto woodBar = (LoadingBar*)Helper::seekWidgetByName(ui, "WoodBar");
    woodCount->setString(GM()->getIntToStr(_woodCount));
    woodCapacity->setString(GM()->getIntToStr(_woodCapacity));
    woodBar->setPercent(100.0 * _woodCount / _woodCapacity);
    // ring
    auto ringCount = (Text*)Helper::seekWidgetByName(ui, "RingCount");
    ringCount->setString(GM()->getIntToStr(_ringCount));
}
Beispiel #20
0
bool IntroScene::init()
{
	//super init
	if (!Layer::init())
	{
		return false;
	}
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	/////////////////////////////////////////////////////
	AudioEngine::getInstance()->createLoop("bgm/intro.ogg");
	auto sceneNode = cocostudio::SceneReader::getInstance()->createNodeWithSceneFile("introScene.json");
	addChild(sceneNode);
	auto UINode = sceneNode->getChildByTag(10003);
	auto UIComponent = (cocostudio::ComRender*) UINode->getComponent("GUIComponent");
	auto UIlayer = UIComponent->getNode();
	auto background = dynamic_cast<ImageView*>(UIlayer->getChildByTag(INTROSCENE_BG));
	auto buttonStart = dynamic_cast<Button*>(UIlayer->getChildByTag(INTROSCENE_START));
	auto title = dynamic_cast<ImageView*>(UIlayer->getChildByTag(INTROSCENE_ECHO));
	title->runAction(RepeatForever::create(Sequence::create(FadeIn::create(3), FadeOut::create(3), NULL)));
	buttonStart->runAction(RepeatForever::create(Sequence::create(FadeIn::create(1), DelayTime::create(1), FadeOut::create(1), NULL)));
	buttonStart->addTouchEventListener(this, toucheventselector(IntroScene::touchEvent));

	auto logo = Sprite::create("introSceneUI/logo.png");
	logo->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
	logo->setLocalZOrder(1);
	sceneNode->addChild(logo);
	logo->runAction(Sequence::create(DelayTime::create(1), CallFunc::create(CC_CALLBACK_0(IntroScene::playIntro, this)), FadeOut::create(2), NULL));//logoÇл»ÌØЧ
	return true;
}
Beispiel #21
0
// on "init" you need to initialize your instance
bool SecondScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !LayerColor::initWithColor(Color4B::BLUE) )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(SecondScene::menuCloseCallback, this));
    
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    auto label = LabelTTF::create("Second Scene \nwith Colored Background", "Arial", 24);
    
    // position the label on the center of the screen
    label->setPosition(Vec2(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - label->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(label, 1);
    
    auto button = cocos2d::ui::Button::create();
    button->loadTextures("button.png", "button_r.png");
    Size layerSize = this->getContentSize();
    button->setPosition(Vec2(layerSize.width/2, layerSize.height/2));
    button->setPressedActionEnabled(true);
    button->addTouchEventListener(CC_CALLBACK_2(SecondScene::onButtonTouchEvent, this));
    button->setTitleFontSize(36.0f);
    button->setTitleText("Back");
    this->addChild(button, 10);
    
    return true;
}
bool EquipmentInfo::init()
{
    mpFontChina = FontChina::getInstance();
    mpFontChina->initStringXml();
    _comer = NULL;

    auto equipInfoUI = GUIReader::getInstance()->widgetFromJsonFile("UI/All/SelectEquip.ExportJson");
    this->addChild(equipInfoUI);

    singleInfo = dynamic_cast<Layout* >(Helper::seekWidgetByName(equipInfoUI, "Panel_Left"));
    equipmentLayer = dynamic_cast<Layout* >(Helper::seekWidgetByName(equipInfoUI, "Panel_Right"));

    auto closeButton = dynamic_cast<Button* >(Helper::seekWidgetByName(equipInfoUI, "Button_Close"));
    closeButton->addTouchEventListener(this, toucheventselector(EquipmentInfo::closeClick));

    auto panelRight = dynamic_cast<Layout* >(Helper::seekWidgetByName(equipmentLayer, "Panel_Right"));
    equipmentScrollView = dynamic_cast<cocos2d::ui::ScrollView* >(Helper::seekWidgetByName(panelRight, "ScrollView_Equip"));

    interGeneralEquipVector = DataManager::getInstance()->interGeneralVector();										// 获取武将装备信息

    initEquipmentData();

    showEquipment();
    if (interGeneralEquipVector[ 0 ].equipID[ DataManager::getInstance()->equipType -1 ] == 0)							// 点击的位置没有装备
    {
        isFull = true;
        if (tempEquipVector.size() != 0)
        {
            singleEquipmentInfo(tempEquipVector[ 0 ].ePKID, 1);
        }
    }
    else
    {
        isFull = false;
        EquipProptyStruct equipStrcut;
        memset(&equipStrcut, 0, sizeof(equipStrcut));
        for (unsigned int i = 0; i < interEquipVector.size(); i ++)
        {
            if (interEquipVector[ i ].itemsID == 0)
            {
                continue;
            }
            if ( interGeneralEquipVector[ 0 ].equipPKID[ DataManager::getInstance()->equipType -1 ] == interEquipVector[ i ].itemPKID )																	// 颜色类型相同并且没有被使用
            {
                equipStrcut.ePKID = interEquipVector[ i ].itemPKID;
                equipStrcut.eID = interEquipVector[ i ].itemsID;
                equipStrcut.eLevel = interEquipVector[ i ].itemsLevel;
                tempEquipVector.push_back(equipStrcut);
            }
        }
        singleEquipmentInfo(interGeneralEquipVector[ 0 ].equipPKID[ DataManager::getInstance()->equipType -1 ], 1);
    }

    return true;
}
Beispiel #23
0
void TollgateScene::loadUI(){
	auto UI = cocostudio::GUIReader::getInstance()->
		widgetFromJsonFile("LittleRunner_1.ExportJson");
	this->addChild(UI);

	auto jumpBtn = (Button*)Helper::seekWidgetByName(UI, "JumpBtn");
	m_scoreLab = (Text*)Helper::seekWidgetByName(UI, "scoreLab");
	m_hpBar = (LoadingBar*)Helper::seekWidgetByName(UI, "hpProgress");

	jumpBtn->addTouchEventListener(this, toucheventselector(TollgateScene::jumpEvent));
}
Beispiel #24
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    auto name = ui::Text::create(LHLocalizedCString("appname"), Common_Font, 70);
    name->setColor(Color3B(64, 119, 215));
    name->setPosition(Vec2(visibleSize.width/2, visibleSize.height/3*2) );
    this->addChild(name);
    
    auto play = ui::Button::create("blue.png");
    play->setTitleFontSize(40);
    play->setTitleText(LHLocalizedCString("play"));
    play->setPosition(Vec2(name->getPositionX(), visibleSize.height/2));
    play->addTouchEventListener([](Ref *ps,ui::Widget::TouchEventType type){
        if (type == ui::Widget::TouchEventType::ENDED) {
            Director::getInstance()->replaceScene(PlayScene::createScene(nullptr));
            CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("pop.wav");
        }
    });
    this->addChild(play);
    
    auto dbt = DeveloperInfo::DevInfoButton("devinfo.png");
    dbt->setPosition(Vec2(visibleSize.width - 80, visibleSize.height - 80));
    this->addChild(dbt);
    
    auto gbt = GuideScene::guideButton("q.png");
    gbt->setPosition(Vec2(dbt->getPosition().x - gbt->getContentSize().width/2*3, visibleSize.height - 80));
    this->addChild(gbt);
    
    if (UserDefault::getInstance()->getBoolForKey("guide", true)) {
        auto gt = ui::Text::create(LHLocalizedCString("guidetext"), Common_Font, 35);
        gt->setColor(Color3B(250, 201, 11));
        gt->setPosition(Vec2(gbt->getPosition().x - gt->getContentSize().width/2 - gbt->getContentSize().width/2 - 2, gbt->getPosition().y));
        
        MoveBy *byl = MoveBy::create(0.4, Vec2(-20, 0));
        MoveBy *byr = MoveBy::create(0.2, Vec2(20, 0));
        Sequence *sq = Sequence::create(byl,byr,NULL);
        RepeatForever *rp = RepeatForever::create(sq);
        gt->runAction(rp);
        
        this->addChild(gt);
        UserDefault::getInstance()->setBoolForKey("guide", false);
    }
    
    return true;
}
bool HelloWorld::init()
{
	if (!Layer::init())
	{
		return false;
	}
	m_score = 0;

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


	//退出程序
	auto listenerEnd = EventListenerKeyboard::create();
	listenerEnd->onKeyReleased = CC_CALLBACK_2(HelloWorld::onKeyReleased, this);
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listenerEnd, this);


	auto layerColorBG = LayerColor::create(Color4B(180, 170, 160, 255));
	addChild(layerColorBG);

	auto labTTFCardNumberName = Label::createWithSystemFont("Score", "fonts/arial.ttf", 60);
	labTTFCardNumberName->setPosition(Point(visibleSize.width / 5, visibleSize.height - 70));
	addChild(labTTFCardNumberName);

	labTTFCardNumber = Label::createWithSystemFont("0", "fonts/arial.ttf", 60);
	labTTFCardNumber->setPosition(Point(visibleSize.width / 2 + 100, visibleSize.height - 70));
	addChild(labTTFCardNumber);


	auto listen = EventListenerTouchOneByOne::create();
	listen->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
	listen->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listen, this);

	//设置重来按钮
	auto m_bunt = ui::Button::create("normal.png", "selected.png");
	m_bunt->setScale9Enabled(true);//可拉伸图片
	m_bunt->setTitleText("Begen");
	m_bunt->setTitleFontSize(50);
	m_bunt->setTitleFontName("fonts/arial.ttf");
	m_bunt->setContentSize(cocos2d::Size(visibleSize.width / 10+200, visibleSize.height / 15));
	m_bunt->setPosition(Point(visibleSize.width / 5 + 180, visibleSize.height - 150));
	m_bunt->addTouchEventListener(CC_CALLBACK_2(HelloWorld::touchEvent, this));
	addChild(m_bunt);


	creatCard(visibleSize);

	autoCreateCardNumber();
	autoCreateCardNumber();

	return true;
}
Beispiel #26
0
ui::Layout* TopScene::pushSecondScene(std::string title, const ui::Widget::ccWidgetTouchCallback& callback)
{
    Size size = Director::getInstance()->getWinSize();
    auto layout = ui::Layout::create();
    layout->setContentSize(Size(size.width, 80));
    layout->setPosition(Point::ZERO);
    auto text = ui::Text::create(title, "fonts/Marker Felt.ttf", 50);
    text->setPosition(Point(size.width * 0.5, layout->getContentSize().height * 0.5));
    text->setTouchEnabled(true);
    text->addTouchEventListener(callback);
    layout->addChild(text);
    return layout;
}
Beispiel #27
0
bool UI_Hall::init()
{
    bool bRet = false;
    do{
        CC_BREAK_IF(!Layer::init());
        auto layout = dynamic_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("UI/UI_Hall.json"));
        addChild(layout);
        // 游客登陆
        auto btn_game1 = dynamic_cast<Button*>(Helper::seekWidgetByName(layout, "btn_game1"));
        btn_game1->addTouchEventListener(CC_CALLBACK_2(UI_Hall::gameEnter,this ));
        // 大房间
        _layout_bigRoom = dynamic_cast<Layout*>(Helper::seekWidgetByName(layout, "panel_bigRoomSelect"));
        // 小房间
        _layout_samllRoom = dynamic_cast<Layout*>(Helper::seekWidgetByName(layout, "panel_roomSelect"));
        // 返回按钮
        _btnBack = dynamic_cast<Button*>(Helper::seekWidgetByName(layout, "btn_back"));
        _btnBack->addTouchEventListener(CC_CALLBACK_2(UI_Hall::changeRoom,this ));
        _btnBack->setTouchEnabled(false);
        _btnBack->setVisible(false);
        // 头像
        _imgPortrait = dynamic_cast<ImageView*>(Helper::seekWidgetByName(layout, "img_portrait"));
        
        //
        auto btn_enterRoom1 = dynamic_cast<Button*>(Helper::seekWidgetByName(layout, "btn_room1"));
        btn_enterRoom1->addTouchEventListener(CC_CALLBACK_2(UI_Hall::roomEnter,this ));
        btn_enterRoom1->setTag(10001);
        
        
        
        SendNetWork::getInstance()->AddNetCommand(new RequestLoginServer());
        
        // 用户名
//        auto label_name = dynamic_cast<Label*>(Helper::seekWidgetByName(layout, "label_name"));
//        label_name->setString(GameData::getInstance()->getUserName());
        
        bRet = true;
    }while(0);
    return bRet;
}
Beispiel #28
0
// on "init" you need to initialize your instance
bool MainMenuScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    m_RootNode = static_cast<Layout*>(CSLoader::createNode("MainMenuScene.csb"));
    this->addChild(m_RootNode);
    
    auto Button_play=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_PLAY"));
    if (Button_play) {
        Button_play->addTouchEventListener(CC_CALLBACK_2(MainMenuScene::Button_play_BtnOnTouch, this));
    }
    auto Button_quit=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_QUIT"));
    if (Button_quit) {
        Button_quit->addTouchEventListener(CC_CALLBACK_2(MainMenuScene::Button_quit_BtnOnTouch, this));
    }
    return true;
}
Beispiel #29
0
void LabDialog::showDialog()
{
    // Action
    auto scale = ScaleTo::create(0.3f, 1.0f);
    auto act = EaseBackOut::create(scale);
    this->runAction(act);
    
    // 阴影遮罩
    auto WIN_SIZE = Director::getInstance()->getWinSize();
    auto bg = Sprite::create(IMG_GRAY_BG);
    bg->setScale(WIN_SIZE.width/1000.0, WIN_SIZE.height/1000.0);
    bg->setPosition(WIN_SIZE/2);
    this->addChild(bg, -1);
    bg->setOpacity(128);

    auto ui = GUIReader::getInstance()->widgetFromJsonFile(UI_DIALOG_LAB);
    this->addChild(ui, 1, "UI");
    
    // 关闭按钮
    auto btnClose = Helper::seekWidgetByName(ui, "CloseButton");
    btnClose->addTouchEventListener(CC_CALLBACK_2(LabDialog::closeCallback, this));
    
    // 信息按钮
    auto btnFighterInfo = Helper::seekWidgetByName(ui, "FighterInfoButton");
    auto btnBowmanInfo = Helper::seekWidgetByName(ui, "BowmanInfoButton");
    auto btnGunnerInfo = Helper::seekWidgetByName(ui, "GunnerInfoButton");
    auto btnMeatInfo = Helper::seekWidgetByName(ui, "MeatShieldInfoButton");
    btnFighterInfo->addTouchEventListener(CC_CALLBACK_2(LabDialog::infoCallback, this));
    btnBowmanInfo->addTouchEventListener(CC_CALLBACK_2(LabDialog::infoCallback, this));
    btnGunnerInfo->addTouchEventListener(CC_CALLBACK_2(LabDialog::infoCallback, this));
    btnMeatInfo->addTouchEventListener(CC_CALLBACK_2(LabDialog::infoCallback, this));
    
    // 购买按钮
    auto btnFighterUp = Helper::seekWidgetByName(ui, "UpFighterButton");
    auto btnBowmanUp = Helper::seekWidgetByName(ui, "UpBowmanButton");
    auto btnGunnerUp = Helper::seekWidgetByName(ui, "UpGunnerButton");
    auto btnMeatUp = Helper::seekWidgetByName(ui, "UpMeatShieldButton");
    btnFighterUp->addTouchEventListener(CC_CALLBACK_2(LabDialog::upCallback, this));
    btnBowmanUp->addTouchEventListener(CC_CALLBACK_2(LabDialog::upCallback, this));
    btnGunnerUp->addTouchEventListener(CC_CALLBACK_2(LabDialog::upCallback, this));
    btnMeatUp->addTouchEventListener(CC_CALLBACK_2(LabDialog::upCallback, this));
    
    showInfo();
}
Beispiel #30
0
bool GameScene::init()
{
	//super init
	if (!Layer::init())
	{
		return false;
	}
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	/////////////////////////////////////////////////////
	auto sceneNode = cocostudio::SceneReader::getInstance()->createNodeWithSceneFile("gameScene.json");
	addChild(sceneNode);
	UINode = sceneNode->getChildByTag(10004);
	MenuNode = sceneNode->getChildByTag(10005);
	auto UIComponent = (cocostudio::ComRender*) UINode->getComponent("gameSceneUI");
	auto PauseComponent = (cocostudio::ComRender*)MenuNode->getComponent("pauseSelectUI");
	auto UILayer = (Layer*)UIComponent->getNode();
	auto MenuLayer = (Layer*)PauseComponent->getNode();
	//////////
	auto buttonPause = dynamic_cast<Button*>(UILayer->getChildByTag(GAMESCENE_BUTTON_PAUSE));
	buttonPause->addTouchEventListener(this, toucheventselector(GameScene::touchEvent));
	buttonPause->setTouchEnabled(false);
	//////////
	auto bgPause = dynamic_cast<ImageView*>(MenuLayer->getChildByTag(GAMESCENE_MENU_BG));
	auto buttonRetry = dynamic_cast<Button*>(MenuLayer->getChildByTag(GAMESCENE_MENU_RETRY));
	auto buttonReturn = dynamic_cast<Button*>(MenuLayer->getChildByTag(GAMESCENE_MENU_RETURN));
	auto buttonResume = dynamic_cast<Button*>(MenuLayer->getChildByTag(GAMESCENE_MENU_RESUME));
	bgPause->addTouchEventListener(this, toucheventselector(GameScene::touchEvent));
	buttonRetry->addTouchEventListener(this, toucheventselector(GameScene::touchEvent));
	buttonReturn->addTouchEventListener(this, toucheventselector(GameScene::touchEvent));
	buttonResume->addTouchEventListener(this, toucheventselector(GameScene::touchEvent));
	bgPause->setEnabled(false);
	buttonRetry->setEnabled(false);
	buttonReturn->setEnabled(false);
	buttonResume->setEnabled(false);
	//////////
	return true;
}