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; }
bool NFCUISelectServer::initLayout() { if(!NFCUIDialog::initLayout()) return false; m_pServerList = ui::ListView::create(); m_pServerList->setSizeType(ui::SizeType::PERCENT); m_pServerList->setSizePercent(Vec2(0.1f, 0.25f)); m_pServerList->setPositionType(ui::PositionType::PERCENT); m_pServerList->setPositionPercent(Vec2(0.5f, 0.5f)); m_pServerList->setBackGroundColorType(ui::LayoutBackGroundColorType::SOLID); m_pServerList->setBackGroundColor(Color3B(150, 200, 255)); m_pServerList->setAnchorPoint(Vec2(0.5, 0.5)); m_pContent->addChild(m_pServerList); auto button = ui::Button::create(); button->loadTextureNormal("Default/Button_Normal.png",ui::TextureResType::LOCAL); button->setScale9Enabled(true); button->setSizePercent(Vec2(1.0f, 0.2f)); button->setSizeType(ui::SizeType::PERCENT); m_pServerList->setItemModel(button); g_pLoginLogic->AddEventCallBack(E_LoginEvent_WorldList, this, &NFCUISelectServer::OnWorldListEvent); g_pLoginLogic->AddEventCallBack(E_LoginEvent_ServerList, this, &NFCUISelectServer::OnServerListEvent); return true; }
void Button::loadTextures(const std::string& normal, const std::string& selected, const std::string& disabled, TextureResType texType) { loadTextureNormal(normal,texType); loadTexturePressed(selected,texType); loadTextureDisabled(disabled,texType); }
void UIButton::setScale9Enabled(bool able) { if (m_bScale9Enabled == able) { return; } m_eBrightStyle = BRIGHT_NONE; m_bScale9Enabled = able; m_pRenderer->removeChild(m_pButtonNormalRenderer, true); m_pRenderer->removeChild(m_pButtonClickedRenderer, true); m_pRenderer->removeChild(m_pButtonDisableRenderer, true); m_pButtonNormalRenderer = NULL; m_pButtonClickedRenderer = NULL; m_pButtonDisableRenderer = NULL; if (m_bScale9Enabled) { m_pButtonNormalRenderer = CCScale9Sprite::create(); m_pButtonClickedRenderer = CCScale9Sprite::create(); m_pButtonDisableRenderer = CCScale9Sprite::create(); } else { m_pButtonNormalRenderer = CCSprite::create(); m_pButtonClickedRenderer = CCSprite::create(); m_pButtonDisableRenderer = CCSprite::create(); } loadTextureNormal(m_strNormalFileName.c_str(), m_eNormalTexType); loadTexturePressed(m_strClickedFileName.c_str(), m_ePressedTexType); loadTextureDisabled(m_strDisabledFileName.c_str(), m_eDisabledTexType); m_pRenderer->addChild(m_pButtonNormalRenderer,NORMALRENDERERZ); m_pRenderer->addChild(m_pButtonClickedRenderer,PRESSEDRENDERERZ); m_pRenderer->addChild(m_pButtonDisableRenderer,DISABLEDRENDERERZ); if (m_bScale9Enabled) { bool ignoreBefore = m_bIgnoreSize; ignoreContentAdaptWithSize(false); m_bPrevIgnoreSize = ignoreBefore; } else { ignoreContentAdaptWithSize(m_bPrevIgnoreSize); } setCapInsetsNormalRenderer(m_capInsetsNormal); setCapInsetsPressedRenderer(m_capInsetsPressed); setCapInsetsDisabledRenderer(m_capInsetsDisabled); setBright(m_bBright); }
void UIButton::setScale9Enabled(bool able) { if (_scale9Enabled == able) { return; } _brightStyle = BRIGHT_NONE; _scale9Enabled = able; _renderer->removeChild(_buttonNormalRenderer, true); _renderer->removeChild(_buttonClickedRenderer, true); _renderer->removeChild(_buttonDisableRenderer, true); _buttonNormalRenderer = NULL; _buttonClickedRenderer = NULL; _buttonDisableRenderer = NULL; if (_scale9Enabled) { _buttonNormalRenderer = Scale9Sprite::create(); _buttonClickedRenderer = Scale9Sprite::create(); _buttonDisableRenderer = Scale9Sprite::create(); } else { _buttonNormalRenderer = CCSprite::create(); _buttonClickedRenderer = CCSprite::create(); _buttonDisableRenderer = CCSprite::create(); } loadTextureNormal(_normalFileName.c_str(), _normalTexType); loadTexturePressed(_clickedFileName.c_str(), _pressedTexType); loadTextureDisabled(_disabledFileName.c_str(), _disabledTexType); _renderer->addChild(_buttonNormalRenderer,NORMALRENDERERZ); _renderer->addChild(_buttonClickedRenderer,PRESSEDRENDERERZ); _renderer->addChild(_buttonDisableRenderer,DISABLEDRENDERERZ); if (_scale9Enabled) { bool ignoreBefore = _ignoreSize; ignoreContentAdaptWithSize(false); _prevIgnoreSize = ignoreBefore; } else { ignoreContentAdaptWithSize(_prevIgnoreSize); } setCapInsetsNormalRenderer(_capInsetsNormal); setCapInsetsPressedRenderer(_capInsetsPressed); setCapInsetsDisabledRenderer(_capInsetsDisabled); setBright(_bright); }
BattleButton* BattleButton::CreateButton(InStageUnit* allyunit, InStageUnit* enemyunit) { auto button = BattleButton::create(); button->loadTextureNormal("Interface/BattleButton.png"); button->addTouchEventListener(CC_CALLBACK_2(BattleButton::ButtonEvent, button)); button->allyUnit = allyunit; button->enemyUnit = enemyunit; button->_hero = NULL; auto particle = ParticleSystemQuad::create("particle_BattleButton.plist"); particle->setScale(0.5f); particle->setPosition(Vec2(30, 20)); button->addChild(particle,-10); return button; }
void Button::setScale9Enabled(bool able) { if (_scale9Enabled == able) { return; } _brightStyle = BrightStyle::NONE; _scale9Enabled = able; removeProtectedChild(_buttonNormalRenderer); removeProtectedChild(_buttonClickedRenderer); removeProtectedChild(_buttonDisableRenderer); _buttonNormalRenderer = nullptr; _buttonClickedRenderer = nullptr; _buttonDisableRenderer = nullptr; if (_scale9Enabled) { _buttonNormalRenderer = extension::Scale9Sprite::create(); _buttonClickedRenderer = extension::Scale9Sprite::create(); _buttonDisableRenderer = extension::Scale9Sprite::create(); } else { _buttonNormalRenderer = Sprite::create(); _buttonClickedRenderer = Sprite::create(); _buttonDisableRenderer = Sprite::create(); } loadTextureNormal(_normalFileName, _normalTexType); loadTexturePressed(_clickedFileName, _pressedTexType); loadTextureDisabled(_disabledFileName, _disabledTexType); addProtectedChild(_buttonNormalRenderer, NORMAL_RENDERER_Z, -1); addProtectedChild(_buttonClickedRenderer, PRESSED_RENDERER_Z, -1); addProtectedChild(_buttonDisableRenderer, DISABLED_RENDERER_Z, -1); if (_scale9Enabled) { bool ignoreBefore = _ignoreSize; ignoreContentAdaptWithSize(false); _prevIgnoreSize = ignoreBefore; } else { ignoreContentAdaptWithSize(_prevIgnoreSize); } setCapInsetsNormalRenderer(_capInsetsNormal); setCapInsetsPressedRenderer(_capInsetsPressed); setCapInsetsDisabledRenderer(_capInsetsDisabled); setBright(_bright); }
OneBtDlg::OneBtDlg() { auto bg = util::graphic::getSprite(Constants::ASS_BG_DLG_TEXT); bg->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); auto bt = ui::Button::create(); bt->loadTextureNormal(util::graphic::getAssetName(Constants::ASS_BG_DLG_BT),ui::Widget::TextureResType::PLIST); bt->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); bt->setZoomScale(0); Size size = bt->getContentSize(); bg->setPosition(Vec2(0, size.height)); size.height += bg->getContentSize().height; bt->setPosition(Vec2(0, 0)); this->setContentSize(size); addChild(bg, 1); addChild(bt, 1); util::graphic::addSwallowTouch(this); util::graphic::addClosedWhenClickOutside(this); util::graphic::addClickBtCallback(bt, CC_CALLBACK_0(OneBtDlg::onBtClick, this)); }
void Button::copySpecialProperties(Widget *widget) { Button* button = dynamic_cast<Button*>(widget); if (button) { _prevIgnoreSize = button->_prevIgnoreSize; setScale9Enabled(button->_scale9Enabled); loadTextureNormal(button->_normalFileName.c_str(), button->_normalTexType); loadTexturePressed(button->_clickedFileName.c_str(), button->_pressedTexType); loadTextureDisabled(button->_disabledFileName.c_str(), button->_disabledTexType); setCapInsetsNormalRenderer(button->_capInsetsNormal); setCapInsetsPressedRenderer(button->_capInsetsPressed); setCapInsetsDisabledRenderer(button->_capInsetsDisabled); setTitleText(button->getTitleText()); setTitleFontName(button->getTitleFontName()); setTitleFontSize(button->getTitleFontSize()); setTitleColor(button->getTitleColor()); setPressedActionEnabled(button->_pressedActionEnabled); } }
//按钮 void UI:: initButton(){ auto visibleSize=Director::getInstance()->getVisibleSize(); auto ub=Button::create(); ub->loadTextureNormal("0.png"); ub->loadTexturePressed("2.png"); ub->loadTextureDisabled("2.png"); ub->setScale9Enabled(true); ub->setContentSize(cocos2d::Size(128,128)); ub->setPressedActionEnabled(true); ub->setZoomScale(2); ub->setTitleFontName("fonts/Marker Felt.ttf"); ub->setTitleFontSize(30); ub->setTitleColor(cocos2d::Color3B::YELLOW); ub->setTitleText("HHLLO Button"); // ub->addClickEventListener(CC_CALLBACK_1(UI::buttonClick, this)); //添加触摸事件 ub->addTouchEventListener (this,toucheventselector(UI::buttonClick)); ub->setPosition(visibleSize/2); addChild(ub); }
void UI::initListView(){ auto lv=ListView::create(); lv->setContentSize(cocos2d::Size(640,480)); lv->setItemsMargin(20);//设置间隔 lv->setDirection(cocos2d::ui::ScrollView::Direction::VERTICAL); for (int i=0; i<50; i++) { auto ub=Button::create(); ub->loadTextureNormal("0.png"); ub->loadTexturePressed("1.png"); ub->loadTextureDisabled("0.png"); ub->setScale9Enabled(true); ub->setContentSize(Size(600,400)); ub->setPressedActionEnabled(true); ub->setZoomScale(0.5f); ub->addClickEventListener(CC_CALLBACK_1(UI::buttonClick, this)); ub->setTag(i); lv->pushBackCustomItem(ub); } lv->addEventListener(CC_CALLBACK_2(UI::ListViewCall, this)); addChild(lv); }
void Button::copySpecialProperties(Widget *widget) { Button* button = dynamic_cast<Button*>(widget); if (button) { _prevIgnoreSize = button->_prevIgnoreSize; setScale9Enabled(button->_scale9Enabled); auto normalSprite = button->_buttonNormalRenderer->getSprite(); if (nullptr != normalSprite) { loadTextureNormal(normalSprite->getSpriteFrame()); } auto clickedSprite = button->_buttonClickedRenderer->getSprite(); if (nullptr != clickedSprite) { loadTexturePressed(clickedSprite->getSpriteFrame()); } auto disabledSprite = button->_buttonDisableRenderer->getSprite(); if (nullptr != disabledSprite) { loadTextureDisabled(disabledSprite->getSpriteFrame()); } setCapInsetsNormalRenderer(button->_capInsetsNormal); setCapInsetsPressedRenderer(button->_capInsetsPressed); setCapInsetsDisabledRenderer(button->_capInsetsDisabled); if(nullptr != button->getTitleRenderer()) { setTitleText(button->getTitleText()); setTitleFontName(button->getTitleFontName()); setTitleFontSize(button->getTitleFontSize()); setTitleColor(button->getTitleColor()); } setPressedActionEnabled(button->_pressedActionEnabled); setZoomScale(button->_zoomScale); } }
void GameScene36::initKey() { //键,12个键的位置 Point pos[12] = {Point(252, 421), Point(375, 421), Point(503, 421), Point(255, 335), Point(375, 335), Point(500, 335), Point(262, 253), Point(375, 253), Point(495, 253), Point(271, 162), Point(375, 162), Point(490, 162)}; //键,随机12个键的位置 int randPos[12]={0,1,2,3,4,5,6,7,8,9,10,11}; std::uniform_int_distribution<unsigned> u(0,11); std::default_random_engine e; e.seed((unsigned)time(NULL)); for (int i = 0; i < 12; i++) { int random_number = u(e); swap(randPos[i], randPos[random_number]); } //加入键 auto key0 = Button::create(); key0->setPosition(pos[randPos[0]]); key0->loadTextureNormal("normal0.png", UI_TEX_TYPE_PLIST); key0->loadTexturePressed("pressed0.png", UI_TEX_TYPE_PLIST); key0->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack0)); this->addChild(key0); auto key1 = Button::create(); key1->setPosition(pos[randPos[1]]); key1->loadTextureNormal("normal1.png", UI_TEX_TYPE_PLIST); key1->loadTexturePressed("pressed1.png", UI_TEX_TYPE_PLIST); key1->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack1)); this->addChild(key1); auto key2 = Button::create(); key2->setPosition(pos[randPos[2]]); key2->loadTextureNormal("normal2.png", UI_TEX_TYPE_PLIST); key2->loadTexturePressed("pressed2.png", UI_TEX_TYPE_PLIST); key2->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack2)); this->addChild(key2); auto key3 = Button::create(); key3->setPosition(pos[randPos[3]]); key3->loadTextureNormal("normal3.png", UI_TEX_TYPE_PLIST); key3->loadTexturePressed("pressed3.png", UI_TEX_TYPE_PLIST); key3->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack3)); this->addChild(key3); auto key4 = Button::create(); key4->setPosition(pos[randPos[4]]); key4->loadTextureNormal("normal4.png", UI_TEX_TYPE_PLIST); key4->loadTexturePressed("pressed4.png", UI_TEX_TYPE_PLIST); key4->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack4)); this->addChild(key4); auto key5 = Button::create(); key5->setPosition(pos[randPos[5]]); key5->loadTextureNormal("normal5.png", UI_TEX_TYPE_PLIST); key5->loadTexturePressed("pressed5.png", UI_TEX_TYPE_PLIST); key5->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack5)); this->addChild(key5); auto key6 = Button::create(); key6->setPosition(pos[randPos[6]]); key6->loadTextureNormal("normal6.png", UI_TEX_TYPE_PLIST); key6->loadTexturePressed("pressed6.png", UI_TEX_TYPE_PLIST); key6->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack6)); this->addChild(key6); auto key7 = Button::create(); key7->setPosition(pos[randPos[7]]); key7->loadTextureNormal("normal7.png", UI_TEX_TYPE_PLIST); key7->loadTexturePressed("pressed7.png", UI_TEX_TYPE_PLIST); key7->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack7)); this->addChild(key7); auto key8 = Button::create(); key8->setPosition(pos[randPos[8]]); key8->loadTextureNormal("normal8.png", UI_TEX_TYPE_PLIST); key8->loadTexturePressed("pressed8.png", UI_TEX_TYPE_PLIST); key8->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack8)); this->addChild(key8); auto key9 = Button::create(); key9->setPosition(pos[randPos[9]]); key9->loadTextureNormal("normal9.png", UI_TEX_TYPE_PLIST); key9->loadTexturePressed("pressed9.png", UI_TEX_TYPE_PLIST); key9->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack9)); this->addChild(key9); auto key10 = Button::create(); key10->setPosition(pos[randPos[10]]); key10->loadTextureNormal("normalok.png", UI_TEX_TYPE_PLIST); key10->loadTexturePressed("pressedok.png", UI_TEX_TYPE_PLIST); key10->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack10)); this->addChild(key10); auto key11 = Button::create(); key11->setPosition(pos[randPos[11]]); key11->loadTextureNormal("normalpoint.png", UI_TEX_TYPE_PLIST); key11->loadTexturePressed("pressedpoint.png", UI_TEX_TYPE_PLIST); key11->addTouchEventListener(this, toucheventselector(GameScene36::keyCallBack11)); this->addChild(key11); }
bool EquipLayer::init() { if (!PopBase::init()){ return false; } //选择背包的ID currSelectBackpackID=-1; //选择穿戴ID currSelectWearpackID=-1; //当前选择英雄ID currSelectHeroID=1; equiplocalBll=EquipmentLocalBLL::create(); equiplocalBll->retain(); m_RootNode = static_cast<Layout*>(CSLoader::createNode("EquipLayer.csb")); this->addChild(m_RootNode); if (kIsPayTest) { APTools::PrintUIWidgetChildrenInfo(m_RootNode); } auto Button_Close=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_Close")); if (Button_Close) { Button_Close->addTouchEventListener(CC_CALLBACK_2(EquipLayer::Button_Exit_BtnOnTouch, this)); } auto Button_xiezai=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_xiezai")); if (Button_xiezai) { Button_xiezai->addTouchEventListener(CC_CALLBACK_2(EquipLayer::Button_xiezai_BtnOnTouch, this)); } auto Button_chushou=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_chushou")); if (Button_chushou) { Button_chushou->addTouchEventListener(CC_CALLBACK_2(EquipLayer::Button_chushou_BtnOnTouch, this)); } auto Button_shiyong=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_shiyong")); if (Button_shiyong) { Button_shiyong->addTouchEventListener(CC_CALLBACK_2(EquipLayer::Button_shiyong_BtnOnTouch, this)); } sv_backpack=dynamic_cast<ui::ScrollView*>(Helper::seekWidgetByName(m_RootNode, "ScrollView_wupinlan")); m_EquipPanel=dynamic_cast<Layout*>(Helper::seekWidgetByName(m_RootNode, "Panel_zhuangbeilan")); m_WearPanel=dynamic_cast<Layout*>(Helper::seekWidgetByName(m_RootNode, "Panel_zhuangbei")); m_BackPanel=dynamic_cast<Layout*>(Helper::seekWidgetByName(m_RootNode, "Panel_wupin")); //选择英雄 sv_Menu = dynamic_cast<ui::ScrollView*>(Helper::seekWidgetByName(m_RootNode, "ScrollView_menu")); auto sv_MenuSize=sv_Menu->getInnerContainerSize(); auto pb=PlayerBLL::create(); int iRow=0; HeroModelBLL *hmb=HeroModelBLL::create(kModelWritablePath); for (int i=0; i<HeroModel_MaxData; i++) { if (pb->getIsBuyHero(i)) { HeroModel *hm=&(hmb->modelData[i]); auto btn=Button::create(); btn->setTag(i+1); btn->loadTextureNormal("imgs/tb_qiehuan_2.png"); btn->loadTextureDisabled("imgs/tb_qiehuan_1.png"); btn->addTouchEventListener(CC_CALLBACK_2(EquipLayer::heroButton_OnTouch, this)); btn->setPosition(Vec2(sv_MenuSize.width/2, sv_MenuSize.height-((iRow * 100)+60))); btn->setTitleText(hm->HeroName); sv_Menu->addChild(btn); m_HeroItemButtons.pushBack(btn); iRow++; } } m_HeroItemButtons.at(0)->setTouchEnabled(false); m_HeroItemButtons.at(0)->setBright(false); m_Panel=dynamic_cast<Layout*>(Helper::seekWidgetByName(m_RootNode, "Panel_juese")); //角色基本属性 t_lv=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "t_LV")); t_currExp=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "t_currExp")); t_power=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "t_strength")); t_currHP=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "t_currHP")); t_attack=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_Attack")); t_def=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_Def")); t_critical=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_critical")); //金币数量 t_gold=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_jinbishu")); //增加的属性 t_addcurrHP=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "t_currHP_add")); t_addattack=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_Attack_add")); t_adddef=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_Def_add")); t_addcritical=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_critical_add")); //佩戴物品说明 t_wearpackDes=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_zhuangbeixinxi")); t_backpackDes=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_shuxing")); //佩戴物品名 t_wearitemname=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_wupinmingcheng_1")); //包裹物品名 t_backitemname=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_wupinmingcheng_2")); //选中物品边框 s_wearborder = Sprite::create("imgs/k_xuanzhong.png"); m_RootNode->addChild(s_wearborder); //英雄 HeroBase *hero=GameObjectFactory::getHero(currSelectHeroID-1); //刷新数据 updateInfo(hero->getHeroModel()); showWearpack(); showBackpack(); setWearpackDataView(false); setBackpackDataView(false); return true; }
void Button::loadTextures(const char* normal,const char* selected,const char* disabled,TextureResType texType) { loadTextureNormal(normal,texType); loadTexturePressed(selected,texType); loadTextureDisabled(disabled,texType); }
bool OptionScene::init() { if (!Scene::init()) return false; Size visibleSize = Director::getInstance()->getVisibleSize(); //--·µ»Ø°´Å¥--// auto exitScene = [](Ref* pSender) { Director::getInstance()->replaceScene(TransitionFlipX::create(0.5f, MainScene::create(), TransitionScene::Orientation::LEFT_OVER)); }; auto backItem = MenuItemImage::create("UI/BackNormal.png", "UI/BackSelected.png", exitScene); backItem->setPosition(Vec2(backItem->getContentSize().width / 2 + 10, visibleSize.height - backItem->getContentSize().height / 2 - 10)); auto backMenu = Menu::create(backItem, NULL); backMenu->setPosition(Vec2::ZERO); this->addChild(backMenu); //--¸ù²Ëµ¥--// auto rootLayout = createLayout(Lang::get("optionTitle"), this->getContentSize()); this->addChild(rootLayout); auto list = ListView::create(); list->setDirection(ScrollView::Direction::VERTICAL); list->setGravity(ListView::Gravity::CENTER_HORIZONTAL); list->setBounceEnabled(true); list->setItemsMargin(10); list->setContentSize(Size(700, 480)); list->setAnchorPoint(Vec2(0.5f, 0.5f)); list->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2 - 20)); rootLayout->addChild(list); //--ÓïÑÔ°´Å¥--// auto langButton = createButton(Lang::get("selectLang"), Size(600, 60), [=](Ref* pSender) { auto button = (Button*)pSender; auto langLayout = createLayout(Lang::get("selectLang"), Size(600, 600)); auto langList = ListView::create(); langList->setDirection(ScrollView::Direction::VERTICAL); langList->setItemsMargin(10); langList->setGravity(ListView::Gravity::CENTER_HORIZONTAL); langList->setBounceEnabled(true); langList->setContentSize(Size(600, 480)); langList->setAnchorPoint(Vec2(0.5f, 0.5f)); langList->setPosition(Vec2(langLayout->getContentSize().width / 2, langLayout->getContentSize().height / 2 - 20)); langLayout->addChild(langList); auto langs = Lang::getAllLangs(); auto autoLangButton = createButton(Lang::get("autoLang"), Size(500, 60), [this](Ref* pSender) { auto button = static_cast<Button*> (pSender); highlightingButton->loadTextureNormal("UI/ButtonNormal.png"); highlightingButton->setContentSize(Size(500, 60)); highlightingButton = button; button->loadTextureNormal("UI/ButtonActive.png"); button->setContentSize(Size(500, 60)); Lang::setAutoLang(true); Lang::loadAutoLang(); }); if (Lang::isAutoLang()) { autoLangButton->loadTextureNormal("UI/ButtonActive.png"); autoLangButton->setContentSize(Size(500, 60)); highlightingButton = autoLangButton; } langList->addChild(autoLangButton); for (auto i : langs) { auto langButton = createButton(i.first, Size(500, 60), [i, this](Ref* pSender) { auto button = static_cast<Button*> (pSender); highlightingButton->loadTextureNormal("UI/ButtonNormal.png"); highlightingButton->setContentSize(Size(500, 60)); highlightingButton = button; button->loadTextureNormal("UI/ButtonActive.png"); button->setContentSize(Size(500, 60)); Lang::setAutoLang(false); Lang::loadLang(i.second); }); if (!Lang::isAutoLang() && i.second == Lang::getCurrentLang()) { langButton->loadTextureNormal("UI/ButtonActive.png"); langButton->setContentSize(Size(500, 60)); highlightingButton = langButton; } langList->addChild(langButton); } goInto(rootLayout, button, langLayout); backItem->setCallback([=](Ref* pSender) { goOut(rootLayout, button, langLayout); backItem->setCallback(exitScene); }); }); list->addChild(langButton); return true; }
Alert* Alert::create() { //usual cocos create, note that I'm skipping handling errors. should fix that Alert* alert = new (std::nothrow) Alert(); if (alert && alert->init()) { alert->autorelease(); } Size visibleSize = Director::getInstance()->getVisibleSize(); Size node_size = visibleSize*0.80f; alert->setContentSize(node_size); alert->setLayoutType(ui::Layout::Type::RELATIVE); //alert->setBackGroundColor(Color3B::BLACK); //alert->setBackGroundColorOpacity(255/1.5); //alert->setBackGroundColorType(ui::LayoutBackGroundColorType::SOLID); alert->setBackGroundImage("main_UI_export_10_x4.png", TextureResType::PLIST); alert->setBackGroundImageScale9Enabled(true); alert->setBackGroundImageColor(Color3B(114, 160, 72)); //alert->setBackGroundImageOpacity(200.0f); //layout->setClippingEnabled(true); auto create_txt = [&](std::string msg, ui::RelativeLayoutParameter* param) { auto txt = ui::Text::create(msg, DEFAULT_FONT, sx(25.0f)); Label* lbl = (Label*)txt->getVirtualRenderer(); lbl->getFontAtlas()->setAliasTexParameters(); txt->setTextColor(Color4B::BLACK); //txt->enableOutline(Color4B::BLACK, 2); txt->ignoreContentAdaptWithSize(false); //word wrap or something alert->addChild(txt); txt->setLayoutParameter(param); return txt; }; auto header_param = ui::RelativeLayoutParameter::create(); header_param->setRelativeName("header_param"); header_param->setAlign(ui::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL); header_param->setMargin(ui::Margin(sx(10), sy(30), sx(10), sy(10))); alert->header_txt = create_txt("Title Here", header_param); auto sub_header_param = ui::RelativeLayoutParameter::create(); sub_header_param->setRelativeName("sub_header_param"); sub_header_param->setAlign(ui::RelativeAlign::LOCATION_BELOW_CENTER); sub_header_param->setMargin(ui::Margin(sx(10), sy(10), sx(10), sy(10))); alert->sub_header_txt = create_txt("Sub header", sub_header_param); sub_header_param->setRelativeToWidgetName("header_param"); auto body_param = ui::RelativeLayoutParameter::create(); body_param->setAlign(ui::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL); body_param->setMargin(ui::Margin(sx(30), sy(10), sx(10), sy(10))); alert->body_txt = create_txt("Body content", body_param); Size body_size = alert->body_txt->getAutoRenderSize(); alert->body_txt->setTextAreaSize(Size( body_size.width, body_size.height )); auto close_btn = ui::Button::create(); close_btn->addTouchEventListener([alert](Ref*, TouchEventType type) { if (type == TouchEventType::ENDED) { Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); Vec2 pos = Vec2( origin.x + visibleSize.width - 20, origin.y + 20 ); alert->shrink_close(pos); }; }); close_btn->setTitleText("X"); close_btn->setTitleColor(Color3B::RED); close_btn->setTitleFontSize(sx(40.0f)); close_btn->getTitleRenderer()->enableOutline(Color4B::GRAY, 10); close_btn->setScaleX(sx(1.0f)); close_btn->setScaleY(sy(1.0f)); alert->close_btn = close_btn; ui::RelativeLayoutParameter* close_param = ui::RelativeLayoutParameter::create(); close_param->setAlign(ui::RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT); close_param->setMargin(ui::Margin(sx(30), sy(20), sx(30), sy(30))); alert->close_btn->setLayoutParameter(close_param); alert->addChild(alert->close_btn); auto done_btn = ui::Button::create(); done_btn->addTouchEventListener([alert](Ref*, TouchEventType type) { if (type == TouchEventType::ENDED) { Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); Vec2 pos = Vec2( origin.x + visibleSize.width - 20, origin.y + 20 ); alert->shrink_close(pos); }; }); done_btn->setScale9Enabled(true); done_btn->loadTextureNormal("main_UI_export_10_scale9_x4.png", ui::TextureResType::PLIST); done_btn->setTitleText("Done"); done_btn->setTitleFontSize(40.0f); done_btn->setTitleFontName(DEFAULT_FONT); auto lbl_size = done_btn->getTitleRenderer()->getContentSize(); done_btn->setContentSize( Size( lbl_size.width * 1.5f, lbl_size.height * 1.5f ) ); done_btn->ignoreContentAdaptWithSize(false); //word wrap or something done_btn->setTitleColor(Color3B::BLACK); done_btn->setScaleX(sx(1.0f)); done_btn->setScaleY(sy(1.0f)); alert->done_btn = done_btn; ui::RelativeLayoutParameter* done_param = ui::RelativeLayoutParameter::create(); done_param->setAlign(ui::RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL); done_param->setMargin(ui::Margin(sx(30), sy(20), sx(30), sy(30))); done_param->setRelativeName("done_btn"); alert->done_btn->setLayoutParameter(done_param); alert->addChild(alert->done_btn); auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan = CC_CALLBACK_2(Alert::onTouchBegan, alert); listener->onTouchEnded = CC_CALLBACK_2(Alert::onTouchEnded, alert); Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, alert); return alert; };
//添加一些显示标签 void GameLayer:: addSprite(){ //显第几关的label auto temp = __String::createWithFormat("Level: %d",level); levelLabel = Label::createWithSystemFont(temp->getCString(), "fonts/Marker Felt.ttf", 32); levelLabel->setPosition(Point(80, visibleSize.height-40)); levelLabel->setColor(Color3B(255, 255, 255)); this->addChild(levelLabel,1); //显分数的label xmller.XmlParse(str); std::string level02= xmller.getLevel02(); int number=atoi(level02.c_str()); log("xml score=%d",number); auto sc = __String::createWithFormat("Money: %d",number); scoreLabel = Label::createWithSystemFont(sc->getCString(), "fonts/Marker Felt.ttf", 32); scoreLabel->setPosition(Point(110, visibleSize.height-80)); scoreLabel->setColor(Color3B(255, 255, 0)); this->addChild(scoreLabel,1); //显示子弹数量 std::string level03 = xmller.getLevel03(); int bb = atoi(level03.c_str()); auto cc = __String::createWithFormat("Bullet: %d",bb); bulletLabel = Label::createWithSystemFont(cc->getCString(), "fonts/Marker Felt.ttf", 32); bulletLabel->setPosition(Point(110, visibleSize.height-120)); bulletLabel->setColor(Color3B(0, 255, 0)); this->addChild(bulletLabel,1); //暂停的按钮 auto ub=Button::create(); ub->loadTextureNormal("newPause_Normal.png"); ub->loadTexturePressed("newPause_Select.png"); ub->setScale(0.4); ub->setScale9Enabled(true); ub->setContentSize(Size(128,128)); ub->setPressedActionEnabled(false); ub->setZoomScale(2.0f);//大于1有效小于1无效 ub->addClickEventListener([this](Ref*){ auto l = PauseLayer::createLayer(); l->setDelegate(this); //设置代理---------------------- this->addChild(l); auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan=([](Touch*, Event*){ return true; }); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, l); Director::getInstance()->pause(); }); ub->setPosition(Vec2(visibleSize.width-50,50)); this->addChild(ub); }