void CHeroExpItem::showItem(CItem* item) { const ItemData * itemData = DataCenter::sharedData()->getItemDesc()->getCfg(item->itemId); CImageView *itembg1 = (CImageView *)(m_ui->findWidgetById("itembg1")); CImageView *mask1 = (CImageView *)(m_ui->findWidgetById("mask1")); mask1->setTexture(setItemQualityTexture(item->quality)); CCSprite *head = getItemSprite(item); if (!head) { head = CCSprite::create("prop/32003.png"); CCLOG("[ ERROR ] CHeroExpItem::showItem Lost Image = %d",item->iconId); } if (head) { head->setScale(82.0f/100.0f); head->setPosition(ccp(itembg1->getContentSize().width/2, itembg1->getContentSize().height/2)); itembg1->addChild(head); } CLabel *name = (CLabel *)(m_ui->findWidgetById("name")); if(itemData) { name->setString(itemData->itemName.c_str()); } CLabel *num = (CLabel *)(m_ui->findWidgetById("num")); num->setString(ToString(item->itemNum)); }
void CHeroExpItem::addTableCell(unsigned int uIdx, CTableViewCell * pCell) { CLayout *lay = UICloneMgr::cloneLayout(m_cell); const CEvolQuest &evol = m_evolInfo.questsList.at(uIdx); const TaskData *task = DataCenter::sharedData()->getTask(Evole_Task)->getCfg(evol.id); for (int i = 1; i <=4; i++) { CCNode *child = lay->getChildByTag(i); lay->removeChild(child); pCell->addChild(child); if (i==1) { CImageView *bgView= (CImageView*)child; bgView->setTouchEnabled(true); bgView->setUserData(&m_evolInfo.questsList.at(uIdx)); bgView->setOnClickListener(this, ccw_click_selector(CHeroExpItem::onRecvTask)); } else if (i==2) { CLabel *taskName = (CLabel*)child; taskName->setString(task->taskName.c_str()); } else if (i==3) { CLabel *taskDesc = (CLabel*)child; taskDesc->setString(task->taskDesc.c_str()); } else if (i==4) { child->setVisible(evol.pass); } } }
void CCommandLayer::updateSelectCity(CCity *data) { CCSprite *build = (CCSprite*)(m_comLayer->findWidgetById("build")); CCTexture2D *textTure = CCTextureCache::sharedTextureCache()->addImage(CCString::createWithFormat("command/%d.jpg",data->cityId*10+1)->getCString()); if (textTure) { build->setTexture(textTure); } CLabel *food = (CLabel*)(m_comLayer->findWidgetById("food")); food->setString(ToString(data->lvFood)); CLabel *heronum = (CLabel*)(m_comLayer->findWidgetById("heronum")); heronum->setString(CCString::createWithFormat("%d/%d",data->haveHeroNum,data->heroNum)->getCString()); CLabel *note1 = (CLabel*)(m_comLayer->findWidgetById("func1")); CLabel *note2 = (CLabel*)(m_comLayer->findWidgetById("func2")); CCArray *strArr = strSplit(data->note.c_str(),"|"); if (strArr->count()==1) { note1->setString(((CCString*)strArr->objectAtIndex(0))->getCString()); note2->setString(""); } else if (strArr->count()==2) { note1->setString(((CCString*)strArr->objectAtIndex(0))->getCString()); note2->setString(((CCString*)strArr->objectAtIndex(1))->getCString()); } CButton *command = (CButton*)(m_comLayer->findWidgetById("strengthen")); UserData *user = DataCenter::sharedData()->getUser()->getUserData(); if (data->cityId != m_commandData.cityInfo.cityId) { if (user->getRoleFood()>=data->lvFood&&data->level< m_commandData.cityInfo.level) { command->setEnabled(true); } else { command->setEnabled(false); } } else { if (user->getRoleFood()>=data->lvFood) { command->setEnabled(true); } else { command->setEnabled(false); } } }
void LoginLayerUC::updateSelectServer() { const Server& gameServer = m_serverInfo.server_list().Get(m_iSelectServerIndex); CLabel* pServerSelect = (CLabel*)m_pCurrentServerUI->findWidgetById("server_select"); pServerSelect->setString(gameServer.server_name().c_str()); CLabel* pServerSelectStatus = (CLabel*)m_pCurrentServerUI->findWidgetById("status_select"); int iShowText[5] = {2002, 1184, 1185, 1186, 1187}; pServerSelectStatus->setString(GETLANGSTR(iShowText[gameServer.server_status()])); UCSdk::s_serverid = 0; UCSdk::s_servername = gameServer.server_name(); }
void CToggleViewGroupTest::onCheck(Ref* pSender, bool bChecked) { CToggleView* pToggle = (CToggleView*) pSender; CLabel* pText = (CLabel*) pToggle->getUserObject(); if( bChecked ) { pText->setString("checked"); } else { pText->setString("unchecked"); } }
int CSmeltArmor::updateInfoToUIAndReturnCount( CLayout* pLayout[], int iNameId[], int iValue[], const char* sRange[], int iMax, const char* sTitle ) { int iMaxLineCount = 0; for(unsigned int i=0; i<iMax; i++) { //有值 if(iValue[i] > 0) { pLayout[iMaxLineCount]->setVisible(true); //设置名称 CLabel* pInfoType = (CLabel*)pLayout[iMaxLineCount]->findWidgetById("info_type"); pInfoType->setString(GETLANGSTR(iNameId[i])); //设置值大小 CLabel* pValue = (CLabel*)pLayout[iMaxLineCount]->findWidgetById("value"); if(atoi(pValue->getString())!=iValue[i]) { pValue->setString(ToString(iValue[i])); pValue->runAction(CCRollLabelAction::create(0.3f, 0, iValue[i], pValue)); } //目标值大小 CLabel* pAimValue = (CLabel*)pLayout[iMaxLineCount]->findWidgetById("aim_value"); pAimValue->setString(sRange[i]); //存ID CCheckBox* pCheck = (CCheckBox*)pLayout[iMaxLineCount]->findWidgetById("check"); pCheck->setTag(i+1); iMaxLineCount++; } //找到四个了,退出循环 if(iMaxLineCount>=4) { break; } } //隐藏掉没有数据填充的cell hideNoneValueCell(iMaxLineCount, pLayout); //如果一个都没有,隐藏标题 if(sTitle != nullptr) { CCNode* pNode = (CCNode*)m_ui->findWidgetById(sTitle); if(pNode) { pNode->setVisible(iMaxLineCount != 0); } } return iMaxLineCount; }
void CSignLayer::updateSignDays() { //更新已签天数 CLabel * pSignNum = (CLabel*)m_ui->findWidgetById("qiandao_num"); pSignNum->setString(ToString(m_signData.sign)); if(!m_signData.bCanSign) { //更新已签天数 CButton * pSignBtn = (CButton*)m_ui->findWidgetById("qiandao_btn"); pSignBtn->setEnabled(false); pSignBtn->getDisabledImage()->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone)); } //未补签天数 CLabel* pRemainResignNum = (CLabel*)m_ui->findWidgetById("buqian_num"); pRemainResignNum->setString(ToString(m_signData.resign)); if(!m_signData.bCanResign || m_signData.resign==0) { //更新已签天数 //CButton * pReSignBtn = (CButton*)m_ui->findWidgetById("buqian_btn"); //pReSignBtn->setEnabled(false); //pReSignBtn->getDisabledImage()->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone)); pRemainResignNum->setVisible(false); CLabel* pRemainResignText = (CLabel*)m_ui->findWidgetById("buqian_text"); pRemainResignText->setVisible(false); CLabel* pRemainResignBg = (CLabel*)m_ui->findWidgetById("buqian_bg"); pRemainResignBg->setVisible(false); CLabel* pRemainResignBtn = (CLabel*)m_ui->findWidgetById("buqian_btn"); pRemainResignBtn->setVisible(false); CLabel* pRemainResignBtnText = (CLabel*)m_ui->findWidgetById("buqian_btn_text"); pRemainResignBtnText->setVisible(false); } ////totalSign //for (int i = 0; i < m_signData.totalList.size()&&i<4; i++) //{ // CSign &sign = m_signData.totalList.at(i); // if (m_signData.sign >= sign.day) // { // CCSprite *getspr = (CCSprite*)(m_ui->findWidgetById(CCString::createWithFormat("get%d",i+1)->getCString())); // getspr->setVisible(true); // } //} }
void LoginLayerUC::addTableCell( unsigned int uIdx, CTableViewCell * pCell ) { CLayout *lay = UICloneMgr::cloneLayout(m_pCell); const Server& server = m_serverInfo.server_list().Get(uIdx); for (unsigned int i=1; i<=4; i++) { CCNode *child = lay->getChildByTag(i); lay->removeChild(child); child->setTag(i); pCell->addChild(child); pCell->setTag(uIdx); switch (i) { case 1: { CImageView* pBoard = (CImageView*)child; pBoard->setTouchEnabled(true); pBoard->setOnClickListener(this, ccw_click_selector(LoginLayerUC::selectServer)); } break; case 3: { CLabel* pLabel = (CLabel*)child; pLabel->setString(server.server_name().c_str()); } break; case 4: { CLabel* pLabel = (CLabel*)child; int iShowText[5] = {2002, 1184, 1185, 1186, 1187}; pLabel->setString(GETLANGSTR(iShowText[server.server_status()])); } break; default: break; } } }
void CHandBookHeroLayer::updateUI( ) { //图鉴收集比例 int iCurrentN = CompleteInHandBook(&m_AtlasResponse); int iMax = m_AtlasResponse.atlas_list_size(); CLabel *pText = (CLabel *)m_ui->findWidgetById("text"); pText->setString(CCString::createWithFormat("%d/%d", iCurrentN, iMax)->getCString()); m_pTableView->setCountOfCell(m_AtlasResponse.atlas_list_size()); m_pTableView->reloadData(); }
void CTopLayer::onEnter() { BaseLayer::onEnter(); this->setTouchPriority(-100); UserData *user = DataCenter::sharedData()->getUser()->getUserData(); m_coinLabel = (CLabel*)m_ui->getChildByTag(13); m_coinLabel->setString(ToString(user->getCoin())); m_moneyLabel = (CLabel*)m_ui->getChildByTag(14); m_moneyLabel->setString(ToString(user->getRoleGold())); // m_foodLabel = (CLabel*)m_ui->getChildByTag(17); //m_foodLabel->setString(ToString(user->getRoleFood())); m_foodLabel->setString(ToString(user->getFriends())); CLabel *action = (CLabel*)(m_ui->findWidgetById("action")); action->setString(CCString::createWithFormat("%d/%d",user->getRoleAction(),user->getActionLimit())->getCString()); CButton* add_food = (CButton*)m_ui->findWidgetById("btn_add_food"); CButton* add_copper = (CButton*)m_ui->findWidgetById("btn_add_copper"); CButton* add_soul = (CButton*)m_ui->findWidgetById("btn_add_soul"); CButton* add_gold = (CButton*)m_ui->findWidgetById("btn_add_gold"); CButton* add_friendship = (CButton*)m_ui->findWidgetById("btn_add_friendship"); add_food->getSelectedImage()->setScale(1.1f); add_copper->getSelectedImage()->setScale(1.1f); add_soul->getSelectedImage()->setScale(1.1f); add_gold->getSelectedImage()->setScale(1.1f); add_friendship->getSelectedImage()->setScale(1.1f); add_food->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_copper->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_soul->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_gold->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_friendship->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); CSceneManager::sharedSceneManager()->addMsgObserver(UPDATE_HERO,this,GameMsghandler_selector(CTopLayer::updateRoleProperty)); //绑定场景隐藏和显示的消息 NOTIFICATION->addObserver(this, callfuncO_selector(CTopLayer::show), SHOW_TOP_LAYER, nullptr); NOTIFICATION->addObserver(this, callfuncO_selector(CTopLayer::hide), HIDE_TOP_LAYER, nullptr); CImageView *coin = (CImageView*)(m_ui->findWidgetById("coin")); CCAnimation *coinAnim = AnimationManager::sharedAction()->getAnimation("7033"); coinAnim->setDelayPerUnit(0.3f); coin->runAction(CCRepeatForever::create(CCAnimate::create(coinAnim))); CImageView *gold = (CImageView*)(m_ui->findWidgetById("gold")); CCAnimation *goldAnim = AnimationManager::sharedAction()->getAnimation("7034"); goldAnim->setDelayPerUnit(0.3f); gold->runAction(CCRepeatForever::create(CCAnimate::create(goldAnim))); }
void CTopLayer::updateActionTime(float dt) { UserData *data = DataCenter::sharedData()->getUser()->getUserData(); if (data->getRoleAction() < data->getActionLimit()) { data->setRoleAction(data->getRoleAction()+1); CLabel *action = (CLabel*)(m_ui->findWidgetById("action")); action->setString(CCString::createWithFormat("%d/%d",data->getRoleAction(),data->getActionLimit())->getCString()); data->setActionTime(data->getActionTime() + data->getInterval()*60*60); } else { this->unschedule(schedule_selector(CTopLayer::updateActionTime)); } }
void CSignLayer::updateTotoalSign() { //更新 //已领取的,宝箱变灰,加对勾 //未领取的,宝箱变亮, //将要领取的,加黄色标题突出 for (int i = 0; i < m_signData.totalList.size()&&i<4; i++) { CSign &sign = m_signData.totalList.at(i); //宝箱 CImageView *mask = (CImageView*)m_ui->findWidgetById(CCString::createWithFormat("mask%d",i+1)->getCString()); mask->setVisible(true); //mask->setTexture(CCTextureCache::sharedTextureCache()->addImage(CCString::createWithFormat("sign/box_%d.png", i+1)->getCString())); mask->setUserData(&sign); mask->setTouchEnabled(true); mask->setOnPressListener(this, ccw_press_selector(CSignLayer::onPress)); //天数 CLabel *day = (CLabel*)(m_ui->findWidgetById(CCString::createWithFormat("day%d",i+1)->getCString())); day->setString(CCString::createWithFormat(GETLANGSTR(209),sign.day)->getCString()); //获得字样 CImageView *getspr = (CImageView*)(m_ui->findWidgetById(CCString::createWithFormat("get%d",i+1)->getCString())); //已领取 if (sign.status==1) { //宝箱变灰 mask->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone)); //加对勾 getspr->setVisible(true); } //未领取 else if(sign.status==2) { //宝箱变灰 mask->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderDefault)); //加对勾 getspr->setVisible(false); } } }
void CSmeltArmor::initSpandAndCheckBox() { CCSprite *coin = (CCSprite *)(m_ui->findWidgetById("coin")); coin->setVisible(true); //m_coin = m_armor.useLevel *360; m_diamond = 0; m_coin = 0; switch (m_armor.quality) { case 1: m_coin =10000; break; case 2: m_coin =20000; break; case 3: m_coin =40000; break; case 4: m_coin =80000; break; case 5: m_coin =160000; break; default: break; } CCSprite *diamond = (CCSprite *)(m_ui->findWidgetById("diamond")); diamond->setVisible(false); CLabel *money = (CLabel *)(m_ui->findWidgetById("money")); money->setString(ToString(m_coin)); for (unsigned int i=0; i< 4; ++i) { CCheckBox* checkBtn = (CCheckBox*)(m_pBaseInfo[i]->findWidgetById("check")); checkBtn->setChecked(false); } }
void CSmeltArmor::showSmeltDataToUI() { const ItemData * itemData = DataCenter::sharedData()->getItemDesc()->getCfg(m_armor.itemId); //贴图 CCSprite *prop = getItemSprite(&m_armor); if (!prop) { prop = CImageView::create("prop/32003.png"); } //选择按钮 CButton *btn = dynamic_cast<CButton*>(m_ui->findWidgetById("select")); btn->removeChildByTag(1); prop->setPosition(ccp(btn->getContentSize().width/2,btn->getContentSize().height/2)); prop->setTag(1); btn->addChild(prop, -1); ((CCSprite*)btn->getNormalImage())->setTexture(setItemQualityTexture(m_armor.quality)); //添加星星层 btn->removeChildByTag(415); CLayout* pStarLayout = getStarLayout(m_armor.iStar); btn->addChild(pStarLayout, 415, 415); //更新名字 CLabel *name = dynamic_cast<CLabel*>(m_ui->findWidgetById("name")); CCString *str = CCString::create("XXX"); if(itemData) { str = CCString::createWithFormat("%s",itemData->itemName.c_str()); } name->setString(str->getCString()); name->setVisible(true); //加号 CCSprite *why = dynamic_cast<CCSprite*>(m_ui->findWidgetById("why")); why->setVisible(false); //设置等级 CLabel* pLevel = dynamic_cast<CLabel*>(m_ui->findWidgetById("level")); CCNode* pLevelBg = dynamic_cast<CCNode*>(m_ui->findWidgetById("level_mask")); if(m_armor.itemLevel>0) { pLevel->setVisible(true); pLevelBg->setVisible(true); pLevel->setString(CCString::createWithFormat("+%d", m_armor.itemLevel)->getCString()); } else { pLevel->setVisible(false); pLevelBg->setVisible(false); } m_attr->setVisible(true); //显示背景框等等 CCNode* pNode4 = (CCNode*)m_ui->findWidgetById("tip"); pNode4->setVisible(false); m_pSpineHero->setVisible(false); initSpandAndCheckBox(); showArmorAttr(); //更新钱 onCheckAttr(nullptr, false); //设置动作 showMoveAction("box_bg"); showMoveAction("select"); showMoveAction("why"); showMoveAction("level"); showMoveAction("level_mask"); }
void CStrengthenItem::addTableCell(unsigned int uIdx, CTableViewCell * pCell) { CLayout *lay = UICloneMgr::cloneLayout(m_cell); CItem &item = *(m_itemList.at(uIdx));// m_itemData.itemList.at(uIdx); pCell->setTag(uIdx); const ItemData * itemData = DataCenter::sharedData()->getItemDesc()->getCfg(item.itemId); for (int i = 1; i <=11; i++) { CCNode *child = lay->getChildByTag(i); if (!child) continue; lay->removeChild(child); pCell->addChild(child); if (i==1) { CImageView *bgImg = (CImageView*)child; if (m_toHero>0) { if (!item.canUse&&item.armor.hero!=m_toHero) { CColorView *colorView = CColorView::create(ccc4(0,0,0,100)); colorView->setContentSize(bgImg->getContentSize()); colorView->setPosition(bgImg->getPosition()); pCell->addChild(colorView,1); } if(item.armor.hero<=0) { //记录库存 m_iCountEquipStock++; } } bgImg->setTouchEnabled(true); bgImg->setUserData(m_itemList.at(uIdx)); bgImg->setOnClickListener(this,ccw_click_selector(CStrengthenItem::onTouchItem)); } else if (i==2) { ((CButton*)child)->setEnabled(false); CCSprite *mask = CCSprite::createWithTexture(setItemQualityTexture(item.quality)); mask->setPosition(ccp(child->getContentSize().width/2,child->getContentSize().height/2)); child->addChild(mask, 10); CCSprite *prop = CCSprite::create(GetImageName(1, item.quality, item.iconId).c_str()); if (!prop) { prop = CImageView::create("prop/32003.png"); } prop->setPosition(ccp(child->getContentSize().width/2,child->getContentSize().height/2)); child->addChild(prop); //添加星星 CLayout* pStarLayout = getStarLayout(item.iStar); child->addChild(pStarLayout, 10); } else if (i==3) { CLabel *label = (CLabel*)child; if(itemData) { label->setString(itemData->itemName.c_str()); } } else if (i==4) { CLabel *label = (CLabel*)child; if (item.itemLevel==0) { label->removeFromParent(); } else { label->setString(CCString::createWithFormat("+%d",item.itemLevel)->getCString()); label->setPositionX(pCell->getChildByTag(3)->getPositionX()+pCell->getChildByTag(3)->getContentSize().width+10); } } else if (i==5) { CLabel *label = (CLabel*)child; if (item.itemLevel==0) { label->setVisible(false); } else { label->setVisible(true); //if (item.itemLevel==item.armor.strenLv) //{ // label->setString(CCString::createWithFormat("Lv.%s",GETLANGSTR(229))->getCString()); //} //else //{ // label->setString(CCString::createWithFormat("Lv.%d",item.itemLevel)->getCString()); //} label->setString(CCString::createWithFormat("+%d",item.itemLevel)->getCString()); } } else if (i==6) { CCSprite *head = (CCSprite*)child; if (item.armor.hero>0) { CCSprite *img = CCSprite::create(getImageName(&item.armor).c_str()); if(!img) { img = CCSprite::create("headIcon/101.png"); CCLOG("ERROR CStrengthenItem::addTableCell"); } CCSprite *mask = (CCSprite*) lay->getChildByTag(7); lay->removeChild(mask); pCell->addChild(mask); img->setScale(0.53f); img->setPosition(ccp(head->getContentSize().width/2,head->getContentSize().height/2+14)); head->addChild(img); } else { pCell->removeChild(child); } } else if (i==7) { pCell->removeChild(child); } else if (i==8) { child->setVisible(item.stren); } else if(i==9) { if (item.itemLevel==0) { child->setVisible(false); } else { child->setVisible(true); } } else if( i ==10) { CCNode* pCombatTip = (CCNode*)child; pCombatTip->setVisible(item.armor.armorType != 5); } else if (i==11) { CLabelAtlas* pLabel = (CLabelAtlas*)child; pLabel->setAnchorPoint(ccp(0, 0.5f)); pLabel->setString(ToString(item.armor.combat)); pLabel->setVisible(item.armor.armorType != 5); } } }
void CMainCityUI::onEnter() { BaseLayer::onEnter(); UserData *user = DataCenter::sharedData()->getUser()->getUserData(); //角色信息相对位置处理 CLayout* headPart = (CLayout*)m_ui->findWidgetById("head_part"); headPart->setPosition(m_ui->convertToNodeSpace(ccp(VLEFT+headPart->getContentSize().width/2, VTOP-headPart->getContentSize().height/2))); //显示角色名,等级,体力,金币 CLabel *nameLabel = (CLabel*)headPart->getChildByTag(10); nameLabel->setString(user->getRoleName().c_str()); nameLabel->setColor(RGB_ROLE_COLOR); CLabel *level = (CLabel*)(headPart->findWidgetById("level")); level->setString(CCString::createWithFormat("Lv%d",user->getLevel())->getCString()); CProgressBar *progressBar = (CProgressBar*)(headPart->getChildByTag(11)); progressBar->setMaxValue(user->getNextExp()); progressBar->startProgress(user->getExp(),0.3f); CLabelAtlas *vip_level = (CLabelAtlas*)(headPart->findWidgetById("level_vip")); vip_level->setString(ToString(user->getVip())); if (user->getVip()==0) { vip_level->setVisible(false); CLabelAtlas *vip_font = (CLabelAtlas*)(headPart->findWidgetById("vip_font")); vip_font->setVisible(false); } CImageView *headbg = (CImageView *)(headPart->findWidgetById("headbg")); headbg->setTouchEnabled(true); headbg->setOnClickListener(this, ccw_click_selector(CMainCityUI::onHeadImgBtn)); CButton *button = nullptr; int i = 1; for (; i<=9; ++i) { CCNode *lay = dynamic_cast<CCNode*>( m_ui->getChildByTag(i)); button = dynamic_cast<CButton*>(lay->getChildByTag(i)); // button->setEnabled(false); button->setOnClickListener(this, ccw_click_selector(CMainCityUI::onClickBtn)); button->setSelectedTexture(((CCSprite*)(button->getNormalImage()))->getTexture()); button->getSelectedImage()->setScale(1.1f); m_btnPos[i] = button->getPosition(); } CCSprite* head = (CCSprite*)headPart->getChildByTag(15); if (user->getThumb()>0) { CCTexture2D *texture = CCTextureCache::sharedTextureCache() ->addImage(CCString::createWithFormat("headIcon/%d.png", user->getThumb())->getCString()); if (texture) { head->setTexture(texture); } } else { string fbName = user->getFbId()+".jpg"; string fullName = CCFileUtils::sharedFileUtils()->fullPathForFilename(fbName.c_str()); bool isFileExist = CCFileUtils::sharedFileUtils()->isFileExist(fullName); if(isFileExist) { CCSprite *headBg = (CCSprite *)(headPart->findWidgetById("headbg")); CCSprite *sp = CCSprite::create(fbName.c_str()); CCSprite* spr = MakeFaceBookHeadToCircle(sp); spr->setPosition(headBg->getPosition()); headPart->removeChild(head); spr->setTag(15); headPart->addChild(spr); } else { HttpLoadImage::getInstance()->bindUiTarget(this); CCString *imgUrl = CCString::createWithFormat(FACEBOOKIMG_106,user->getFbId().c_str()); HttpLoadImage::getInstance()->requestUrlImage(imgUrl->getCString(),user->getFbId().c_str()); } } CImageView* vip = (CImageView*)headPart->findWidgetById("vip"); vip->setTouchEnabled(true); vip->setOnClickListener(this,ccw_click_selector(CMainCityUI::onVip)); //添加签到,充值等其他入口 CAccessLayer* pAccess = CAccessLayer::create(); this->addChild(pAccess, 99); CSceneManager::sharedSceneManager()->addMsgObserver(UPDATE_HERO,this,GameMsghandler_selector(CMainCityUI::updateRoleProperty)); CSceneManager::sharedSceneManager()->addMsgObserver(TASK_NOTICE,this,GameMsghandler_selector(CMainCityUI::updateTaskNotice)); CSceneManager::sharedSceneManager()->addMsgObserver(MAIL_NOTICE,this,GameMsghandler_selector(CMainCityUI::updateMailNotice)); CSceneManager::sharedSceneManager()->addMsgObserver(UPDATE_FUNCTIONOPEN,this,GameMsghandler_selector(CMainCityUI::updateFuctionOpen)); CSceneManager::sharedSceneManager()->addMsgObserver(UPDATE_GAMETIP,this,GameMsghandler_selector(CMainCityUI::updateGameTip)); CSceneManager::sharedSceneManager()->addMsgObserver(SHOW_HEAD,this,GameMsghandler_selector(CMainCityUI::showHead)); CCSprite *red = (CCSprite*)(m_ui->findWidgetById("redPoint")); CCSprite *mailPoint = (CCSprite*)(m_ui->findWidgetById("mailPoint")); if (user->getRoleAction()<user->getActionLimit()) { this->schedule(schedule_selector(CMainCityUI::updateActionTime),user->getInterval()*60); } GetTcpNet->registerMsgHandler(FriendReqNumMsg,this,CMsgHandler_selector(CMainCityUI::processNetMsg)); GetTcpNet->registerMsgHandler(CBExchangeMsg,this,CMsgHandler_selector(CMainCityUI::exchangeMsg)); //正在引导,不自动弹窗 if(user->getNewStep()==2||user->getNewStep()==17/*CGuideManager::getInstance()->getIsRunGuide()*/) { DataCenter::sharedData()->setCityActionType(CA_None); } else if(user->getNewStep()<=0 || user->getNewStep()>=100) { //自动弹签到 runAction(CCSequence::createWithTwoActions(CCDelayTime::create(0.7f), CCCallFunc::create(this, callfunc_selector(CMainCityUI::autoShowSign)))); } switch (DataCenter::sharedData()->getCityActionType()) { case CA_Levelup: { CButton *btn = (CButton*)m_ui->getChildByTag(HeroInfo_Btn); btn->runAction(CCSequence::create(CCDelayTime::create(0.6f), CCCallFuncN::create(this, callfuncN_selector(CMainCityUI::onTimeWaitCityAction)), NULL)); DataCenter::sharedData()->setCityActionType(CA_None); } break; case CA_GoToChapater: { CButton *btn = (CButton*)m_ui->getChildByTag(Battle_Btn); btn->runAction(CCSequence::create(CCDelayTime::create(0.2f), CCCallFuncN::create(this, callfuncN_selector(CMainCityUI::onTimeWaitCityAction)), NULL)); m_bShowChapterFlag = true; DataCenter::sharedData()->setCityActionType(CA_None); } break; case CA_GoToStage: { this->runAction(CCSequence::create(CCDelayTime::create(0.8f), CCCallFunc::create(this, callfunc_selector(CMainCityUI::runTollgatepreviewCallBack)), NULL)); DataCenter::sharedData()->setCityActionType(CA_None); }break; default: break; } //绑定场景隐藏和显示的消息 NOTIFICATION->addObserver(this, callfuncO_selector(CMainCityUI::show), SHOW_MAIN_SCENE, nullptr); NOTIFICATION->addObserver(this, callfuncO_selector(CMainCityUI::hide), HIDE_MAIN_SCENE, nullptr); NOTIFICATION->addObserver(this, callfuncO_selector(CMainCityUI::checkShowActivity), "CheckShowActivity", nullptr); CCNode *lay = dynamic_cast<CCNode*>( m_ui->getChildByTag(6)); button = dynamic_cast<CButton*>(lay->getChildByTag(6)); CCAnimation *batAnim = AnimationManager::sharedAction()->getAnimation("9015"); batAnim->setDelayPerUnit(0.1f); CCSprite *batLight = createAnimationSprite("skill/9015.png",button->getPosition(),batAnim,true); batLight->setScale(1.4f); m_ui->addChild(batLight); showNoticeTip(CTaskControl::getInstance()->getGameTips()); // CCSprite *spr = CCSprite::create("headImg/506.png"); // spr->setScale(1.2f); // CCSprite *sp = maskedSprite(spr); // CCSprite *headBg = (CCSprite *)(headPart->findWidgetById("headbg")); // sp->setPosition(headBg->getPosition()); // headPart->addChild(sp); //在线礼包 int iNexTime = user->getOnlinePrizeTime(); if (iNexTime!=-1) { if (m_pTimeGift==nullptr) { m_pTimeGift = CTimeGift::create(); m_pTimeGift->setTouchPriority(-3); this->addChild(m_pTimeGift, 2); } m_pTimeGift->setTime(iNexTime); } }
void CTopLayer::updateRoleProperty(const TMessage& tMsg) { UserData *user = DataCenter::sharedData()->getUser()->getUserData(); CCScaleTo* sc1 = CCScaleTo::create(0.15f,1.3f); CCScaleTo* sc2 = CCScaleTo::create(0.35f,1.0f); CCSequence* sqes = CCSequence::create(sc1,sc2,nullptr); if (user->getCoin()!=atoi(m_coinLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_coinLabel); prolab->changeValueTo(user->getCoin(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_coinLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(130); int coin = user->getCoin()-atoi(m_coinLabel->getString()); changeLabel(label, coin); } if (user->getRoleGold()!=atoi(m_moneyLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_moneyLabel); prolab->changeValueTo(user->getRoleGold(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_moneyLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(140); int coin = user->getRoleGold()-atoi(m_moneyLabel->getString()); changeLabel(label, coin); } /* if (user->getRoleFood()!=atoi(m_foodLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_foodLabel); prolab->changeValueTo(user->getRoleFood(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_foodLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(170); int coin = user->getRoleFood()-atoi(m_foodLabel->getString()); changeLabel(label, coin); } */ if (user->getFriends()!=atoi(m_foodLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_foodLabel); prolab->changeValueTo(user->getFriends(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_foodLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(170); int coin = user->getFriends()-atoi(m_foodLabel->getString()); changeLabel(label, coin); } CLabel *action = (CLabel*)(m_ui->findWidgetById("action")); if (user->getRoleAction()!=atoi(action->getString())) { CCSequence* sqes2 = (CCSequence*)sqes->copy(); action->runAction(sqes2); action->setString(CCString::createWithFormat("%d/%d",user->getRoleAction(), user->getActionLimit())->getCString()); } }
void CCommandLayer::addTableCell(unsigned int uIdx, CTableViewCell * pCell) { CCity &data = m_commandData.cityList[uIdx]; CLayout *lay = UICloneMgr::cloneLayout(m_cell); for (int i=1;i<=6;++i) { CCNode *child = lay->getChildByTag(i); lay->removeChild(child); pCell->addChild(child); if (i==1) { child->setTag(uIdx+100); child->setUserData((void*)&m_commandData.cityList[uIdx]); ((CButton*)child)->setOnClickListener(this,ccw_click_selector(CCommandLayer::onSelectCity)); } else if(i==3) { CLabel *name = (CLabel*)child; name->setString(data.cityName.c_str()); } else if (i==2) { ((CButton*)child)->setEnabled(false); CCSprite *prop = CCSprite::create(CCString::createWithFormat("command/%d.jpg",data.cityId*10)->getCString()); if (prop) { prop->setPosition(ccp(child->getContentSize().width/2,child->getContentSize().height/2)); child->addChild(prop,0,1); } else { prop = CImageView::create("command/30.jpg"); prop->setPosition(ccp(child->getContentSize().width/2,child->getContentSize().height/2)); child->addChild(prop,0,1); } } else if(i==4) { CLabel *level = (CLabel*)child; level->setString(CCString::createWithFormat(GETLANGSTR(230),data.level)->getCString()); } else if (i==5) { UserData *user = DataCenter::sharedData()->getUser()->getUserData(); if (user->getRoleFood()>=data.lvFood) { child->setVisible(false); } } else if (i==6) { UserData *user = DataCenter::sharedData()->getUser()->getUserData(); if (m_commandData.cityInfo.level>=data.level&&m_commandData.cityInfo.cityId!=data.cityId&&user->getRoleFood()>=data.lvFood) { child->setVisible(false); } else if(m_commandData.cityInfo.cityId==data.cityId&&user->getRoleFood()>=data.lvFood) { child->setVisible(false); } } } }
// on "init" you need to initialize your instance bool HelloWorld::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// //init GUI system CCSize size = CCDirector::sharedDirector()->getWinSize(); m_pGUI = new CGui(size.width,size.height); m_pGUI->setRect(CreateCRect(0,0,CLayoutParam::WRAP_CONTENT,CLayoutParam::WRAP_CONTENT)); m_pGUI->setBkColor(CreateCColor(0,0,0,255)); //add panel to gui CPanel* pPanel = new CPanel(); pPanel->setBkColor(CreateCColor(0,255,0,255)); pPanel->setRect(CreateCRect(200,200,CLayoutParam::WRAP_CONTENT,CLayoutParam::WRAP_CONTENT)); pPanel->setZOrder(0); m_pGUI->add(pPanel); // // //add panel2 to panel1 // CPanel* pPanel2 = new CPanel(); // pPanel2->setBkColor(CreateCColor(0,0,255,128)); // pPanel2->setRect(CreateCRect(0,25,100,10)); // pPanel->add(pPanel2); // //set scale to parent all child will be effected!! // pPanel->setScale(2.0); // //add a btn to gui CCTexture2D* pPicNormal = CCTextureCache::sharedTextureCache()->addImage("CloseNormal.png"); CCTexture2D* pPicSel = CCTextureCache::sharedTextureCache()->addImage("CloseSelected.png"); CPushButton* pBtn = new CPushButton(); pBtn->setNormalPic(pPicNormal); pBtn->setClickPic(pPicSel); pBtn->setRect(CreateCRect(0,0,CLayoutParam::WRAP_CONTENT,CLayoutParam::WRAP_CONTENT)); //pBtn->setScale(1.0f); pBtn->setZOrder(1); pBtn->setcmdID(HelloWorld::CMD_ID_EIXT); pBtn->setlongClick(true,1234567); pPanel->add(pBtn); // // // // m_pGUI->add(pBtn); // CCTexture2D* pPicSel = CCTextureCache::sharedTextureCache()->addImage("CloseSelected.png"); // CImageWidget* pImage = new CImageWidget(); // pImage->setPic(pPicSel); // pImage->setRect(CreateCRect(0,0,CLayoutParam::WRAP_CONTENT,CLayoutParam::WRAP_CONTENT)); // pPanel->add(pImage); //for test using //do not care memory link here!!! CActionMoveBy* pMoveBy = new CActionMoveBy(); pMoveBy->init(2,CreateCPoint(100,100)); CActionMoveTo* pMoveTo = new CActionMoveTo(); pMoveTo->init(2,CreateCPoint(100,100)); CActionFadeTo* pFade = new CActionFadeTo(); pFade->init(2,0); CActionScaleTo* pScale = new CActionScaleTo(); pScale->init(2,1); //pPanel->setScale(0); pPanel->runAction(pMoveTo); CLabel* pLabel = new CLabel(); pLabel->setString(std::string("HelloWorld"),20,CreateCColor(255,0,0,255),std::string("宋体")); pLabel->setPos(100,0); CActionSpwan* pSpwan = new CActionSpwan(); pSpwan->initWidthActions(pMoveBy,pFade); pLabel->runAction(pSpwan); m_pGUI->add(pLabel); //registe handler m_MyCmdHandler.addInterestCmdID(HelloWorld::CMD_ID_EIXT); CCommandHandlerMgr::instance()->addCmdHander(&m_MyCmdHandler); CC_BREAK_IF(! CCLayer::init()); this->setTouchEnabled(true); bRet = true; GameApplication application; application.onCreate(); application.didEnterApplication(); // CHttpRequest request1; // request1.setRequestUrl("http://h.hiphotos.baidu.com/album/w%3D1366%3Bcrop%3D0%2C0%2C1366%2C768/sign=83acd2dbfaedab64747249c3c10094a0/c83d70cf3bc79f3ddf7f4820bba1cd11728b2907.jpg"); // request1.setSaveTargerFileAddr("download1.jpg"); // CLoader loader; // loader.load(&request1); this->testRichTxt(); //this->testLinearLayout(); this->testSimpleList(); this->scheduleUpdate(); ZThread::Thread t(new ThreadExample()); } while (0); return bRet; }
void CSmeltArmor::onCheckAttr(CCObject *pSender, bool bChecked) { int checknum =0; int iShowCount = 0; for (unsigned int i=0; i<4; ++i) { CCheckBox* pCheckBtn = (CCheckBox*)(m_pBaseInfo[i]->findWidgetById("check")); if (pCheckBtn->isChecked()) { checknum++; } if(m_pBaseInfo[i]->isVisible()) { iShowCount++; } setYellowBgState(pCheckBtn, pCheckBtn->isChecked()); } //如果选中了四个,则屏蔽掉一个,提示不能全选 if(checknum>=iShowCount && pSender!=nullptr) { CCheckBox* pCheck = (CCheckBox*)pSender; pCheck->setEnabled(false); pCheck->setChecked(false); pCheck->setEnabled(true); setYellowBgState(pCheck, false); ShowPopTextTip(GETLANGSTR(1182)); return; } if (checknum==0) { CCSprite *coin = (CCSprite *)(m_ui->findWidgetById("coin")); coin->setVisible(true); m_coin = 0; switch (m_armor.quality) { case 1: m_coin =10000; break; case 2: m_coin =20000; break; case 3: m_coin =40000; break; case 4: m_coin =80000; break; case 5: m_coin =160000; break; default: break; } m_diamond = 0; CCSprite *diamond = (CCSprite *)(m_ui->findWidgetById("diamond")); diamond->setVisible(false); CLabel *money = (CLabel *)(m_ui->findWidgetById("money")); money->setString(ToString(m_coin)); //检查货币数量 if(!CheckCoin(atoi(money->getString()))) { money->setColor(RGB_RED); } else { money->setColor(RGB_WHITE); } showFireWithType(0); } else { CCSprite *coin = (CCSprite *)(m_ui->findWidgetById("coin")); coin->setVisible(false); CCSprite *diamond = (CCSprite *)(m_ui->findWidgetById("diamond")); diamond->setVisible(true); CLabel *money = (CLabel *)(m_ui->findWidgetById("money")); money->setString(ToString(100*checknum)); //检查货币数量 if(!CheckGold(atoi(money->getString()))) { money->setColor(RGB_RED); } else { money->setColor(RGB_WHITE); } m_coin = 0; m_diamond = 100*checknum; showFireWithType(1); } }
void CMainCityUI::updateRoleProperty(const TMessage& tMsg) { UserData *user = DataCenter::sharedData()->getUser()->getUserData(); CLayout* headPart = (CLayout*)m_ui->findWidgetById("head_part"); CLabel *nameLabel = (CLabel*)headPart->getChildByTag(10); nameLabel->setString(user->getRoleName().c_str()); CLabel *level = (CLabel*)(headPart->findWidgetById("level")); level->setString(CCString::createWithFormat("Lv%d",user->getLevel())->getCString()); CLabelAtlas *vip = (CLabelAtlas*)(headPart->findWidgetById("level_vip")); vip->setString(ToString(user->getVip())); if (user->getVip()==0) { vip->setVisible(false); CLabelAtlas *vip_font = (CLabelAtlas*)(headPart->findWidgetById("vip_font")); vip_font->setVisible(false); } CCSprite* head = (CCSprite*)headPart->getChildByTag(15); if (user->getThumb()>0) { // CCTexture2D *texture = CCTextureCache::sharedTextureCache() // ->addImage(CCString::createWithFormat("headIcon/%d.png", user->getThumb())->getCString()); // if (texture) // { // head->setTexture(texture); // } // head->setFlipY(false); CCSprite *headBg = (CCSprite *)(headPart->findWidgetById("headbg")); CCString *strnName = CCString::createWithFormat("headIcon/%d.png", user->getThumb()); CCSprite *sp = CCSprite::create(strnName->getCString()); sp->setPosition(ccpAdd(headBg->getPosition(),ccp(0,10))); sp->setScale(0.75f); headPart->removeChild(head); sp->setTag(15); headPart->addChild(sp); } else { string fbName = user->getFbId()+".jpg"; string fullName = CCFileUtils::sharedFileUtils()->fullPathForFilename(fbName.c_str()); bool isFileExist = CCFileUtils::sharedFileUtils()->isFileExist(fullName); if(isFileExist) { CCSprite *headBg = (CCSprite *)(headPart->findWidgetById("headbg")); CCSprite *sp = CCSprite::create(fullName.c_str()); CCSprite* spr = MakeFaceBookHeadToCircle(sp); spr->setPosition(headBg->getPosition()); headPart->removeChild(head); spr->setTag(15); headPart->addChild(spr); } else { HttpLoadImage::getInstance()->bindUiTarget(this); CCString *imgUrl = CCString::createWithFormat(FACEBOOKIMG_106,user->getFbId().c_str()); HttpLoadImage::getInstance()->requestUrlImage(imgUrl->getCString(),user->getFbId().c_str()); } } CProgressBar *progressBar = (CProgressBar*)(headPart->getChildByTag(11)); progressBar->setMaxValue(user->getNextExp()); progressBar->startProgress(user->getExp(),0.3f); }
void LoginLayerUC::initLogin() { CCLOG("LoginLayerUC::initLogin"); if(m_ui!=nullptr) { return; } //播放背景音乐 PlayBackgroundMusic(BGM_Login,true); m_ui = LoadComponent("EnterGameUC.xaml"); m_ui->setTag(1); m_ui->setPosition(VCENTER); m_LayoutRoot->addChild(m_ui, 2); //自己的登陆框隐藏 m_pLoginLay = (CLayout *)m_ui->getChildByTag(10); m_pLoginLay->setVisible(false); //选择好的服务器列表 m_pCurrentServerUI = (CLayout *)m_ui->findWidgetById("current_server"); m_pCurrentServerUI->setVisible(true); //默认服务器 updateSelectServer(); //服务器选区 CLayout* pLayout = (CLayout*)m_ui->findWidgetById("serverCell"); pLayout->retain(); m_ui->removeChild(pLayout); m_pCell = pLayout; //获取空的滑动列表Scroll m_pTableView = (CTableView*)m_ui->findWidgetById("serverScroll"); m_pTableView->setDirection(eScrollViewDirectionVertical); m_pTableView->setSizeOfCell(m_pCell->getContentSize()); m_pTableView->setCountOfCell(m_serverInfo.server_list().size()); m_pTableView->setBounceable(true); m_pTableView->setDataSourceAdapter(this, ccw_datasource_adapter_selector(LoginLayerUC::tableviewDataSource)); m_pTableView->reloadData(); //按钮打开服务器列表 CImageView* pBtnServer = (CImageView*)m_ui->findWidgetById("serverBtn"); //快速登录按钮 CButton * pQuickLogin = (CButton *)m_ui->getChildByTag(1); pQuickLogin->setOnClickListener(this,ccw_click_selector(LoginLayerUC::onQuickLogin)); CCActionInterval *scaleSmall = CCScaleTo::create(0.9f,0.98f); CCFadeTo *out = CCFadeTo::create(0.9f,60); CCSpawn *spawn = CCSpawn::createWithTwoActions(scaleSmall,out); CCActionInterval *scaleBig = CCScaleTo::create(1.2f,1.0f); CCFadeTo *in = CCFadeTo::create(1.2f,255); CCSpawn *spawn1 = CCSpawn::createWithTwoActions(scaleBig,in); CCSequence *seque = CCSequence::createWithTwoActions(spawn,spawn1); CCRepeatForever *action = CCRepeatForever::create(seque); pQuickLogin->runAction(action); pQuickLogin->setVisible(true); //清除用户信息 DataCenter::sharedData()->getUser()->clear(); //版本做相对位置处理 CLabel* pLabel = (CLabel *)m_ui->findWidgetById("version"); pLabel->setAnchorPoint(ccp(1.0f, 0.0f)); pLabel->setPosition(ccp(VRIGHT-20, VBOTTOM+20)); CC_SAFE_RETAIN(pLabel); pLabel->removeFromParentAndCleanup(true); this->addChild(pLabel); CC_SAFE_RELEASE(pLabel); pLabel->setString(CCString::createWithFormat("Version:%s", m_serverInfo.game_version().c_str())->getCString()); //隐藏服务器列表 showServerList(); hideServerList(); //TODO //初始化UC_SDK?-放在最前面 //还是点击登录再初始化? //点击登录再初始化吧 //初始化完直接请求登录 //先连接连接服务器 const Server& gameServer = m_serverInfo.server_list().Get(m_iSelectServerIndex); //检查服务器是否可用 if(!checkServerStatus(gameServer)) { return; } LinkedGameServer(gameServer); }
void CHeroEvolveEffectLayer::updateData( ) { //面板数据 int iValue[][2] = { {m_pBaseHero->combat, m_pAimHero->combat}, {m_pBaseHero->hp, m_pAimHero->hp}, {m_pBaseHero->atk, m_pAimHero->atk}, {m_pBaseHero->def, m_pAimHero->def}, {m_pBaseHero->dex, m_pAimHero->dex}, {m_pBaseHero->hit, m_pAimHero->hit}, {m_pBaseHero->crit, m_pAimHero->crit}, {m_pBaseHero->dodge, m_pAimHero->dodge}, {m_pBaseHero->renew, m_pAimHero->renew} }; //更新数据 for(int i=0; i<9; i++) { CLayout *pLay = (CLayout *)m_pUI->findWidgetById(CCString::createWithFormat("data%d", i+1)->getCString()); pLay->setVisible(false); CLabel *pBaseValue = (CLabel *)pLay->findWidgetById(CCString::createWithFormat("base_value%d", i+1)->getCString()); pBaseValue->setString(ToString(iValue[i][0])); CLabel *pAimValue = (CLabel *)pLay->findWidgetById(CCString::createWithFormat("aim_value%d", i+1)->getCString()); pAimValue->setString(ToString(iValue[i][1])); } }