Example #1
0
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;
	}
}