diff --git a/client/windows/CKingdomInterface.cpp b/client/windows/CKingdomInterface.cpp index 2023613c4..1002f8dc7 100644 --- a/client/windows/CKingdomInterface.cpp +++ b/client/windows/CKingdomInterface.cpp @@ -506,15 +506,31 @@ void CKingdomInterface::generateObjectsList(const std::vectorID == Obj::CREATURE_GENERATOR1) + if(auto * dwelling = dynamic_cast(object)) { - OwnedObjectInfo & info = visibleObjects[object->subID]; - if(info.count++ == 0) + auto kingdomOverviewImage = dwelling->getKingdomOverviewImage(); + + if(!kingdomOverviewImage.empty()) { - info.hoverText = object->getObjectName(); - info.imageID = object->subID; + OwnedObjectInfo & info = visibleObjects[object->subID]; + if(info.count++ == 0) + { + info.hoverText = object->getObjectName(); + info.imagePath = kingdomOverviewImage; + info.imageID = 0; + } + } + else if(object->ID == Obj::CREATURE_GENERATOR1) + { + OwnedObjectInfo & info = visibleObjects[object->subID]; + if(info.count++ == 0) + { + info.hoverText = object->getObjectName(); + info.imageID = object->subID; + } } } + //Special objects from idToImage map that should be displayed in objects list auto iter = idToImage.find(std::make_pair(object->ID, object->subID)); if(iter != idToImage.end()) @@ -543,7 +559,7 @@ std::shared_ptr CKingdomInterface::createOwnedObject(size_t index) { OwnedObjectInfo & obj = objects[index]; std::string value = std::to_string(obj.count); - auto data = std::make_shared(value, "", AnimationPath::builtin("FLAGPORT"), obj.imageID, obj.hoverText); + auto data = std::make_shared(value, "", obj.imagePath.empty() ? AnimationPath::builtin("FLAGPORT") : obj.imagePath, obj.imageID, obj.hoverText); return std::make_shared(Point(), InfoBox::POS_CORNER, InfoBox::SIZE_SMALL, data); } return std::shared_ptr(); diff --git a/client/windows/CKingdomInterface.h b/client/windows/CKingdomInterface.h index 940a60dad..e45fb9315 100644 --- a/client/windows/CKingdomInterface.h +++ b/client/windows/CKingdomInterface.h @@ -207,6 +207,7 @@ private: struct OwnedObjectInfo { int imageID; + AnimationPath imagePath; ui32 count; std::string hoverText; OwnedObjectInfo(): diff --git a/docs/modders/Map_Objects/Dwelling.md b/docs/modders/Map_Objects/Dwelling.md index 39ede9356..9fb5cc783 100644 --- a/docs/modders/Map_Objects/Dwelling.md +++ b/docs/modders/Map_Objects/Dwelling.md @@ -22,7 +22,10 @@ "guards" : true, "guards" : [ { "amount" : 12, "type" : "earthElemental" } - ] + ], + + /// Image showed on kingdom overview (animation; only frame 0 displayed) + "kingdomOverviewImage" : "image.def" } ``` diff --git a/lib/mapObjectConstructors/DwellingInstanceConstructor.cpp b/lib/mapObjectConstructors/DwellingInstanceConstructor.cpp index c468ea3e2..e3e6cbb45 100644 --- a/lib/mapObjectConstructors/DwellingInstanceConstructor.cpp +++ b/lib/mapObjectConstructors/DwellingInstanceConstructor.cpp @@ -55,6 +55,7 @@ void DwellingInstanceConstructor::initTypeData(const JsonNode & input) } guards = input["guards"]; bannedForRandomDwelling = input["bannedForRandomDwelling"].Bool(); + kingdomOverviewImage = AnimationPath::fromJson(input["kingdomOverviewImage"]); for (const auto & mapTemplate : getTemplates()) onTemplateAdded(mapTemplate); @@ -179,4 +180,9 @@ std::vector DwellingInstanceConstructor::getProducedCreatures return creatures; } +AnimationPath DwellingInstanceConstructor::getKingdomOverviewImage() const +{ + return kingdomOverviewImage; +} + VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjectConstructors/DwellingInstanceConstructor.h b/lib/mapObjectConstructors/DwellingInstanceConstructor.h index 71efa79a1..4da3b2800 100644 --- a/lib/mapObjectConstructors/DwellingInstanceConstructor.h +++ b/lib/mapObjectConstructors/DwellingInstanceConstructor.h @@ -24,6 +24,7 @@ class DwellingInstanceConstructor : public CDefaultObjectTypeHandler JsonNode guards; bool bannedForRandomDwelling = false; + AnimationPath kingdomOverviewImage; protected: bool objectFilter(const CGObjectInstance * obj, std::shared_ptr tmpl) const override; @@ -39,6 +40,7 @@ public: bool isBannedForRandomDwelling() const; bool producesCreature(const CCreature * crea) const; std::vector getProducedCreatures() const; + AnimationPath getKingdomOverviewImage() const; }; VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/CGDwelling.cpp b/lib/mapObjects/CGDwelling.cpp index 34599c211..012b7df3e 100644 --- a/lib/mapObjects/CGDwelling.cpp +++ b/lib/mapObjects/CGDwelling.cpp @@ -586,6 +586,13 @@ ResourceSet CGDwelling::dailyIncome() const return {}; } +AnimationPath CGDwelling::getKingdomOverviewImage() const +{ + const auto & baseHandler = getObjectHandler(); + const auto & ourHandler = std::dynamic_pointer_cast(baseHandler); + return ourHandler ? ourHandler->getKingdomOverviewImage() : AnimationPath{}; +} + std::vector CGDwelling::providedCreatures() const { if (ID == Obj::WAR_MACHINE_FACTORY || ID == Obj::REFUGEE_CAMP) diff --git a/lib/mapObjects/CGDwelling.h b/lib/mapObjects/CGDwelling.h index e69ce3dd1..07ee00923 100644 --- a/lib/mapObjects/CGDwelling.h +++ b/lib/mapObjects/CGDwelling.h @@ -47,6 +47,7 @@ public: const IOwnableObject * asOwnable() const final; ResourceSet dailyIncome() const override; std::vector providedCreatures() const override; + AnimationPath getKingdomOverviewImage() const; protected: void serializeJsonOptions(JsonSerializeFormat & handler) override;