bool UILabelTest::init() { if (UIScene::init()) { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); UILabel *alert = UILabel::create(); alert->setText("Label"); alert->setFontName("Marker Felt"); alert->setFontSize(30); alert->setColor(ccc3(159, 168, 176)); // alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75)); m_pUiLayer->addWidget(alert); // Create the label UILabel* label = UILabel::create(); label->setText("Label"); label->setFontName("AmericanTypewriter"); label->setFontSize(30); // label->setPosition(ccp(screenSize.width / 2, screenSize.height / 2 + label->getRect().size.height / 4)); m_pUiLayer->addWidget(label); return true; } return false; }
bool ChallengeLayer::init() { if (!CCLayer::init()) return false; //窗口大小 CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); //当前层的位置 CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCLayerColor* layercolor = CCLayerColor::create(ccc4(0,0,0,150),800,480) ; addChild(layercolor); ui = TouchGroup::create(); ui->addWidget(GUIReader::shareReader()->widgetFromJsonFile("UI/GameMainMenu_1/challengeLayer.ExportJson")); ui->setScale(0.8); addChild(ui, 2); registerTouchEvent(ui, "resume_challenge", this, ChallengeLayer::buttonClicked) ; registerTouchEvent(ui, "backtomain", this, ChallengeLayer::buttonClicked) ; registerTouchEvent(ui, "reagain", this, ChallengeLayer::buttonClicked) ; //playSound("music/win.ogg"); ::playUIBackgroundMusic(); UIImageView* pImageNewRecord= imageObj_name(ui, "new_record"); pImageNewRecord -> setVisible(false); Achievement& achi = RunningData::getInstance()->getAchievement(); int mostTopTimes = achi.getMostTopTimes(); if(mostTopTimes < repeatTimes) { achi.setMostTopTimes(repeatTimes); achi.save(); CCActionInterval* action1 =CCShake::create(0.1,8); pImageNewRecord->runAction(action1); pImageNewRecord -> setVisible(true); } UILabel* times = labelObj_name(ui, "challenge_num_1"); UILabel* top = labelObj_name(ui, "challenge_num_2"); UILabel* gold = labelObj_name(ui, "challenge_num_3"); char tem[10]; sprintf(tem, "%i", repeatTimes); times->setText(tem); sprintf(tem, "%i", achi.getMostTopTimes()); top->setText(tem); sprintf(tem, "%i", totolGold); gold->setText(tem); return true; }
void Scene_GameItem::itemBtnCallBack(cocos2d::CCObject *object) { UIButton* btn = (UIButton*)object; UIImageView* img; //通过游戏的道具信息获取道具价钱. sItemData* itemData = CGameInfoMan::sharedInstance().getItemDate(GameShare_Global::shareGlobal()->gameType, btn->getTag()); UILabel* itemInfo = dynamic_cast<UILabel*>(ul->getWidgetByName("Label_591")); switch (btn->getTag()) { case Btn_1: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_1")); break; case Btn_2: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_2")); break; case Btn_3: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_3")); break; case Btn_4: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_4")); break; default: break; } if (img->isVisible()) { img->setVisible(false); if (itemData) { CCString infoStr; infoStr.initWithFormat("%s:%s",itemData->ItemName.c_str(),itemData->ItemDetail.c_str()); itemInfo->setText(infoStr.getCString()); needGold -= itemData->CurrencyValue; } }else{ img->setVisible(true); if (itemData) { CCString infoStr; infoStr.initWithFormat("%s:%s",itemData->ItemName.c_str(),itemData->ItemDetail.c_str()); itemInfo->setText(infoStr.getCString()); needGold += itemData->CurrencyValue; if (CPlayerInfoMan::sharedInstance().getPlayerInfo().nMoney < needGold) { GameLayer_Alert *alertUl = GameLayer_Alert::creatWithOnlySure(Type_OnlySure); needGold -= itemData->CurrencyValue; alertUl->setText(GET_STRING_CSV(1010000021)); this->addChild(alertUl,1); img->setVisible(false); } } } this->setItemByTag(btn->getTag()); }
void KHeroLevUpResultPanel::Show(const KHeroDef& oldHero,const KHeroDef& newHero) { m_bPlay = true; if(!m_Panel->getParent()) m_layer->addWidget(m_Panel); m_oldHero = oldHero; m_newHero = newHero; m_elapsed = 0.0f; CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(KHeroLevUpResultPanel::DoClose),this,6,0,0.0f,false); char sz[64]; UILabel* labelOldStrong = (UILabel*)m_Panel->getChildByName("old_strong_val"); sprintf(sz,"%d",oldHero.GetStrong()); labelOldStrong->setText(sz); UIWidget* strongTo = m_Panel->getChildByName("strong_to"); UILabel* labelNewStrong = (UILabel*)m_Panel->getChildByName("new_strong_val"); strongTo->setVisible(false); labelNewStrong->setVisible(false); sprintf(sz,"%d",newHero.GetStrong()); labelNewStrong->setText(sz); UILabel* labelOldLucky = (UILabel*)m_Panel->getChildByName("old_lucky_val"); sprintf(sz,"%d",oldHero.GetLucky()); labelOldLucky->setText(sz); UIWidget* luckyTo = m_Panel->getChildByName("lucky_to"); UILabel* labelNewLucky = (UILabel*)m_Panel->getChildByName("new_lucky_val"); sprintf(sz,"%d",newHero.GetLucky()); labelNewLucky->setText(sz); luckyTo->setVisible(false); labelNewLucky->setVisible(false); m_pNewSkill = NULL; for(int i=0; i<MAX_HERO_SKILL_NUM; i++) { if(newHero._skill[i]._id>0 && oldHero._skill[i]._id==0) { m_pNewSkill = &newHero._skill[i]; break; } } UILabel* lableSkill = (UILabel*)m_Panel->getChildByName("skill_name"); lableSkill->setVisible(false); if(m_pNewSkill) { lableSkill->setText(m_pNewSkill->GetName()); } for(int i=0; i<MAX_HERO_LEV_NUM; i++) { UIWidget* widgetStar = KUIAssist::GetIndexWidget(m_Panel,"star",i); widgetStar->setVisible(false); } }
bool UIImageViewTest_Scale9::init() { if (UIScene::init()) { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); UILabel *alert = UILabel::create(); alert->setText("ImageView scale9 render"); alert->setFontName("Marker Felt"); alert->setFontSize(30); alert->setColor(ccc3(159, 168, 176)); // alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75)); m_pUiLayer->addWidget(alert); // Create the ui layer UILayer *ul = UILayer::create(); ul->scheduleUpdate(); addChild(ul); // Create the imageview UIImageView *imageView = UIImageView::create(); imageView->setScale9Enabled(true); imageView->loadTexture("cocosgui/buttonHighlighted.png"); // imageView->setScale9Size(CCSizeMake(200, 85)); // imageView->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + imageView->getRect().size.height / 4.0f)); ul->addWidget(imageView); return true; } return false; }
bool UITextAreaTest::init() { if (UIScene::init()) { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); UILabel *alert = UILabel::create(); alert->setText("TextArea"); alert->setFontName("Marker Felt"); alert->setFontSize(30); alert->setColor(ccc3(159, 168, 176)); alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75)); m_pUiLayer->addWidget(alert); // Create the text area UITextArea* textArea = UITextArea::create(); textArea->setTextAreaSize(CCSizeMake(280, 150)); textArea->setTextHorizontalAlignment(kCCTextAlignmentCenter); textArea->setText("TextArea widget can line wrap"); textArea->setFontName("AmericanTypewriter"); textArea->setFontSize(32); textArea->setPosition(ccp(screenSize.width / 2, screenSize.height / 2 - textArea->getRect().size.height / 8)); m_pUiLayer->addWidget(textArea); return true; } return false; }
bool UILoadingBarTest_Left_Scale9::init() { if (UIScene::init()) { scheduleUpdate(); CCSize widgetSize = m_pWidget->getSize(); // Add the alert UILabel *alert = UILabel::create(); alert->setText("LoadingBar left scale9 render"); alert->setFontName("Marker Felt"); alert->setFontSize(20); alert->setColor(ccc3(159, 168, 176)); alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7)); m_pUiLayer->addWidget(alert); // Create the loading bar UILoadingBar* loadingBar = UILoadingBar::create(); loadingBar->setName("LoadingBar"); loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png"); loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(CCRectMake(0, 0, 0, 0)); /*===*/ loadingBar->setSize(CCSizeMake(300, loadingBar->getContentSize().height)); /*=*/ loadingBar->setPercent(0); loadingBar->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); m_pUiLayer->addWidget(loadingBar); return true; } return false; }
bool UILoadingBarTest::init() { if (UIScene::init()) { scheduleUpdate(); CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); // Add the alert UILabel *alert = UILabel::create(); alert->setText("LoadingBar"); alert->setFontName("Marker Felt"); alert->setFontSize(30); alert->setColor(ccc3(159, 168, 176)); // alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75)); m_pUiLayer->addWidget(alert); // Create the loading bar UILoadingBar* loadingBar = UILoadingBar::create(); loadingBar->setName("LoadingBar"); loadingBar->loadTexture("cocosgui/sliderProgress.png"); // loadingBar->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + loadingBar->getRect().size.height / 4.0f)); m_pUiLayer->addWidget(loadingBar); return true; } return false; }
bool UIWidgetAddNodeTest::init() { if (UIScene::init()) { CCSize widgetSize = m_pWidget->getSize(); // Add the alert UILabel *alert = UILabel::create(); alert->setText("Widget Add Node"); 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 ui node container UIWidget* widget = UIWidget::create(); widget->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); m_pUiLayer->addWidget(widget); CCSprite* sprite = CCSprite::create("cocosui/ccicon.png"); sprite->setPosition(ccp(0, sprite->boundingBox().size.height / 4)); widget->addNode(sprite); return true; } return false; }
bool UILoadingBarTest_Left::init() { if (UIScene::init()) { scheduleUpdate(); CCSize widgetSize = m_pWidget->getSize(); // Add the alert UILabel *alert = UILabel::create(); alert->setText("LoadingBar left"); 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 loading bar UILoadingBar* loadingBar = UILoadingBar::create(); loadingBar->setName("LoadingBar"); loadingBar->loadTexture("cocosui/sliderProgress.png"); loadingBar->setPercent(0); loadingBar->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); m_pUiLayer->addWidget(loadingBar); return true; } return false; }
void CocosGUIExamplesPageScene::onEnter() { CCScene::onEnter(); m_pUILayer = UILayer::create(); m_pUILayer->scheduleUpdate(); addChild(m_pUILayer); PageInit(); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); UILabel* label = UILabel::create(); label->setText("Move by horizontal direction"); label->setFontName("Marker Felt"); label->setFontSize(32); label->setAnchorPoint(ccp(0.5f, -1)); label->setPosition(ccp(winSize.width / 2.0f, winSize.height / 2.0f + label->getContentSize().height * 1.5)); m_pUILayer->addWidget(label); // left button UIButton* left_button = UIButton::create(); left_button->setTouchEnable(true); left_button->loadTextures("cocosgui/UITest/b1.png", "cocosgui/UITest/b2.png", ""); float left_button_width = left_button->getContentSize().width; left_button->setPosition(ccp(left_button_width - left_button_width / 2, m_pUILayer->getContentSize().height / 2)); left_button->addReleaseEvent(this, coco_releaseselector(CocosGUIExamplesPageScene::toCocosGUIExamplesMapScene)); m_pUILayer->addWidget(left_button); }
UILabel* UI::addLabel(int id, int x, int y, int width, int height, const char* text) { UILabel* label = new UILabel(mRootNode); label->nodeID = id; label->setPos(x, y); label->setText(text); label->setSize(width, height); nodeList.push_back(label); return label; }
/*===*/ bool UISliderTest::init() { if (UIScene::init()) { CCSize widgetSize = m_pWidget->getSize(); // Add a label in which the slider alert will be displayed m_pDisplayValueLabel = UILabel::create(); m_pDisplayValueLabel->setText("Move the slider thumb"); 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("Slider"); 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 slider UISlider* slider = UISlider::create(); slider->setTouchEnabled(true); slider->loadBarTexture("cocosgui/sliderTrack.png"); slider->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", ""); slider->loadProgressBarTexture("cocosgui/sliderProgress.png"); slider->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); // slider->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + slider->getSize().height * 2)); slider->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent)); m_pUiLayer->addWidget(slider); /* // Create the slider that set allow min progress and allow max progress UISlider* sliderAllow = UISlider::create(); //===// // sliderAllow->setMinAllowPercent(20); // sliderAllow->setMaxAllowPercent(80); // sliderAllow->setTouchEnabled(true); sliderAllow->loadBarTexture("cocosgui/sliderTrack.png"); sliderAllow->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", ""); sliderAllow->loadProgressBarTexture("cocosgui/sliderProgress.png"); sliderAllow->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - sliderAllow->getSize().height * 2)); sliderAllow->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent)); m_pUiLayer->addWidget(sliderAllow); */ return true; } return false; }
bool UIScrollViewTest_Both::init() { if (UIScene::init()) { CCSize widgetSize = m_pWidget->getSize();; // Add a label in which the dragpanel events will be displayed m_pDisplayValueLabel = UILabel::create(); m_pDisplayValueLabel->setText("Move by any direction"); 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_pDisplayValueLabel->getSize().height * 1.5)); m_pUiLayer->addWidget(m_pDisplayValueLabel); // Add the alert UILabel *alert = UILabel::create(); alert->setText("ScrollView both"); 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 * 3.075)); m_pUiLayer->addWidget(alert); Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel")); // Create the dragpanel UIScrollView* scrollView = UIScrollView::create(); scrollView->setDirection(SCROLLVIEW_DIR_BOTH); scrollView->setTouchEnabled(true); scrollView->setBounceEnabled(true); scrollView->setBackGroundImageScale9Enabled(true); scrollView->setBackGroundImage("cocosgui/green_edit.png"); scrollView->setSize(CCSizeMake(210, 122.5)); CCSize backgroundSize = background->getContentSize(); scrollView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 + (backgroundSize.width - scrollView->getSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + (backgroundSize.height - scrollView->getSize().height) / 2)); UIImageView* imageView = UIImageView::create(); imageView->setTouchEnabled(true); imageView->loadTexture("cocosgui/b11.png"); scrollView->addChild(imageView); scrollView->setInnerContainerSize(imageView->getContentSize()); CCSize innerSize = scrollView->getInnerContainerSize(); imageView->setPosition(ccp(innerSize.width / 2, innerSize.height / 2)); m_pUiLayer->addWidget(scrollView); return true; } return false; }
bool UILayoutTest_Color::init() { if (UIScene::init()) { CCSize widgetSize = m_pWidget->getSize(); // Add the alert UILabel* alert = UILabel::create(); alert->setText("Layout color render"); 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 * 3.075)); m_pUiLayer->addWidget(alert); UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel")); // Create the layout with color render UILayout* layout = UILayout::create(); layout->setBackGroundColorType(LAYOUT_COLOR_SOLID); layout->setBackGroundColor(ccc3(128, 128, 128)); layout->setSize(CCSizeMake(280, 150)); CCSize backgroundSize = background->getContentSize(); layout->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 + (backgroundSize.width - layout->getSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + (backgroundSize.height - layout->getSize().height) / 2)); m_pUiLayer->addWidget(layout); UIButton* button = UIButton::create(); button->setTouchEnabled(true); button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setPosition(ccp(button->getSize().width / 2, layout->getSize().height - button->getSize().height / 2)); layout->addChild(button); UIButton* titleButton = UIButton::create(); titleButton->setTouchEnabled(true); titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); titleButton->setTitleText("Title Button"); titleButton->setPosition(ccp(layout->getSize().width / 2, layout->getSize().height / 2)); layout->addChild(titleButton); UIButton* button_scale9 = UIButton::create(); button_scale9->setTouchEnabled(true); button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setScale9Enabled(true); button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height)); button_scale9->setPosition(ccp(layout->getSize().width - button_scale9->getSize().width / 2, button_scale9->getSize().height / 2)); layout->addChild(button_scale9); return true; } return false; }
void GameLayer_Menu::setInfoNum() { UIImageView* img = dynamic_cast<UIImageView*>(gameMenu->getWidgetByName("Email_RemindImg")); if (CPlayerInfoMan::sharedInstance().getPlayerInfo().sysInfoNum <= 0) { img->setVisible(false); }else{ img->setVisible(true); UILabel* label = dynamic_cast<UILabel*>(gameMenu->getWidgetByName("InfoLabel")); CCString str; str.initWithFormat("%d",CPlayerInfoMan::sharedInstance().getPlayerInfo().sysInfoNum); label->setText(str.getCString()); } }
void ShopLayer::updateBuyLayout(CCObject* pSender,bool isVis) { UIButton* btn = dynamic_cast<UIButton*>(pSender); UILabel* nameLab = dynamic_cast<UILabel*>(m_buyLayout->getChildByName("propNameLabel")); nameLab->setText(dynamic_cast<UILabel*>(btn->getChildByName("nameLabel"))->getStringValue()); UIImageView* discountImg = dynamic_cast<UIImageView*>(m_buyLayout->getChildByName("discountImg")); discountImg->setVisible(isVis); m_onePri = atoi(dynamic_cast<UILabel*>(btn->getChildByName("priLabel"))->getStringValue()); m_onePriLabel->setText(CCString::createWithFormat("%d",m_onePri)->getCString()); m_buyNum = 1; m_totalPriLabel->setText(CCString::createWithFormat("%d",m_onePri*m_buyNum)->getCString()); }
bool QiangHuaLayer::init(HeroType hero) { if(!CCLayer::init()) { return false; } m_hero=hero; bUpgrade=false; m_pUiLayer=UILayer::create(); this->addChild(m_pUiLayer); CCSize winSize =CCDirector::sharedDirector()->getWinSize(); UIImageView* imageView = UIImageView::create(); imageView->setTexture("herolistbg.png"); imageView->setPosition(ccp(winSize.width/2,winSize.height/2)); m_pUiLayer->addWidget(imageView); UIImageView* heroImage = UIImageView::create(); heroImage->setTexture(hero.textureName.c_str()); heroImage->setPosition(ccp(winSize.width/2,winSize.height/2)); m_pUiLayer->addWidget(heroImage); UIImageView* coinImage = UIImageView::create(); coinImage->setTexture("coins.png"); coinImage->setPosition(ccp(coinImage->getContentSize().width/2+30,winSize.height/2)); coinImage->setTag(111); m_pUiLayer->addWidget(coinImage); UILabel *label = UILabel::create(); char str[32]; sprintf(str,"%d",hero.level); label->setText(str); m_pUiLayer->addWidget(label); UIButton *btn=UIButton::create(); btn->setTouchEnabled(true); btn->setTextures("qianghua1.png","qianghua2.png",""); btn->setPosition(ccp(winSize.width/2,winSize.height/2-250)); btn->addReleaseEvent(this, coco_releaseselector(QiangHuaLayer::qianghua)); m_pUiLayer->addWidget(btn); UIButton *btnclose=UIButton::create(); btnclose->setTouchEnabled(true); btnclose->setTextures("close1.png","close2.png","close2.png"); btnclose->setPosition(ccp(winSize.width-60, winSize.height/2+300)); btnclose->addReleaseEvent(this, coco_releaseselector(QiangHuaLayer::close)); m_pUiLayer->addWidget(btnclose); getHeros(); return true; }
bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init() { if (UIScene::init()) { CCSize widgetSize = m_pWidget->getSize(); // Add a label in which the dragpanel 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_pDisplayValueLabel->getSize().height * 1.5)); m_pUiLayer->addWidget(m_pDisplayValueLabel); // Add the alert UILabel *alert = UILabel::create(); alert->setText("ScrollView scroll to percent both directrion bounce"); alert->setFontName("Marker Felt"); alert->setFontSize(20); alert->setColor(ccc3(159, 168, 176)); alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5)); m_pUiLayer->addWidget(alert); UILayout* background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel")); UIScrollView* sc = UIScrollView::create(); sc->setBackGroundColor(ccGREEN); sc->setBackGroundColorType(LAYOUT_COLOR_SOLID); sc->setBounceEnabled(true); sc->setDirection(SCROLLVIEW_DIR_BOTH); sc->setInnerContainerSize(CCSizeMake(480, 320)); sc->setSize(CCSizeMake(100,100)); CCSize backgroundSize = background->getContentSize(); sc->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 + (backgroundSize.width - sc->getSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + (backgroundSize.height - sc->getSize().height) / 2)); sc->scrollToPercentBothDirection(ccp(50, 50), 1, true); UIImageView* iv = UIImageView::create(); iv->loadTexture("cocosgui/Hello.png"); iv->setPosition(ccp(240, 160)); sc->addChild(iv); m_pUiLayer->addWidget(sc); return true; } return false; }
bool UISwitchTest_VerticalAndTitleVertical::init() { if (UIScene::init()) { CCSize widgetSize = m_pWidget->getSize(); // Add a label in which the switch 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("Switch Vertical and Title Vertical"); alert->setFontName("Marker Felt"); alert->setFontSize(20); alert->setColor(ccc3(159, 168, 176)); alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7)); m_pUiLayer->addWidget(alert); // Create the switch UISwitch* pSwitch = UISwitch::create(); pSwitch->setTouchEnabled(true); pSwitch->loadTextures("cocosgui/switch-mask_v.png", "cocosgui/switch-on_v.png", "cocosgui/switch-off_v.png", "cocosgui/switch-thumb_v.png"); pSwitch->setOnTitleText("On"); pSwitch->setOffTitleText("Off"); pSwitch->setOnTitleFontName("Arial-BoldMT"); pSwitch->setOnTitleFontSize(16); pSwitch->setOffTitleFontName("Arial-BoldMT"); pSwitch->setOffTitleFontSize(16); CCSize switchSize = pSwitch->getSize(); pSwitch->setPosition(ccp((widgetSize.width - switchSize.width) / 2.0f, (widgetSize.height - switchSize.height) / 2.0f)); pSwitch->addEventListenerSwitch(this, switchselector(UISwitchTest_Horizontal::switchEvent)); m_pUiLayer->addWidget(pSwitch); pSwitch->setDirection(SWITCH_DIRECTION_VERTICAL); // set unicode text with title vertical direction pSwitch->setTitleDirection(SWITCH_TITLE_DIRECTION_VERTICAL); return true; } return false; }
void UIMenu::addMenuBreak() { UILabel* label = new UILabel(gfx); label->setColor(MENU_TEXT_COLOR); label->setText("...", 0, text_size); label->setPosition(vector2()); label->setActive(false); // label->fadeIn(); //size[0] = 18; size[1] = (labels_n+1)*text_size; gfx->addSceneNode(label, this); labels.push_back(label); labels_n++; }
void UIMenu::addMenuOption(const char* text, bool isSelected) { UILabel* label = new UILabel(gfx); if(isSelected) label->setColor(MENU_TEXT_COLOR_SELECTED); else label->setColor(MENU_TEXT_COLOR); label->setText(text, text_font, text_size); label->setPosition(vector2()); label->setActive(false); // label->fadeIn(); float minMenuSizeX = strlen(text)*(text_size-text_size/2); if(minMenuSizeX > size[0]) size[0] = minMenuSizeX; size[1] = (labels_n+1)*text_size; gfx->addSceneNode(label, this); labels.push_back(label); labels_n++; }
bool UISwitchTest_Horizontal::init() { if (UIScene::init()) { CCSize widgetSize = m_pWidget->getSize(); // Add a label in which the switch 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("Switch Horizontal"); 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 switch UISwitch* pSwitch = UISwitch::create(); pSwitch->setTouchEnabled(true); pSwitch->loadTextures("cocosgui/switch-mask.png", "cocosgui/switch-on.png", "cocosgui/switch-off.png", "cocosgui/switch-thumb.png"); pSwitch->setOnTitleText("Hello\nWorld"); pSwitch->setOffTitleText("Come\nOn"); pSwitch->setOnTitleFontName("Arial-BoldMT"); pSwitch->setOnTitleFontSize(10); pSwitch->setOffTitleFontName("Arial-BoldMT"); pSwitch->setOffTitleFontSize(10); CCSize switchSize = pSwitch->getSize(); pSwitch->setPosition(ccp((widgetSize.width - switchSize.width) / 2.0f, (widgetSize.height - switchSize.height) / 2.0f)); pSwitch->addEventListenerSwitch(this, switchselector(UISwitchTest_Horizontal::switchEvent)); m_pUiLayer->addWidget(pSwitch); return true; } return false; }
bool UITextFieldTest_LineWrap::init() { if (UIScene::init()) { CCSize widgetSize = m_pWidget->getSize(); // Add a label in which the textfield events will be displayed m_pDisplayValueLabel = UILabel::create(); m_pDisplayValueLabel->setText("No Event"); m_pDisplayValueLabel->setFontName("Marker Felt"); m_pDisplayValueLabel->setFontSize(30); m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1)); m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getSize().height * 1.5)); m_pUiLayer->addWidget(m_pDisplayValueLabel); // Add the alert UILabel *alert = UILabel::create(); alert->setText("TextField line wrap"); 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 * 3.075)); m_pUiLayer->addWidget(alert); // Create the textfield UITextField* textField = UITextField::create(); UICCTextField* render = static_cast<UICCTextField*>(textField->getVirtualRenderer()); render->setDimensions(CCSizeMake(240, 160)); render->setHorizontalAlignment(kCCTextAlignmentCenter); render->setVerticalAlignment(kCCVerticalTextAlignmentCenter); textField->setTouchEnabled(true); textField->setFontName("Marker Felt"); textField->setFontSize(30); textField->setPlaceHolder("input words here"); textField->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_LineWrap::textFieldEvent)); m_pUiLayer->addWidget(textField); return true; } return false; }
bool UITextFieldTest_Password::init() { if (UIScene::init()) { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); // Add a label in which the textfield 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(screenSize.width / 2.0f, screenSize.height / 2.0f + m_pDisplayValueLabel->getSize().height * 1.5)); m_pUiLayer->addWidget(m_pDisplayValueLabel); // Add the alert UILabel *alert = UILabel::create(); alert->setText("TextField password"); alert->setFontName("Marker Felt"); alert->setFontSize(30); alert->setColor(ccc3(159, 168, 176)); alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getSize().height * 3.0f)); m_pUiLayer->addWidget(alert); // Create the textfield UITextField* textField = UITextField::create(); textField->setPasswordEnabled(true); textField->setPasswordStyleText("*"); textField->setTouchEnabled(true); textField->setFontName("Marker Felt"); textField->setFontSize(30); textField->setPlaceHolder("input password here"); textField->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_Password::textFieldEvent)); m_pUiLayer->addWidget(textField); return true; } return false; }
bool UIScene::init() { if (CCLayer::init()) { m_pUiLayer = UILayer::create(); addChild(m_pUiLayer); m_pWidget = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile("cocosgui/UITest/UITest.json")); m_pUiLayer->addWidget(m_pWidget); m_pSceneTitle = dynamic_cast<UILabel*>(m_pUiLayer->getWidgetByName("UItest")); UILabel *back_label = dynamic_cast<UILabel*>(m_pUiLayer->getWidgetByName("back")); back_label->setVisible(false); // back_label->addReleaseEvent(this, coco_releaseselector(UIScene::toExtensionsMainLayer)); UIButton *left_button = dynamic_cast<UIButton*>(m_pUiLayer->getWidgetByName("left_Button")); left_button->addTouchEventListener(this, toucheventselector(UIScene::previousCallback)); UIButton *middle_button = dynamic_cast<UIButton*>(m_pUiLayer->getWidgetByName("middle_Button")); middle_button->addTouchEventListener(this, toucheventselector(UIScene::restartCallback)); UIButton *right_button = dynamic_cast<UIButton*>(m_pUiLayer->getWidgetByName("right_Button")); right_button->addTouchEventListener(this, toucheventselector(UIScene::nextCallback)); UILabel* mainMenuLabel = UILabel::create(); mainMenuLabel->setText("MainMenu"); mainMenuLabel->setFontSize(20); mainMenuLabel->setTouchScaleChangeEnabled(true); mainMenuLabel->setPosition(Point(430,30)); mainMenuLabel->setTouchEnabled(true); mainMenuLabel->addTouchEventListener(this, toucheventselector(UIScene::menuCloseCallback)); m_pUiLayer->addWidget(mainMenuLabel); return true; } return false; }
bool UIButtonTest_Scale9::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 scale9 render"); 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); // open scale9 render button->setScale9Enabled(true); button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->setSize(CCSizeMake(150, button->getContentSize().height * 1.5f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest_Scale9::touchEvent)); m_pUiLayer->addWidget(button); return true; } return false; }
bool UINodeContainerTest::init() { if (UIScene::init()) { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); // Add a label in which the UINodeContainer alert will be displayed m_pDisplayValueLabel = UILabel::create(); m_pDisplayValueLabel->setText("NodeContainer Add CCNode"); m_pDisplayValueLabel->setFontName("Marker Felt"); m_pDisplayValueLabel->setFontSize(32); m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1)); // m_pDisplayValueLabel->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5)); m_pUiLayer->addWidget(m_pDisplayValueLabel); // Add the alert UILabel *alert = UILabel::create(); alert->setText("NodeContainer"); alert->setFontName("Marker Felt"); alert->setFontSize(30); alert->setColor(ccc3(159, 168, 176)); // alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75)); m_pUiLayer->addWidget(alert); // Create the ui node container UINodeContainer* nodeContainer = UINodeContainer::create(); nodeContainer->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); m_pUiLayer->addWidget(nodeContainer); CCSprite* sprite = CCSprite::create("cocosgui/ccicon.png"); sprite->setPosition(ccp(0, sprite->boundingBox().size.height / 4)); nodeContainer->addCCNode(sprite); return true; } return false; }
bool UIImageViewTest::init() { if (UIScene::init()) { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); UILabel *alert = UILabel::create(); alert->setText("ImageView"); alert->setFontName("Marker Felt"); alert->setFontSize(30); alert->setColor(ccc3(159, 168, 176)); // alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75)); m_pUiLayer->addWidget(alert); // Create the imageview UIImageView *imageView = UIImageView::create(); imageView->loadTexture("cocosgui/ccicon.png"); // imageView->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + imageView->getRect().size.height / 4.0f)); m_pUiLayer->addWidget(imageView); return true; } return false; }
void GameLayerPkBar::setName(std::string name) { UILabel* label = dynamic_cast<UILabel*>(ul->getWidgetByName("NameLabel")); label->setText(name.c_str()); }