void ConfigMgr::loadTilesConfig(const std::string& configFilePath) { // Datei öffnen rapidxml::file<> xmlFile(configFilePath.c_str()); rapidxml::xml_document<>* xmlDocument = new rapidxml::xml_document<>(); xmlDocument->parse<0>(xmlFile.data()); rapidxml::xml_node<>* tilesConfigNode = xmlDocument->first_node("tiles-config", 12, true); rapidxml::xml_node<>* tilesNode = tilesConfigNode->first_node("tiles", 5, true); // Tiles auslesen for (rapidxml::xml_node<>* tileNode = tilesNode->first_node("tile", 4, true); tileNode != nullptr; tileNode = tileNode->next_sibling("tile", 4, true)) { const char* tileName = tileNode->first_attribute("name", 4, true)->value(); const char* mapTileTypeName = tileNode->first_attribute("type", 4, true)->value(); const MapTileType mapTileType = getMapTileTypeByName(mapTileTypeName); MapTileConfig& mapTileConfig = mapTileConfigs[tileName]; mapTileConfig.tileName = std::string(tileName); mapTileConfig.mapTileType = mapTileType; // TODO konfigurierbar machen if (mapTileConfig.tileName == "grass") { mapTileConfig.goodToHarvest = getGood("grass"); } for (rapidxml::xml_node<>* tmxTileNode = tileNode->first_node("tmx-tile", 8, true); tmxTileNode != nullptr; tmxTileNode = tmxTileNode->next_sibling("tmx-tile", 8, true)) { int tmxTileIndex = stringToInteger(tmxTileNode->first_attribute("tmx-tile-index", 14, true)->value()); const char* tileViewName = tmxTileNode->first_attribute("view", 4, true)->value(); int xOffsetInTileset = stringToInteger(tmxTileNode->first_attribute("x", 1, true)->value()); int yOffsetInTileset = stringToInteger(tmxTileNode->first_attribute("y", 1, true)->value()); FourthDirection tileView = Direction::fromString(tileViewName); if (tileView == Direction::NONE) { Log::error(_("Illegal dirName '%s'."), tileViewName); throw std::runtime_error("Illegal dirName"); } mapTileConfig.mapTileViewsOffsetXYInTileset[tileView] = std::make_pair(xOffsetInTileset, yOffsetInTileset); // Zuordnung zu Tiled-Kachel-ID und View-Offset merken tiledIdToMapTileConfig[tmxTileIndex] = &mapTileConfig; tiledIdToViewOffset[tmxTileIndex] = tileView / 2; } // Den Ozean separat merken // TODO Was, wenn mehrere Ozean-Kacheln in der tiles.xml stehen? if (mapTileType == MapTileType::OCEAN) { mapTileConfigOcean = &mapTileConfig; } } delete xmlDocument; }
void ConfigMgr::readGoodSlotConfig(GoodsSlot& goodSlot, rapidxml::xml_node<>* produtionSlotNode) { const char* goodName = produtionSlotNode->first_attribute("good", 4, true)->value(); const Good* good = getGood(goodName); goodSlot.good = good; goodSlot.capacity = (unsigned int) stringToUnsignedLong( produtionSlotNode->first_attribute("capacity", 8, true)->value()); }
void ShopPanel::selectedItemEvent(Ref *pSender, ListView::EventType type) { switch (type) { case cocos2d::ui::ListView::EventType::ON_SELECTED_ITEM_START: { ListView* listView = static_cast<ListView*>(pSender); CC_UNUSED_PARAM(listView); CCLOG("select child start index = %ld", listView->getCurSelectedIndex()); //auto tag = listView->getItem(listView->getCurSelectedIndex())->getTag(); //auto goodUnit = _goodsUnit.at(listView->getCurSelectedIndex()); break; } case cocos2d::ui::ListView::EventType::ON_SELECTED_ITEM_END: { ListView* listView = static_cast<ListView*>(pSender); CC_UNUSED_PARAM(listView); CCLOG("select child end index = %ld", listView->getCurSelectedIndex()); auto goodUnit = _goodsUnit.at(listView->getCurSelectedIndex()); auto good = goodUnit->getGood(); PopPanel::getInstance()->confirm("buy","type:Text---text:"+ a2u("确定要花费 ") + cocos2d::Value(goodUnit->getPrice()).asString() + a2u("元 购买 ") + cocos2d::Value(goodUnit->getNum()).asString() + a2u("个") + good->getNickName() + a2u(" 吗?"),PromptPanel::TYPE_DONE_CANCEL,[=](){ // 加速药水 if(good->getTypeId() == 2003011 && Detect::shareDetect()->getUser()->getBuffByTypeId(4001001) != nullptr) { PopPanel::getInstance()->note("treaMap","type:Text---text:"+ a2u("已拥有该效果"),2.0f,false,true); } else { #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID //确定购买 JniMethodInfo jmi; if(JniHelper::getStaticMethodInfo(jmi ,"IAP/IAPJni" ,"orderGood" ,"(I)V")) { jmi.env->CallStaticVoidMethod(jmi.classID , jmi.methodID, listView->getCurSelectedIndex()); } #else JniTest::getInstance()->orderSuccess(listView->getCurSelectedIndex()); #endif } },nullptr,true,true); break; } default: break; } }
void ConfigMgr::loadPopulationTiers(const std::string& configFilePath) { rapidxml::file<> xmlFile(configFilePath.c_str()); rapidxml::xml_document<>* xmlDocument = new rapidxml::xml_document<>(); xmlDocument->parse<0>(xmlFile.data()); rapidxml::xml_node<>* populationTiersNode = xmlDocument->first_node("population-tiers", 16, true); // Bevölkerungsgruppen unsigned char index = 1; for (rapidxml::xml_node<>* node = populationTiersNode->first_node("population-tier", 15, true); node != nullptr; node = node->next_sibling("population-tier", 15, true)) { PopulationTier populationTier; populationTier.index = index++; populationTier.name = std::string(node->first_attribute("name", 4, true)->value()); // <advancement> rapidxml::xml_node<>* advancementNode = node->first_node("advancement", 11, true); rapidxml::xml_node<>* advancementMissingGoodsOkNode = advancementNode->first_node("missing-goods-ok", 16, true); if (advancementMissingGoodsOkNode != nullptr) { populationTier.advancementMissingGoodsOk = (unsigned char) stringToUnsignedLong(advancementMissingGoodsOkNode->value()); } rapidxml::xml_node<>* advancementCostsNode = advancementNode->first_node("costs", 5, true); readBuildingCosts(populationTier.advancementCosts, advancementCostsNode); // <needs> rapidxml::xml_node<>* needsNode = node->first_node("needs", 5, true); if (needsNode != nullptr) { // <good> for (rapidxml::xml_node<>* goodNode = needsNode->first_node("good", 4, true); goodNode != nullptr; goodNode = goodNode->next_sibling("good", 4, true)) { std::string goodName = std::string(goodNode->first_attribute("name", 4, true)->value()); NeededGood neededGood; neededGood.good = getGood(goodName); neededGood.consumePerCycle = stringToDouble( goodNode->first_attribute("consume-per-cycle", 17, true)->value()); populationTier.needsGoods.push_back(neededGood); } // <public-building> for (rapidxml::xml_node<>* publicBuildingNode = needsNode->first_node("public-building", 15, true); publicBuildingNode != nullptr; publicBuildingNode = publicBuildingNode->next_sibling("public-building", 15, true)) { std::string mapObjectTypeName = std::string(publicBuildingNode->first_attribute("name", 4, true)->value()); const MapObjectType* mapObjectType = getMapObjectType(mapObjectTypeName); populationTier.needsPublicBuildings.push_back(mapObjectType); } } // sonstige Tags populationTier.maxPopulationPerHouse = (unsigned char) stringToUnsignedLong( node->first_node("max-population-per-house", 24, true)->value()); populationTier.taxesPerInhabitant = stringToDouble( node->first_node("taxes-per-inhabitant", 20, true)->value()); populationTiers.insert(populationTier); Log::info(_("Loaded populationTier '%s'."), populationTier.name.c_str()); } // Nahrungsbedürfnis rapidxml::xml_node<>* foodGoodNode = populationTiersNode->first_node("food-good", 9, true); std::string foodGoodName = std::string(foodGoodNode->first_attribute("name", 4, true)->value()); foodGood.good = getGood(foodGoodName); foodGood.consumePerCycle = stringToDouble( foodGoodNode->first_attribute("consume-per-cycle", 17, true)->value()); // XML-Datei schließen delete xmlDocument; // Jetzt sind alle PopulationTiers geladen. Wir ordnen diese nun den MapObjectTypes zu. for (auto iter = mapObjectTypeToPopulationTierName.cbegin(); iter != mapObjectTypeToPopulationTierName.cend(); iter++) { MapObjectType* mapObjectType = iter->first; const std::string& populationTierString = iter->second; const PopulationTier* populationTier = getPopulationTier(populationTierString); if (populationTier == nullptr) { throw ErrorInConfigException(string_sprintf( _("Illegal value '%s' for populationTier."), populationTierString.c_str())); } mapObjectType->populationTier = populationTier; } mapObjectTypeToPopulationTierName.clear(); // Daten wegräumen, brauchen wir nicht mehr }