1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

added CMarketWindow::getMarketTitle()

This commit is contained in:
SoundSSGood 2024-08-24 13:05:11 +03:00
parent 0c5022cae8
commit 4035ab1550
5 changed files with 23 additions and 13 deletions

View File

@ -27,6 +27,7 @@
#include "../CGameInfo.h"
#include "../CPlayerInterface.h"
#include "../../lib/entities/building/CBuilding.h"
#include "../../lib/texts/CGeneralTextHandler.h"
#include "../../lib/mapObjects/CGTownInstance.h"
#include "../../lib/mapObjects/CGMarket.h"
@ -182,13 +183,28 @@ void CMarketWindow::initWidgetInternals(const EMarketMode mode, const std::pair<
redraw();
}
std::string CMarketWindow::getMarketTitle(const ObjectInstanceID marketId, const EMarketMode mode) const
{
assert(LOCPLINT->cb->getMarket(marketId));
assert(vstd::contains(LOCPLINT->cb->getMarket(marketId)->availableModes(), mode));
if(const auto town = LOCPLINT->cb->getTown(marketId))
{
for(const auto & buildingId : town->getBuildings())
{
if(const auto building = town->town->buildings.at(buildingId); vstd::contains(building->marketModes, mode))
return building->getNameTranslated();
}
}
return LOCPLINT->cb->getObj(marketId)->getObjectName();
}
void CMarketWindow::createArtifactsBuying(const IMarket * market, const CGHeroInstance * hero)
{
OBJECT_CONSTRUCTION;
background = createBg(ImagePath::builtin("TPMRKABS.bmp"), PLAYER_COLORED);
marketWidget = std::make_shared<CArtifactsBuying>(market, hero, LOCPLINT->cb->getTown(market->getObjInstanceID()) ?
VLC->generaltexth->translate("building.core.conflux.special1.name") : CGI->generaltexth->allTexts[349]);
marketWidget = std::make_shared<CArtifactsBuying>(market, hero, getMarketTitle(market->getObjInstanceID(), EMarketMode::RESOURCE_ARTIFACT));
initWidgetInternals(EMarketMode::RESOURCE_ARTIFACT, CGI->generaltexth->zelp[600]);
}
@ -200,9 +216,7 @@ void CMarketWindow::createArtifactsSelling(const IMarket * market, const CGHeroI
// Create image that copies part of background containing slot MISC_1 into position of slot MISC_5
artSlotBack = std::make_shared<CPicture>(background->getSurface(), Rect(20, 187, 47, 47), 0, 0);
artSlotBack->moveTo(pos.topLeft() + Point(18, 339));
const auto mapObj = LOCPLINT->cb->getObj(market->getObjInstanceID());
auto artsSellingMarket = std::make_shared<CArtifactsSelling>(market, hero, LOCPLINT->cb->getTown(mapObj->id) ?
VLC->generaltexth->translate("building.core.conflux.special1.name") : mapObj->getObjectName());
auto artsSellingMarket = std::make_shared<CArtifactsSelling>(market, hero, getMarketTitle(market->getObjInstanceID(), EMarketMode::ARTIFACT_RESOURCE));
artSets.clear();
const auto heroArts = artsSellingMarket->getAOHset();
heroArts->showPopupCallback = [this, heroArts](CArtPlace & artPlace, const Point & cursorPosition){showArifactInfo(*heroArts, artPlace, cursorPosition);};

View File

@ -27,6 +27,7 @@ public:
private:
void createChangeModeButtons(EMarketMode currentMode, const IMarket * market, const CGHeroInstance * hero);
void initWidgetInternals(const EMarketMode mode, const std::pair<std::string, std::string> & quitButtonHelpContainer);
std::string getMarketTitle(const ObjectInstanceID marketId, const EMarketMode mode) const;
void createArtifactsBuying(const IMarket * market, const CGHeroInstance * hero);
void createArtifactsSelling(const IMarket * market, const CGHeroInstance * hero);

View File

@ -97,7 +97,7 @@
"type" : "array",
"description" : "Bonuses that are provided by this building in any town where this building has been built. Only affects town itself (including siege), to propagate effect to player or team please use bonus propagators",
"items" : { "$ref" : "bonus.json" }
}
},
"marketModes" : {
"type" : "array",
"enum" : [ "resource-resource", "resource-player", "creature-resource", "resource-artifact", "artifact-resource", "artifact-experience", "creature-experience", "creature-undead", "resource-skill"],

View File

@ -86,7 +86,7 @@ public:
STRONG_INLINE
bool IsTradeBuilding() const
{
return bid == BuildingID::MARKETPLACE || subId == BuildingSubID::ARTIFACT_MERCHANT || subId == BuildingSubID::FREELANCERS_GUILD;
return !marketModes.empty();
}
void addNewBonus(const std::shared_ptr<Bonus> & b, BonusList & bonusList) const;

View File

@ -908,12 +908,7 @@ const CArmedInstance * CGTownInstance::getUpperArmy() const
bool CGTownInstance::hasBuiltSomeTradeBuilding() const
{
for(const auto & bid : builtBuildings)
{
if(town->buildings.at(bid)->IsTradeBuilding())
return true;
}
return false;
return availableModes().empty() ? false : true;
}
bool CGTownInstance::hasBuilt(BuildingSubID::EBuildingSubID buildingID) const