1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Merge pull request #6099 from Laserlicht/kingdom_overview

kingdom overview dwellings for mods
This commit is contained in:
Ivan Savenko
2025-09-21 20:19:17 +03:00
committed by GitHub
7 changed files with 43 additions and 7 deletions

View File

@@ -506,15 +506,31 @@ void CKingdomInterface::generateObjectsList(const std::vector<const CGObjectInst
for(const CGObjectInstance * object : ownedObjects)
{
//Dwellings
if(object->ID == Obj::CREATURE_GENERATOR1)
if(auto * dwelling = dynamic_cast<const CGDwelling *>(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<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>();

View File

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

View File

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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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;