void LevelGame05::musicCallback(CCObject *pSender) { CCMenu *pmenu=(CCMenu *)getChildByTag(101); pmenu->setEnabled(true); CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); CCLayerColor *layer=( CCLayerColor *)getChildByTag(80); if(isMusic == true) { isMusic = false; /*CCDirector::sharedDirector()->end();*/ CCMenu* pMenu = (CCMenu *)layer->getChildByTag(128); CCMenuItemImage *Item = (CCMenuItemImage *)pMenu->getChildByTag(127); Item->setNormalSpriteFrame(cache->spriteFrameByName("close-pause-music.png")); if(flagMusic == true) SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); } else { isMusic =true; CCMenu* pMenu = (CCMenu *)layer->getChildByTag(128); CCMenuItemImage *Item = (CCMenuItemImage *)pMenu->getChildByTag(127); Item->setNormalSpriteFrame(cache->spriteFrameByName("pause-music.png")); if(flagMusic == true) { SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); } else { SimpleAudioEngine::sharedEngine()->playBackgroundMusic("back2.mp3",true); flagMusic = true; } } //removeChildByTag(80); }
void NovelScene::makeSelectSpriteButton(string str1, int next1Id, string str2, int next2Id) { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCMenu* pMenu = (CCMenu*) this->getChildByTag(kTag_MenuSelect); if (pMenu) { pMenu->setVisible(true); MenuItemSelectLabelSprite* menuSprite1 = (MenuItemSelectLabelSprite*) pMenu->getChildByTag(kTag_MenuSelect1); menuSprite1->setNovelText(str1.c_str(), next1Id); MenuItemSelectLabelSprite* menuSprite2 = (MenuItemSelectLabelSprite*) pMenu->getChildByTag(kTag_MenuSelect2); menuSprite2->setNovelText(str2.c_str(), next2Id); } else { //선택지1 MenuItemSelectLabelSprite* menuSprite1 = MenuItemSelectLabelSprite::createWithLabelSprite("menu_button.png", str1.c_str(), "Arial", BASE_FONT_SIZE, ccBLACK, ccBLUE, ccRED, next1Id, this, menu_selector(NovelScene::menuSelectCallback)); menuSprite1->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.55)); menuSprite1->setTag(kTag_MenuSelect1); menuSprite1->setZOrder(kZOrder_MenuSelect); //선택지2 MenuItemSelectLabelSprite* menuSprite2 = MenuItemSelectLabelSprite::createWithLabelSprite("menu_button.png", str2.c_str(), "Arial", BASE_FONT_SIZE, ccBLACK, ccBLUE, ccRED, next2Id, this, menu_selector(NovelScene::menuSelectCallback)); menuSprite2->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.45)); menuSprite2->setTag(kTag_MenuSelect2); menuSprite2->setZOrder(kZOrder_MenuSelect); //메뉴 작성 pMenu = CCMenu::create(menuSprite1, menuSprite2, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, kZOrder_MenuSelect, kTag_MenuSelect); } }
void GamePan::showHideConfirmPad(bool isShow) { CCLayerColor* pBaseNode = dynamic_cast<CCLayerColor*>(m_pCcbNode->getChildByTag(kTagGamePanConfirmPad)); pBaseNode->setVisible(isShow); CCLabelTTF* pText = dynamic_cast<CCLabelTTF*>(pBaseNode->getChildByTag(1)); pText->setVisible(!_isPlayer); CCMenu* pMenu = dynamic_cast<CCMenu*>(pBaseNode->getChildByTag(0)); pMenu->setVisible(isShow && _isPlayer); pMenu->setTouchPriority(-1000); if(pMenu) { CCMenuItemImage* btn = dynamic_cast<CCMenuItemImage*>(pMenu->getChildByTag(kTagGamePanConfirmPadOkBtn)); btn->setTarget(this,menu_selector(GamePan::ConfirmBtnCallback)); btn = dynamic_cast<CCMenuItemImage*>(pMenu->getChildByTag(kTagGamePanConfirmPadCancelBtn)); btn->setTarget(this,menu_selector(GamePan::ConfirmBtnCallback)); } }
void MarketScene::checkCard(int index) { CCMenu *pMenu = (CCMenu *)this->getChildByTag(TAG_MENU); char szFileName[32] = { 0 }; for (int i = 0; i < CARD_COUNT; i++) { int tag = BTN_CARD + i; CCMenuItemToggle *pToggle = (CCMenuItemToggle *)pMenu->getChildByTag(tag); if (tag == index) { selectedIndex = index; pToggle->setSelectedIndex(1); pToggle->setEnabled(false); sprintf(szFileName, s_pathCardInfo.m_strPath, i); int price = getPrice(tag); updateLabelAtlas(price, LabelAtlas_PRICE); CCMenuItemImage *pMenuItem = (CCMenuItemImage *)pMenu->getChildByTag(BTN_BUY); if (g_Control.cards[i] <= 0 && g_Control.m_nCoin > price) { pMenuItem->setEnabled(true); } else { pMenuItem->setEnabled(false); } } else { pToggle->setSelectedIndex(0); pToggle->setEnabled(true); } } this->removeChildByTag(CARD_INFO); CCSprite *pcdSprite = CCSprite::create(szFileName); pcdSprite->setPosition(s_pathCardInfo.m_Position); pcdSprite->setTag(CARD_INFO); this->addChild(pcdSprite); pcdSprite->runAction(CCSequence::create(CCSpawn::create(CCScaleTo::create(0.2f, 1.0f), CCFadeTo::create(0.2f, 255), NULL), NULL)); }
void LayerGoods::updateMe() { UserInfo *user_info = Topwo::getInstance()->getTopwoData()->getUserInfo(); CCMenu* menu = static_cast<CCMenu*>(this->getChildByTag(0)); //体魄 int goods_level = 0; CCMenuItemSprite* item = NULL; CCSprite* sprite = NULL; CCLabelAtlas* la = NULL; for (int i = 1; i <= 5; i++) { if (i == 1) { goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelTiPo()); } else if (i == 2) { goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelMeiLi()); } else if (i == 3) { goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelZhiLi()); } else if (i == 4) { goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelEQ()); } else if (i == 5) { goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelGanXing()); } item = static_cast<CCMenuItemSprite*>(menu->getChildByTag(i)); if (goods_level >= 9) { item->setEnabled(false); item->setColor(ccc3(128, 128, 128)); } sprite = static_cast<CCSprite*>(this->getChildByTag(i)); la = static_cast<CCLabelAtlas*>(sprite->getChildByTag(0)); la->setString(CCString::createWithFormat("%d", goods_level)->getCString()); la = static_cast<CCLabelAtlas*>(sprite->getChildByTag(1)); la->setString(CCString::createWithFormat("%d", getGoodsBonus(goods_level))->getCString()); la = static_cast<CCLabelAtlas*>(sprite->getChildByTag(2)); la->setString(CCString::createWithFormat("%d", getGoodsPrice(goods_level))->getCString()); } SceneMain* scene_main = static_cast<SceneMain*>(CCDirector::sharedDirector()->getRunningScene()->getChildByTag(0)); scene_main->updateMe(); }
bool RPGMapItemsMenuLayer::init(cocos2d::CCDictionary *stringList, CppSQLite3DB *db, float width, float height) { if(CCLayerColor::initWithColor(ccc4(0, 0, 0, 200), width, height)) { this->m_stringList = stringList; this->m_stringList->retain(); this->m_db = db; this->m_itemsList = new CCArray(); this->m_itemsList->init(); CCTMXTiledMap *mainBg = CCTMXTiledMap::create(CCString::createWithFormat("map_menu3_%s.tmx", CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE).c_str())->getCString()); mainBg->setPosition(CCPointZero); mainBg->setTag(kRPGMapItemsMenuLayerTagBg); this->addChild(mainBg); CCMenu *mainMenu = CCMenu::create(); mainMenu->setTag(kRPGMapItemsMenuLayerTagMainMenu); mainMenu->setAnchorPoint(CCPointZero); mainMenu->setPosition(CCPointZero); this->addChild(mainMenu); CCMenuItemSprite *menuBack = (CCMenuItemSprite*)mainMenu->getChildByTag(kRPGMapItemsMenuLayerTagMainMenuBack); if(!menuBack) { menuBack = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapItemsMenuLayer::onMenu)); menuBack->setPosition(ccp(40, 600)); menuBack->setTag(kRPGMapItemsMenuLayerTagMainMenuBack); menuBack->setScale(0.5); mainMenu->addChild(menuBack); } CCTableView *tableView = CCTableView::create(this, CCSizeMake(900, 570)); tableView->setDirection(kCCScrollViewDirectionVertical); tableView->setPosition(ccp(80, 30)); tableView->setDelegate(this); tableView->setVerticalFillOrder(kCCTableViewFillTopDown); tableView->setTag(kRPGMapItemsMenuLayerTagItemListTable); this->addChild(tableView); this->loadItemsData(); return true; } return false; }
void MarketScene::buyCard(CCNode * pNode) { int price = getPrice(selectedIndex); if (g_Control.m_nCoin >= price) { CCMenuItemImage *pItem = (CCMenuItemImage *)pNode; pItem->setEnabled(false); //¹´Ñ¡ÒÑÂòÏî CCMenu *pMenu = (CCMenu *)this->getChildByTag(TAG_MENU); CCMenuItemToggle *pToggle = (CCMenuItemToggle *)pMenu->getChildByTag(selectedIndex); CCSprite *sprite = CCSprite::create(s_pathCardbuy.m_strPath); sprite->setPosition(s_pathCardbuy.m_Position); pToggle->addChild(sprite, TAG_CARD_BUY, TAG_CARD_BUY); //¿ÛÇ® g_Control.m_nCoin -= price; updateLabelAtlas(g_Control.m_nCoin, LabelAtlas_COIN); g_Control.cards[selectedIndex - BTN_CARD] = 1; g_Control.save(); } }
void CNFRockerLayer::update( float delta ) { do { //得到主角 CNFProtagonist * pPro = dynamic_cast<CNFProtagonist *>(m_p3DLayer->getChildByTag(enTagProtagonist)); if (pPro!=NULL) { //得到摇杆 CCSprite * pRockerBg = dynamic_cast<CCSprite *>(getChildByTag(enTagRockerBg)); CC_BREAK_IF(pRockerBg==NULL); CCSprite * pRocker = dynamic_cast<CCSprite *>(getChildByTag(enTagRocker)); CC_BREAK_IF(pRocker==NULL); //若正在触摸 if (m_bIsTouching==true) { pRocker->setOpacity(255.f); pRockerBg->setOpacity(255.f); //触摸点与摇杆背景的距离 float fRockerDisX = m_ptTouching.x - pRockerBg->getPositionX(); float fRockerDisY = m_ptTouching.y - pRockerBg->getPositionY(); float fLen = sqrt(pow(fRockerDisX,2)+pow(fRockerDisY,2)); //触摸点与摇杆背景的角度 float fRate = (float)CC_RADIANS_TO_DEGREES( atanf(fRockerDisX/fRockerDisY) ); if(fRockerDisY<0) fRate += 180.f; else if(fRockerDisX<0) fRate += 360.f; //触摸点的实际位置 CCPoint ptRockerMoveTo; if (fLen >= m_fRockerMaxDis) fLen = m_fRockerMaxDis; ptRockerMoveTo.x = sin(fRate/180*3.1415)*fLen + pRockerBg->getPositionX(); ptRockerMoveTo.y = cos(fRate/180*3.1415)*fLen + pRockerBg->getPositionY(); //触摸点与摇杆的距离 float fDisX = ptRockerMoveTo.x - pRocker->getPositionX(); float fDisY = ptRockerMoveTo.y - pRocker->getPositionY(); float fLength = sqrt(pow(fDisX,2)+pow(fDisY,2)); //出发每次移动的条件:距离至少大于速度。 防止颤动 if (fLength > m_fRockerSpeed) { //触摸点与摇杆的角度 float fRateRocker = (float)CC_RADIANS_TO_DEGREES( atanf(fDisX/fDisY) ); if(fDisY<0) fRateRocker += 180.f; else if(fDisX<0) fRateRocker += 360.f; ptRockerMoveTo.x = sin(fRateRocker/180*3.1415)*m_fRockerSpeed + pRocker->getPositionX(); ptRockerMoveTo.y = cos(fRateRocker/180*3.1415)*m_fRockerSpeed + pRocker->getPositionY(); pRocker->setPosition(ptRockerMoveTo); } else //距离小于速度,则直接命中 { pRocker->setPosition(ptRockerMoveTo); } //主角移动 pPro->OnCtrlMoveByRotation(fRate); } //若触摸结束 else { pRocker->setOpacity(100.f); pRockerBg->setOpacity(100.f); pPro->OnCtrlStop(); //移动距离 float fDisX = pRockerBg->getPositionX() - pRocker->getPositionX(); float fDisY = pRockerBg->getPositionY() - pRocker->getPositionY(); float fLen = sqrt(pow(fDisX,2)+pow(fDisY,2)); //若距离大于速度,则移动 if (fLen > m_fRockerSpeed) { float at = (float)CC_RADIANS_TO_DEGREES( atanf(fDisX/fDisY) ); if(fDisY<0) at += 180.f; else if(fDisX<0) at += 360.f; CCPoint ptRockerMoveTo; ptRockerMoveTo.x = sin(at/180*3.1415)*m_fRockerSpeed + pRocker->getPositionX(); ptRockerMoveTo.y = cos(at/180*3.1415)*m_fRockerSpeed + pRocker->getPositionY(); pRocker->setPosition(ptRockerMoveTo); } else //若距离小雨速度,则直接命中 { pRocker->setPosition(pRockerBg->getPosition()); } } //若为副本,则执行按钮逻辑 if (m_nStageID >= _NF_TOWN_OR_BATTLE_ID_ && m_nStageID <_NF_TOWN_FB_ID_) { //得到菜单 CCMenu * pMenu = dynamic_cast<CCMenu *>(getChildByTag(enTagMenu)); CC_BREAK_IF(pMenu==NULL); //遍历按钮,同步CD for (int i=enTagBtnSkill1;i<=enTagBtnSkill5;i++) { //技能CD CCProgressTimer* pProgress = dynamic_cast<CCProgressTimer *>(getChildByTag(i+100)); CC_BREAK_IF(pProgress==NULL); //得到按钮 CCMenuItemSprite * pBtn = dynamic_cast<CCMenuItemSprite *>(pMenu->getChildByTag(i)); CC_BREAK_IF(pBtn==NULL); switch (i) { case enTagBtnSkill1: { //同步技能CD pProgress->setPercentage( 100*(float)pPro->GetSkillInfo_1().nSkill_CD_Time_Temp/(float)pPro->GetSkillInfo_1().nSkill_CD_Time ); //判断按钮是否可按 if (pPro->GetSkillInfo_1().nSkill_CD_Time_Temp == 0 && m_bIsPublicCD==false) pBtn->setEnabled(true); else pBtn->setEnabled(false); }break; case enTagBtnSkill2: { pProgress->setPercentage( 100*(float)pPro->GetSkillInfo_2().nSkill_CD_Time_Temp/(float)pPro->GetSkillInfo_2().nSkill_CD_Time ); if (pPro->GetSkillInfo_2().nSkill_CD_Time_Temp == 0 && m_bIsPublicCD==false) pBtn->setEnabled(true); else pBtn->setEnabled(false); }break; case enTagBtnSkill3: { pProgress->setPercentage( 100*(float)pPro->GetSkillInfo_3().nSkill_CD_Time_Temp/(float)pPro->GetSkillInfo_3().nSkill_CD_Time ); if (pPro->GetSkillInfo_3().nSkill_CD_Time_Temp == 0 && m_bIsPublicCD==false) pBtn->setEnabled(true); else pBtn->setEnabled(false); }break; case enTagBtnSkill4: { pProgress->setPercentage( 100*(float)pPro->GetSkillInfo_4().nSkill_CD_Time_Temp/(float)pPro->GetSkillInfo_4().nSkill_CD_Time ); if (pPro->GetSkillInfo_4().nSkill_CD_Time_Temp == 0 && m_bIsPublicCD==false) pBtn->setEnabled(true); else pBtn->setEnabled(false); }break; case enTagBtnSkill5: { pProgress->setPercentage( 100*(float)pPro->GetSkillInfo_5().nSkill_CD_Time_Temp/(float)pPro->GetSkillInfo_5().nSkill_CD_Time ); if (pPro->GetSkillInfo_5().nSkill_CD_Time_Temp == 0 && m_bIsPublicCD==false) pBtn->setEnabled(true); else pBtn->setEnabled(false); }break; } } CCProgressTimer* pProgressCom = dynamic_cast<CCProgressTimer *>(getChildByTag(enTagCommonAttackCD)); if(pProgressCom!=NULL){ pProgressCom->setPercentage( 100*pPro->GetCommonAttackCDBFB()); } CCLabelBMFont* pComonFont = dynamic_cast<CCLabelBMFont *>(getChildByTag(enTagCommonAttackFont)); if(pComonFont!=NULL){ if(pPro->GetCommonAttackStatus()!=0){ pComonFont->setString(CCString::createWithFormat("%d",pPro->GetCommonAttackStatus())->m_sString.c_str()); } } //判断是否有技能刚释放 bool bIsSkillStart = false; if (pPro->GetSkillInfo_1().nSkill_CD_Time_Temp==pPro->GetSkillInfo_1().nSkill_CD_Time-1) bIsSkillStart = true; if (pPro->GetSkillInfo_2().nSkill_CD_Time_Temp==pPro->GetSkillInfo_2().nSkill_CD_Time-1) bIsSkillStart = true; if (pPro->GetSkillInfo_3().nSkill_CD_Time_Temp==pPro->GetSkillInfo_3().nSkill_CD_Time-1) bIsSkillStart = true; if (pPro->GetSkillInfo_4().nSkill_CD_Time_Temp==pPro->GetSkillInfo_4().nSkill_CD_Time-1) bIsSkillStart = true; if (pPro->GetSkillInfo_5().nSkill_CD_Time_Temp==pPro->GetSkillInfo_5().nSkill_CD_Time-1) bIsSkillStart = true; //若有技能刚释放 if (bIsSkillStart==true) { m_bIsPublicCD = true; this->runAction(CCSequence::create(CCDelayTime::create(1.f),CCCallFunc::create(this,callfunc_selector(CNFRockerLayer::OnSkillPublicCallBack)),NULL)); for (int i=enTagBtnSkill1;i<=enTagBtnSkill5;i++) { //判断是否显示公共CD bool bIsSkillPublicCD = false; if (i==enTagBtnSkill1 && pPro->GetSkillInfo_1().nSkill_CD_Time_Temp==0) bIsSkillPublicCD = true; else if (i==enTagBtnSkill2 && pPro->GetSkillInfo_2().nSkill_CD_Time_Temp==0) bIsSkillPublicCD = true; else if (i==enTagBtnSkill3 && pPro->GetSkillInfo_3().nSkill_CD_Time_Temp==0) bIsSkillPublicCD = true; else if (i==enTagBtnSkill4 && pPro->GetSkillInfo_4().nSkill_CD_Time_Temp==0) bIsSkillPublicCD = true; else if (i==enTagBtnSkill5 && pPro->GetSkillInfo_5().nSkill_CD_Time_Temp==0) bIsSkillPublicCD = true; //若显示公共CD if (bIsSkillPublicCD==true) { //显示公共CD CCProgressTimer* pProgress = dynamic_cast<CCProgressTimer *>(getChildByTag(i+200)); CC_BREAK_IF(pProgress==NULL); pProgress->setVisible(true); pProgress->setPercentage(99.f); pProgress->runAction(CCSequence::create(CCProgressTo::create(_NF_PUBLIC_SKILL_CD_,0),NULL)); } } } } } return ; } while (false); CCLog("Fun CNFRockerLayer::update Error!"); }
CCTableViewCell* MailListScene::tableCellAtIndex(CCTableView *table, unsigned int idx) { CCString *string = (CCString *)mArrayList->objectAtIndex(idx); CCSize size = this->tableCellSizeForIndex(table, idx); CCTableViewCell *cell = table->dequeueCell(); if (!cell) { cell = new CCTableViewCell(); cell->autorelease(); CCSprite *sState = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("mail_state_read.png")); sState->setAnchorPoint(CCPointMake(0, 0.5)); sState->setPosition(ccp(10,size.height * 0.5)); sState->setTag(120); cell->addChild(sState); CCLabelTTF *lblName = CCLabelTTF::create(string->getCString(), "Arial", 14.0); lblName->setPosition(ccp(65,size.height * 0.5)); lblName->setColor(ccc3(255, 255, 204)); //lblName->enableStroke(ccc3(51, 0, 0), 0.6); lblName->setTag(121); lblName->setHorizontalAlignment(kCCTextAlignmentLeft); lblName->setString(string->getCString()); cell->addChild(lblName); CCLabelTTF *lblSubject = CCLabelTTF::create("100", "Arial", 14.0); lblSubject->setPosition(ccp(130,size.height * 0.5)); lblSubject->setColor(ccc3(255, 255, 204)); //lblSubject->enableStroke(ccc3(51, 0, 0), 0.6); lblSubject->setTag(122); lblSubject->setString(string->getCString()); cell->addChild(lblSubject); CCScale9Sprite *sline = CCScale9Sprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("mail_line.png")); sline->setPreferredSize(CCSizeMake(310, 1)); sline->setPosition(ccp(0,size.height-2)); sline->setAnchorPoint(CCPointZero); cell->addChild(sline); CCMenu *menuCheck = this->generateCheckBox(); cell->addChild(menuCheck); CCMenuItemToggle *toggle= (CCMenuItemToggle *)menuCheck->getChildByTag(1); toggle->setUserData(&vUserData[idx]); if (vUserData[idx] == 1) { toggle->setSelectedIndex(1); } else { toggle->setSelectedIndex(0); } menuCheck->setTag(123); menuCheck->setAnchorPoint(CCPointMake(0, 0.5)); menuCheck->setPosition(CCPointMake(280, size.height * 0.5)); } else { CCLabelTTF *lblName = (CCLabelTTF*)cell->getChildByTag(121); lblName->setString(string->getCString()); CCLabelTTF *lblSubject = (CCLabelTTF*)cell->getChildByTag(122); lblSubject->setString(string->getCString()); CCMenu *menuCheck = (CCMenu *)cell->getChildByTag(123); CCMenuItemToggle *toggle= (CCMenuItemToggle *)menuCheck->getChildByTag(1); toggle->setUserData(&vUserData[idx]); if (vUserData[idx] == 1) { toggle->setSelectedIndex(1); } else { toggle->setSelectedIndex(0); } } return cell; }