From 46619f35fe6a7c527609d6df1c0c881e6915c4bb Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 4 Oct 2025 17:14:24 +0200 Subject: [PATCH] load mine image in kingdom overview --- client/windows/CKingdomInterface.cpp | 44 +++++++++++++++++-- client/windows/CKingdomInterface.h | 4 ++ .../CommonConstructors.cpp | 7 +++ .../CommonConstructors.h | 2 + 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/client/windows/CKingdomInterface.cpp b/client/windows/CKingdomInterface.cpp index db0e0af77..d2abecf6a 100644 --- a/client/windows/CKingdomInterface.cpp +++ b/client/windows/CKingdomInterface.cpp @@ -43,6 +43,8 @@ #include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/mapObjects/CGTownInstance.h" #include "../../lib/mapObjects/MiscObjects.h" +#include "../../lib/mapObjectConstructors/CommonConstructors.h" +#include "../../lib/mapObjectConstructors/CObjectClassesHandler.h" #include "texts/CGeneralTextHandler.h" #include "../../lib/GameSettings.h" @@ -595,6 +597,25 @@ std::shared_ptr CKingdomInterface::createMainTab(size_t index) } } +std::shared_ptr CKingdomInterface::getMineHandler(const GameResID & res) +{ + std::shared_ptr mineHandler; + for(auto & subObjID : LIBRARY->objtypeh->knownSubObjects(Obj::MINE)) + { + auto handler = std::dynamic_pointer_cast(LIBRARY->objtypeh->getHandlerFor(Obj::MINE, subObjID)); + if(handler->getResourceType() == res) + mineHandler = handler; + } + + if(!mineHandler) + { + logGlobal->error("No mine for resource %s found!", res.toResource()->getJsonKey()); + return nullptr; + } + + return mineHandler; +} + void CKingdomInterface::generateMinesList(const std::vector & ownedObjects, int line) { OBJECT_CONSTRUCTION; @@ -625,10 +646,22 @@ void CKingdomInterface::generateMinesList(const std::vectorinterface()->cb->getPlayerState(GAME->interface()->playerID)->valOfBonuses(BonusType::RESOURCES_CONSTANT_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD))) * playerSettings->handicap.percentIncome / 100; totalIncome += GAME->interface()->cb->getPlayerState(GAME->interface()->playerID)->valOfBonuses(BonusType::RESOURCES_TOWN_MULTIPLYING_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD))) * towns.size() * playerSettings->handicap.percentIncome / 100; - for(int i=0; i(value, "", AnimationPath::builtin("OVMINES"), i, LIBRARY->generaltexth->translate("core.minename", i)); + std::shared_ptr data; + if(line == 0) + data = std::make_shared(value, "", AnimationPath::builtin("OVMINES"), i, LIBRARY->generaltexth->translate("core.minename", i)); + else + { + int resID = line * GameConstants::RESOURCE_QUANTITY + i; + if(resID >= LIBRARY->resourceTypeHandler->getAllObjects().size()) + break; + auto mine = getMineHandler(GameResID(resID)); + if(!mine || mine->getKingdomOverviewImage().empty()) + continue; + data = std::make_shared(value, "", mine->getKingdomOverviewImage(), 0, mine->getNameTranslated()); + } minesBox[i] = std::make_shared(Point(20+i*80, 31+footerPos), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, data); minesBox[i]->removeUsedEvents(LCLICK|SHOW_POPUP); //fixes #890 - mines boxes ignore clicks } @@ -636,7 +669,12 @@ void CKingdomInterface::generateMinesList(const std::vectorresourceTypeHandler->getAllObjects().size() > GameConstants::RESOURCE_QUANTITY) { int lines = vstd::divideAndCeil(LIBRARY->resourceTypeHandler->getAllObjects().size(), GameConstants::RESOURCE_QUANTITY); - minesSlider = std::make_shared(Point(723, 495), 57, [this, ownedObjects](int to){ generateMinesList(ownedObjects, to); setRedrawParent(true); redraw(); }, 1, lines, line, Orientation::VERTICAL, CSlider::BROWN); + minesSlider = std::make_shared(Point(723, 495), 57, [this, ownedObjects](int to){ + generateMinesList(ownedObjects, to); + statusbar->clear(); + setRedrawParent(true); + redraw(); + }, 1, lines, line, Orientation::VERTICAL, CSlider::BROWN); minesSlider->setPanningStep(57); minesSlider->setScrollBounds(Rect(-735, 0, 735, 57)); } diff --git a/client/windows/CKingdomInterface.h b/client/windows/CKingdomInterface.h index 2a1f5e167..7b2f231f0 100644 --- a/client/windows/CKingdomInterface.h +++ b/client/windows/CKingdomInterface.h @@ -11,6 +11,8 @@ #include "CWindowWithArtifacts.h" +#include "../../lib/mapObjectConstructors/CommonConstructors.h" + VCMI_LIB_NAMESPACE_BEGIN class CGObjectInstance; VCMI_LIB_NAMESPACE_END @@ -242,6 +244,8 @@ private: void activateTab(size_t which); + std::shared_ptr getMineHandler(const GameResID & res); + //Internal functions used during construction void generateButtons(); void generateObjectsList(const std::vector &ownedObjects); diff --git a/lib/mapObjectConstructors/CommonConstructors.cpp b/lib/mapObjectConstructors/CommonConstructors.cpp index 74929af7e..9f946e5ca 100644 --- a/lib/mapObjectConstructors/CommonConstructors.cpp +++ b/lib/mapObjectConstructors/CommonConstructors.cpp @@ -107,6 +107,8 @@ void MineInstanceConstructor::initTypeData(const JsonNode & input) if (!config["description"].isNull()) LIBRARY->generaltexth->registerString(config.getModScope(), getDescriptionTextID(), config["description"]); + + kingdomOverviewImage = AnimationPath::fromJson(config["kingdomOverviewImage"]); } GameResID MineInstanceConstructor::getResourceType() const @@ -129,6 +131,11 @@ std::string MineInstanceConstructor::getDescriptionTranslated() const return LIBRARY->generaltexth->translate(getDescriptionTextID()); } +AnimationPath MineInstanceConstructor::getKingdomOverviewImage() const +{ + return kingdomOverviewImage; +} + void CTownInstanceConstructor::initTypeData(const JsonNode & input) { LIBRARY->identifiers()->requestIdentifier("faction", input["faction"], [&](si32 index) diff --git a/lib/mapObjectConstructors/CommonConstructors.h b/lib/mapObjectConstructors/CommonConstructors.h index 38851f897..40f409eb9 100644 --- a/lib/mapObjectConstructors/CommonConstructors.h +++ b/lib/mapObjectConstructors/CommonConstructors.h @@ -67,6 +67,7 @@ class DLL_LINKAGE MineInstanceConstructor : public CDefaultObjectTypeHandler