//TODO 屏蔽事件穿透 void BattleScene::createBottomBar() { LayerColor *bottom = LayerColor::create(Color4B(0, 0, 100, 100)); bottom->setContentSize(Size(WINSIZE.width, 120)); bottom->setPosition(Point(0, 0)); addChild(bottom); int totalCount = 11; int index = 0; Vector<MenuItem *> items; auto soldierInCamp = BattleData::getInstance()->getAttackSoldierInCamp(); map<int, vector<DSoldier *>>::iterator it; for(it=soldierInCamp.begin(); it!=soldierInCamp.end(); it++) { MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this)); item->setTag(it->first); items.pushBack(item); index++; //head Size size = item->getContentSize(); char img[20]; sprintf(img, "ui/%d.png", it->first / 100); auto head = Sprite::create(img); head->setAnchorPoint(Point(0.5, 0.5)); head->setPosition(size.width/2, size.height/2); item->addChild(head); char text[20]; sprintf(text, "X %d", it->second.size()); TTFConfig config("fonts/tahoma.ttf",16); auto count = Label::createWithTTF(config, text, TextHAlignment::LEFT); count->setPosition(size.width/2, size.height - count->getContentSize().height); item->addChild(count); //初始化为第一个兵种 if (m_selectedSoldierType <= 0) { m_selectedSoldierType = it->first; } } for (int i = index; i < totalCount; i++) { MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this)); item->setEnabled(false); items.pushBack(item); } Size bottomSize = bottom->getContentSize(); Sprite *spItem = Sprite::create("ui/618.0.png"); Size itemSize = spItem->getContentSize(); float padding = (bottomSize.width - itemSize.width * totalCount) / (totalCount + 1); UIRadioButton *radio = UIRadioButton::createWithArray(items); radio->alignItemsHorizontallyWithPadding(padding); radio->setPosition(Point(bottomSize.width / 2, bottomSize.height / 2)); radio->setSelectedIndex(0); bottom->addChild(radio); }
bool PopupLayer::addButton(const char *normalImage, const char *selectedImage, const char *title, int tag) { //Size winSize = CCDirector::getInstance()->getWinSize(); Point pCenter = ccp(winSize.width / 2, winSize.height / 2); // 创建图片菜单按钮 MenuItemImage* menuImage = MenuItemImage::create(normalImage, selectedImage, this, menu_selector(PopupLayer::buttonCallback)); menuImage->setTag(tag); menuImage->setPosition(pCenter); // 添加文字说明并设置位置 Size imenu = menuImage->getContentSize(); LabelTTF* ttf = LabelTTF::create(title, "", 20); ttf->setColor(ccc3(0, 0, 0)); ttf->setPosition(ccp(imenu.width / 2, imenu.height / 2)); menuImage->addChild(ttf); getMenuButton()->addChild(menuImage); return true; }
void RequestAPIScene::buildScene() { // Call super build scene. BaseScene::buildScene(); BaseScene::addTipBoard("Do you know that you can use EziSocial to send gifts, invites and challenges to user's Facebook friends? Also you can process these requests on receiver's device"); SpriteBatchNode* batchNode = SpriteBatchNode::create(PNG_FILE(kRESOURCE_REQUEST)); this->addChild(batchNode); SpriteFrameCache::getInstance()->addSpriteFramesWithFile(PLIST_FILE(kRESOURCE_REQUEST)); buildHeader(-1, "Request APIs", "Send gifts, invites and much more with Facebook"); // Build the tiles. MenuItemImage* menuItem = NULL; menuItem = this->buildAndPlaceTile("btn_send_gifts_nrl", "btn_send_gifts_prd", 0, 0); menuItem->setCallback(CC_CALLBACK_1(RequestAPIScene::sendGifts, this)); menuItem = this->buildAndPlaceTile("btn_challenge_nrl", "btn_challenge_prd", 2, 0); menuItem->setCallback(CC_CALLBACK_1(RequestAPIScene::challengeFriends, this)); menuItem = this->buildAndPlaceTile("btn_invite_friends_nrl", "btn_invite_friends_prd", 1, 1); menuItem->setCallback(CC_CALLBACK_1(RequestAPIScene::inviteFriends, this)); menuItem = this->buildAndPlaceTile("btn_new_requests_nrl", "btn_new_requests_prd", 0, 2); menuItem->setCallback(CC_CALLBACK_1(RequestAPIScene::refreshIncomingRequests, this)); Size menuSize = menuItem->getContentSize(); _pendingRequestLabel = LabelTTF::create("0", "Arial", AppDelegate::SCREEN_SCALE_FACTOR * 20); menuItem->addChild(_pendingRequestLabel, 5); _pendingRequestLabel->cocos2d::CCNode::setPosition(menuSize.width * 0.2, menuSize.height * 0.2); menuItem = this->buildAndPlaceTile("btn_view_open_nrl", "btn_view_open_prd", 2, 2); menuItem->setCallback(CC_CALLBACK_1(RequestAPIScene::viewOpenRequestItems, this)); }
bool PopLayer::addButton(const char* normalImage, const char* selectedImage, const char* title, int tag /*= 0*/) { Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 pCenter(visibleSize.width / 2, visibleSize.height / 2); // 创建图片菜单按钮 MenuItemImage* menuImage = MenuItemImage::create(normalImage, selectedImage, CC_CALLBACK_1(PopLayer::buttonCallback, this)); menuImage->setTag(tag); //menuImage->setPosition(pCenter); // 添加文字说明并设置位置 if(title != NULL) { Size imenu = menuImage->getContentSize(); LabelTTF* ttf = LabelTTF::create(title, "", 20); ttf->setColor(Color3B(0, 0, 0)); ttf->setPosition(Vec2(imenu.width / 2, imenu.height / 2)); menuImage->addChild(ttf); } getMenuButton()->addChild(menuImage); return true; }