UITextButton* UITextButton::create() { UITextButton* widget = new UITextButton(); if (widget && widget->init()) { return widget; } CC_SAFE_DELETE(widget); return NULL; }
bool MailLayer::init() { bool bRet = false; do { CC_BREAK_IF(!CCLayer::init()); m_Mediator = NULL; m_pUILayer = UILayer::create(); m_pUILayer->setTouchPriority(-200); m_pUILayer->scheduleUpdate(); addChild(m_pUILayer); Layout* lay = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile("ui/MailUI/MailUI.json")); m_pUILayer->addWidget(lay); m_mailLayout = dynamic_cast<Layout*>(lay->getChildByName("mailPanel")); layerNum = MAILLAYER_TAG_MAIL; m_writeLayout = dynamic_cast<Layout*>(lay->getChildByName("writePanel")); m_writeLayout->setTouchEnable(false,true); m_writeLayout->setVisible(false); m_fujianLayout = dynamic_cast<Layout*>(lay->getChildByName("fujianPanel")); m_fujianLayout->setTouchEnable(false,true); m_fujianLayout->setVisible(false); UITextButton* returnBtn = dynamic_cast<UITextButton*>(lay->getChildByName("returnBtn")); returnBtn->addReleaseEvent(this, coco_releaseselector(MailLayer::closeBtnCallBack)); UIScrollView* scroV = dynamic_cast<UIScrollView*>(m_mailLayout->getChildByName("ScrollView")); for (int i = 0; i <5; i++) { UIButton* scroPanel = dynamic_cast<UIButton*>(scroV->getChildByName(CCString::createWithFormat("listBtn_%d", i)->getCString())); scroPanel->addReleaseEvent(this, coco_releaseselector(MailLayer::scroCallBack)); } m_leftBtn = dynamic_cast<UITextButton*>(m_writeLayout->getChildByName("leftBtn")); m_leftBtn->addReleaseEvent(this, coco_releaseselector(MailLayer::leftBtnCallBack)); m_rightBtn = dynamic_cast<UITextButton*>(m_writeLayout->getChildByName("rightBtn")); m_rightBtn->addReleaseEvent(this, coco_releaseselector(MailLayer::rightBtnCallBack)); UITextButton* writeBtn = dynamic_cast<UITextButton*>(m_mailLayout->getChildByName("writeBtn")); writeBtn->addReleaseEvent(this, coco_releaseselector(MailLayer::writeBtnCallBack)); for (int i = 0; i < 2; i++) { UIImageView* img = dynamic_cast<UIImageView*>(m_writeLayout->getChildByName(CCString::createWithFormat("fujian_%d", i)->getCString())); img->addReleaseEvent(this,coco_releaseselector(MailLayer::fujianBtnCallBack)); } bRet = true; } while (0); return bRet; }
bool SportLayer::initWidgets4PanelSportRule(Layout* _sportRuleLay) { bool bRet = false; do { UIWidget* bgSportRule = _sportRuleLay->getChildByName("bg_rule"); UITextButton* txtBtnSportRuleBack = dynamic_cast<UITextButton*>(bgSportRule->getChildByName("txtBtn_rule_back")); txtBtnSportRuleBack->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportRuleCallback)); txtBtnSportRuleBack->setWidgetTag(sportRuleBackBtnTag); bRet = true; } while (0); return bRet; }
/** * 创建 */ UITextButton* UITextButton::create(const char *text) { UITextButton *node = new UITextButton(); if (node) { node->_textUp = CCLabelTTF::create(text, "Arial", 12); node->_textDown = CCLabelTTF::create(text, "Arial", 16); if (node->_textUp && node->_textDown) { node->addChild(node->_textUp); node->addChild(node->_textDown ); node->_textUp->setVisible(true); node->_textDown->setVisible(false); // node->_textUp->retain(); // node->_textDown->retain(); node->autorelease(); return node; } } CC_SAFE_DELETE(node); return NULL; }
bool UIPanelTest_Color::init() { if (UIScene::init()) { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); // Add the alert UILabel *alert = UILabel::create(); alert->setText("Panel color 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 * 2.925)); m_pUiLayer->addWidget(alert); UIPanel *background = dynamic_cast<UIPanel*>(m_pUiLayer->getWidgetByName("background_Panel")); // Create the panel with color render UIPanel* panel = UIPanel::create(); panel->setBackGroundColorType(PANEL_COLOR_SOLID); panel->setBackGroundColor(ccc3(128, 128, 128)); panel->setClippingEnable(true); panel->setSize(CCSizeMake(280, 150)); CCSize backgroundSize = background->getContentSize(); panel->setPosition(ccp((screenSize.width - backgroundSize.width) / 2 + (backgroundSize.width - panel->getRect().size.width) / 2, (screenSize.height - backgroundSize.height) / 2 + (backgroundSize.height - panel->getRect().size.height) / 2)); m_pUiLayer->addWidget(panel); UIButton* button = UIButton::create(); button->setTouchEnable(true); button->setTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); button->setPosition(ccp(button->getRect().size.width / 2, panel->getRect().size.height - button->getRect().size.height / 2)); panel->addChild(button); UITextButton* textButton = UITextButton::create(); textButton->setTouchEnable(true); textButton->setTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", ""); textButton->setText("Text Button"); textButton->setPosition(ccp(panel->getRect().size.width / 2, panel->getRect().size.height / 2)); panel->addChild(textButton); UIZoomButton* zoomButton = UIZoomButton::create(); zoomButton->setTouchEnable(true); zoomButton->setTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "cocosgui/button.png"); zoomButton->setTitle("ControlButton", "ControlButton", "ControlButton"); zoomButton->setNormalFontSize(16); zoomButton->setNormalFontName("Marker Felt"); zoomButton->setPressedFontSize(16); zoomButton->setPressedFontName("Marker Felt"); zoomButton->setDisabledFontSize(16); zoomButton->setDisabledFontName("Marker Felt"); zoomButton->setPreferredSize(CCSizeMake(100, zoomButton->getContentSize().height * 2.0f)); zoomButton->setPosition(ccp(panel->getRect().size.width - zoomButton->getRect().size.width / 2, zoomButton->getRect().size.height / 2)); panel->addChild(zoomButton); return true; } return false; }
bool SportLayer::initWidgets4PanelSportTop(Layout* _sportTopLay) { bool bRet = false; do { UIWidget* bgSportRule = _sportTopLay->getChildByName("bg_top"); UITextButton* txtBtnSportTopWinRatetag = dynamic_cast<UITextButton*>(bgSportRule->getChildByName("txtBtn_top_win_rate_tag")); txtBtnSportTopWinRatetag->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportTopCallback)); txtBtnSportTopWinRatetag->setWidgetTag(sportTopWinRateTagBtnTag); UITextButton* txtBtnSportTopWinCnttag = dynamic_cast<UITextButton*>(bgSportRule->getChildByName("txtBtn_top_win_cnt_tag")); txtBtnSportTopWinCnttag->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportTopCallback)); txtBtnSportTopWinCnttag->setWidgetTag(sportTopWinCntTagBtnTag); UITextButton* txtBtnSportTopScoreTag = dynamic_cast<UITextButton*>(bgSportRule->getChildByName("txtBtn_top_score_tag")); txtBtnSportTopScoreTag->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportTopCallback)); txtBtnSportTopScoreTag->setWidgetTag(sportTopScoreTagBtnTag); UITextButton* txtBtnSportTopBack = dynamic_cast<UITextButton*>(bgSportRule->getChildByName("txtBtn_top_back")); txtBtnSportTopBack->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportTopCallback)); txtBtnSportTopBack->setWidgetTag(sportTopBackBtnTag); UITextButton* txtBtnSportTopPlayerNicknameTag = dynamic_cast<UITextButton*>(bgSportRule->getChildByName("txtBtn_player_nickname_tag")); txtBtnSportTopPlayerNicknameTag->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportTopCallback)); txtBtnSportTopPlayerNicknameTag->setWidgetTag(sportTopPlayerNicknameBtnTag); //friend list UIScrollView* scvwTopList = dynamic_cast<UIScrollView*>(bgSportRule->getChildByName("scvw_top_list")); CC_BREAK_IF(! scvwTopList); int itemCount = 10; //listitem CCString* name = CCString::createWithFormat("ui/SportUI/%s.json",m_allListItemNames->valueForKey(topListItem)->getCString() ); Layout* pListItem = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile(name->getCString() )); CC_BREAK_IF(! pListItem); pListItem->setPosition(CCPointZero); scvwTopList->addChild(pListItem); CCSize scvwSize = scvwTopList->getInnerContainerSize(); scvwTopList->setInnerContainerSize(CCSizeMake(scvwSize.width, pListItem->getContentSize().height * itemCount)); for(int i=1; i<itemCount; i++){ pListItem = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile(name->getCString() )); CC_BREAK_IF(! pListItem); pListItem->setPosition(ccp(0,i*(pListItem->getContentSize().height))); scvwTopList->addChild(pListItem); } bRet = true; } while (0); return bRet; }
bool SportLayer::initWidgets4PanelSportFriend(Layout* _sportFriendLay) { bool bRet = false; do { UIWidget* bgSportFriend = _sportFriendLay->getChildByName("bg_friend"); UITextButton* txtBtnSportFriendBack = dynamic_cast<UITextButton*>(bgSportFriend->getChildByName("txtBtn_friend_back")); txtBtnSportFriendBack->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportFriendCallback)); txtBtnSportFriendBack->setWidgetTag(sportFriendBackBtnTag); UITextButton* txtBtnSportFriendOLPlayerTag = dynamic_cast<UITextButton*>(bgSportFriend->getChildByName("txtBtn_friend_olplayer_tag")); txtBtnSportFriendOLPlayerTag->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportFriendCallback)); txtBtnSportFriendOLPlayerTag->setWidgetTag(sportFriendOLPlayerTagBtnTag); UITextButton* txtBtnSportFriendClubTag = dynamic_cast<UITextButton*>(bgSportFriend->getChildByName("txtBtn_friend_club_tag")); txtBtnSportFriendClubTag->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportFriendCallback)); txtBtnSportFriendClubTag->setWidgetTag(sportFriendClubTagBtnTag); UITextButton* txtBtnSportFriendFriendTag = dynamic_cast<UITextButton*>(bgSportFriend->getChildByName("txtBtn_friend_friend_tag")); txtBtnSportFriendFriendTag->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportFriendCallback)); txtBtnSportFriendFriendTag->setWidgetTag(sportFriendFriendTagBtnTag); //friend list UIScrollView* scvwFriendList = dynamic_cast<UIScrollView*>(bgSportFriend->getChildByName("scvw_friend_list")); //scvwFriendList->scrollToTop(); //listitem int itemCount = 10; CCString* name = CCString::createWithFormat("ui/SportUI/%s.json",m_allListItemNames->valueForKey(friendListItem)->getCString() ); Layout* pListItem = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile(name->getCString() )); CC_BREAK_IF(! pListItem); pListItem->setPosition(CCPointZero); scvwFriendList->addChild(pListItem); CCSize scvwSize = scvwFriendList->getInnerContainerSize(); scvwFriendList->setInnerContainerSize(CCSizeMake(scvwSize.width, pListItem->getContentSize().height * itemCount)); for(int i=1; i<itemCount; i++){ pListItem = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile(name->getCString() )); CC_BREAK_IF(! pListItem); pListItem->setPosition(ccp(0,i*(pListItem->getContentSize().height))); scvwFriendList->addChild(pListItem); } bRet = true; } while (0); return bRet; }
bool SportLayer::initWidgets4PanelSport(Layout* _sportLay) { bool bRet = false; do { //btn back UIWidget* bgSport = _sportLay->getChildByName("bg_sport"); UITextButton* txtBtnSportBack = dynamic_cast<UITextButton*>(bgSport->getChildByName("txtBtn_sport_back")); txtBtnSportBack->addReleaseEvent(this, coco_releaseselector(SportLayer::closeBtnCallBack)); //btn rule UITextButton* txtBtnSportRule = dynamic_cast<UITextButton*>(bgSport->getChildByName("txtBtn_sport_rule")); txtBtnSportRule->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportCallback)); txtBtnSportRule->setWidgetTag(sportRuleBtnTag); //btn start UITextButton* txtBtnSportStart = dynamic_cast<UITextButton*>(bgSport->getChildByName("txtBtn_sport_start")); txtBtnSportStart->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportCallback)); txtBtnSportStart->setWidgetTag(sportStartBtnTag); //btn top UITextButton* txtBtnSportTop = dynamic_cast<UITextButton*>(bgSport->getChildByName("txtBtn_sport_top")); txtBtnSportTop->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportCallback)); txtBtnSportTop->setWidgetTag(sportTopBtnTag); //btn clear UITextButton* txtBtnSportClear = dynamic_cast<UITextButton*>(bgSport->getChildByName("txtBtn_sport_clear")); txtBtnSportClear->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportCallback)); txtBtnSportClear->setWidgetTag(sportClearBtnTag); //btn sport reward obtain UIWidget* bgSportReward = bgSport->getChildByName("bg_sport_reward"); UITextButton* txtBtnRewardObtain = dynamic_cast<UITextButton*>(bgSportReward->getChildByName("txtBtn_reward_obtain")); txtBtnRewardObtain->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportCallback)); txtBtnRewardObtain->setWidgetTag(sportRewardObtainBtnTag); //btn sport player seat invite UIWidget* bgSportPlayerSeat = bgSport->getChildByName("bg_sport_player_seat"); UIButton* txtBtnSeatInvite = dynamic_cast<UIButton*>(bgSportPlayerSeat->getChildByName("btn_seat_invite")); txtBtnSeatInvite->addReleaseEvent(this, coco_releaseselector(SportLayer::panelSportCallback)); txtBtnSeatInvite->setWidgetTag(sportPlayerSeatInivteBtnTag); bRet = true; } while (0); return bRet; }
bool ChaosFightUI::init(){ bool bRef = false; do{ CC_BREAK_IF(! CCLayer::init()); ul = UILayer::create(); // 设置 UI 层的tag this->addChild(ul, 0, 100); ul->addWidget(CCUIHELPER->createWidgetFromJsonFile("ChaosFight_1/ChaosFight_1.json")); // 获得各个控件,并添加点击事件 UITextButton* tbChangePwd = dynamic_cast<UITextButton*>(ul->getWidgetByName("tbChangePwd")); UITextButton* tbBindingEmail = dynamic_cast<UITextButton*>(ul->getWidgetByName("tbBindingEmail")); UITextButton* tbChangeRole = dynamic_cast<UITextButton*>(ul->getWidgetByName("tbChangeRole")); UITextButton* tbLogout = dynamic_cast<UITextButton*>(ul->getWidgetByName("tbLogout")); UIButton* btnSoundEffect = dynamic_cast<UIButton*>(ul->getWidgetByName("btnSoundEffect")); UIButton* btnMusic = dynamic_cast<UIButton*>(ul->getWidgetByName("btnMusic")); UIButton* btnSavingElectricity = dynamic_cast<UIButton*>(ul->getWidgetByName("btnSavingElectricity")); UIButton* btnVideo = dynamic_cast<UIButton*>(ul->getWidgetByName("btnVideo")); UITextButton* tbAbout = dynamic_cast<UITextButton*>(ul->getWidgetByName("tbAbout")); UITextButton* tbClearCache = dynamic_cast<UITextButton*>(ul->getWidgetByName("tbClearCache")); // 设置字体颜色 tbChangePwd->setTextColor(0, 0, 0); tbBindingEmail->setTextColor(0, 0, 0); tbChangeRole->setTextColor(0, 0, 0); tbLogout->setTextColor(0, 0, 0); tbAbout->setTextColor(0, 0, 0); tbClearCache->setTextColor(0, 0, 0); // 为控件添加处理事件 tbChangePwd->addReleaseEvent(this, coco_releaseselector(ChaosFightUI::tbChangePwdCallback)); tbBindingEmail->addReleaseEvent(this, coco_releaseselector(ChaosFightUI::tbBindingEmailCallback)); tbChangeRole->addReleaseEvent(this, coco_releaseselector(ChaosFightUI::tbChangeRoleCallback)); tbLogout->addReleaseEvent(this, coco_releaseselector(ChaosFightUI::tbLogoutCallback)); btnSoundEffect->addReleaseEvent(this, coco_releaseselector(ChaosFightUI::btnSoundEffectCallback)); btnMusic->addReleaseEvent(this, coco_releaseselector(ChaosFightUI::btnMusicEffectCallback)); btnSavingElectricity->addReleaseEvent(this, coco_releaseselector(ChaosFightUI::btnSavingElectricityCallback)); btnVideo->addReleaseEvent(this, coco_releaseselector(ChaosFightUI::btnVideoCallback)); tbAbout->addReleaseEvent(this, coco_releaseselector(ChaosFightUI::tbAboutCallback)); tbClearCache->addReleaseEvent(this, coco_releaseselector(ChaosFightUI::tbClearCacheCallback)); bRef = true; }while(0); return bRef; }
bool ShopLayer::init() { bool bRet = false; do { CC_BREAK_IF(!CCLayer::init()); m_Mediator = NULL; m_buyNum = 1; m_onePri = 5000; m_curTapMenu = SHOP_LAYOUT_TAG_TEJIA; m_pUILayer = UILayer::create(); m_pUILayer->setTouchPriority(-200); m_pUILayer->scheduleUpdate(); addChild(m_pUILayer); Layout* lay; lay = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile("ui/ShopUI/ShopUI.json")); m_pUILayer->addWidget(lay); m_layerLayout = dynamic_cast<Layout*>(lay->getChildByName("layerPanel")); m_buyLayout = dynamic_cast<Layout*>(lay->getChildByName("buyRootPanel")); UIButton* returnBtn1 = dynamic_cast<UIButton*>(m_buyLayout->getChildByName("returnBtn")); returnBtn1->addReleaseEvent(this, coco_releaseselector(ShopLayer::closeBtnDlgCallBack)); UIScrollView* scroV = dynamic_cast<UIScrollView*>(m_layerLayout->getChildByName("ScrollView")); // UIScrollViewP* scroV = dynamic_cast<UIScrollViewP*>(m_layerLayout->getChildByName("ScrollView")); // UIImageView* spr = dynamic_cast<UIImageView*>(m_layerLayout->getChildByName("slideImge")); // CCSize a = scroV->getInnerContainerSize(); // CCSize b =scroV->getSize(); // float scale = b.height/a.height; // spr->setScaleY(scale); // scroV->setSlideSprite(spr,scale); for (int i = 0; i < 8; i++) { UIButton* scroPanel = dynamic_cast<UIButton*>(scroV->getChildByName(CCString::createWithFormat("Panel_%d", i)->getCString())); scroPanel->addReleaseEvent(this, coco_releaseselector(ShopLayer::scroCallBack)); } UIButton* returnBtn = dynamic_cast<UIButton*>(m_layerLayout->getChildByName("returnBtn")); returnBtn->addReleaseEvent(this, coco_releaseselector(ShopLayer::closeBtnCallBack)); UIButton* payBtn = dynamic_cast<UIButton*>(m_layerLayout->getChildByName("payBtn")); payBtn->addReleaseEvent(this, coco_releaseselector(ShopLayer::payBtnCallBack)); UIButton* subBtn = dynamic_cast<UIButton*>(m_buyLayout->getChildByName("subBtn")); subBtn->addReleaseEvent(this, coco_releaseselector(ShopLayer::subBtnCallBack)); UIButton* addBtn = dynamic_cast<UIButton*>(m_buyLayout->getChildByName("addBtn")); addBtn->addReleaseEvent(this, coco_releaseselector(ShopLayer::addBtnCallBack)); Layout* buyNumPanel = dynamic_cast<Layout*>(m_buyLayout->getChildByName("buyNumPanel")); buyNumPanel->addReleaseEvent(this,coco_releaseselector(ShopLayer::callForNumInput)); m_buyNumLabel = dynamic_cast<UILabel*>(buyNumPanel->getChildByName("Label")); m_totalPriLabel = dynamic_cast<UILabel*>(m_buyLayout->getChildByName("totalPriLabel")); m_onePriLabel = dynamic_cast<UILabel*>(m_buyLayout->getChildByName("onePriLabel")); UITextButton* buyBtn = dynamic_cast<UITextButton*>(m_buyLayout->getChildByName("buyBtn")); buyBtn->addReleaseEvent(this, coco_releaseselector(ShopLayer::buyBtnCallBack)); Layout* tapbtn_panel = dynamic_cast<Layout*>(m_layerLayout->getChildByName("tapbtn_Panel")); tapbtn_panel->setWidgetTag(SHOP_LAYOUT_TAG_ROOT); UIButton* equipBtn = dynamic_cast<UIButton*>(tapbtn_panel->getChildByName("equipBtn")); equipBtn->addReleaseEvent(this, coco_releaseselector(ShopLayer::tapMenuCallBack)); equipBtn->setWidgetTag(SHOP_LAYOUT_TAG_EQUIP); UIButton* tejiaBtn = dynamic_cast<UIButton*>(tapbtn_panel->getChildByName("tejiaBtn")); tejiaBtn->addReleaseEvent(this, coco_releaseselector(ShopLayer::tapMenuCallBack)); tejiaBtn->setWidgetTag(SHOP_LAYOUT_TAG_TEJIA); tejiaBtn->disable(); UIButton* diamondBtn = dynamic_cast<UIButton*>(tapbtn_panel->getChildByName("diamondBtn")); diamondBtn->addReleaseEvent(this, coco_releaseselector(ShopLayer::tapMenuCallBack)); diamondBtn->setWidgetTag(SHOP_LAYOUT_TAG_DIAMOND); UIButton* yaoshuiBtn = dynamic_cast<UIButton*>(tapbtn_panel->getChildByName("yaoshuiBtn")); yaoshuiBtn->addReleaseEvent(this, coco_releaseselector(ShopLayer::tapMenuCallBack)); yaoshuiBtn->setWidgetTag(SHOP_LAYOUT_TAG_YAOSHUI); UIButton* otherBtn = dynamic_cast<UIButton*>(tapbtn_panel->getChildByName("otherBtn")); otherBtn->addReleaseEvent(this, coco_releaseselector(ShopLayer::tapMenuCallBack)); otherBtn->setWidgetTag(SHOP_LAYOUT_TAG_OTHER); bRet = true; } while (0); return bRet; }