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:
@@ -506,15 +506,31 @@ void CKingdomInterface::generateObjectsList(const std::vector<const CGObjectInst
|
|||||||
for(const CGObjectInstance * object : ownedObjects)
|
for(const CGObjectInstance * object : ownedObjects)
|
||||||
{
|
{
|
||||||
//Dwellings
|
//Dwellings
|
||||||
if(object->ID == Obj::CREATURE_GENERATOR1)
|
if(auto * dwelling = dynamic_cast<const CGDwelling *>(object))
|
||||||
{
|
{
|
||||||
OwnedObjectInfo & info = visibleObjects[object->subID];
|
auto kingdomOverviewImage = dwelling->getKingdomOverviewImage();
|
||||||
if(info.count++ == 0)
|
|
||||||
|
if(!kingdomOverviewImage.empty())
|
||||||
{
|
{
|
||||||
info.hoverText = object->getObjectName();
|
OwnedObjectInfo & info = visibleObjects[object->subID];
|
||||||
info.imageID = 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
|
//Special objects from idToImage map that should be displayed in objects list
|
||||||
auto iter = idToImage.find(std::make_pair(object->ID, object->subID));
|
auto iter = idToImage.find(std::make_pair(object->ID, object->subID));
|
||||||
if(iter != idToImage.end())
|
if(iter != idToImage.end())
|
||||||
@@ -543,7 +559,7 @@ std::shared_ptr<CIntObject> CKingdomInterface::createOwnedObject(size_t index)
|
|||||||
{
|
{
|
||||||
OwnedObjectInfo & obj = objects[index];
|
OwnedObjectInfo & obj = objects[index];
|
||||||
std::string value = std::to_string(obj.count);
|
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::make_shared<InfoBox>(Point(), InfoBox::POS_CORNER, InfoBox::SIZE_SMALL, data);
|
||||||
}
|
}
|
||||||
return std::shared_ptr<CIntObject>();
|
return std::shared_ptr<CIntObject>();
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ private:
|
|||||||
struct OwnedObjectInfo
|
struct OwnedObjectInfo
|
||||||
{
|
{
|
||||||
int imageID;
|
int imageID;
|
||||||
|
AnimationPath imagePath;
|
||||||
ui32 count;
|
ui32 count;
|
||||||
std::string hoverText;
|
std::string hoverText;
|
||||||
OwnedObjectInfo():
|
OwnedObjectInfo():
|
||||||
|
|||||||
@@ -22,7 +22,10 @@
|
|||||||
"guards" : true,
|
"guards" : true,
|
||||||
"guards" : [
|
"guards" : [
|
||||||
{ "amount" : 12, "type" : "earthElemental" }
|
{ "amount" : 12, "type" : "earthElemental" }
|
||||||
]
|
],
|
||||||
|
|
||||||
|
/// Image showed on kingdom overview (animation; only frame 0 displayed)
|
||||||
|
"kingdomOverviewImage" : "image.def"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ void DwellingInstanceConstructor::initTypeData(const JsonNode & input)
|
|||||||
}
|
}
|
||||||
guards = input["guards"];
|
guards = input["guards"];
|
||||||
bannedForRandomDwelling = input["bannedForRandomDwelling"].Bool();
|
bannedForRandomDwelling = input["bannedForRandomDwelling"].Bool();
|
||||||
|
kingdomOverviewImage = AnimationPath::fromJson(input["kingdomOverviewImage"]);
|
||||||
|
|
||||||
for (const auto & mapTemplate : getTemplates())
|
for (const auto & mapTemplate : getTemplates())
|
||||||
onTemplateAdded(mapTemplate);
|
onTemplateAdded(mapTemplate);
|
||||||
@@ -179,4 +180,9 @@ std::vector<const CCreature *> DwellingInstanceConstructor::getProducedCreatures
|
|||||||
return creatures;
|
return creatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AnimationPath DwellingInstanceConstructor::getKingdomOverviewImage() const
|
||||||
|
{
|
||||||
|
return kingdomOverviewImage;
|
||||||
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class DwellingInstanceConstructor : public CDefaultObjectTypeHandler<CGDwelling>
|
|||||||
|
|
||||||
JsonNode guards;
|
JsonNode guards;
|
||||||
bool bannedForRandomDwelling = false;
|
bool bannedForRandomDwelling = false;
|
||||||
|
AnimationPath kingdomOverviewImage;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool objectFilter(const CGObjectInstance * obj, std::shared_ptr<const ObjectTemplate> tmpl) const override;
|
bool objectFilter(const CGObjectInstance * obj, std::shared_ptr<const ObjectTemplate> tmpl) const override;
|
||||||
@@ -39,6 +40,7 @@ public:
|
|||||||
bool isBannedForRandomDwelling() const;
|
bool isBannedForRandomDwelling() const;
|
||||||
bool producesCreature(const CCreature * crea) const;
|
bool producesCreature(const CCreature * crea) const;
|
||||||
std::vector<const CCreature *> getProducedCreatures() const;
|
std::vector<const CCreature *> getProducedCreatures() const;
|
||||||
|
AnimationPath getKingdomOverviewImage() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|||||||
@@ -586,6 +586,13 @@ ResourceSet CGDwelling::dailyIncome() const
|
|||||||
return {};
|
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
|
std::vector<CreatureID> CGDwelling::providedCreatures() const
|
||||||
{
|
{
|
||||||
if (ID == Obj::WAR_MACHINE_FACTORY || ID == Obj::REFUGEE_CAMP)
|
if (ID == Obj::WAR_MACHINE_FACTORY || ID == Obj::REFUGEE_CAMP)
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public:
|
|||||||
const IOwnableObject * asOwnable() const final;
|
const IOwnableObject * asOwnable() const final;
|
||||||
ResourceSet dailyIncome() const override;
|
ResourceSet dailyIncome() const override;
|
||||||
std::vector<CreatureID> providedCreatures() const override;
|
std::vector<CreatureID> providedCreatures() const override;
|
||||||
|
AnimationPath getKingdomOverviewImage() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void serializeJsonOptions(JsonSerializeFormat & handler) override;
|
void serializeJsonOptions(JsonSerializeFormat & handler) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user