void SelectMenuView::noticeShowLock(int beautyIndex, int needHeart) { _panelUnlock->setVisible(true); _panelUnlock->setTouchEnabled(true); // setting head UIImageView* head = (UIImageView*)_panelUnlock->getChildByName("panelLock_head"); char tmp[32]; sprintf(tmp,"head_%d.png",beautyIndex); head->loadTexture(tmp,UI_TEX_TYPE_PLIST); // setting heart number for(int i=0; i<MAX_HEART; i++) { sprintf(tmp,"panelLock_heart_%d",i+1); if(i<needHeart) { _panelUnlock->getChildByName(tmp)->setVisible(true); } else { _panelUnlock->getChildByName(tmp)->setVisible(false); } } // setting beauty name UILabelBMFont* labelName = (UILabelBMFont*) _panelUnlock->getChildByName("panelLock_txt_name"); labelName->setText(BeautyStaticData::getInstance()->getName(beautyIndex)); // setting unlock price UILabelBMFont* labelPrice = (UILabelBMFont*) _panelUnlock->getChildByName("panelLock_txt_price"); sprintf(tmp,"$%d",BeautyStaticData::getInstance()->getRequiement(beautyIndex+1)); labelPrice->setText(tmp); // animation UIWidget* bg = _panelUnlock->getChildByName("panelLock_bg"); bg->setScale(0.1f); bg->runAction(CCScaleTo::create(0.3f,1)); UIButton* button = (UIButton*)_panelUnlock->getChildByName("panelLock_btn_back"); button->setTouchEnabled(true); button->setPressedActionEnabled(true); button->addTouchEventListener(this,toucheventselector(SelectMenuView::onTouchUnlock)); button = (UIButton*)_panelUnlock->getChildByName("panelLock_btn_unlock"); button->setTouchEnabled(true); button->setPressedActionEnabled(true); button->addTouchEventListener(this,toucheventselector(SelectMenuView::onTouchUnlock)); this->addWidget(_panelUnlock); }
void GameLayer_Menu::addTaskBtnCallback(cocos2d::CCObject *target, SEL_CallFuncO callfun) { UIButton* taskBtn = dynamic_cast<UIButton*>(gameMenu->getWidgetByName("SysInfoBtn")); taskBtn->addReleaseEvent(target, callfun); taskBtn->setPressedActionEnabled(true); }
void PlayScene::onEnter() { CCScene::onEnter(); CCLOG("%s", __FUNCTION__); // load ui ui_layer_ = UILayer::create(); ui_layer_text_ = UILayer::create(); char path[1024]; snprintf(path, 1024, "MainScene/GirlScene%d.json", stageid_); Layout *layout = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile(path)); ui_layer_->addWidget(layout); card_mgr_.CreateLayer(this); this->addChild(ui_layer_, 0, 100); this->addChild(card_mgr_.card_layer(), 1, 101); this->addChild(ui_layer_text_, 2, 100); card_mgr_.Init(stageid_); UIButton *btn = (UIButton *)ui_layer_->getWidgetByName("BtnBack"); if (btn) { btn->addTouchEventListener(this, toucheventselector(PlayScene::onBtnBack)); btn->setPressedActionEnabled(true); } UIPanel *panel = (UIPanel *)ui_layer_->getWidgetByName("PanelSecond"); if(panel == NULL) { return; } panel->setVisible(false); panel->setTouchEnable(false); btn = (UIButton *)ui_layer_->getWidgetByName("BtnStartPlay"); if (btn) { btn->addTouchEventListener(this, toucheventselector(PlayScene::onBtnStartPlay)); CCScaleTo* scale1 = CCScaleTo::create( 1.0f, 1.2f); CCScaleTo* scale2 = CCScaleTo::create( 1.0f, 0.8f); CCSequence* scale = CCSequence::createWithTwoActions(scale1, scale2); btn->getVirtualRenderer()->runAction(CCRepeatForever::create(scale)); } btn = (UIButton *)ui_layer_->getWidgetByName("BtnShirt"); if (btn) { btn->setTouchEnable(false); } card_mgr_.SetEnable(false); be_back_ = false; property_state_ = -1; }
bool GameLayer_GoldMarket::init() { if (!CCLayer::init()) { return false; } //系统设置界面. goldMarket = UILayer::create(); auto layout = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("./CocoStudioResources/GoldMarket.json")); goldMarket->addWidget(layout); // sysSet->setVisible(true); this->addChild(goldMarket, 0, 101); UIPanel* panel = dynamic_cast<UIPanel*>(goldMarket->getWidgetByName("Panel")); panel->setBackGroundColor(ccBLACK); panel->setBackGroundColorOpacity(150); //关闭按钮 UIButton* closeBtn = dynamic_cast<UIButton*>(goldMarket->getWidgetByName("CloseBtn")); closeBtn->setTouchEnable(true); closeBtn->addReleaseEvent(this, coco_releaseselector(GameLayer_GoldMarket::closeBtnCallback)); closeBtn->setPressedActionEnabled(true); //购买按钮. UIButton* buyBtn_0 = dynamic_cast<UIButton*>(goldMarket->getWidgetByName("BuyBtn_0")); buyBtn_0->setTag(Buy_0); buyBtn_0->setPressedActionEnabled(true); buyBtn_0->addReleaseEvent(this, coco_releaseselector(GameLayer_GoldMarket::buyBtnCallback)); UIButton* buyBtn_1 = dynamic_cast<UIButton*>(goldMarket->getWidgetByName("BuyBtn_1")); buyBtn_1->setTag(Buy_1); buyBtn_1->setPressedActionEnabled(true); buyBtn_1->addReleaseEvent(this, coco_releaseselector(GameLayer_GoldMarket::buyBtnCallback)); UIButton* buyBtn_2 = dynamic_cast<UIButton*>(goldMarket->getWidgetByName("BuyBtn_2")); buyBtn_2->setTag(Buy_2); buyBtn_2->setPressedActionEnabled(true); buyBtn_2->addReleaseEvent(this, coco_releaseselector(GameLayer_GoldMarket::buyBtnCallback)); UIButton* buyBtn_3 = dynamic_cast<UIButton*>(goldMarket->getWidgetByName("BuyBtn_3")); buyBtn_3->setTag(Buy_3); buyBtn_3->setPressedActionEnabled(true); buyBtn_3->addReleaseEvent(this, coco_releaseselector(GameLayer_GoldMarket::buyBtnCallback)); //UIButton* buyBtn_4 = dynamic_cast<UIButton*>(goldMarket->getWidgetByName("BuyBtn_4")); //buyBtn_4->setTag(Buy_4); //buyBtn_4->setPressedActionEnabled(true); //buyBtn_4->addReleaseEvent(this, coco_releaseselector(GameLayer_GoldMarket::buyBtnCallback)); this->setValue(); //添加兑换按钮 this->setVisible(true); return true; }
bool GameLayerPkBar::init() { if (!CCLayer::init()) { return false; } ul = UILayer::create(); auto myLayout = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile(CStringUtil::convertToUIResPath("PkBar.json").c_str())); ul->addWidget(myLayout); this->addChild(ul, 0, 100); UIButton* btn = dynamic_cast<UIButton*>(ul->getWidgetByName("Sure")); btn->setPressedActionEnabled(true); btn->setTouchEnable(true); btn->addReleaseEvent(this, coco_releaseselector(GameLayerPkBar::sureBtnCallback)); return true; }
bool UIButtonTest_PressedAction::init() { if (UIScene::init()) { CCSize widgetSize = m_pWidget->getSize(); // Add a label in which the button events will be displayed m_pDisplayValueLabel = UILabel::create(); m_pDisplayValueLabel->setText("No Event"); m_pDisplayValueLabel->setFontName("Marker Felt"); m_pDisplayValueLabel->setFontSize(32); m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1)); m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); m_pUiLayer->addWidget(m_pDisplayValueLabel); // Add the alert UILabel* alert = UILabel::create(); alert->setText("Button Pressed Action"); alert->setFontName("Marker Felt"); alert->setFontSize(30); alert->setColor(ccc3(159, 168, 176)); alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75)); m_pUiLayer->addWidget(alert); // Create the button UIButton* button = UIButton::create(); button->setTouchEnabled(true); button->setPressedActionEnabled(true); button->loadTextures("cocosui/animationbuttonnormal.png", "", ""); button->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest_PressedAction::touchEvent)); m_pUiLayer->addWidget(button); return true; } return false; }
void ShopScene::onEnter() { CCScene::onEnter(); CCLOG("%s", __FUNCTION__); // load ui ui_layer_ = UILayer::create(); Layout *layout = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile("MainScene/ShopScene.json")); ui_layer_->addWidget(layout); this->addChild(ui_layer_, 0, 100); UIButton *btn = (UIButton *)ui_layer_->getWidgetByName("BtnBack"); if (btn) { btn->addTouchEventListener(this, toucheventselector(ShopScene::onBtnBack)); btn->setPressedActionEnabled(true); } struct ButtonListener bl[] = { {"BtnSale10", toucheventselector(ShopScene::onBtnSale1)}, {"BtnSale20", toucheventselector(ShopScene::onBtnSale2)}, {"BtnSale70", toucheventselector(ShopScene::onBtnSale3)}, {"BtnSale150", toucheventselector(ShopScene::onBtnSale4)}, {"BtnSaleSpecial", toucheventselector(ShopScene::onBtnSale5)}, }; for (size_t i = 0; i < sizeof(bl) / sizeof(bl[0]); i++) { btn = (UIButton *)ui_layer_->getWidgetByName(bl[i].name); if (btn) { btn->addTouchEventListener(this, bl[i].selector); } } if (iap_ == NULL) { iap_ = ProductList(); CCLOG("init iap %p\n", iap_); } }
bool GameLayerPk2::init() { if (!CCLayer::init()) { return false; } UILayer* ul = UILayer::create(); auto myLayout = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile(CStringUtil::convertToUIResPath("Pk2.json").c_str())); ul->addWidget(myLayout); this->addChild(ul, 0, 100); UIButton* sureBtn = dynamic_cast<UIButton*>(ul->getWidgetByName("Sure")); sureBtn->setPressedActionEnabled(true); sureBtn->addReleaseEvent(this, coco_releaseselector(GameLayerPk2::sureBtnCallback)); //设置自己的头像. UIImageView* cellBg = dynamic_cast<UIImageView*>(ul->getWidgetByName("Avatar1Bg")); CCSprite* img = CCSprite::create(); img->setContentSize(CCSize(145, 145)); img->setAnchorPoint(ccp(0, 0)); cellBg->addRenderer(img, 10); CImageDownloader::GetInstance()->SendHttpRequest(CPlayerInfoMan::sharedInstance().getPlayerInfo().strImg.c_str(), img, "1000", 1000); //设置自己的名字 UILabel* nameLabel = dynamic_cast<UILabel*>(ul->getWidgetByName("Name1Label")); nameLabel->setText(CPlayerInfoMan::sharedInstance().getPlayerInfo().strName.c_str()); //设置对方的头像 UIImageView* cellBg2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Avatar2Bg")); CCSprite* img2 = CCSprite::create(); img2->setContentSize(CCSize(145, 145)); img2->setAnchorPoint(ccp(0, 0)); cellBg2->addRenderer(img2, 10); CImageDownloader::GetInstance()->SendHttpRequest(CPkSysManager::sharedInstance().playerUrl.c_str(), img2, "1000", 1000); //设置对方名字 UILabel* nameLabel2 = dynamic_cast<UILabel*>(ul->getWidgetByName("Name2Label")); nameLabel2->setText(CPkSysManager::sharedInstance().playerName.c_str()); //设置自己的分数. CCSprite* score = NumSprite::getNumSprite(CPkSysManager::sharedInstance().myScore, "./CocoStudioResources/FriendListTimeNum", 17.0); score->setPosition(ccp(-35, 0)); UIImageView* scoreBg1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("ScoreBg")); scoreBg1->addRenderer(score, 10); //等待迎战; m_iSetTime = 1; Deng = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label1")); Dai = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label2")); Ying = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label3")); Zhan = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label4")); Dain1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label5")); Dain2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label6")); Dain3 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label7")); CCActionInterval* actionTo = CCJumpTo::create(2, ccp(200,200),50, 4); CCActionInterval* actionBy = CCJumpBy::create(2, ccp(300,0), 50, 4); actionUp = CCJumpBy::create(0.3f, ccp(0,0), 20,1); CCActionInterval* actionByBack = actionUp->reverse(); //设置光效旋转 UIImageView* Ray2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("lightimg")); CCActionInterval * rotateto = CCRotateBy::create(6.0f, 360); CCFiniteTimeAction* seq1 = CCSequence::create(rotateto,NULL); CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq1); Ray2->runAction(repeatForever2); //Deng->runAction( CCSequence::create(actionUp, NULL)); //Dai->runAction( CCSequence::create(actionUp, NULL)); // for(int i = 0;i<10;i++) // { // if(i%2==0) // { // // Deng->runAction(actionByBack); // } // else{ // // Dai->runAction(actionByBack); // } // } //this->schedule(schedule_selector(GameLayerPk2::SetDDTime), 0.2f); Deng->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Dai->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Ying->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Zhan->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Dain1->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Dain2->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Dain3->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); return true; }