//---------------------------------------------------------------------------------------------------------------------------/ CCocosTipBox *CCocosTipBox::Create(BoxType type, const char *szName, float sizeOrScale, unsigned char alpha, bool bUseFrame, const char *szBoxTexture) { ccColor4B color = {0, 0, 0, alpha}; CCSize sScreen = CCDirector::sharedDirector()->getWinSizeInPixels(); CCocosTipBox *pNewTipBox = CCocosTipBox::create(); CCLayerColor *pLayer = CCLayerColor::create(color, sScreen.width*2.0f, sScreen.height*2.0f); pLayer->setPosition(ccp(-pLayer->getContentSize().width*0.5f, -pLayer->getContentSize().height*0.5f)); pNewTipBox->addChild(pLayer); pNewTipBox->InitState(type, szName, sizeOrScale, bUseFrame, szBoxTexture); return pNewTipBox; }
bool NovelScene::init() { if (!CCLayer::init()) { return false; } this->setTouchEnabled(true); this->setTouchMode(kCCTouchesOneByOne); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite* background = CCSprite::create("013-PostTown01.jpg"); background->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.5)); this->addChild(background, kZOrder_Background, kTag_Background); CCLayerColor * textLayer = CCLayerColor::create(ccc4(0, 0, 0, 255 * 0.7), winSize.width, winSize.height * 0.25); textLayer->setPosition(CCPointZero); this->addChild(textLayer, kZOrder_TextLayer, kTag_TextLayer); CCString* string = CCString::createWithFormat("w = %f.1 h = %f.1 f = %f", winSize.width, winSize.height, BASE_FONT_SIZE); CCLog("%s", string->getCString()); CCLabelTTF* textLabel = CCLabelTTF::create(string->getCString(), "", BASE_FONT_SIZE); textLabel->setAnchorPoint(ccp(0, 0)); textLabel->setColor(ccWHITE); textLabel->setPosition(ccp(BASE_FONT_SIZE, textLayer->getContentSize().height - textLabel->getContentSize().height - BASE_FONT_SIZE)); textLayer->addChild(textLabel, kZOrder_TextLayer, kTag_TextLayer_textLabel); CCLayerColor * nameTextLayer = CCLayerColor::create(ccc4(0, 0, 0, 255 * 0.7), winSize.width * 0.4, winSize.height * 0.1); nameTextLayer->setPosition(ccp(textLayer->getPositionX(), textLayer->getPositionY() + textLayer->getContentSize().height + nameTextLayer->getContentSize().height * 0.05)); this->addChild(nameTextLayer, kZOrder_TextLayer, kTag_TextLayer_name); CCLabelTTF* nameTextLabel = CCLabelTTF::create("시스템 메세지", "", BASE_FONT_SIZE); nameTextLabel->setAnchorPoint(ccp(0, 0)); nameTextLabel->setColor(ccGREEN); nameTextLabel->setPosition(ccp(BASE_FONT_SIZE, nameTextLayer->getContentSize().height - nameTextLabel->getContentSize().height - BASE_FONT_SIZE * 0.5)); nameTextLayer->addChild(nameTextLabel, kZOrder_TextLayer, kTag_TextLayer_nameTextLabel); CCLabelTTF* logButtonLabel = CCLabelTTF::create("Log", "Arial", BASE_FONT_SIZE); CCMenuItemLabel* logButtonMenuItem = CCMenuItemLabel::create(logButtonLabel, this, menu_selector(NovelScene::logMenuSelectCallback)); logButtonMenuItem->setPosition(ccp(winSize.width * 0.95, logButtonMenuItem->getContentSize().height)); CCMenu* pMenu = CCMenu::create(logButtonMenuItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, kZOrder_MenuItem, kTag_MenuItem_log); return true; }
bool TipLayer::initTipLayer() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCLayerColor *maskLayer = CCLayerColor::node(); maskLayer->initWithColorWidthHeight(ccc4f(0x00,0x00,0x00,0x80),335,350); //maskLayer->setOpacity(200); maskLayer->setAnchorPoint(ccp(0.5, 0.5)); maskLayer->setPosition(ccp(winSize.width/2-maskLayer->getContentSize().width/2, winSize.height/2-maskLayer->getContentSize().height/2)); this->addChild(maskLayer); /*CCSprite *bgSprite = CCSprite::spriteWithFile("actor_pause_bg.png"); this->addChild(bgSprite); bgSprite->setPosition(ccp(winSize.width / 2, winSize.height / 2));*/ std::string stdNameOne = ""; std::string stdNameTwo = ""; std::string contentImageName = ""; stdNameOne = s_touchfile + s_language + "actor_btn_cancel.png"; stdNameTwo = s_touchfile + s_language + "actor_btn_confirm.png"; contentImageName = s_language + "actor_img_tipContent.png"; //content CCSprite *pContentSprite = CCSprite::spriteWithFile(contentImageName.c_str()); this->addChild(pContentSprite); pContentSprite->setPosition(ccp(winSize.width / 2, winSize.height / 2 +100)); CCMenuItemImage *cancelItem = CCMenuItemImage::itemFromNormalImage(stdNameOne.c_str(), stdNameOne.c_str(), this, menu_selector(TipLayer::cancel)); CCMenuItemImage *confirmItem = CCMenuItemImage::itemFromNormalImage(stdNameTwo.c_str(), stdNameTwo.c_str(), this, menu_selector(TipLayer::confirm)); CCMenu *menu = CCMenu::menuWithItems(confirmItem,cancelItem,NULL); menu->alignItemsVertically(); menu->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 50)); this->addChild(menu); CCLayer::setIsKeypadEnabled(true); return true; }
void AchievementLayer::updateAchievement(AchievementUpdateType type) { if (_achievementAchievementsLayer != NULL) _achievementAchievementsLayer->removeFromParentAndCleanup(true); _type = type; std::vector<CCNode*> nodes; //we have to create a variable with the AchievementSystem //otherwise it will delete the content of the vector AchievementSystem achSys = AchievementSystem(); std::vector<Achievement*> achievements = achSys.getAchievements(); float achievement_width = 0; for (std::vector<Achievement*>::iterator achi = achievements.begin(); achi != achievements.end(); ++achi) { if (type == AUT_ACHIEVED && !(*achi)->isAchieved()) continue; else if (type == AUT_NOT_ACHIEVED && (*achi)->isAchieved()) continue; CCLayerColor* ach = ViewTools::createLayerFromAchievement(*achi); nodes.push_back(ach); if (achievement_width == 0) { achievement_width = ach->getContentSize().width; } } float scale = Model::getInstance()->getGUIElementScaleMultiplicator(); float percent = (float) achSys.getPoints() / (float) achSys.getMaxPoints() * 100; std::string title = "Score: " + Tools::toString(achSys.getPoints()) + " (" + Tools::toString((int) percent) + "%)"; _achievementAchievementsLayer = ScrollLayer::create(title.c_str(), nodes, achievement_width, 10 * scale); getParent()->addChild(_achievementAchievementsLayer); }
// LayerIgnoreAnchorPointScale void LayerIgnoreAnchorPointScale::onEnter() { LayerTest::onEnter(); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLayerColor *l = CCLayerColor::create(ccc4(255, 0, 0, 255), 200, 200); l->setAnchorPoint(ccp(0.5f, 1.0f)); l->setPosition(ccp( s.width/2, s.height/2)); CCScaleBy *scale = CCScaleBy::create(2, 2); CCScaleBy* back = (CCScaleBy*)scale->reverse(); CCSequence *seq = CCSequence::create(scale, back, NULL); l->runAction(CCRepeatForever::create(seq)); this->addChild(l, 0, kLayerIgnoreAnchorPoint); CCSprite *child = CCSprite::create("Images/grossini.png"); l->addChild(child); CCSize lsize = l->getContentSize(); child->setPosition(ccp(lsize.width/2, lsize.height/2)); CCMenuItemFont *item = CCMenuItemFont::create("Toogle ignore anchor point", this, menu_selector(LayerIgnoreAnchorPointScale::onToggle)); CCMenu *menu = CCMenu::create(item, NULL); this->addChild(menu); menu->setPosition(ccp(s.width/2, s.height/2)); }
bool SGBaseBox::init(SGBoxDelegate *dg, BoxTag bt, CCSize size, bool ishaveinfobg,bool isHaveBg,CCSize bottomsize,bool useDefaultBg) { if (!SGBaseShow::init(NULL, bt, false)) { return false; } ResourceManager::sharedInstance()->bindTexture("sgmainlayer/sgmainlayer.plist", RES_TYPE_LAYER_UI, sg_baseBox, LIM_PNG_AS_PNG); ResourceManager::sharedInstance()->bindTexture("sgsoldierslayer/sgsoldierslayer.plist", RES_TYPE_LAYER_UI, sg_baseBox, LIM_PNG_AS_PNG); ResourceManager::sharedInstance()->bindTexture("sgcountrylayer/sgcountrylayer.plist", RES_TYPE_LAYER_UI, sg_baseBox); CCSize s = CCDirector::sharedDirector() -> getWinSize(); boxSize = size; deletage = dg; if (isHaveBg) { CCPoint center = ccpAdd(SGLayout::getPoint(kMiddleCenter), ccp(0, 0)); CCSprite *bg1 = NULL; if (useDefaultBg) { biao=CCSprite::createWithSpriteFrameName("box_bian.png"); this->addChild(biao, -1); biao->setPosition(ccpAdd(center, ccp(0, size.height*.5 -45))); ResourceManager::sharedInstance()->bindTexture("sanguobigpic/Tips.plist", RES_TYPE_LAYER_UI, sg_baseBox); cocos2d::extension::CCScale9Sprite *frame2 = cocos2d::extension::CCScale9Sprite::createWithSpriteFrameName("Tips.png"); //cocos2d::extension::CCScale9Sprite *frame2 = cocos2d::extension::CCScale9Sprite::create("sanguobigpic/Tips.png"); this->addChild(frame2,0); frame2->setScaleX(size.width/frame2->getContentSize().width); frame2->setScaleY(size.height/frame2->getContentSize().height); frame2->setPosition(ccpAdd(center, ccp(0,0))); CCLayerColor *bgLayer =CCLayerColor::create(ccc4(0, 0, 0, 180), skewing(320)*3, skewingY(960)*3); this->addChild(bgLayer,-3); bgLayer->setPosition(ccpAdd(CCPointZero, ccp(-bgLayer->getContentSize().width*.5, -bgLayer->getContentSize().height*.5))); } else { ResourceManager::sharedInstance()->bindTexture("sanguobigpic/barrack_bg.plist", RES_TYPE_LAYER_UI, sg_baseBox); bg1 = CCSprite::createWithSpriteFrameName("barrack_bg.png"); this->addChild(bg1 ,-2); bg1->setScaleY(s.height/bg1->getContentSize().height); bg1->setScaleX(s.width/bg1->getContentSize().width); bg1->setPosition(center); } if (ishaveinfobg) { ResourceManager::sharedInstance()->bindTexture("sanguobigpic/tipsinside.plist", RES_TYPE_LAYER_UI, sg_baseBox); fontbg = cocos2d::extension::CCScale9Sprite::createWithSpriteFrameName("tipsinside.png"); this->addChild(fontbg,0); fontbg->setPreferredSize(CCSizeMake(size.width-55, size.height-162));//-112 fontbg->setPosition(ccpAdd(center, ccp(0, 0)));//-27 } } this->runactionwithscale(); return true; }
bool CPullMachHelpLayer::init() { if (!CCLayer::init()) return false; CCSize barDownSize; //µ×Ãæ±ß¿ò³ß´ç CCSize barUpSize; //ÉÏÃæ±ß¿ò³ß´ç CCSize infoBgSize; //ÐÅÏ¢±³¾°³ß´ç CCSize infoViewSize; //ÐÅÏ¢¿ÉÊӳߴç CCSprite * pSprite = NULL; if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Bar_Down, pSprite)) { barDownSize = pSprite->getContentSize(); pSprite->setAnchorPoint(CCPointZero); pSprite->setPosition(CCPointZero); this->addChild(pSprite); } { float fHeight = this->getContentSize().height - 200; infoBgSize.setSize(barDownSize.width, (fHeight > 600) ? 600 : fHeight); CCLayerColor * bgLayer = CCLayerColor::create(ccc4(0, 24, 85, 255), infoBgSize.width, infoBgSize.height); bgLayer->setPosition(ccp(0, barDownSize.height)); this->addChild(bgLayer); } if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Bar_Up, pSprite)) { barUpSize = pSprite->getContentSize(); pSprite->setAnchorPoint(CCPointZero); pSprite->setPosition(ccp(0, barDownSize.height + infoBgSize.height)); this->addChild(pSprite); } //Ìí¼Ó¹ö¶¯ÄÚÈÝ infoViewSize.setSize(infoBgSize.width - 20, infoBgSize.height); if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Info, pSprite)) { pSprite->setAnchorPoint(ccp(0.5f, 0.0f)); pSprite->setPosition(ccp(infoViewSize.width / 2, 0)); } CCLayerColor * layerColor = CCLayerColor::create(ccc4(0, 13, 32, 255), infoViewSize.width, pSprite->getContentSize().height); layerColor->setPosition(CCPointZero); layerColor->addChild(pSprite); m_pScroll = CCScrollView::create(); m_pScroll->setViewSize(infoViewSize); m_pScroll->setPosition(ccp(10, barDownSize.height)); m_pScroll->setDirection(kCCScrollViewDirectionVertical); m_pScroll->addChild(layerColor); m_pScroll->setContentSize(layerColor->getContentSize()); m_pScroll->setContentOffset(m_pScroll->minContainerOffset()); m_pScroll->setTouchPriority(kCCMenuHandlerPriority - 1); this->addChild(m_pScroll); this->setContentSize(CCSize(infoBgSize.width, barDownSize.height + barUpSize.height + infoBgSize.height)); //Ìí¼Ó¹Ø±Õ°´Å¥ CCControlButton* pCloseButton = m_pResManager->CreateControlButton(PullMach_Bt_Help_Close_N, PullMach_Bt_Help_Close_C); pCloseButton->setAnchorPoint(ccp(1, 1)); pCloseButton->setPosition(getContentSize().width - 10, getContentSize().height - 4); pCloseButton->addTargetWithActionForControlEvents(this, cccontrol_selector(CPullMachHelpLayer::OnTouchClose), CCControlEventTouchUpInside); pCloseButton->setScaleX(1.5f); this->addChild(pCloseButton); return true; }
void SGAdvancedEffectLayer::initView() { // ccColor3B color[4] = {ccc3(0 , 239 , 22) , ccc3(75, 147, 255) ,ccc3(215,56,255) , ccc3(249, 158, 0)}; // // ccColor3B titleColor; ResourceManager::sharedInstance()->bindTexture("animationFile/Lightspot.plist",RES_TYPE_LAYER_UI ,sg_advancedEffectLayer); ResourceManager::sharedInstance()->bindTexture("animationFile/VisitArray.plist",RES_TYPE_LAYER_UI ,sg_advancedEffectLayer); int adNum = 0; int quality=0; //类型是全局通用的那个物品类型 char beforeItemPicStr[32] = "\0"; char afterItemPicStr[32] = "\0"; char itemNameStr[32] = "\0"; char itemAdNum[32] = "\0";// 小转生次次数 //6:将领卡牌 7:装备卡牌 8:士兵卡牌 9:道具卡牌 1:铜钱 0:金子 2天梯积分 3:军功 5:炼丹秘方 4:小喇叭 10:碎片 11军魂 12体力 13军粮 14号(废弃) 15消耗品 16 勋章 17 材料 //各种类型参数 switch (itemType) { case BIT_EQUIP://装备卡牌 { SGEquipmentDataModel *beforeEquipModel = SGStaticDataManager::shareStatic()->getEquipById(beforeAdvanceItemId); SGEquipmentDataModel *afterEquipModel = SGStaticDataManager::shareStatic()->getEquipById(afterAdvanceItemId); int beforeId = beforeEquipModel->getIconId(); int afterId = afterEquipModel->getIconId(); SGMainManager::shareMain()->addEquipPng(beforeId, sg_advancedEffectLayer); SGMainManager::shareMain()->addEquipPng(afterId, sg_advancedEffectLayer); sprintf(beforeItemPicStr, "equip%d.png", beforeId); sprintf(afterItemPicStr, "equip%d.png", afterId); sprintf(itemNameStr, "%s", afterEquipModel->getEquipName()->getCString()); adNum = afterEquipModel->getAdvNum(); if (adNum > 0) { sprintf(itemAdNum, "+%d", adNum); } //装备边框颜色 quality = afterEquipModel->getEquipCurrStarLevel(); // if(quality < 3 || quality > 6) // titleColor = ccGREEN; // else // titleColor = color[quality - 3]; } break; case BIT_OFFICER://武将卡牌 { SGOfficerDataModel *beforeEquipModel = SGStaticDataManager::shareStatic()->getOfficerById(beforeAdvanceItemId); SGOfficerDataModel *afterEquipModel = SGStaticDataManager::shareStatic()->getOfficerById(afterAdvanceItemId); int beforeId = beforeEquipModel->getIconId(); int afterId = afterEquipModel->getIconId(); SGMainManager::shareMain()->addOfficerPng(beforeId, sg_advancedEffectLayer); SGMainManager::shareMain()->addOfficerPng(afterId, sg_advancedEffectLayer); sprintf(beforeItemPicStr, "officer_%d.png", beforeId); sprintf(afterItemPicStr, "officer_%d.png", afterId); sprintf(itemNameStr, "%s", afterEquipModel->getOfficerName()->getCString()); adNum = afterEquipModel->getAdvNum(); if (adNum > 0) { sprintf(itemAdNum, "+%d", adNum); } //装备边框颜色 quality = afterEquipModel->getOfficerCurrStarLevel(); // if(quality < 3 || quality > 6) // titleColor = ccGREEN; // else // titleColor = color[quality - 3]; break; } default: break; } //构造sprite beforeAdvancedItemPic = CCSprite::createWithSpriteFrameName(beforeItemPicStr); afterAdvancedItemPic = CCSprite::createWithSpriteFrameName(afterItemPicStr); itemName = SGCCLabelTTF::create(itemNameStr, FONT_PANGWA, 35, SGTools::getColorByQuality(quality)); if (adNum) { adNumLabel = SGCCLabelTTF::create(itemAdNum, FONT_PANGWA, 34, ccGREEN); } //黑背景 CCLayerColor *blackBg = CCLayerColor::create(ccc4(0, 0, 0, 255), CCDirector::sharedDirector()->getWinSize().width, CCDirector::sharedDirector()->getWinSize().height); this->addChild(blackBg, 0); blackBg->setPosition(ccp(0, 0)); blackBg->addChild(beforeAdvancedItemPic, 1); blackBg->addChild(itemName, 1); beforeAdvancedItemPic->setPosition(ccpAdd(blackBg->getPosition(), ccp(blackBg->getContentSize().width / 2, blackBg->getContentSize().height / 2))); itemName->setPosition(ccpAdd(beforeAdvancedItemPic->getPosition(), ccp(0, beforeAdvancedItemPic->getContentSize().height / 2 + itemName->getContentSize().height + 20))); if (adNumLabel) { blackBg->addChild(adNumLabel, 1); adNumLabel->setPosition(ccpAdd(itemName->getPosition(), ccp(itemName->getContentSize().width / 2 + 10 + adNumLabel->getContentSize().width, 0))); } CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //添加动画 法阵旋转 CCSpriterX *visitArray = CCSpriterX::create("animationFile/Array.scml",true,true); visitArray->setisloop(true); visitArray->play(); visitArray->setanimaID(0); blackBg->addChild(visitArray,1); visitArray->setPosition(ccp(winSize.width/2, winSize.height*(0.8-0.28) - 50)); //法阵上升粒子 CCSpriterX *lightSpot = CCSpriterX::create("animationFile/Lightspot.scml",true,true); lightSpot->setisloop(true); lightSpot->play(); lightSpot->setanimaID(0); blackBg->addChild(lightSpot,50); lightSpot->setPosition(ccp(winSize.width/2, winSize.height*(0.8-0.2))); //构造动画 CCCallFuncN *setPicVisiable = CCCallFuncN::create(this, callfuncN_selector(SGAdvancedEffectLayer::setPictureVisiable)); CCCallFuncN *setTipsVisiable = CCCallFuncN::create(this, callfuncN_selector(SGAdvancedEffectLayer::setSuccessTipsVisiable)); CCCallFuncN *setComplete = CCCallFuncN::create(this, callfuncN_selector(SGAdvancedEffectLayer::setisPlayCompleted)); afterAdvancedItemPic->setScale(5); blackBg->addChild(afterAdvancedItemPic, 2); afterAdvancedItemPic->setPosition(beforeAdvancedItemPic->getPosition()); CCString * str = NULL; int fSize = 36; if(m_officerFrom == 1) str = CCString::create(str_adv_eff_1); else if (2 == m_officerFrom) str = CCString::create(str_adv_eff_2); else if(-1 == m_officerFrom) str = CCString::create(str_adv_eff_1); else if (3 == m_officerFrom) { str = CCString::createWithFormat(str_adv_eff_3, _extArg); fSize = 26; } else { //默认只显示 『转生成功』 str = CCString::create(str_adv_eff_1); } successTips = SGCCLabelTTF::create(str->getCString(), FONT_PANGWA, fSize); blackBg->addChild(successTips, 3); successTips->setPosition(ccpAdd(afterAdvancedItemPic->getPosition(), ccp(0, -afterAdvancedItemPic->getContentSize().height / 2 - successTips->getContentSize().height - 100))); successTips->setVisible(false); CCSequence *seq = CCSequence::create(CCDelayTime::create(0.1),setPicVisiable, CCScaleTo::create(SHOWCARDGAPTIME*2,0.89), CCScaleTo::create(SHOWCARDGAPTIME,1.13), CCScaleTo::create(SHOWCARDGAPTIME,1.06), CCScaleTo::create(SHOWCARDGAPTIME,1), CCDelayTime::create(0.15), setTipsVisiable, CCDelayTime::create(0.15), setComplete, NULL); afterAdvancedItemPic->runAction(seq); CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, -255, true); }
// on "init" you need to initialize your instance bool MainMenuScene::init() { // Parent CCLayerColor *layer = CCLayerColor::create(); layer->initWithColor(ccc4(255, 255, 255, 255), VisibleRect::right().x , VisibleRect::top().y); layer->setPosition(VisibleRect::center()); layer->setAnchorPoint(ccp(0.5f, 0.5f)); layer->ignoreAnchorPointForPosition(false); addChild(layer, 0); CCSprite *fondo = CCSprite::create("fondo.png"); fondo->setPosition(VisibleRect::center()); layer->addChild(fondo); // 1st Son CCLayerColor *upperLayer = CCLayerColor::create(); upperLayer->setContentSize(ccp(VisibleRect::right().x , VisibleRect::top().y/2)); //upperLayer->initWithColor(ccc4(120, 120, 120, 120), VisibleRect::right().x , VisibleRect::top().y/2); upperLayer->setPosition(ccp(VisibleRect::left().x, VisibleRect::center().y)); upperLayer->setAnchorPoint(ccp(0,0)); upperLayer->ignoreAnchorPointForPosition(false); layer->addChild(upperLayer, 0); CCSprite *spriteLogo = CCSprite::create("logo_opciones.png"); spriteLogo->setPosition(ccp(layer->getPosition().x, layer->getPosition().y/2)); upperLayer->addChild(spriteLogo); // 2nd Son CCLayerColor *lowerLayer = CCLayerColor::create(); lowerLayer->setContentSize(ccp(VisibleRect::right().x , VisibleRect::top().y/2)); //lowerLayer->initWithColor(ccc4(200, 200, 200, 200), VisibleRect::right().x , VisibleRect::top().y/2); lowerLayer->setPosition(ccp(VisibleRect::left().x, VisibleRect::bottom().y)); lowerLayer->setAnchorPoint(ccp(0,0)); lowerLayer->ignoreAnchorPointForPosition(false); layer->addChild(lowerLayer, 0); int mySize = lowerLayer->getContentSize().height / 3; // Button SAILKAPENA CCTexture2D *texture1 = CCTextureCache::sharedTextureCache()->addImage("botoia_normal.png"); SpriteButton *pButton1 = SpriteButton::create(texture1 ,this, callfuncO_selector(MainMenuScene::menuSelector), 1.0f); pButton1->setTag(2); pButton1->setPosition(ccp( lowerLayer->getContentSize().width / 2, lowerLayer->getContentSize().height / 2)); pButton1->setAnchorPoint(ccp(0.5f, 0.5f)); CCLabelTTF *pLabel1 = CCLabelTTF::create("Sailkapena", "fonts/PT_Sans-Web-Bold.ttf", 30.0); pLabel1->setPosition(ccp( lowerLayer->getContentSize().width / 2, lowerLayer->getContentSize().height / 2)); lowerLayer->addChild(pButton1); lowerLayer->addChild(pLabel1); // Button JOKATU CCTexture2D *texture2 = CCTextureCache::sharedTextureCache()->addImage("botoia_normal.png"); SpriteButton *pButton2 = SpriteButton::create(texture2 ,this, callfuncO_selector(MainMenuScene::menuSelector), 1.0f); pButton2->setTag(1); pButton2->setPosition(ccp( lowerLayer->getContentSize().width / 2, (mySize * 3) - texture2->getContentSize().height)); pButton2->setAnchorPoint(ccp(0.5f, 0.5f)); CCLabelTTF *pLabel2 = CCLabelTTF::create("Jokatu", "fonts/PT_Sans-Web-Bold.ttf", 30.0); pLabel2->setPosition(ccp( lowerLayer->getContentSize().width / 2, (mySize * 3) - texture2->getContentSize().height)); lowerLayer->addChild(pButton2); lowerLayer->addChild(pLabel2); // Button HONI BURUZ CCTexture2D *texture3 = CCTextureCache::sharedTextureCache()->addImage("botoia_normal.png"); SpriteButton *pButton3 = SpriteButton::create(texture3 ,this, callfuncO_selector(MainMenuScene::menuSelector), 1.0f); pButton3->setTag(3); pButton3->setPosition(ccp( lowerLayer->getContentSize().width / 2, mySize - (texture2->getContentSize().height / 2))); pButton3->setAnchorPoint(ccp(0.5f, 0.5f)); CCLabelTTF *pLabel3 = CCLabelTTF::create("Honi buruz", "fonts/PT_Sans-Web-Bold.ttf", 30.0); pLabel3->setPosition(ccp( lowerLayer->getContentSize().width / 2, mySize - (texture2->getContentSize().height / 2))); lowerLayer->addChild(pButton3); lowerLayer->addChild(pLabel3); return true; }
ScreenProgressBar::ScreenProgressBar() :_nodeBase(NULL), _layerFrame(NULL), _layerProgressBar(NULL), _controller(NULL) { { CCSize size; size.width = SingleElementWidth(); size.height = CCDirector::sharedDirector()->getWinSize().height; setContentSize(size); } { CCLayerColor* layerN = CCLayerColor::create(normalColor(), SingleElementWidth(), 30); CCLabelTTF *label = CCLabelTTF::create("Loading. Please stand by.", MAX_DEFAULT_FONT, 10); label->setTag(BUTTON_LABEL_TAG); label->setColor(MAX_COLOR_WHITE); CCSize sz = layerN->getContentSize(); sz.height /= 2; label->setPosition(ccp((int)(sz.width * 0.25), (int)(sz.height * 0.25))); sz.width *= CCDirector::sharedDirector()->getContentScaleFactor(); sz.height *= CCDirector::sharedDirector()->getContentScaleFactor(); label->setContentSize(sz); label->setAnchorPoint(ccp(0, 0)); layerN->addChild(label); CocosHelper::MoveNode(layerN->getChildByTag(11), ccp(15, 5)); addChild(layerN); _buttons->addObject(layerN); } if (!_nodeBase) { _nodeBase = CCNode::create(); _nodeBase->setContentSize(CCSizeMake(SingleElementWidth(), SingleElementHeight())); _nodeBase->setAnchorPoint(ccp(0, 0)); _nodeBase->setPosition(ccp(0, 0)); addChild(_nodeBase); _buttons->addObject(_nodeBase); } ccColor4B color; color = normalColor(); if (!_layerFrame) { _layerFrame = CCLayerColor::create(color, SingleElementWidth(), 50); _layerFrame->setAnchorPoint(ccp(0, 0)); _layerFrame->setPosition(ccp(0, 0)); _nodeBase->addChild(_layerFrame); } color = selectedColor(); if (!_layerProgressBar) { _layerProgressBar = CCLayerColor::create(color, 0, 50); _layerProgressBar->setAnchorPoint(ccp(0, 0)); _layerProgressBar->setPosition(ccp(0, 0)); _nodeBase->addChild(_layerProgressBar); } SetProgress(0.0); }
//创建一个对应的简单的button,代表具体的章 CCLayerColor *SGSpecialBattleLayer::createChapButton(int buttonTag, SpecialBattleData *data) { CCLayerColor *layerColor = CCLayerColor::create(ccc4(0, 255, 0, 0), 160, 160); layerColor->setTag(111); layerColor->setAnchorPoint(ccp(0.5, 0.5)); if (data) { CCSprite *headIcon = SGDrawCards::createPureSprite(data->itemId, data->itemType, sg_specialBattleLayer); CCSprite *borderIcon = CCSprite::createWithSpriteFrameName("equipPinzhi_5_0.png"); headIcon->addChild(borderIcon, 1); borderIcon->setPosition(ccpAdd(ccp(headIcon->getContentSize().width / 2, headIcon->getContentSize().height / 2), ccp(0, 0))); CCSprite *headIcon1 = SGDrawCards::createPureSprite(data->itemId, data->itemType, sg_specialBattleLayer); CCSprite *borderIcon1 = CCSprite::createWithSpriteFrameName("equipPinzhi_5_0.png"); headIcon1->addChild(borderIcon1, 1); borderIcon1->setPosition(ccpAdd(ccp(headIcon1->getContentSize().width / 2, headIcon1->getContentSize().height / 2), ccp(0, 0))); //章节的按钮 SGButton *chapButton = SGButton::createFromSprite(headIcon, headIcon1, this, menu_selector(SGSpecialBattleLayer::enterSpBattleSection)); chapButton->setTag(buttonTag); //章节的名称 //250 197 68 SGCCLabelTTF *chapNameTTF = SGCCLabelTTF::create(data->chapName.c_str(), FONT_PANGWA, 24); chapButton->addChild(chapNameTTF, 2); chapNameTTF->setInsideColor(ccc3(250, 197, 68)); chapNameTTF->setPosition(ccpAdd(ccp(chapNameTTF->getContentSize().width / 2, chapNameTTF->getContentSize().height / 3.5), ccp(0, 0))); //如果没有开启,蒙灰 if (!data->isOpen) { CCSprite *greyMask = CCSprite::createWithSpriteFrameName("sp_battle_entry_mask.png"); greyMask->setOpacity(150); chapButton->addChild(greyMask, 10); greyMask->setPosition(ccpAdd(ccp(greyMask->getContentSize().width / 2 - 5, greyMask->getContentSize().height / 2 - 5), ccp(0, 0))); //未开启,不可用 chapButton->setEnabled(false); } CCMenu *menu = CCMenu::create(); menu->setTouchPriority(10); menu->setPosition(CCPointZero); menu->addChild(chapButton); layerColor->addChild(menu); chapButton->setPosition(ccpAdd(ccp(0, 0), ccp(layerColor->getContentSize().width / 2, layerColor->getContentSize().height / 1.5))); //显示描述的背景 CCSprite *descBg = CCSprite::createWithSpriteFrameName("sp_battle_infobg.png"); layerColor->addChild(descBg, 1); descBg->setPosition(ccpAdd(chapButton->getPosition(), ccp(0, -descBg->getContentSize().height / 2 - chapButton->getContentSize().height / 1.7))); //下方对应的描述 std::string desc; if (data->isOpen) { desc = data->chapOpenDesc; //如果是开启的,加上光效 ResourceManager::sharedInstance()->bindTexture("animationFile/ms_niubility.plist", RES_TYPE_LAYER_UI, sg_specialBattleLayer); CCSpriterX *newRewardEffect = CCSpriterX::create("animationFile/ms_niubility.scml", true, true); layerColor->addChild(newRewardEffect, -1); newRewardEffect->setanimaID(0); newRewardEffect->setisloop(true); newRewardEffect->setScale(1.15); newRewardEffect->setPosition(ccpAdd(chapButton->getPosition(), ccp(0, 0))); newRewardEffect->play(); } else { desc = data->chapClosedDesc; } SGCCLabelTTF *chapDescTTF = SGCCLabelTTF::create(desc.c_str(), FONT_PANGWA, 21); descBg->addChild(chapDescTTF, 1); chapDescTTF->setPosition(ccpAdd(ccp(descBg->getContentSize().width / 2, descBg->getContentSize().height / 2), ccp(0, 0))); //如果开启状态,显示剩余次数 if (data->isOpen) { SGCCLabelTTF *residueTimeTTF = SGCCLabelTTF::create(CCString::createWithFormat(str_SpecailBattleResidueCoint, data->freePlayTimes)->getCString(), FONT_PANGWA, 20); residueTimeTTF->setInsideColor(ccGREEN); layerColor->addChild(residueTimeTTF, 1); residueTimeTTF->setPosition(ccpAdd(descBg->getPosition(), ccp(0, -residueTimeTTF->getContentSize().height * 1.2))); } } else { //没有的,直接问号显示 SGButton *chapButton = SGButton::create("sp_battle_unlock.png", "equipPinzhi_5_0.png", this, NULL); chapButton->setEnabled(false); layerColor->addChild(chapButton); chapButton->setPosition(ccpAdd(ccp(0, 0), ccp(layerColor->getContentSize().width / 2, layerColor->getContentSize().height / 1.5))); } return layerColor; }
void SGAnnouncementLayer::initScrollView() { //ResourceManager::sharedInstance()->bindTexture("sgannouncementlayer/sgannouncementlayer2.plist", RES_TYPE_LAYER_UI, sg_announcementLayer); m_scrollview->getContainer()->removeAllChildrenWithCleanup(true); int positionY = 0;// Y轴纵向偏移, int border_shift = 20;//内容窗口偏移 int text_wid_expand = 40;//文本区宽度扩展 if (CCEGLView::sharedOpenGLView()->getFrameSize().width == ipadResource.size.width ||CCEGLView::sharedOpenGLView()->getFrameSize().width == ipadhdResource.size.width) { text_wid_expand = 28; } //记录上一个内容窗口的底线位置 float lastWindowBorderPos = 0.0f; for(int i = 0; i < m_arrayAnn->count(); i++) //for (int i = 0; i < 6; i++) { //=======================获取数据================================ SGAnnouncementDataModel *ann = (SGAnnouncementDataModel *)m_arrayAnn->objectAtIndex(i); CCString *title = ann->getTitle(); CCString *content = ann->getContent(); int viewId = ann->getViewId();//跳转至哪个页面 //=======================获取数据================================ CCLayer *layer = (CCLayer*)m_scrollview->getContainer();//获取scrollview的容器 CCLayerColor* contentWindow = initContentWindow(content, viewId > 0); contentWindow->setAnchorPoint(ccp(0.5, 0)); contentWindow->ignoreAnchorPointForPosition(false); CCSize cwSize = contentWindow->getContentSize(); CCSprite * sprite = CCSprite::createWithSpriteFrameName("Tips.png"); sprite->setScaleX(cwSize.width / 584.0); sprite->setScaleY(cwSize.height / 522.0); sprite->setPosition(ccp(cwSize.width * 0.5, cwSize.height * 0.5)); contentWindow->addChild(sprite, 2); //根据上一个内容窗口的位置计算下一个窗口的位置 contentWindow->setPosition(ccp(layer->getContentSize().width * 0.5, lastWindowBorderPos + border_shift)); /* tips.png图片拉长的倍数 */ float pngScale = cwSize.height / 522 ; // CCLOG("*******************>>>"); // CCLOG("i = %d" , i); // CCLOG("title = %s" , title->getCString()); // CCLOG("content = %s" , content->getCString()); // CCLOG("pos: x=%f , y = %f" , contentWindow->getPositionX() , contentWindow->getPositionY()); // CCLOG("cwSize: width=%f, height=%f", cwSize.width, cwSize.height); // CCLOG("lastWindowBorderPos = %f" , lastWindowBorderPos); // CCLOG("<<<********************"); lastWindowBorderPos = contentWindow->getPositionY() + cwSize.height; //公告title CCLabelTTF *label = CCLabelTTF::create(title->getCString(), FONT_PANGWA, 35); label->setColor(COLOR_RED); label->setAnchorPoint(ccp(0.5 , 1)); label->setPosition(ccp(cwSize.width *0.5f, cwSize.height - pngScale * 20)); contentWindow->addChild(label, 100); //公告内容 // CCSize maybeTextSize = stringInLabelRect(content->getCString()); // CCLabelTTF *label_content=CCLabelTTF::create(content->getCString(), FONT_PENGYOU, 24,CCSizeMake(maybeTextSize.width + text_wid_expand * 4,maybeTextSize.height + text_hei_expand),kCCTextAlignmentLeft); CCLabelTTF *label_content=CCLabelTTF::create(content->getCString(), FONT_PENGYOU, 24,CCSizeMake(cwSize.width - 40 * widthFactor, cwSize.height - label->getContentSize().height),kCCTextAlignmentLeft); label_content->setAnchorPoint(ccp(0.5, 1));//内容顶线对齐 label_content->setColor(ccBLACK); label_content->setPosition(ccp(label->getPositionX(), label->getPositionY() - label->getContentSize().height)); label_content->setZOrder(102); contentWindow->addChild(label_content); //点击前往按钮 if (viewId > 0) { SGButton *goButton = SGButton::create("box_btnbg.png", NULL, this, menu_selector(SGAnnouncementLayer::AnnounceButton),CCPointZero,false,true); CCString *go = CCString::createWithFormat(str_Hit_goto); SGCCLabelTTF *go_label = SGCCLabelTTF::create(go->getCString(), FONT_PANGWA, 30); goButton->addChild(go_label); goButton->setTag(viewId);//跳转到某个视图界面 go_label->setPosition(ccp(goButton->getContentSize().width / 2, goButton->getContentSize().height / 2)); //立即前往Button CCMenu *menu = CCMenu::create(goButton, NULL); menu->setTouchPriority(0); menu->setPosition(CCPointZero); goButton->setScale(0.7); goButton->setZOrder(200); //goButton->setPosition(ccp(label->getPositionX(), goButton->getContentSize().height / 1.5)); goButton->setAnchorPoint(ccp(0.5, 0)); goButton->setPosition(ccp(label->getPositionX(), pngScale * 18)); menu->setZOrder(200); contentWindow->addChild(menu); } layer->addChild(contentWindow); //每次加对应的contentWindow的大小,为之后计算scrollview的内容体偏移 positionY += (cwSize.height + border_shift); } //layer->setContentSize(CCSizeMake(504, m_scrollview->getContentSize().height)); //控制是否可以滑动 iscanmove = (positionY)>791?true:false;//@note:591是m_scrollview的可视区域高度 m_scrollview->setContentOffset(ccp(0, -positionY + m_scrollview->getContentSize().height - 30));//20是顶部窗口的起始位置偏移,不减去会有一小部分遮挡 m_scrollview->setContentSize(CCSizeMake(m_scrollview->getContentSize().width, positionY));//scrollview的真正大小 m_scrollview->getContainer()->setContentSize(CCSizeMake(m_scrollview->getContentSize().width, positionY + 10));//滚动重置时的container位置 }