mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-02 00:10:22 +02:00
Merge pull request #4850 from IvanSavenko/object_descriptions
Implemented optional descriptions for market map objects
This commit is contained in:
commit
e45be3c5e6
@ -205,6 +205,12 @@ AnimationPath BoatInstanceConstructor::getBoatAnimationName() const
|
|||||||
|
|
||||||
void MarketInstanceConstructor::initTypeData(const JsonNode & input)
|
void MarketInstanceConstructor::initTypeData(const JsonNode & input)
|
||||||
{
|
{
|
||||||
|
if (!input["description"].isNull())
|
||||||
|
{
|
||||||
|
description = input["description"].String();
|
||||||
|
VLC->generaltexth->registerString(input.getModScope(), TextIdentifier(getBaseTextID(), "description"), description);
|
||||||
|
}
|
||||||
|
|
||||||
for(auto & element : input["modes"].Vector())
|
for(auto & element : input["modes"].Vector())
|
||||||
{
|
{
|
||||||
if(MappedKeys::MARKET_NAMES_TO_TYPES.count(element.String()))
|
if(MappedKeys::MARKET_NAMES_TO_TYPES.count(element.String()))
|
||||||
@ -218,6 +224,11 @@ void MarketInstanceConstructor::initTypeData(const JsonNode & input)
|
|||||||
speech = input["speech"].String();
|
speech = input["speech"].String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MarketInstanceConstructor::hasDescription() const
|
||||||
|
{
|
||||||
|
return !description.empty();
|
||||||
|
}
|
||||||
|
|
||||||
CGMarket * MarketInstanceConstructor::createObject(IGameCallback * cb) const
|
CGMarket * MarketInstanceConstructor::createObject(IGameCallback * cb) const
|
||||||
{
|
{
|
||||||
if(marketModes.size() == 1)
|
if(marketModes.size() == 1)
|
||||||
|
@ -118,6 +118,7 @@ protected:
|
|||||||
JsonNode predefinedOffer;
|
JsonNode predefinedOffer;
|
||||||
int marketEfficiency;
|
int marketEfficiency;
|
||||||
|
|
||||||
|
std::string description;
|
||||||
std::string title;
|
std::string title;
|
||||||
std::string speech;
|
std::string speech;
|
||||||
|
|
||||||
@ -127,6 +128,7 @@ public:
|
|||||||
void randomizeObject(CGMarket * object, vstd::RNG & rng) const override;
|
void randomizeObject(CGMarket * object, vstd::RNG & rng) const override;
|
||||||
|
|
||||||
const std::set<EMarketMode> & availableModes() const;
|
const std::set<EMarketMode> & availableModes() const;
|
||||||
|
bool hasDescription() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,6 +39,22 @@ void CGMarket::onHeroVisit(const CGHeroInstance * h) const
|
|||||||
cb->showObjectWindow(this, EOpenWindowMode::MARKET_WINDOW, h, true);
|
cb->showObjectWindow(this, EOpenWindowMode::MARKET_WINDOW, h, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CGMarket::getPopupText(PlayerColor player) const
|
||||||
|
{
|
||||||
|
if (!getMarketHandler()->hasDescription())
|
||||||
|
return getHoverText(player);
|
||||||
|
|
||||||
|
MetaString message = MetaString::createFromRawString("{%s}\r\n\r\n%s");
|
||||||
|
message.replaceName(ID);
|
||||||
|
message.replaceTextID(TextIdentifier(getObjectHandler()->getBaseTextID(), "description").get());
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CGMarket::getPopupText(const CGHeroInstance * hero) const
|
||||||
|
{
|
||||||
|
return getPopupText(hero->getOwner());
|
||||||
|
}
|
||||||
|
|
||||||
int CGMarket::getMarketEfficiency() const
|
int CGMarket::getMarketEfficiency() const
|
||||||
{
|
{
|
||||||
return marketEfficiency;
|
return marketEfficiency;
|
||||||
@ -49,12 +65,16 @@ int CGMarket::availableUnits(EMarketMode mode, int marketItemSerial) const
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<EMarketMode> CGMarket::availableModes() const
|
std::shared_ptr<MarketInstanceConstructor> CGMarket::getMarketHandler() const
|
||||||
{
|
{
|
||||||
const auto & baseHandler = getObjectHandler();
|
const auto & baseHandler = getObjectHandler();
|
||||||
const auto & ourHandler = std::dynamic_pointer_cast<MarketInstanceConstructor>(baseHandler);
|
const auto & ourHandler = std::dynamic_pointer_cast<MarketInstanceConstructor>(baseHandler);
|
||||||
|
return ourHandler;
|
||||||
|
}
|
||||||
|
|
||||||
return ourHandler->availableModes();
|
std::set<EMarketMode> CGMarket::availableModes() const
|
||||||
|
{
|
||||||
|
return getMarketHandler()->availableModes();
|
||||||
}
|
}
|
||||||
|
|
||||||
CGMarket::CGMarket(IGameCallback *cb):
|
CGMarket::CGMarket(IGameCallback *cb):
|
||||||
|
@ -15,8 +15,12 @@
|
|||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
class MarketInstanceConstructor;
|
||||||
|
|
||||||
class DLL_LINKAGE CGMarket : public CGObjectInstance, public IMarket
|
class DLL_LINKAGE CGMarket : public CGObjectInstance, public IMarket
|
||||||
{
|
{
|
||||||
|
std::shared_ptr<MarketInstanceConstructor> getMarketHandler() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int marketEfficiency;
|
int marketEfficiency;
|
||||||
|
|
||||||
@ -25,6 +29,9 @@ public:
|
|||||||
void onHeroVisit(const CGHeroInstance * h) const override; //open trading window
|
void onHeroVisit(const CGHeroInstance * h) const override; //open trading window
|
||||||
void initObj(vstd::RNG & rand) override;//set skills for trade
|
void initObj(vstd::RNG & rand) override;//set skills for trade
|
||||||
|
|
||||||
|
std::string getPopupText(PlayerColor player) const override;
|
||||||
|
std::string getPopupText(const CGHeroInstance * hero) const override;
|
||||||
|
|
||||||
///IMarket
|
///IMarket
|
||||||
ObjectInstanceID getObjInstanceID() const override;
|
ObjectInstanceID getObjInstanceID() const override;
|
||||||
int getMarketEfficiency() const override;
|
int getMarketEfficiency() const override;
|
||||||
|
@ -1333,6 +1333,22 @@ void HillFort::fillUpgradeInfo(UpgradeInfo & info, const CStackInstance &stack)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string HillFort::getPopupText(PlayerColor player) const
|
||||||
|
{
|
||||||
|
MetaString message = MetaString::createFromRawString("{%s}\r\n\r\n%s");
|
||||||
|
|
||||||
|
message.replaceName(ID);
|
||||||
|
message.replaceTextID(getDescriptionToolTip());
|
||||||
|
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string HillFort::getPopupText(const CGHeroInstance * hero) const
|
||||||
|
{
|
||||||
|
return getPopupText(hero->getOwner());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string HillFort::getDescriptionToolTip() const
|
std::string HillFort::getDescriptionToolTip() const
|
||||||
{
|
{
|
||||||
return TextIdentifier(getObjectHandler()->getBaseTextID(), "description").get();
|
return TextIdentifier(getObjectHandler()->getBaseTextID(), "description").get();
|
||||||
|
@ -437,6 +437,9 @@ protected:
|
|||||||
public:
|
public:
|
||||||
using CGObjectInstance::CGObjectInstance;
|
using CGObjectInstance::CGObjectInstance;
|
||||||
|
|
||||||
|
std::string getPopupText(PlayerColor player) const override;
|
||||||
|
std::string getPopupText(const CGHeroInstance * hero) const override;
|
||||||
|
|
||||||
std::string getDescriptionToolTip() const;
|
std::string getDescriptionToolTip() const;
|
||||||
std::string getUnavailableUpgradeMessage() const;
|
std::string getUnavailableUpgradeMessage() const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user