From a833b53432bba9471c2a8e45c09e906eed3ca995 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 21 Sep 2025 19:35:23 +0200 Subject: [PATCH] resbar --- client/adventureMap/AdventureMapWidget.cpp | 39 +++++++++++++++------- client/adventureMap/AdventureMapWidget.h | 1 + client/adventureMap/CResDataBar.cpp | 16 +++++++++ client/adventureMap/CResDataBar.h | 1 + client/render/AssetGenerator.cpp | 19 +++++++++++ client/render/AssetGenerator.h | 1 + config/widgets/adventureMap.json | 5 ++- 7 files changed, 67 insertions(+), 15 deletions(-) diff --git a/client/adventureMap/AdventureMapWidget.cpp b/client/adventureMap/AdventureMapWidget.cpp index 65c0828a0..f91b2af09 100644 --- a/client/adventureMap/AdventureMapWidget.cpp +++ b/client/adventureMap/AdventureMapWidget.cpp @@ -43,18 +43,19 @@ AdventureMapWidget::AdventureMapWidget( std::shared_ptr s pos.w = ENGINE->screenDimensions().x; pos.h = ENGINE->screenDimensions().y; - REGISTER_BUILDER("adventureInfobar", &AdventureMapWidget::buildInfobox ); - REGISTER_BUILDER("adventureMapImage", &AdventureMapWidget::buildMapImage ); - REGISTER_BUILDER("adventureMapButton", &AdventureMapWidget::buildMapButton ); - REGISTER_BUILDER("adventureMapContainer", &AdventureMapWidget::buildMapContainer ); - REGISTER_BUILDER("adventureMapGameArea", &AdventureMapWidget::buildMapGameArea ); - REGISTER_BUILDER("adventureMapHeroList", &AdventureMapWidget::buildMapHeroList ); - REGISTER_BUILDER("adventureMapIcon", &AdventureMapWidget::buildMapIcon ); - REGISTER_BUILDER("adventureMapTownList", &AdventureMapWidget::buildMapTownList ); - REGISTER_BUILDER("adventureMinimap", &AdventureMapWidget::buildMinimap ); - REGISTER_BUILDER("adventureResourceDateBar", &AdventureMapWidget::buildResourceDateBar ); - REGISTER_BUILDER("adventureStatusBar", &AdventureMapWidget::buildStatusBar ); - REGISTER_BUILDER("adventurePlayerTexture", &AdventureMapWidget::buildTexturePlayerColored); + REGISTER_BUILDER("adventureInfobar", &AdventureMapWidget::buildInfobox ); + REGISTER_BUILDER("adventureMapImage", &AdventureMapWidget::buildMapImage ); + REGISTER_BUILDER("adventureMapButton", &AdventureMapWidget::buildMapButton ); + REGISTER_BUILDER("adventureMapContainer", &AdventureMapWidget::buildMapContainer ); + REGISTER_BUILDER("adventureMapGameArea", &AdventureMapWidget::buildMapGameArea ); + REGISTER_BUILDER("adventureMapHeroList", &AdventureMapWidget::buildMapHeroList ); + REGISTER_BUILDER("adventureMapIcon", &AdventureMapWidget::buildMapIcon ); + REGISTER_BUILDER("adventureMapTownList", &AdventureMapWidget::buildMapTownList ); + REGISTER_BUILDER("adventureMinimap", &AdventureMapWidget::buildMinimap ); + REGISTER_BUILDER("adventureResourceDateBar", &AdventureMapWidget::buildResourceDateBar ); + REGISTER_BUILDER("adventureStatusBar", &AdventureMapWidget::buildStatusBar ); + REGISTER_BUILDER("adventurePlayerTexture", &AdventureMapWidget::buildTexturePlayerColored); + REGISTER_BUILDER("adventureResourceAdditional", &AdventureMapWidget::buildResourceAdditional ); for (const auto & entry : shortcuts->getShortcuts()) addShortcut(entry.shortcut, entry.callback); @@ -316,6 +317,20 @@ std::shared_ptr AdventureMapWidget::buildTexturePlayerColored(const return std::make_shared(area); } +std::shared_ptr AdventureMapWidget::buildResourceAdditional(const JsonNode & input) +{ + OBJECT_CONSTRUCTION; + logGlobal->debug("Building widget ResourceAdditional"); + Rect area = readTargetArea(input["area"]); + auto obj = std::make_shared(); + auto result = std::make_shared(ImagePath::builtin("ResBarElement"), area.topLeft()); + result->setResourcePosition(GameResID::CRYSTAL, Point(35, 3)); + addWidget("", result); + obj->addChild(result.get()); + //auto area = std::make_shared(area) + return obj; +} + std::shared_ptr AdventureMapWidget::getHeroList() { return heroList; diff --git a/client/adventureMap/AdventureMapWidget.h b/client/adventureMap/AdventureMapWidget.h index 742e7d683..3be5a264a 100644 --- a/client/adventureMap/AdventureMapWidget.h +++ b/client/adventureMap/AdventureMapWidget.h @@ -55,6 +55,7 @@ class AdventureMapWidget : public InterfaceObjectConfigurable std::shared_ptr buildResourceDateBar(const JsonNode & input); std::shared_ptr buildStatusBar(const JsonNode & input); std::shared_ptr buildTexturePlayerColored(const JsonNode &); + std::shared_ptr buildResourceAdditional(const JsonNode &); void setPlayerChildren(CIntObject * widget, const PlayerColor & player); void updateActiveStateChildden(CIntObject * widget); diff --git a/client/adventureMap/CResDataBar.cpp b/client/adventureMap/CResDataBar.cpp index ab540b935..16e622609 100644 --- a/client/adventureMap/CResDataBar.cpp +++ b/client/adventureMap/CResDataBar.cpp @@ -18,15 +18,19 @@ #include "../GameInstance.h" #include "../gui/TextAlignment.h" #include "../widgets/Images.h" +#include "../widgets/CComponent.h" +#include "../windows/InfoWindows.h" #include "../../lib/CConfigHandler.h" #include "../../lib/callback/CCallback.h" #include "../../lib/texts/CGeneralTextHandler.h" #include "../../lib/ResourceSet.h" #include "../../lib/GameLibrary.h" +#include "../../lib/networkPacks/Component.h" CResDataBar::CResDataBar(const ImagePath & imageName, const Point & position) { + addUsedEvents(SHOW_POPUP); pos.x += position.x; pos.y += position.y; @@ -89,3 +93,15 @@ void CResDataBar::setPlayerColor(PlayerColor player) { background->setPlayerColor(player); } + +void CResDataBar::showPopupWindow(const Point & cursorPosition) +{ + if((cursorPosition.x - pos.x) > 600) + return; + + std::vector> comp; + for(auto i = 0; i < GameConstants::RESOURCE_QUANTITY - 1; i++) + comp.push_back(std::make_shared(ComponentType::RESOURCE, GameResID(i), GAME->interface()->cb->getResourceAmount(i))); + + CRClickPopup::createAndPush(LIBRARY->generaltexth->translate("core.genrltxt.270"), comp); +} diff --git a/client/adventureMap/CResDataBar.h b/client/adventureMap/CResDataBar.h index 3363802c4..ec578756a 100644 --- a/client/adventureMap/CResDataBar.h +++ b/client/adventureMap/CResDataBar.h @@ -35,6 +35,7 @@ public: void setResourcePosition(const GameResID & resource, const Point & position); void setPlayerColor(PlayerColor player); + void showPopupWindow(const Point & cursorPosition) override; void showAll(Canvas & to) override; }; diff --git a/client/render/AssetGenerator.cpp b/client/render/AssetGenerator.cpp index 0f8119911..bd706c3a7 100644 --- a/client/render/AssetGenerator.cpp +++ b/client/render/AssetGenerator.cpp @@ -51,6 +51,11 @@ void AssetGenerator::initialize() imageFiles[ImagePath::builtin("CampaignBackground8.png")] = [this]() { return createCampaignBackground(8); }; imageFiles[ImagePath::builtin("SpelTabNone.png")] = [this](){ return createSpellTabNone();}; + for (PlayerColor color(-1); color < PlayerColor::PLAYER_LIMIT; ++color) + { + std::string name = "ResBarElement" + (color == -1 ? "" : "-" + color.toString()); + imageFiles[ImagePath::builtin(name)] = [this, color](){ return createResBarElement(std::max(PlayerColor(0), color));}; + } imageFiles[ImagePath::builtin("stackWindow/info-panel-0.png")] = [this](){ return createCreatureInfoPanel(2);}; imageFiles[ImagePath::builtin("stackWindow/info-panel-1.png")] = [this](){ return createCreatureInfoPanel(3);}; @@ -322,6 +327,20 @@ AssetGenerator::CanvasPtr AssetGenerator::createCampaignBackground(int selection return image; } +AssetGenerator::CanvasPtr AssetGenerator::createResBarElement(const PlayerColor & player) const +{ + auto locator = ImageLocator(ImagePath::builtin("ARESBAR"), EImageBlitMode::COLORKEY); + std::shared_ptr img = ENGINE->renderHandler().loadImage(locator); + img->playerColored(player); + + auto image = ENGINE->renderHandler().createImage(Point(84, 22), CanvasScalingPolicy::IGNORE); + Canvas canvas = image->getCanvas(); + canvas.draw(img, Point(0, 0), Rect(2, 0, 84, 22)); + canvas.draw(img, Point(4, 0), Rect(29, 0, 22, 22)); + + return image; +} + AssetGenerator::CanvasPtr AssetGenerator::createSpellTabNone() const { auto img1 = ENGINE->renderHandler().loadAnimation(AnimationPath::builtin("SPELTAB"), EImageBlitMode::COLORKEY)->getImage(0); diff --git a/client/render/AssetGenerator.h b/client/render/AssetGenerator.h index 0259db88f..d3752f4c5 100644 --- a/client/render/AssetGenerator.h +++ b/client/render/AssetGenerator.h @@ -51,6 +51,7 @@ private: CanvasPtr createCombatUnitNumberWindow(float multR, float multG, float multB) const; CanvasPtr createCampaignBackground(int selection) const; CanvasPtr createSpellTabNone() const; + CanvasPtr createResBarElement(const PlayerColor & player) const; CanvasPtr createChroniclesCampaignImages(int chronicle) const; CanvasPtr createPaletteShiftedImage(const AnimationPath & source, const std::vector & animation, int frameIndex, int paletteShiftCounter) const; CanvasPtr createAdventureMapButtonClear(const PlayerColor & player) const; diff --git a/config/widgets/adventureMap.json b/config/widgets/adventureMap.json index c6ef397e4..2284d4221 100644 --- a/config/widgets/adventureMap.json +++ b/config/widgets/adventureMap.json @@ -467,9 +467,8 @@ }, // Resource & Data bar { - "type": "adventurePlayerTexture", - "name" : "backgroundLeftOfResourceDateBar", - "image" : "DiBoxBck.pcx", + "type": "adventureResourceAdditional", + "name" : "resourceAdditional", "area" : { "left": 3, "bottom" : 4, "right" : 797, "height" : 21 } }, {