diff --git a/client/widgets/CArtifactsOfHeroBackpack.cpp b/client/widgets/CArtifactsOfHeroBackpack.cpp index 90ecd7567..ed25c1357 100644 --- a/client/widgets/CArtifactsOfHeroBackpack.cpp +++ b/client/widgets/CArtifactsOfHeroBackpack.cpp @@ -11,12 +11,9 @@ #include "CArtifactsOfHeroBackpack.h" #include "../gui/CGuiHandler.h" -#include "../gui/Shortcut.h" -#include "Buttons.h" #include "Images.h" #include "GameSettings.h" -#include "IHandlerBase.h" #include "ObjectLists.h" #include "../CPlayerInterface.h" @@ -37,21 +34,12 @@ CArtifactsOfHeroBackpack::CArtifactsOfHeroBackpack(const Point & position) backpack.resize(visibleCapacityMax); size_t artPlaceIdx = 0; - - const int slotSizeWithMargin = 46; - - for(int i = 0; i < visibleCapacityMax; i++) - { - auto artifactSlotBackground = std::make_shared("heroWindow/artifactSlotEmpty", - Point(slotSizeWithMargin * (i % HERO_BACKPACK_WINDOW_SLOT_COLUMNS), slotSizeWithMargin * (i / HERO_BACKPACK_WINDOW_SLOT_COLUMNS))); - - backpackSlotsBackgrounds.emplace_back(artifactSlotBackground); - } - for(auto & artPlace : backpack) { - artPlace = std::make_shared( - Point(slotSizeWithMargin * (artPlaceIdx % HERO_BACKPACK_WINDOW_SLOT_COLUMNS), slotSizeWithMargin * (artPlaceIdx / HERO_BACKPACK_WINDOW_SLOT_COLUMNS))); + const auto pos = Point(slotSizeWithMargin * (artPlaceIdx % HERO_BACKPACK_WINDOW_SLOT_COLUMNS), + slotSizeWithMargin * (artPlaceIdx / HERO_BACKPACK_WINDOW_SLOT_COLUMNS)); + backpackSlotsBackgrounds.emplace_back(std::make_shared("heroWindow/artifactSlotEmpty", pos)); + artPlace = std::make_shared(pos); artPlace->setArtifact(nullptr); artPlace->leftClickCallback = std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1); artPlace->rightClickCallback = std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1); @@ -70,8 +58,18 @@ CArtifactsOfHeroBackpack::CArtifactsOfHeroBackpack(const Point & position) }; backpackListBox = std::make_shared( posMoved, onCreate, Point(0, 0), Point(0, 0), HERO_BACKPACK_WINDOW_SLOT_ROWS, 0, 0, 1, - Rect(HERO_BACKPACK_WINDOW_SLOT_COLUMNS * slotSizeWithMargin + 10, 0, HERO_BACKPACK_WINDOW_SLOT_ROWS * slotSizeWithMargin - 5, 0)); + Rect(HERO_BACKPACK_WINDOW_SLOT_COLUMNS * slotSizeWithMargin + sliderPosOffsetX, 0, HERO_BACKPACK_WINDOW_SLOT_ROWS * slotSizeWithMargin - 2, 0)); } + + pos.w = visibleCapacityMax > HERO_BACKPACK_WINDOW_SLOT_COLUMNS ? HERO_BACKPACK_WINDOW_SLOT_COLUMNS : visibleCapacityMax; + pos.w *= slotSizeWithMargin; + if(backpackListBox) + pos.w += sliderPosOffsetX + 16; // 16 is slider width. TODO: get it from CListBox directly; + + pos.h = (visibleCapacityMax / HERO_BACKPACK_WINDOW_SLOT_COLUMNS); + if(visibleCapacityMax % HERO_BACKPACK_WINDOW_SLOT_COLUMNS != 0) + pos.h += 1; + pos.h *= slotSizeWithMargin; } void CArtifactsOfHeroBackpack::swapArtifacts(const ArtifactLocation & srcLoc, const ArtifactLocation & dstLoc) @@ -88,7 +86,7 @@ void CArtifactsOfHeroBackpack::pickUpArtifact(CHeroArtPlace & artPlace) void CArtifactsOfHeroBackpack::scrollBackpack(int offset) { if(backpackListBox) - backpackListBox->resize(getActiveSlotLinesNum()); + backpackListBox->resize(getActiveSlotRowsNum()); backpackPos += offset; auto slot = ArtifactPosition(GameConstants::BACKPACK_START + backpackPos); for(auto artPlace : backpack) @@ -102,11 +100,11 @@ void CArtifactsOfHeroBackpack::scrollBackpack(int offset) void CArtifactsOfHeroBackpack::updateBackpackSlots() { if(backpackListBox) - backpackListBox->resize(getActiveSlotLinesNum()); + backpackListBox->resize(getActiveSlotRowsNum()); CArtifactsOfHeroBase::updateBackpackSlots(); } -size_t CArtifactsOfHeroBackpack::getActiveSlotLinesNum() +size_t CArtifactsOfHeroBackpack::getActiveSlotRowsNum() { return (curHero->artifactsInBackpack.size() + HERO_BACKPACK_WINDOW_SLOT_COLUMNS - 1) / HERO_BACKPACK_WINDOW_SLOT_COLUMNS; } diff --git a/client/widgets/CArtifactsOfHeroBackpack.h b/client/widgets/CArtifactsOfHeroBackpack.h index e6767a601..ce51531ef 100644 --- a/client/widgets/CArtifactsOfHeroBackpack.h +++ b/client/widgets/CArtifactsOfHeroBackpack.h @@ -27,11 +27,13 @@ public: void pickUpArtifact(CHeroArtPlace & artPlace); void scrollBackpack(int offset) override; void updateBackpackSlots() override; - size_t getActiveSlotLinesNum(); + size_t getActiveSlotRowsNum(); private: std::shared_ptr backpackListBox; std::vector> backpackSlotsBackgrounds; const size_t HERO_BACKPACK_WINDOW_SLOT_COLUMNS = 8; const size_t HERO_BACKPACK_WINDOW_SLOT_ROWS = 8; + const int slotSizeWithMargin = 46; + const int sliderPosOffsetX = 10; }; diff --git a/client/windows/CHeroBackpackWindow.cpp b/client/windows/CHeroBackpackWindow.cpp index 46bcfda40..3455b2b0b 100644 --- a/client/windows/CHeroBackpackWindow.cpp +++ b/client/windows/CHeroBackpackWindow.cpp @@ -24,22 +24,26 @@ CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); - stretchedBackground = std::make_shared("DIBOXBCK", Rect(0, 0, 410, 425)); - pos.w = stretchedBackground->pos.w; - pos.h = stretchedBackground->pos.h; - center(); + stretchedBackground = std::make_shared("DIBOXBCK", Rect()); - - arts = std::make_shared(/*Point(-100, -170)*/Point(10, 10)); + arts = std::make_shared(Point(windowMargin, windowMargin)); arts->setHero(hero); addSet(arts); addCloseCallback(std::bind(&CHeroBackpackWindow::close, this)); - quitButton = std::make_shared(Point(173, 385), "IOKAY32.def", CButton::tooltip(""), [this]() { close(); }, EShortcut::GLOBAL_RETURN); + quitButton = std::make_shared(Point(), "IOKAY32.def", CButton::tooltip(""), [this]() { close(); }, EShortcut::GLOBAL_RETURN); + + stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin; + stretchedBackground->pos.h = arts->pos.h + quitButton->pos.h + 3 * windowMargin; + pos.w = stretchedBackground->pos.w; + pos.h = stretchedBackground->pos.h; + center(); + + quitButton->moveBy(Point(GH.screenDimensions().x / 2 - quitButton->pos.w / 2 - quitButton->pos.x, arts->pos.h + 2 * windowMargin)); } -void CHeroBackpackWindow::showAll(Canvas &to) +void CHeroBackpackWindow::showAll(Canvas & to) { CIntObject::showAll(to); CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to.getInternalSurface(), pos.w+28, pos.h+29, pos.x-14, pos.y-15); diff --git a/client/windows/CHeroBackpackWindow.h b/client/windows/CHeroBackpackWindow.h index df9aeb08d..73d736b0a 100644 --- a/client/windows/CHeroBackpackWindow.h +++ b/client/windows/CHeroBackpackWindow.h @@ -23,6 +23,7 @@ private: std::shared_ptr arts; std::shared_ptr quitButton; std::shared_ptr stretchedBackground; + const int windowMargin = 10; - void showAll(Canvas &to) override; + void showAll(Canvas & to) override; };