CCMenuItemSprite * CCMenuItemDynamic::dynamicItemWithText(const char* text, const char* font, const CCSize &minSize, const char*normalImage, const char *selectedImage, CCObject* target, SEL_MenuHandler selector, const CCRect& centerRegion, GLubyte opacity) { //Create the label CCLabelBMFont *label = CCLabelBMFont ::labelWithString(text ,font); label ->setOpacity(opacity); //Calculate the Dynamic Button size float minWidth = label->getContentSize().width>minSize.width?label->getContentSize().width:minSize.width; float minHeight = label->getContentSize().height>minSize.height?label->getContentSize().height:minSize.height; CCSize size(minWidth+30,minHeight+24); label->setPosition(ccp(size.width*0.5f, size.height*0.5f)); //Sprite normal CCScale9Sprite *normalSprite = CCScale9Sprite::scale9SpriteWithFile(normalImage, centerRegion); normalSprite ->setContentSize(size); normalSprite ->setOpacity(opacity); //Sprite selected CCScale9Sprite *selectedSprite = NULL; if(selectedImage){ selectedSprite = CCScale9Sprite::scale9SpriteWithFile(selectedImage, centerRegion); selectedSprite ->setContentSize(size); selectedSprite->setOpacity(opacity); } //Create the CCMenuItemSprite CCMenuItemSprite* returnItem = CCMenuItemSprite::itemFromNormalSprite(normalSprite,selectedSprite,target, selector); returnItem->addChild(label); return returnItem; }
CCMenuItemSprite* CCLayerParent::getSpriteButton(int tag,int price,const char* frameName,SEL_MenuHandler selector) { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCMenuItemSprite *quirkButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("spawn.png"),CCSprite::createWithSpriteFrameName("spawn_sel.png"),this,selector); CCSize contentSize = quirkButton->getContentSize(); //quirkButton->setPosition (ccp(contentSize.width* tag, contentSize.height/2)); quirkButton->setTag(tag); CCSprite* quirk = CCSprite::createWithSpriteFrameName(frameName); quirk->setPosition(ccp(quirk->getContentSize().width/2, contentSize.height-quirk->getContentSize().height/2)); quirkButton->addChild(quirk); char temp[64]; sprintf(temp, "%d", price); //CCLabel* quirkLabel = CCLabelBMFont::create(temp,"Courier_green.fnt"); CCLabelTTF* quirkLabel = CCLabelTTF::create(temp, "Helvetica-Bold", fontSizeBig, ccp(xMARGIN,yMARGIN), kCCTextAlignmentCenter ); quirkLabel->setColor(ccc3(255,255,255)); quirkLabel->setPosition(ccp(quirk->getContentSize().width/2, yMARGIN*0.4)); quirkButton->addChild(quirkLabel); quirkButton->setZOrder(3); return quirkButton; }
CCMenuItemSprite *CWaterpump::initMenuItemWithFiles(int type, const char *normal, const char *selected, const char *disable, SEL_MenuHandler selector) { CCSprite *pNormal = CCSprite::create(normal); CCSprite *pSelected = CCSprite::create(selected); CCSprite *pDisable = CCSprite::create(disable); CCMenuItemSprite *pItem = CCMenuItemSprite::create(pNormal, pSelected, pDisable, this, selector); int cnt = CPlayerAccount::GetAccountInstance()->GetAccountPropsNum(type); char szCntStr[8] = {0}; sprintf(szCntStr, "%d", cnt); CCLabelAtlas *pCntFnt = CCLabelAtlas::create(szCntStr, "UI_02_05.png", 48, 57, '0'); pCntFnt->setAnchorPoint(ccp(1, 0)); pCntFnt->setPosition(ccp(pItem->getContentSize().width, 0)); pItem->addChild(pCntFnt, 1, Tag_ItemFnt); pItem->setTag(type); return pItem; }
Loading::Loading() { glClearColor(0.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 1.0f); setTouchEnabled( true ); float scale = ScreenHelper::getTextureScale(); float scaleX = ScreenHelper::getTextureScaleX(); float scaleY = ScreenHelper::getTextureScaleY(); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Buttons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Buttons.plist"); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Icons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Icons.plist"); CCTextureCache::sharedTextureCache()->addPVRImage("LoadingScreen.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("LoadingScreen.plist"); CCPoint scalePoint; scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.y += -5*scale; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_Screen_ver2.png"); sprite->setScale(scale); sprite->setPosition(scalePoint); addChild(sprite); sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_ProgressScroll_Graphic.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY*1.2f); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_LEFT,-140.0f,-50.0f)); loadingBar = sprite; addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_TopPanel.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-55.0f)); addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_TopOverlay.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY); sprite->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER)); addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("BackgroundPlate.png"); sprite->setScale(scale); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += -135.0f*scale; scalePoint.y += -97.0f*scale; sprite->setPosition(scalePoint); addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("BronzeText.png"); sprite->setScale(scale); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += -135.0f*scale; scalePoint.y += -97.0f*scale; sprite->setPosition(scalePoint); addChild(sprite,2); CCLabelTTF *label = CCLabelTTF::create(LevelSelect::getLevelName(), "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(0,0,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,2.0f,-44.0f)); label = CCLabelTTF::create(LevelSelect::getLevelName(), "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(237,188,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-42.0f)); int currentLevel = LevelSelect::getCurrentLevel(); if(currentLevel >= BONUS_LEVELSTART) g_isTrickLevel = true; else g_isTrickLevel = false; int medalLevel = SaveLoad::m_SaveData.medalLockLevel; int showMedal = 0; if(medalLevel==0) { if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::ONE_COCONUT) showMedal = 1; } if(medalLevel==1) { if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::TWO_COCONUT) showMedal = 2; } if(medalLevel==2) { if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::THREE_COCONUT) showMedal = 3; } if(!showMedal) { CCSize dimensions; dimensions.width = 100*scale; dimensions.height = 25*scale; label = CCLabelTTF::create("Time:", "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(237,188,0)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+90.0f)*scale; scalePoint.y += 50.0f*scale; label->setPosition(scalePoint); char tempLabelStr[32]; sprintf(tempLabelStr,"%.2f",LevelSelect::getLevelGoals()->time); label = CCLabelTTF::create(tempLabelStr, "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(255,255,255)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+150.0f)*scale; scalePoint.y += 50.0f*scale; label->setPosition(scalePoint); label = CCLabelTTF::create("Peanuts:", "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(237,188,0)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+90.0f)*scale; scalePoint.y += 20.0f*scale; label->setPosition(scalePoint); sprintf(tempLabelStr,"%d",LevelSelect::getLevelGoals()->peanuts); label = CCLabelTTF::create(tempLabelStr, "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(255,255,255)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+170.0f)*scale; scalePoint.y += 20.0f*scale; label->setPosition(scalePoint); label = CCLabelTTF::create("Points:", "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(237,188,0)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+90.0f)*scale; scalePoint.y += -10.0f*scale; label->setPosition(scalePoint); sprintf(tempLabelStr,"%d",LevelSelect::getLevelGoals()->points); label = CCLabelTTF::create(tempLabelStr, "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(255,255,255)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+160.0f)*scale; scalePoint.y += -10.0f*scale; label->setPosition(scalePoint); } else { CCTextureCache::sharedTextureCache()->addPVRImage("LoadingScreen2.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("LoadingScreen2.plist"); if(showMedal == 1) sprite = CCSprite::createWithSpriteFrameName("ctm_BronzeMedalBig.png"); if(showMedal == 2) sprite = CCSprite::createWithSpriteFrameName("ctm_SilverMedalBig.png"); if(showMedal == 3) sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_LargeGold.png"); sprite->setScale(scale); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += -135.0f*scale; scalePoint.y += 5.0f*scale; sprite->setPosition(scalePoint); addChild(sprite,2); } CCMenuItem *StoreButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Button_17.png"), CCSprite::createWithSpriteFrameName("ctm_Button_17_Down.png"), this, menu_selector(Loading::storeButtonTapped)); StoreButton->setScale(scale); scalePoint = ccp(0,0); scalePoint.x += 85.0f*scale; scalePoint.y += -100.0f*scale; StoreButton->setPosition(scalePoint); CCMenu* menu = CCMenu::create(StoreButton, NULL); menu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER)); addChild(menu,4); CCMenuItemSprite *items[3]; //if(SaveLoad::m_SaveData.numDoubleNuts) { CCSize dim; dim.width = 200.0f; dim.height = 35.0f; CCSprite *barImage = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); CCSprite *barImageSel = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); barImage->setOpacity(0); barImageSel->setOpacity(0); CCMenuItemSprite *menuImage = CCMenuItemSprite::create(barImage,barImageSel,this,menu_selector(Loading::nutsButtonTapped)); CCLabelTTF *blabel = CCLabelTTF::create(" Use 2X Peanuts","Jacoby ICG Black.ttf",18,dim,kCCTextAlignmentLeft); blabel->setColor(ccc3(237,188,0)); blabel->setPosition(ccp(157.0f,18.0f)); menuImage->addChild(blabel,0,1234); items[1] = menuImage; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_icon_Store_17_2X-peanuts.png"); sprite->setPosition(ccp(30,23)); sprite->setScale(0.925f); menuImage->addChild(sprite,0,4321); menuImage->setScale(scale); if(!SaveLoad::m_SaveData.numDoubleNuts) { //[menuImage setIsEnabled:NO]; blabel->setColor(ccc3(237/2,188/2,0)); sprite->setColor(ccc3(128,128,128)); } } //if(SaveLoad::m_SaveData.numLevelFire) { CCSize dim; dim.width = 200.0f; dim.height = 35.0f; CCSprite *barImage = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); CCSprite *barImageSel = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); barImage->setOpacity(0); barImageSel->setOpacity(0); CCMenuItemSprite *menuImage = CCMenuItemSprite::create(barImage,barImageSel,this,menu_selector(Loading::fireButtonTapped)); CCLabelTTF *blabel = CCLabelTTF::create(" Use Permanent Fire","Jacoby ICG Black.ttf",18,dim,kCCTextAlignmentLeft); blabel->setColor(ccc3(237,188,0)); blabel->setPosition(ccp(157.0f,18.0f)); menuImage->addChild(blabel,0,1234); items[2] = menuImage; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_icon_Store_18_Fire.png"); sprite->setPosition(ccp(30,23)); sprite->setScale(0.925f); menuImage->addChild(sprite,0,4321); menuImage->setScale(scale); if(!SaveLoad::m_SaveData.numLevelFire) { //[menuImage setIsEnabled:NO]; blabel->setColor(ccc3(237/2,188/2,0)); sprite->setColor(ccc3(128,128,128)); } } //if(SaveLoad::m_SaveData.numTimeSlow) { CCSize dim; dim.width = 200.0f; dim.height = 35.0f; CCSprite *barImage = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); CCSprite *barImageSel = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); barImage->setOpacity(0); barImageSel->setOpacity(0); CCMenuItemSprite *menuImage = CCMenuItemSprite::create(barImage,barImageSel,this,menu_selector(Loading::timeButtonTapped)); CCLabelTTF *blabel = CCLabelTTF::create(" Use Slow Clock","Jacoby ICG Black.ttf",18,dim,kCCTextAlignmentLeft); blabel->setColor(ccc3(237,188,0)); blabel->setPosition(ccp(157.0f,18.0f)); menuImage->addChild(blabel,0,1234); items[0] = menuImage; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_icon_Store_16_Slow-Clock.png"); sprite->setPosition(ccp(30,23)); sprite->setScale(0.925f); menuImage->addChild(sprite,0,4321); menuImage->setScale(scale); if(!SaveLoad::m_SaveData.numTimeSlow) { //[menuImage setIsEnabled:NO]; blabel->setColor(ccc3(237/2,188/2,0)); sprite->setColor(ccc3(128,128,128)); } } CCMenu *powerUpMenu = CCMenu::create(items[0], items[1], items[2], NULL); powerUpMenu->alignItemsVerticallyWithPadding(-10.0); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += 100.0f*scale; scalePoint.y += 10.0f*scale; powerUpMenu->setPosition(scalePoint); addChild(powerUpMenu); m_TimeOut = 3.0f; scheduleUpdate(); }
// on "init" you need to initialize your instance bool InGameTopMenuLayer::init() { if (!CCLayerColor::initWithColor(ccc4(255, 255, 255, 255))) return false; float scaleMult = Model::getInstance()->getGUIElementScaleMultiplicator(); float button_length = 66 * scaleMult; float button_heigth = 66 * scaleMult; float padding = 10 * scaleMult; _soundOnString = "on"; _soundOffString = "off"; CCMenuItemSprite *shutdown = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("shutdown0.png"), CCSprite::createWithSpriteFrameName("shutdown1.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::shutdownTouched)); shutdown->setScaleX(button_length / shutdown->getContentSize().width); shutdown->setScaleY(button_heigth / shutdown->getContentSize().height); CCMenuItemSprite *autoCam = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("autoCam0.png"), CCSprite::createWithSpriteFrameName("autoCam1.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::autoCamTouched)); autoCam->setScaleX(button_length / autoCam->getContentSize().width); autoCam->setScaleY(button_heigth / autoCam->getContentSize().height); float scale = button_heigth / autoCam->getContentSize().height; _autCamOnOffLabel = CCLabelTTF::create("auto", FONT_NAME, PRICE_LABEL_FONT_SIZE / scale * scaleMult, CCSize(autoCam->getContentSize().width, PRICE_LABEL_HEIGTH / scale * scaleMult), kCCTextAlignmentCenter); autoCam->addChild(_autCamOnOffLabel); _autCamOnOffLabel->setColor(Model::getInstance()->getInGameGameLayer()->getAutoCam() ? ccc3(0, 255, 0) : ccc3(255, 0, 0)); _autCamOnOffLabel->setPosition(CCPoint(autoCam->getContentSize().width / 2, PRICE_LABEL_BOTTOM_SPACE / scale * scaleMult)); _autCamOnOffLabel->enableStroke(PRICE_LABEL_COLOR_STROKE, PRICE_LABEL_STROKE_SIZE / scale * scaleMult, true); CCMenuItemSprite *autoCamSwitch = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("autoCamSwitch0.png"), CCSprite::createWithSpriteFrameName("autoCamSwitch1.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::flipThisPlayerForCamTouched)); autoCamSwitch->setScaleX(button_length / autoCamSwitch->getContentSize().width); autoCamSwitch->setScaleY(button_heigth / autoCamSwitch->getContentSize().height); CCMenuItemSprite *pause = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("pause1.png"), CCSprite::createWithSpriteFrameName("pause2.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::pauseTouched)); pause->setScaleX(button_length / pause->getContentSize().width); pause->setScaleY(button_heigth / pause->getContentSize().height); CCMenuItemSprite *zoomIn = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ZoomIn1.png"), CCSprite::createWithSpriteFrameName("ZoomIn2.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::zoomInTouched)); zoomIn->setScaleX(button_length / zoomIn->getContentSize().width); zoomIn->setScaleY(button_heigth / zoomIn->getContentSize().height); CCMenuItemSprite *zoomOut = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ZoomOut1.png"), CCSprite::createWithSpriteFrameName("ZoomOut2.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::zoomOutTouched)); zoomOut->setScaleX(button_length / zoomOut->getContentSize().width); zoomOut->setScaleY(button_heigth / zoomOut->getContentSize().height); CCMenuItemSprite *toggleGUI = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("toggleGUI1.png"), CCSprite::createWithSpriteFrameName("toggleGUI2.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::toggleGUITouched)); toggleGUI->setScaleX(button_length / toggleGUI->getContentSize().width); toggleGUI->setScaleY(button_heigth / toggleGUI->getContentSize().height); CCMenuItemSprite *enableSound = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("soundEnable0.png"), CCSprite::createWithSpriteFrameName("soundEnable1.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::enableSoundTouched)); enableSound->setScaleX(button_length / enableSound->getContentSize().width); enableSound->setScaleY(button_heigth / enableSound->getContentSize().height); scale = button_heigth / enableSound->getContentSize().height; _enableSoundLabel = CCLabelTTF::create(SoundHandler::getInstance()->isSoundEnabled() ? _soundOnString.c_str() : _soundOffString.c_str(), FONT_NAME, PRICE_LABEL_FONT_SIZE / scale * scaleMult, CCSize(enableSound->getContentSize().width, PRICE_LABEL_HEIGTH / scale * scaleMult), kCCTextAlignmentCenter); enableSound->addChild(_enableSoundLabel); _enableSoundLabel->setColor(SoundHandler::getInstance()->isSoundEnabled() ? ccc3(0, 255, 0) : ccc3(255, 0, 0)); _enableSoundLabel->setPosition(CCPoint(enableSound->getContentSize().width / 2, PRICE_LABEL_BOTTOM_SPACE / scale * scaleMult)); _enableSoundLabel->enableStroke(PRICE_LABEL_COLOR_STROKE, PRICE_LABEL_STROKE_SIZE / scale * scaleMult, true); CCMenu* menu = CCMenu::create(); int x = 0; int y = 1; ViewTools::addToMenu(menu, zoomIn, button_length, button_heigth, x++, y, padding); ViewTools::addToMenu(menu, zoomOut, button_length, button_heigth, x++, y, padding); ViewTools::addToMenu(menu, autoCamSwitch, button_length, button_heigth, x++, y, padding); ViewTools::addToMenu(menu, autoCam, button_length, button_heigth, x++, y, padding); ViewTools::addToMenu(menu, toggleGUI, button_length, button_heigth, x++, y, padding); if (Model::getInstance()->getGameMode() != NETWORK) ViewTools::addToMenu(menu, pause, button_length, button_heigth, x++, y, padding); ViewTools::addToMenu(menu, shutdown, button_length, button_heigth, x, y, padding); ViewTools::addToMenu(menu, enableSound, button_length, button_heigth, x, y - 1, padding); // resizing this layer to the menu and place the menu correct float width = (x + 1) * button_length + x * padding; float height = button_heigth * 2 + padding; setContentSize(CCSize(width, height)); menu->setPosition(0, 0); addChild(menu); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); setPosition(winSize.width - width - (UNITS_INFO_OVERLAY_WIDTH * scaleMult), winSize.height - height); setOpacity(0); // 0- total transparent, 255 not return true; }
bool MultiplayerLayer::init() { bool bRet = false; do { CC_BREAK_IF(! OverlayBase::init()); CCSize size = CCDirector::sharedDirector()->getWinSize(); int leftSpace = 100; _opponentType = kHuman; CCMenuItemSprite* hItem = createMenuItemSprite((char*)"btnHotSeat128x128.png", (char*)"btnHotSeatPressed.png", menu_selector(MultiplayerLayer::onHotSeat)); CCMenuItemSprite* onlineItem = createMenuItemSprite((char*)"btnOnlineGame128x128.png", (char*)"btnOnlineGamePressed.png", menu_selector(MultiplayerLayer::onOnlineGame)); CCMenu* menu = CCMenu::create(hItem, onlineItem, NULL); menu->alignItemsVertically(); menu->setPosition(ccp(leftSpace, size.height - 2 * leftSpace)); addChild(menu, 1); if (!sgl_ConnectionManager.getRoomNumber().empty()) { CCMenuItemSprite* onlineReconnectItem = createMenuItemSprite((char*)"btnOnlineGameReconnect.png", (char*)"btnOnlineGamePressed.png", menu_selector(MultiplayerLayer::onOnlineGame)); menu->cocos2d::CCNode::addChild(onlineReconnectItem); } float menuLimit = hItem->getPosition().x + hItem->boundingBox().size.width + 20; CCLabelTTF* lH = new CCLabelTTF(); lH->initWithString("Hot seat", S_F_TYPE.c_str(), 32); lH->setPosition(ccp(menuLimit, hItem->getPosition().y)); lH->setAnchorPoint(ccp(0,0)); hItem->addChild(lH); CCLabelTTF* lO = new CCLabelTTF(); lO->initWithString("Random online game", S_F_TYPE.c_str(), 32); lO->setPosition(ccp(menuLimit, hItem->getPosition().y)); lO->setAnchorPoint(ccp(0,0)); onlineItem->addChild(lO); //Cancel - Go Menu CCMenuItemSprite* mRightArrow = sgl_SpriteFactory.createMenuItemSprite("btnArrow_Back128x128.png", "btnArrow_Back128x128Pressed.png", menu_selector(MultiplayerLayer::onQuit), this); CCMenu* menuReturn = CCMenu::create(mRightArrow, NULL); CCMenuItemSprite* mLeftArrow = sgl_SpriteFactory.createMenuItemSprite("btnArrow128x128.png", "btnArrow128x128Pressed.png", menu_selector(MultiplayerLayer::onConnect), this); CCMenu* mStartGame = CCMenu::create(mLeftArrow, NULL); menuReturn->setPosition(leftSpace, 150); mStartGame->setPosition(size.width - leftSpace - mLeftArrow->boundingBox().size.width * 0.5f, 150); addChild(mStartGame); addChild(menuReturn); _connectionStatus = CCLabelTTF::create("", S_F_TYPE.c_str(), 32); _connectionStatus->setPosition(ccp(size.width/2, 150)); this->addChild(_connectionStatus); bRet = true; } while (0); return bRet; }
void LevelMap::adjustMap(bool isResetLevel) { int num = floor(offsetY/442); currentMap = -num; int offnum = num%3; float tmpoff = offsetY - num*442; mapLayer->setPosition(ccp(0, (offnum-1)*442 + tmpoff)); if(isResetLevel) { int offlevel = 1000 + currentMap*3 -3; for (int i = 0; i < 9 ; i++) { MapItem* tmpLevelItemData = NULL; tmpLevelItemData = CData::getCData()->getConfigOfMapLevel(offlevel + i); CCMenuItemSprite* tmp = (CCMenuItemSprite*)levelSpDic->objectForKey(i); tmp->removeChildByTag(9999); if (tmpLevelItemData!= NULL && tmpLevelItemData->bid < currentLevelId) { CCSize tmpsz = tmp->getContentSize(); CCSprite* ssp = CCSprite::create(); int num = data["citylist"][tmpLevelItemData->bid - 1000].asInt(); for (int k = 0; k<num; k++) { CCSprite * star = CCSprite::create("zjm_star.png"); star->setPosition(ccp(k*30, 0)); ssp->addChild(star); } ssp->setPosition(ccp(tmpsz.width/2-15*num+15, 0)); ssp->setTag(9999); tmp->addChild(ssp, 0); } if(tmpLevelItemData != NULL) { if(tmpLevelItemData->bid > currentLevelId) { tmp->setEnabled(false); } else { tmp->setEnabled(true); } tmp->setUserObject(tmpLevelItemData); } //for (int j = 1001; j<=1005; j++) //{ CCLabelTTF* tmpName = (CCLabelTTF*)(tmp->getChildByTag(1002)); if(tmpLevelItemData) { tmpName->setString(tmpLevelItemData->nickname.c_str()); } //} } } levelsMenu->setPosition(ccp(0, -442 + tmpoff)); }
bool LevelMap::init() { if(!CCLayer::init()) { return false; } this->setTouchEnabled(true); levelSpDic = CCDictionary::create(); levelSpDic->retain(); currentMap = 0; size = CCDirector::sharedDirector()->getWinSize(); // CCSprite* bkg = CCSprite::create("zjm_bkg.png"); // bkg->setAnchorPoint(ccp(0, 0)); // bkg->setPosition(ccp(0, 0)); // this->addChild(bkg); mapLayer = CCSprite::create(); CCSprite* m1 = CCSprite::create("map3.png"); m1->setAnchorPoint(ccp(0, 0)); m1->setPosition(ccp(0, 0)); CCSprite* m2 = CCSprite::create("map1.png"); m2->setAnchorPoint(ccp(0, 0)); m2->setPosition(ccp(0, 441)); CCSprite* m3 = CCSprite::create("map2.png"); m3->setAnchorPoint(ccp(0, 0)); m3->setPosition(ccp(0, 441*2)); CCSprite* m4 = CCSprite::create("map3.png"); m4->setAnchorPoint(ccp(0, 0)); m4->setPosition(ccp(0, 441*3)); CCSprite* m5 = CCSprite::create("map1.png"); m5->setAnchorPoint(ccp(0, 0)); m5->setPosition(ccp(0, 441*4)); mapLayer->addChild(m1); mapLayer->addChild(m2); mapLayer->addChild(m3); mapLayer->addChild(m4); mapLayer->addChild(m5); mapLayer->setAnchorPoint(ccp(0, 0)); mapLayer->setPosition(ccp(0, 0)); // 将一个Layer添加到CCSprite里面 mapSp = CCSprite::create(); mapSp->addChild(mapLayer); mapSp->setAnchorPoint(ccp(0, 0)); mapSp->setPosition(ccp(0, 0)); this->addChild(mapSp); levelsMenu = CCMenu::create(); levelsMenu->setAnchorPoint(ccp(0, 0)); levelsMenu->setPosition(ccp(0, 0)); this->addChild(levelsMenu); CCSprite* bkg = CCSprite::create("zjm_bkg.png"); bkg->setAnchorPoint(ccp(0, 0)); bkg->setPosition(ccp(0, 0)); this->addChild(bkg); for (int i = 0; i < 9; i++) { // 地图上的选中框,并添加点击事件clkBuilding; CCMenuItemSprite* leveltmp = CCMenuItemImage::create("zjm_building_1.png", "zjm_building_1.png", "zjm_building_2.png",this, menu_selector(LevelMap::clkBuilding)); int num = (int)floor((float)i/3); leveltmp->setPosition(ccp((i-3*num)%2==1?140:size.width-130, (130)*(i%3) + 442*(int)floor((float)i/3) +240));//160 levelSpDic->setObject(leveltmp, i); levelsMenu->addChild(leveltmp); const ccColor3B color3 = {255,175,100}; const ccColor3B colorbg = {255,175,51}; CCSize tmpsz = leveltmp->getContentSize(); CCLabelTTF * name11=CCLabelTTF::create("", "hycc.ttf", 20); name11->setDimensions(CCSizeMake(200, 0)); name11->setHorizontalAlignment(kCCTextAlignmentCenter); name11->setVerticalAlignment(kCCVerticalTextAlignmentTop); name11->setPosition(ccp(tmpsz.width/2-1, 35)); name11->setColor(colorbg); // leveltmp->addChild(name11); leveltmp->addChild(name11, 10); name11->setTag(1002); } char * json=CData::getCData()->cityData; Json::Reader read; Json::Value root; if(read.parse(json, root)) { data=root["data"]; } currentLevelId = data["cityid"].asInt(); if (CData::getCData()->levelMapOffsetY > 0) { offsetY = -((int)ceil(((float)currentLevelId-1000)/3))*442; //size.height; } else { offsetY = CData::getCData()->levelMapOffsetY; } // offsetY = 0; mapNum = CData::getCData()->getLevelMapNum(); adjustMap(true); return true; }
bool PrepareLayer::init() { CCSize size = ToolsFun::sharedTools()->getSceneSize(); //背景 CCSprite *spBkg = CCSprite::create("ui/shared/bkg.png"); this->addChild(spBkg,-1); spBkg->setPosition(size/2); //放置人物设定背景 CCSprite *spBkgHero = CCSprite::create("ui/prepareUI/mainbkg.png"); this->addChild(spBkgHero,-1); spBkgHero->setPosition(ccp(size.width/2,size.height - spBkgHero->getContentSize().height/2 - 50*gScaleY)); //购物 CCSprite *spBkgTop = CCSprite::create("ui/shared/top.png"); this->addChild(spBkgTop,0,108); spBkgTop->setPosition(ccp(size.width/2,size.height - spBkgTop->getContentSize().height/2)); //人物游戏记录背景 CCSprite *spRecoreBkg = CCSprite::create("ui/prepareUI/recordbkg.png"); this->addChild(spRecoreBkg,-1); spRecoreBkg->setPosition(ccp(315*gScaleX,600*gScaleY)); //spRecoreBkg->setScale(PRE_SCALE); //宠物,道具背景 for (int i=0;i!=1;++i) { CCSprite *sp = CCSprite::create("ui/shared/placeboard.png"); this->addChild(sp,-1); sp->setPosition(ccp(size.width/4 + i * size.width/2,165*gScaleY)); sp->setScale(1.10f); } int level = GameConfigData::initialGameData().getCurLevel(); int killTotal = 0; killTotal = atoi( GameConfigData::initialGameData().getKillTotal().c_str()); char buf[64]; sprintf(buf,"%d",killTotal); int levelMaxStr = GameConfigData::initialGameData().getMaxUnLockLevel(); string strs[4] = { GameConfigData::initialGameData().getHScores(), GameConfigData::initialGameData().getHLenght(), string(buf), ToolsFun::sharedTools()->intToString(levelMaxStr) }; for (int i=0;i!=4;++i) { CCLabelBMFont *hScores = CCLabelBMFont::create(strs[i].c_str() ,"font/white_30.fnt"); spRecoreBkg->addChild(hScores); hScores->setPosition(ccp(150*gScaleX,(165-8-38*i))*gScaleY); hScores->setAnchorPoint(ccp(0,0.5f)); } m_menu = CCMenu::create(); this->addChild(m_menu,1); m_menu->setPosition(CCPointZero); //所有按钮的放置 const char* fName[9] = { "ui/shared/back.png",//返回 "ui/shared/coinplus.png",//添加金币 "ui/prepareUI/head.png",//主角头像 "ui/prepareUI/upgrade.png",//升级按钮 "ui/shared/shop_item.png",//宠物1 "ui/shared/shop_item.png",//宠物2 "ui/shared/shop_item.png",//道具1 // "ui/shared/shop_item.png",//道具2 "ui/shared/confirm.png"//确定开始游戏 }; const CCPoint posArray[9] = { ccp(37*gScaleX,size.height-37*gScaleY),ccp(430*gScaleX,size.height-30*gScaleY),ccp(290*gScaleX,435*gScaleY),ccp(360*gScaleX,335*gScaleY), ccp(54*gScaleX,145*gScaleY),ccp(144*gScaleX,145*gScaleY),ccp(355*gScaleX,145*gScaleY),ccp(235*gScaleX,40*gScaleY),ccp(235*gScaleX,40*gScaleY) }; for (int i=0;i!=8;++i) { CCSprite *spNml = CCSprite::create(fName[i]); CCSprite *spSel = CCSprite::create(fName[i]); spSel->setColor(ccc3(80,80,80)); CCMenuItemSprite *itemSp = CCMenuItemSprite::create(spNml,spSel, this,menu_selector(PrepareLayer::menuTouch)); if(i==2) { m_menu->addChild(itemSp,1,100+i); itemSp->setPosition(posArray[i]); itemSp->setScale(0.8f); } else if(i ==3) { m_menu->addChild(itemSp,1,100+i); itemSp->setPosition(posArray[i]); itemSp->setScale(PRE_SCALE); CCLabelBMFont *upGrade = CCLabelBMFont::create(gGetLanguageDesc(K.UPGRADE_DES).c_str(),"font/upgrade_des.fnt"); itemSp->addChild(upGrade); upGrade->setPosition(ccp(80*gScaleX,-25*gScaleY)); } else { m_menu->addChild(itemSp,1,100+i); itemSp->setPosition(posArray[i]); } } int curLevel = GameConfigData::initialGameData().getCurHeroLevel(); if (curLevel >= HERO_MAXLEVEL) { CCMenuItemSprite *upItem = (CCMenuItemSprite*)m_menu->getChildByTag(103); upItem->setEnabled(false); upItem->setVisible(false); if (this->getChildByTag(1430)) { this->getChildByTag(1430)->setVisible(false); } } //金币放置最上方商城 CCSprite *coinIcon = CCSprite::create("ui/shared/coin.png"); this->addChild(coinIcon,2,1429); coinIcon->setPosition(ccp(280 * gScaleX, size.height - 30 * gScaleY)); m_moneyLabel = CCLabelBMFont::create("10000000","font/level_big.fnt"); this->addChild(m_moneyLabel,4); m_moneyLabel->setAnchorPoint(ccp(0,0.5f)); m_moneyLabel->setPosition(ccp(300*gScaleX,size.height-25*gScaleY)); m_moneyLabel->setScale(0.6F); setCoin(); //升级所需金币数 m_nextLevelPriceLabel = CCLabelBMFont::create("1000000000","font/level_big.fnt"); this->addChild(m_nextLevelPriceLabel,2); m_nextLevelPriceLabel->setPosition(ccp(345*gScaleX,342*gScaleY)); m_nextLevelPriceLabel->setScale(0.45); int curHeroId = GameConfigData::initialGameData().getCurHeroId(); int heroLevel = GameConfigData::initialGameData().getCurHeroLevel(); //名字label m_heroNameLabel = CCLabelBMFont::create("name","font/hero_name.fnt"); this->addChild(m_heroNameLabel,10); m_heroNameLabel->setPosition(ccp(390*gScaleX,475*gScaleY)); m_heroNameLabel->setScale(0.8f); //主角现在等级 CCSprite* curHeroLevel=CCSprite::create("ui/prepareUI/level.png"); this->addChild(curHeroLevel,2); curHeroLevel->setPosition(ccp(370*gScaleX,445*gScaleY)); curHeroLevel->setScale(0.8f); //数字改变部分 m_curHeroLevel = CCLabelBMFont::create("10000000",GOLD_FONT); this->addChild(m_curHeroLevel,2); m_curHeroLevel->setPosition(ccp(420*gScaleX,445*gScaleY)); string levelStr = ToolsFun::sharedTools()->intToString(heroLevel); m_curHeroLevel->setString((levelStr).c_str()); m_curHeroLevel->setScale(0.8f); //点击头像改变 CCSprite* changeName=CCSprite::create("ui/prepareUI/changename.png"); this->addChild(changeName,2); changeName->setPosition(ccp(390*gScaleX,400*gScaleY)); changeName->setScale(0.8f); CCSprite *itemBkg = CCSprite::create("ui/shared/itemBkg.png"); this->addChild(itemBkg); itemBkg->setPosition(ccp(360,145)); initPet(0); initPet(1); initHeroSp(GameConfigData::initialGameData().getCurHeroId()); initItem(0); //initItem(1); playUpEffect(heroLevel,false); registerNDK(); return true; }
void PrepareLayer::initPet(int leftOrRight) { ///**初始化已经出战的左边的宠物**/// int petId = -1; for (int i =0;i !=6; ++i ) { if (GameConfigData::initialGameData().getPetStateById(i) == "2") { if (GameConfigData::initialGameData().getPetPosById(i) == leftOrRight) { petId = i; } } } CCMenuItemSprite *petAddLeft = (CCMenuItemSprite *)m_menu->getChildByTag(100+4+leftOrRight); if (petAddLeft->getChildByTag(1000)) { petAddLeft->removeChildByTag(1000); } CCPoint leftPoint[6] = {petAddLeft->getContentSize()/2+ccp(20*gScaleX,0),petAddLeft->getContentSize()/2+ccp(20*gScaleX,0),petAddLeft->getContentSize()/2+ccp(30*gScaleX,0), petAddLeft->getContentSize()/2+ccp(30*gScaleX,0),petAddLeft->getContentSize()/2+ccp(30*gScaleX,0),petAddLeft->getContentSize()/2+ccp(30*gScaleX,0)}; float scale[6] = {0.4*PRE_SCALE,0.4*PRE_SCALE,0.5*PRE_SCALE,0.5*PRE_SCALE,0.5*PRE_SCALE,0.5*PRE_SCALE}; CCSprite *sp = NULL; if (petId != -1) { char petFile[48]; sprintf(petFile,"ui/petUI/pet%d_0.png",petId); sp = CCSprite::create(petFile); sp->setScale(scale[petId]); if(leftOrRight ==0) { sp->setPosition(leftPoint[petId]); m_leftPitId = petId; } else { sp->setPosition(leftPoint[petId]); m_rightPetId =petId; } showHeroPet(leftOrRight,petId); } else { sp = CCSprite::create("ui/shared/plus.png"); sp->setPosition(petAddLeft->getContentSize()/2+ccp(20*gScaleX,0)); if(leftOrRight ==0) { if(this->getChildByTag(45456)!=NULL) { this->getChildByTag(45456)->setVisible(false); } } else { if(this->getChildByTag(45457)!=NULL) { this->getChildByTag(45457)->setVisible(false); } } } petAddLeft->addChild(sp,1,1000); }