bool SkillTableView::init() { if (!Node::init()) return false; LayerColor* bg = LayerColor::create(Color4B(255, 255, 255, 127), 450, 500); bg->setPosition(bg->getContentSize()/-2); this->addChild(bg, -1); CCLabelTTF* title = CCLabelTTF::create("技能列表", "fonts/Marker Felt.ttf", 40); title->setPosition(Point(bg->getContentSize().width/2, bg->getContentSize().height-30)); bg->addChild(title); ControlButton* button = ControlButton::create(Scale9Sprite::create("ui/closed_normal.png")); button->setBackgroundSpriteForState(Scale9Sprite::create("ui/closed_selected.png"), Control::State::HIGH_LIGHTED); button->setPreferredSize(Size(57, 58)); button->setPosition(ccpSub(ccpAdd(bg->getPosition(), bg->getContentSize()), button->getContentSize()/2)); this->addChild(button); button->addTargetWithActionForControlEvents(GAME_UILAYER, cccontrol_selector(GameInfoUIController::removeSmallMenuAndButton), Control::EventType::TOUCH_UP_INSIDE); // button->setTouchPriority(0); m_skillTableView = TableView::create(this, Size(420, 420)); m_skillTableView->setPosition(Point(15, 15)); // m_skillTableView->setDirection(kCCScrollViewDirectionVertical); m_skillTableView->setDelegate(this); // m_skillTableView->setVerticalFillOrder(kCCTableViewFillTopDown); bg->addChild(m_skillTableView); m_skillTableView->reloadData(); return true; }
//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 LoadingScene::init() { if (Layer::init()) { // add background to current scene LayerColor *bkGround = LayerColor::create(Color4B(0, 255, 255, 255)); this->addChild(bkGround); LabelTTF *logo = LabelTTF::create("tashaxing's 2048", "Arial", 30); logo->setColor(Color3B(255, 255, 0)); bkGround->addChild(logo); logo->setPosition(bkGround->getContentSize().width / 2, bkGround->getContentSize().height / 2); //添加音频预加载回调,注意,只有layer才能用schedule,scene不行 this->scheduleOnce(schedule_selector(LoadingScene::loadingCallBack), 0); return true; } else { return false; } }
bool WaitingNode::init() { if (!CustomNode::init()) { return false; } LayerColor* pBackground = LayerColor::create(ccc4(7, 25, 44, 150)); pBackground->setContentSize(CCSizeMake(640.0f, 960.0f)); this->addChild(pBackground); this->setContentSize(pBackground->getContentSize()); Sprite* pBackgroundBoard = Sprite::create("popup/panel_popup_waiting.png"); pBackgroundBoard->setPosition(Point(320.0f, 480.0f)); pBackgroundBoard->setScaleY(0.7f); this->addChild(pBackgroundBoard); m_pLabelTitle = LabelBMFont::create(m_sTitle, "fonts/font_title-popup.fnt", 410.0f, TextHAlignment::CENTER); m_pLabelTitle->setAnchorPoint(Point(0.5f, 0.5f)); m_pLabelTitle->setPosition(Point(320.0f, 485.0f)); this->addChild(m_pLabelTitle); return true; }
bool EndGameNode::initWin() { if (!Node::init()) { return false; } LevelConfig* pLevelConfig = &GameConfigManager::getInstance()->GetLevelConfig(m_sChapterId, m_iCurrentLevel); m_iTotalBonusQuest = pLevelConfig->m_BonusQuestConfig.m_iBonusQuestCount; LayerColor* pBackground = LayerColor::create(ccc4(7, 25, 44, 150)); pBackground->setContentSize(CCSizeMake(640.0f, 960.0f)); auto listener = EventListenerTouch::create(Touch::DispatchMode::ONE_BY_ONE); listener->setSwallowTouches(true); listener->onTouchBegan = [](Touch* touch, Event* event) { return true; }; EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, pBackground); this->addChild(pBackground); this->setContentSize(pBackground->getContentSize()); //m_pSpriteBatchNode = SpriteBatchNode::create("Target-End-Game/TargetEndgame.pvr.ccz"); //SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Target-End-Game/TargetEndgame.plist"); //this->addChild(m_pSpriteBatchNode); Sprite* pBackgroundBoard = Sprite::create("Target-End-Game/panel-level_popup.png"); pBackgroundBoard->setPosition(Point(320.0f, 610.0f)); this->addChild(pBackgroundBoard); m_pStarAndBonusQuestNode = Node::create(); this->addChild(m_pStarAndBonusQuestNode); this->generateLayoutStartAndBonusQuest(); Sprite* pCompletedImage = Sprite::create("Target-End-Game/text_level_completed.png"); pCompletedImage->setPosition(Point(320.0f, 654.0f)); this->addChild(pCompletedImage); FlashCardNode* pFlashCard = FlashCardNode::createLayout(m_mainWord); pFlashCard->setPosition(70.0f, 200.0f); pFlashCard->setScale(0.52f); this->addChild(pFlashCard); char sLevel[20]; int iCalLevel = GameConfigManager::getInstance()->CountLevelOfPreviousChapters(m_sChapterId); sprintf(sLevel, "Level %d", m_iCurrentLevel + iCalLevel); LabelBMFont *pLabelLevel = LabelBMFont::create(sLevel, "fonts/font-bechic.fnt"); pLabelLevel->setAnchorPoint(Point(0.5f, 0.5f)); pLabelLevel->setPosition(Point(320.0f, 870.0f)); this->addChild(pLabelLevel); LabelBMFont *pLabelScore = LabelBMFont::create("SCORE:", "fonts/font_score.fnt"); pLabelScore->setAnchorPoint(Point(0.5f, 0.5f)); pLabelScore->setPosition(Point(474.0f, 525.0f)); this->addChild(pLabelScore); LabelBMFont *pLabelNumScore = LabelBMFont::create(formatNumber(m_iScore).getCString(), "fonts/font_score.fnt"); pLabelNumScore->setAnchorPoint(Point(0.5f, 0.5f)); pLabelNumScore->setPosition(Point(474.0f, 480.0f)); pLabelNumScore->setScale(1.4f); this->addChild(pLabelNumScore); Sprite* pButtonNextGameSprite = Sprite::create("Target-End-Game/btn_next.png"); ButtonNode* buttonNextNode = ButtonNode::createButtonSprite(pButtonNextGameSprite, CC_CALLBACK_1(EndGameNode::menuNextLevelCallBack, this)); buttonNextNode->setPosition(Point(425.0f, 279.0f)); Sprite* pButtonReplayGameSprite = Sprite::create("Target-End-Game/btn_replay.png"); ButtonNode* buttonReplayNode = ButtonNode::createButtonSprite(pButtonReplayGameSprite, CC_CALLBACK_1(EndGameNode::menuRetryLevelWinCallBack, this)); buttonReplayNode->setPosition(Point(225.0f, 279.0f)); Sprite* pButtonCloseSprite = Sprite::create("Target-End-Game/btn_close.png"); ButtonNode* buttonCloseNode = ButtonNode::createButtonSprite(pButtonCloseSprite, CC_CALLBACK_1(EndGameNode::menuCloseWinCallBack, this)); buttonCloseNode->setPosition(Point(572.0f, 894.0f)); ButtonManagerNode* pButtonManagerNode = ButtonManagerNode::create(); pButtonManagerNode->addButtonNode(buttonNextNode); pButtonManagerNode->addButtonNode(buttonCloseNode); pButtonManagerNode->addButtonNode(buttonReplayNode); this->addChild(pButtonManagerNode); m_levelInfo = LevelTable::getInstance()->getLevel(m_sChapterId, m_iCurrentLevel); m_chapterInfo = ChapterTable::getInstance()->getChapterInfo(m_sChapterId); if (m_levelInfo.bIsUnlock == false) { m_chapterInfo.iTotalLevelUnlock++; UserInfo userInfo = UserTable::getInstance()->getUserInfo(); userInfo.sCurrentChapterId = m_levelInfo.sChapterId; userInfo.iCurrentLevel = m_levelInfo.iLevel + 1; // Unlock chapter WordlMapConfig worldMapConfig = GameConfigManager::getInstance()->GetWordlMapConfig(); int iIndexCurrentChapter = worldMapConfig.m_WorlMapChapterConfigMap[m_levelInfo.sChapterId]; WordlMapConfig::WordMapChapterConfig worldMapChapterConfig = worldMapConfig.m_WorlMapChapterConfigs[iIndexCurrentChapter]; if (m_iCurrentLevel >= worldMapChapterConfig.m_iTotalevel) { //userInfo.iCurrentLevel = worldMapChapterConfig.m_iTotalevel; // Create data for new chapter std::string sNextChapterID; if ( GameConfigManager::getInstance()->GetNextChapterID(worldMapChapterConfig.m_sChapterId, sNextChapterID)) { InitDatabase::getInstance()->createDataChapterAndLevel(sNextChapterID); userInfo.sCurrentChapterId = sNextChapterID; userInfo.iCurrentLevel = 1; UserDefault::getInstance()->setStringForKey("ChapterPlayGame", userInfo.sCurrentChapterId); } else // the last chapter is finished so game is end now!!!! { } } UserTable::getInstance()->updateUser(userInfo); } m_levelInfo.bIsUnlock = true; m_levelInfo.iTotalBonusQuest = m_iTotalBonusQuest; if (m_levelInfo.iScore < m_iScore) { m_levelInfo.iScore = m_iScore; } if(m_levelInfo.iBonusQuest < m_iBonusQuestCompleted) { m_levelInfo.iBonusQuest = m_iBonusQuestCompleted; } if(m_levelInfo.iStar < m_iYellowStar) { m_chapterInfo.iTotalStar += m_iYellowStar - m_levelInfo.iStar; m_levelInfo.iStar = m_iYellowStar; } // Update Word for chapter const std::string sWordId = GameWordManager::getInstance()->GetWordIdFromWord(m_mainWord); WordInfo wordInfo = WordTable::getInstance()->getWordInfoOnChapter(m_levelInfo.sChapterId, sWordId); wordInfo.iCountCollected++; LevelTable::getInstance()->updateLevel(m_levelInfo); WordTable::getInstance()->updateWord(wordInfo); ChapterTable::getInstance()->updateChapter(m_chapterInfo); m_iCountYellowStar = 0; m_iCountBonusQuest = 0; this->sequenceUpdateStar(); LeaderBoardtNode* pLeaderBoard = LeaderBoardtNode::createLayout(m_iCurrentLevel, m_sChapterId); pLeaderBoard->setPosition(Point(320.0f, 114.0f)); this->addChild(pLeaderBoard); auto actionupdateDatabaseAndSync = CallFunc::create(this, callfunc_selector(EndGameNode::updateDatabaseAndSync)); this->runAction(Sequence::create(DelayTime::create(0.01f), actionupdateDatabaseAndSync, NULL)); return true; }
bool EndGameNode::initLose() { if (!Node::init()) { return false; } LayerColor* pBackground = LayerColor::create(ccc4(7, 25, 44, 150)); pBackground->setContentSize(CCSizeMake(640.0f, 960.0f)); auto listener = EventListenerTouch::create(Touch::DispatchMode::ONE_BY_ONE); listener->setSwallowTouches(true); listener->onTouchBegan = [](Touch* touch, Event* event) { return true; }; EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, pBackground); this->addChild(pBackground); this->setContentSize(pBackground->getContentSize()); //m_pSpriteBatchNode = SpriteBatchNode::create("Target-End-Game/TargetEndgame.pvr.ccz"); //SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Target-End-Game/TargetEndgame.plist"); //this->addChild(m_pSpriteBatchNode); Sprite* pBackgroundBoard = Sprite::create("Target-End-Game/panel-level_popup.png"); pBackgroundBoard->setPosition(Point(320.0f, 610.0f)); this->addChild(pBackgroundBoard); Sprite* pLevelFailImage3 = Sprite::create("Target-End-Game/text_level_fail.png"); pLevelFailImage3->setPosition(Point(320.0f, 750.0f)); this->addChild(pLevelFailImage3); Sprite* pIconBoosterLock1 = Sprite::create("Target-End-Game/lock-icon-powerup.png"); pIconBoosterLock1->setPosition(Point(220.0f, 415.0f)); this->addChild(pIconBoosterLock1); Sprite* pIconBoosterLock2 = Sprite::create("Target-End-Game/lock-icon-powerup.png"); pIconBoosterLock2->setPosition(Point(320.0f, 415.0f)); this->addChild(pIconBoosterLock2); Sprite* pIconBoosterLock3 = Sprite::create("Target-End-Game/lock-icon-powerup.png"); pIconBoosterLock3->setPosition(Point(420.0f, 415.0f)); this->addChild(pIconBoosterLock3); FlashCardNode* pFlashCard = FlashCardNode::createLayout(m_mainWord); pFlashCard->setPosition(70.0f, 285.0f); pFlashCard->setScale(0.52f); this->addChild(pFlashCard); char sLevel[20]; int iCalLevel = GameConfigManager::getInstance()->CountLevelOfPreviousChapters(m_sChapterId); sprintf(sLevel, "Level %d", m_iCurrentLevel + iCalLevel); LabelBMFont *pLabelLevel = LabelBMFont::create(sLevel, "fonts/font-bechic.fnt"); pLabelLevel->setAnchorPoint(Point(0.5f, 0.5f)); pLabelLevel->setPosition(Point(320.0f, 870.0f)); this->addChild(pLabelLevel); LabelBMFont *pLabelScore = LabelBMFont::create("SCORE:", "fonts/font_score.fnt"); pLabelScore->setAnchorPoint(Point(0.5f, 0.5f)); pLabelScore->setPosition(Point(474.0f, 630.0f)); this->addChild(pLabelScore); LabelBMFont *pLabelNumScore = LabelBMFont::create(formatNumber(m_iScore).getCString(), "fonts/font_score.fnt"); pLabelNumScore->setAnchorPoint(Point(0.5f, 0.5f)); pLabelNumScore->setPosition(Point(474.0f, 585.0f)); pLabelNumScore->setScale(1.4f); this->addChild(pLabelNumScore); LeaderBoardtNode* pLeaderBoard = LeaderBoardtNode::createLayout(m_iCurrentLevel, m_sChapterId); pLeaderBoard->setPosition(Point(320.0f, 114.0f)); this->addChild(pLeaderBoard); Sprite* pButtonPlayGameSprite = Sprite::create("Target-End-Game/btn_replay.png"); ButtonNode* buttonPlayNode = ButtonNode::createButtonSprite(pButtonPlayGameSprite, CC_CALLBACK_1(EndGameNode::menuRetryLevelLoseCallBack, this)); buttonPlayNode->setPosition(Point(320.0f, 279.0f)); Sprite* pButtonCloseSprite = Sprite::create("Target-End-Game/btn_close.png"); ButtonNode* buttonCloseNode = ButtonNode::createButtonSprite(pButtonCloseSprite, CC_CALLBACK_1(EndGameNode::menuCloseLoseCallBack, this)); buttonCloseNode->setPosition(Point(572.0f, 894.0f)); ButtonManagerNode* pButtonManagerNode = ButtonManagerNode::create(); pButtonManagerNode->addButtonNode(buttonPlayNode); pButtonManagerNode->addButtonNode(buttonCloseNode); this->addChild(pButtonManagerNode); return true; }
void Akuerdate::JuegoTerminado(){ CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("ganar.mp3"); escuchadores = false; juegoTerminado = true; LayerColor *lyConseguido = LayerColor::create(Color4B(124,180,224,200)); lyConseguido->setPosition(cuadroJuego->getPosition()); lyConseguido->setContentSize(cuadroJuego->getContentSize()); lyConseguido->setLocalZOrder(20); addChild(lyConseguido); Sprite *foco = Sprite::create("preguntator_focoLuz.png"); foco->setScaleX(escalaAlta); foco->setScaleY(0); foco->setScaleZ(escalaAlta); foco->setAnchorPoint(Vec2(0.5,1)); foco->setPosition(lyConseguido->getContentSize().width/2,lyConseguido->getContentSize().height); lyConseguido->addChild(foco); //animacion foco ScaleTo *aniFoco = ScaleTo::create(0.7, escalaAlta); foco->runAction(aniFoco); __String *txtConsegido = __String::createWithFormat("%s %s",LanguageManager::getInstance()->getString("JUEGO_TX_FINAL_EXITO_2").c_str(),sNombreProfesion->getCString()); CCLabelTTF *txConseguido = CCLabelTTF::create(txtConsegido->getCString(), "HVD_Comic_Serif_Pro.ttf",120*escala,Size((visibleSize.width),(220*escala)*2), TextHAlignment::CENTER); txConseguido->setColor(Color3B(25,78,121)); txConseguido->setVerticalAlignment(TextVAlignment::CENTER); txConseguido->setAnchorPoint(Vec2(0.5,1)); txConseguido->setPosition(lyConseguido->getContentSize().width/2,visibleSize.height+(280*escala)); lyConseguido->addChild(txConseguido); //animacion textoConsegido MoveTo *aniTxConseguido = MoveTo::create(0.3, Vec2(lyConseguido->getContentSize().width/2,(lyConseguido->getContentSize().height))); txConseguido->runAction(aniTxConseguido); Sprite *pizzarra = Sprite::create("pizzarra_final_tiempo.png"); pizzarra->setScale(escalaAlta); pizzarra->setAnchorPoint(Vec2(0.5,1)); pizzarra->setPosition(visibleSize.width,(lyConseguido->getContentSize().height)-(txConseguido->getContentSize().height)); lyConseguido->addChild(pizzarra); CCLabelTTF *nAciertosPizarra = CCLabelTTF::create(reloj->getString(), "HVD_Comic_Serif_Pro.ttf",200,pizzarra->getContentSize(), TextHAlignment::CENTER); nAciertosPizarra->setColor(Color3B(255,255,255)); nAciertosPizarra->setVerticalAlignment(TextVAlignment::CENTER); nAciertosPizarra->setAnchorPoint(Vec2(0,0)); nAciertosPizarra->setPosition(0,0); pizzarra->addChild(nAciertosPizarra); //animacion pizzara MoveTo *aniPizzarra = MoveTo::create(0.3, Vec2(lyConseguido->getContentSize().width/2,pizzarra->getPositionY())); pizzarra->runAction(aniPizzarra); CGestorRecursos *gRecursos = new CGestorRecursos(); CRecurso *recursoAleatorio = gRecursos->obtenerRecursoBloqueadoAleatorio(); if(recursoAleatorio!=NULL){ gRecursos->quitarRecursoBloqueado(recursoAleatorio); Sprite *txPremio = Sprite::create("preguntator_finjuego_texto_inferior.png"); txPremio->setScale(escalaAlta); txPremio->setAnchorPoint(Vec2(0.5,0)); txPremio->setPosition(foco->getPositionX(),foco->getPositionY()-(foco->getContentSize().height*escalaAlta)); txPremio->setOpacity(0); lyConseguido->addChild(txPremio); //animacion txPremio Sequence *aniPremio1 = Sequence::create(DelayTime::create(0.7),FadeIn::create(1),NULL); txPremio->runAction(aniPremio1); Sprite *premio = Sprite::create(recursoAleatorio->uri->getCString()); float escalaPremio = ((pizzarra->getContentSize().height*pizzarra->getScale())/2)/premio->getContentSize().height; float escalaPremioAncha = ((pizzarra->getContentSize().width*pizzarra->getScale()))/premio->getContentSize().width; if(escalaPremioAncha<escalaPremio) escalaPremio = escalaPremioAncha; premio->setScale(escalaPremio); premio->setAnchorPoint(Vec2(0.5,0)); premio->setPosition(txPremio->getPositionX(),txPremio->getPositionY()+(20*escalaPremio)+(txPremio->getContentSize().height*txPremio->getScaleY())); premio->setOpacity(0); //nuevo if(recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoOjos&&recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoAccesorio&&recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoDientes&&recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoColor) premio->runAction(TintTo::create(0,0,0,0)); lyConseguido->addChild(premio); string textoTraducido1 = LanguageManager::getInstance()->getString("kitDe"); string keyTexto2 = __String::createWithFormat("tipoRecurso%i",recursoAleatorio->tipoRecurso->getValue())->getCString(); string textoTraducido2 = LanguageManager::getInstance()->getString(keyTexto2); string textoFinal = __String::createWithFormat("%s %s",textoTraducido1.c_str(),textoTraducido2.c_str())->getCString(); CCLabelTTF *nAciertosPizarra = CCLabelTTF::create(textoFinal, "HVD_Comic_Serif_Pro.ttf",60,Size(lyConseguido->getContentSize().width,txPremio->getContentSize().height), TextHAlignment::CENTER); nAciertosPizarra->setColor(Color3B(229,57,57)); nAciertosPizarra->setVerticalAlignment(TextVAlignment::BOTTOM); nAciertosPizarra->setAnchorPoint(Vec2(0.5,0)); nAciertosPizarra->setPosition(txPremio->getContentSize().width/2,80); nAciertosPizarra->setOpacity(0); txPremio->addChild(nAciertosPizarra); Sequence *aniNAciertosPizarra = Sequence::create(DelayTime::create(0.7),FadeIn::create(1),NULL); nAciertosPizarra->runAction(aniNAciertosPizarra); //nuevo Sequence *aniPremio = Sequence::create(DelayTime::create(0.7),FadeIn::create(1),NULL); premio->runAction(aniPremio); //efecto flotando RotateTo *rotarIzq = RotateTo::create(1, 10); RotateTo *rotarDer = RotateTo::create(1, -10); Sequence *total1 = Sequence::create(rotarIzq,rotarDer, NULL); Sequence *total2 = Sequence::create(rotarDer->clone(),rotarIzq->clone(), NULL); RepeatForever *repeticion1 = RepeatForever::create(total1); RepeatForever *repeticion2 = RepeatForever::create(total2); premio->runAction(repeticion1); } }
void Ajustes::initTitulo(){ LayerColor *capaPosTitulo = LayerColor::create(Color4B(23, 70, 108, 210), cuadroJuego->getContentSize().width-(espacioBordesCuadro*escala*2), 200*escala); capaPosTitulo->setAnchorPoint(Vec2(0,1)); capaPosTitulo->setPosition(anchoLateralCE+(espacioSuperiorBtAtras*escala),visibleSize.height-(200*escala)-(espacioSuperiorBtAtras*escala)); capaPosTitulo->setZOrder(1); this->addChild(capaPosTitulo); tituloEscena = CCLabelTTF::create(LanguageManager::getInstance()->getString("AjustesLbTitulo"), "HVD_Comic_Serif_Pro.ttf", 130*escala,CCSizeMake(anchoNoLateralCE, capaPosTitulo->getContentSize().height), TextHAlignment::CENTER); tituloEscena->setColor(Color3B(216,254,51)); tituloEscena->setVerticalAlignment(TextVAlignment::CENTER); tituloEscena->setAnchorPoint(Vec2(0, 0)); tituloEscena->setPosition(anchoLateralCE,capaPosTitulo->getPositionY()); tituloEscena->setZOrder(10); this->addChild(tituloEscena, 1); tituloEscena->retain(); }
void FriendListScene::buildScene() { _friendDictionary.clear(); _friendList.clear(); _tableView = NULL; _downloadCount = 0; const char* headerString = ""; switch (_selectedFriendCircle) { case ALL_FRIENDS: headerString = "All Friends"; break; case INSTALLED_ONLY: headerString = "Friends Playing Game"; break; case NON_PLAYING_ONLY: headerString = "Friends not Playing Game"; break; case MY_DEVICE_ONLY: #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) headerString = "Friends playing on iOS Device"; #else headerString = "Friends playing on Android Device"; #endif default: break; } //_friendList = CCArray::createWithCapacity(5); //_friendList->retain(); CCLOG("ALL Request count = %lu", _friendList.size()); // Add background layers to the scene. LayerColor *bg = LayerColor::create(Color4B(255, 255, 255, 255), AppDelegate::SCREEN_WIDTH, AppDelegate::SCREEN_HEIGHT); this->addChild(bg); LayerColor *secondBG = LayerColor::create(Color4B(95, 95, 95, 255), AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f), AppDelegate::SCREEN_HEIGHT - SCALED_VALUE(20.0f)); secondBG->setPosition(Point(SCALED_VALUE(10.0f), SCALED_VALUE(10.0f))); this->addChild(secondBG); // Set the table header. LayerColor *header = LayerColor::create(Color4B(66, 66, 66, 255), AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f), SCALED_VALUE(100.0f)); header->setAnchorPoint(Point(0, 0)); header->setPosition(Point(SCALED_VALUE(10.0f), AppDelegate::SCREEN_HEIGHT - SCALED_VALUE(110.0f))); this->addChild(header); // Set the header text. auto headerText = LabelTTF::create(headerString, "Arial", SCALED_VALUE(40.0f)); headerText->setAnchorPoint(Point(0.0f, 0.5f)); header->addChild(headerText); headerText->setPositionX(SCALED_VALUE(28.0f)); headerText->setPositionY(header->getContentSize().height/2); // Add back button go back to previous scene MenuItemImage *backButton = MenuItemImage::create(); backButton->setNormalSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_table_back_nrl")); backButton->setSelectedSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_table_back_prd")); backButton->setCallback(CC_CALLBACK_1(FriendListScene::backButtonPressed, this)); backButton->setAnchorPoint(Point(1.0f, 0.5)); Menu* backMenu = Menu::create(backButton, NULL); header->addChild(backMenu); backMenu->setPositionX(header->getContentSize().width - SCALED_VALUE(20.0f)); backMenu->setPositionY(header->getContentSize().height/2); // Create the table view. float tableHeight = bg->getContentSize().height - secondBG->getPositionY() - (header->getContentSize().height) - SCALED_VALUE(10); _tableView = TableView::create(this, Size(secondBG->getContentSize().width, tableHeight)); _tableView->setAnchorPoint(Point(0, 0.0)); _tableView->setDirection(ScrollView::Direction::VERTICAL); _tableView->setPosition(Point(SCALED_VALUE(10.0f), SCALED_VALUE(10))); _tableView->setDelegate(this); this->addChild(_tableView); }
TableViewCell* FriendListScene::tableCellAtIndex(TableView *table, ssize_t idx) { int index = idx; EziFacebookFriend* myFriend = (EziFacebookFriend*)_friendList.at(index); std::string friendName = myFriend->getName(); //const char* photoPath = myFriend->getPhotoPath().c_str(); bool toRequestForPhoto = false; if (myFriend->getPhoto() == nullptr) { toRequestForPhoto = true; //EziSocialObject::sharedObject()->getProfilePicForID(this, myFriend->getFBID(), SCALED_VALUE(85.0f), SCALED_VALUE(85.0f), false); } // Build the table cell. TableViewCell *cell = table->cellAtIndex(idx); if (cell == NULL) { cell = new TableViewCell(); cell->autorelease(); LayerColor* colorLayer = LayerColor::create(Color4B(100, 100, 100, 200), AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f), SCALED_VALUE(124.0f)); //cell->addChild(colorLayer); LayerColor* photoLayer = LayerColor::create(Color4B(255, 255, 255, 255), SCALED_VALUE(100.0f), SCALED_VALUE(100.0f)); photoLayer->setPosition(SCALED_VALUE(40.0f), SCALED_VALUE(12.0f)); cell->addChild(photoLayer); Sprite* userPhotoSprite = NULL; if (toRequestForPhoto) { userPhotoSprite = Sprite::create(); userPhotoSprite->setContentSize(Size(SCALED_VALUE(85.0f), SCALED_VALUE(85.0f))); } else { userPhotoSprite = myFriend->getPhoto(CC_CALLBACK_2(FriendListScene::applyPhoto, this), false, SCALED_VALUE(85.0f), SCALED_VALUE(85.0f)); if (userPhotoSprite == nullptr) { userPhotoSprite = Sprite::create(); } } cell->addChild(userPhotoSprite); userPhotoSprite->setAnchorPoint(Point(0.0f, 0.0)); userPhotoSprite->cocos2d::CCNode::setPosition(SCALED_VALUE(47.0f), SCALED_VALUE(18.0f)); userPhotoSprite->setTag(TAG_PHOTO); auto message = LabelTTF::create(friendName.c_str(), "Arial", SCALED_VALUE(30.0f)); message->setAnchorPoint(Point(0, 0.5)); message->setPosition(Point(photoLayer->getContentSize().width + photoLayer->getPositionX() + SCALED_VALUE(20.0f), colorLayer->getContentSize().height/2)); cell->addChild(message); message->setTag(TAG_MESSAGE); /* Sprite* consumedIcon = Sprite::createWithSpriteFrameName("green_tick"); consumedIcon->setAnchorPoint(Point(1.0, 0.5)); cell->addChild(consumedIcon); consumedIcon->setPosition(Point(colorLayer->getContentSize().width - SCALED_VALUE(20.0f), colorLayer->getContentSize().height/2)); message->setTag(TAG_CONSUMED_ICON); MenuItemImage* useButton = MenuItemImage::create(); useButton->setSelectedSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_use_prd")); useButton->setNormalSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_use_nrl")); useButton->setAnchorPoint(Point(1.0, 0.5)); useButton->setTarget(this, menu_selector(FriendListScene::useRequest)); Menu* useMenu = Menu::create(useButton, NULL); cell->addChild(useMenu); useMenu->setPosition(Point(colorLayer->getContentSize().width - SCALED_VALUE(20.0f), colorLayer->getContentSize().height/2)); useButton->setTag(index); useMenu->setTag(TAG_USE_MENU); */ } else { Sprite* cellProfilePic = (Sprite*)cell->getChildByTag(TAG_PHOTO); if (toRequestForPhoto == false) { //cellProfilePic->setTexture(Sprite::create(myFriend->getPhotoPath())->getTexture()); Sprite* tempSprite = myFriend->getPhoto(); if (myFriend->getPhoto() != nullptr) { cellProfilePic->setTexture(tempSprite->getTexture()); } else { myFriend->getPhoto(CC_CALLBACK_2(FriendListScene::applyPhoto, this), false, SCALED_VALUE(85.0f), SCALED_VALUE(85.0f)); } } // Update the message Label. auto messageLabel = (LabelTTF*)cell->getChildByTag(TAG_MESSAGE); CCLOG("Friend Name = %s", friendName.c_str()); if (messageLabel) { messageLabel->setString(friendName.c_str()); } } return cell; }