mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-20 20:23:03 +02:00
Merge pull request #2720 from SoundSSGood/backpack-variable-cap
Support for different backpack window capacities
This commit is contained in:
commit
211bcb6e82
@ -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<CPicture>("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<CHeroArtPlace>(
|
||||
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<CPicture>("heroWindow/artifactSlotEmpty", pos));
|
||||
artPlace = std::make_shared<CHeroArtPlace>(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<CListBoxWithCallback>(
|
||||
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;
|
||||
}
|
||||
|
@ -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<CListBoxWithCallback> backpackListBox;
|
||||
std::vector<std::shared_ptr<CPicture>> 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;
|
||||
};
|
||||
|
@ -24,22 +24,26 @@ CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero)
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
|
||||
stretchedBackground = std::make_shared<CFilledTexture>("DIBOXBCK", Rect(0, 0, 410, 425));
|
||||
pos.w = stretchedBackground->pos.w;
|
||||
pos.h = stretchedBackground->pos.h;
|
||||
center();
|
||||
stretchedBackground = std::make_shared<CFilledTexture>("DIBOXBCK", Rect());
|
||||
|
||||
|
||||
arts = std::make_shared<CArtifactsOfHeroBackpack>(/*Point(-100, -170)*/Point(10, 10));
|
||||
arts = std::make_shared<CArtifactsOfHeroBackpack>(Point(windowMargin, windowMargin));
|
||||
arts->setHero(hero);
|
||||
addSet(arts);
|
||||
|
||||
addCloseCallback(std::bind(&CHeroBackpackWindow::close, this));
|
||||
|
||||
quitButton = std::make_shared<CButton>(Point(173, 385), "IOKAY32.def", CButton::tooltip(""), [this]() { close(); }, EShortcut::GLOBAL_RETURN);
|
||||
quitButton = std::make_shared<CButton>(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);
|
||||
|
@ -23,6 +23,7 @@ private:
|
||||
std::shared_ptr<CArtifactsOfHeroBackpack> arts;
|
||||
std::shared_ptr<CButton> quitButton;
|
||||
std::shared_ptr<CFilledTexture> stretchedBackground;
|
||||
const int windowMargin = 10;
|
||||
|
||||
void showAll(Canvas &to) override;
|
||||
void showAll(Canvas & to) override;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user