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 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); } } } }
void CCommandLayer::processNetMsg(int type, google::protobuf::Message *msg) { this->setVisible(true); switch (type) { case CommanderMsg: { CommanderResponse *res = (CommanderResponse*)msg; m_commandData.cityInfo.read(res->info()); for (int i = 0; i < res->citylist_size(); i++) { CCity city; city.read(res->citylist(i)); m_commandData.cityList.push_back(city); } showCommandList(); } break; case LevelUpMsg: { LevelUpResponse *res = (LevelUpResponse*)msg; //1 升级成功,2 粮食不足,3 指挥府等级限制,4 已达到最大等级,5 数据错误 switch (res->result()) { case 1: ShowPopTextTip(GETLANGSTR(244)); if (res->has_city()) { UserData *user = DataCenter::sharedData()->getUser()->getUserData(); int food = user->getRoleFood() - m_selectCity->lvFood; user->setRoleFood(food); CSceneManager::sharedSceneManager()->PostMessageA(UPDATE_HERO,0,nullptr,nullptr); m_selectCity->read(res->city()); CCity *city = new CCity; *city = *m_selectCity; CSceneManager::sharedSceneManager()->PostMessageA(UPDATE_BUILD,0,nullptr, city); //更新指挥塔数据 if (m_selectCity->cityId==m_commandData.cityInfo.cityId) { m_commandData.cityInfo = *m_selectCity; } m_tableView->setContentOffset(m_tableView->getContentOffset()); m_tableView->reloadData(); updateSelectCity(m_selectCity); } break; case 2: ShowPopTextTip(GETLANGSTR(241)); break; case 3: ShowPopTextTip(GETLANGSTR(242)); break; case 4: ShowPopTextTip(GETLANGSTR(243)); break; case 5: ShowPopTextTip(GETLANGSTR(170),RGB_RED); break; default: break; } } break; default: break; } }