Browse Source

kingdom overview dwellings for mods

Laserlicht 2 months ago
parent
commit
a3a234f8e0

+ 17 - 1
client/windows/CKingdomInterface.cpp

@@ -515,6 +515,22 @@ void CKingdomInterface::generateObjectsList(const std::vector<const CGObjectInst
 				info.imageID = object->subID;
 			}
 		}
+		else if(auto * dwelling = dynamic_cast<const CGDwelling *>(object))
+		{
+			auto kingdomOverviewImage = dwelling->getKingdomOverviewImage();
+
+			if(!kingdomOverviewImage.empty())
+			{
+				OwnedObjectInfo & info = visibleObjects[object->subID];
+				if(info.count++ == 0)
+				{
+					info.hoverText = object->getObjectName();
+					info.imagePath = kingdomOverviewImage;
+					info.imageID = 0;
+				}
+			}
+		}
+
 		//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<CIntObject> CKingdomInterface::createOwnedObject(size_t index)
 	{
 		OwnedObjectInfo & obj = objects[index];
 		std::string value = std::to_string(obj.count);
-		auto data = std::make_shared<InfoBoxCustom>(value, "", AnimationPath::builtin("FLAGPORT"), obj.imageID, obj.hoverText);
+		auto data = std::make_shared<InfoBoxCustom>(value, "", obj.imagePath.empty() ? AnimationPath::builtin("FLAGPORT") : obj.imagePath, obj.imageID, obj.hoverText);
 		return std::make_shared<InfoBox>(Point(), InfoBox::POS_CORNER, InfoBox::SIZE_SMALL, data);
 	}
 	return std::shared_ptr<CIntObject>();

+ 1 - 0
client/windows/CKingdomInterface.h

@@ -207,6 +207,7 @@ private:
 	struct OwnedObjectInfo
 	{
 		int imageID;
+		AnimationPath imagePath;
 		ui32 count;
 		std::string hoverText;
 		OwnedObjectInfo():

+ 4 - 1
docs/modders/Map_Objects/Dwelling.md

@@ -22,7 +22,10 @@
 	"guards" : true,
 	"guards" : [
 		{ "amount" : 12, "type" : "earthElemental" }
-	]
+	],
+
+	/// Optional image showed on kingdom overview (animation; only frame 0 displayed)
+	"kingdomOverviewImage" : "image.def"
 }
 ```
 

+ 6 - 0
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<const CCreature *> DwellingInstanceConstructor::getProducedCreatures
 	return creatures;
 }
 
+AnimationPath DwellingInstanceConstructor::getKingdomOverviewImage() const
+{
+	return kingdomOverviewImage;
+}
+
 VCMI_LIB_NAMESPACE_END

+ 2 - 0
lib/mapObjectConstructors/DwellingInstanceConstructor.h

@@ -24,6 +24,7 @@ class DwellingInstanceConstructor : public CDefaultObjectTypeHandler<CGDwelling>
 
 	JsonNode guards;
 	bool bannedForRandomDwelling = false;
+	AnimationPath kingdomOverviewImage;
 
 protected:
 	bool objectFilter(const CGObjectInstance * obj, std::shared_ptr<const ObjectTemplate> tmpl) const override;
@@ -39,6 +40,7 @@ public:
 	bool isBannedForRandomDwelling() const;
 	bool producesCreature(const CCreature * crea) const;
 	std::vector<const CCreature *> getProducedCreatures() const;
+	AnimationPath getKingdomOverviewImage() const;
 };
 
 VCMI_LIB_NAMESPACE_END

+ 7 - 0
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<const DwellingInstanceConstructor>(baseHandler);
+	return ourHandler ? ourHandler->getKingdomOverviewImage() : AnimationPath{};
+}
+
 std::vector<CreatureID> CGDwelling::providedCreatures() const
 {
 	if (ID == Obj::WAR_MACHINE_FACTORY || ID == Obj::REFUGEE_CAMP)

+ 1 - 0
lib/mapObjects/CGDwelling.h

@@ -47,6 +47,7 @@ public:
 	const IOwnableObject * asOwnable() const final;
 	ResourceSet dailyIncome() const override;
 	std::vector<CreatureID> providedCreatures() const override;
+	AnimationPath getKingdomOverviewImage() const;
 
 protected:
 	void serializeJsonOptions(JsonSerializeFormat & handler) override;