1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

add sort buttons

This commit is contained in:
SoundSSGood
2024-09-30 18:26:16 +03:00
parent e22d15b1d8
commit e6f4a63951
4 changed files with 38 additions and 12 deletions

View File

@@ -340,6 +340,12 @@
"vcmi.heroWindow.openCommander.help" : "Shows details about the commander of this hero.",
"vcmi.heroWindow.openBackpack.hover" : "Open artifact backpack window",
"vcmi.heroWindow.openBackpack.help" : "Opens window that allows easier artifact backpack management.",
"vcmi.heroWindow.sortBackpackByCost.hover" : "Sort by cost",
"vcmi.heroWindow.sortBackpackByCost.help" : "Sort artifacts in backpack by cost.",
"vcmi.heroWindow.sortBackpackBySlot.hover" : "Sort by slot",
"vcmi.heroWindow.sortBackpackBySlot.help" : "Sort artifacts in backpack by equipped slot.",
"vcmi.heroWindow.sortBackpackByClass.hover" : "Sort by class",
"vcmi.heroWindow.sortBackpackByClass.help" : "Sort artifacts in backpack by artifact class. Treasure, Minor, Major, Relic",
"vcmi.tavernWindow.inviteHero" : "Invite hero",

View File

@@ -44,21 +44,37 @@ CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std:
addSet(arts);
arts->setHero(hero);
quitButton = std::make_shared<CButton>(Point(), AnimationPath::builtin("IOKAY32.def"), CButton::tooltip(""),
[this]() { WindowBase::close(); }, EShortcut::GLOBAL_RETURN);
pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
pos.h = stretchedBackground->pos.h = arts->pos.h + quitButton->pos.h + 3 * windowMargin;
quitButton->moveTo(Point(pos.x + pos.w / 2 - quitButton->pos.w / 2, pos.y + arts->pos.h + 2 * windowMargin));
buttons.emplace_back(std::make_unique<CButton>(Point(), AnimationPath::builtin("ALTFILL.DEF"),
CButton::tooltipLocalized("vcmi.heroWindow.sortBackpackByCost"),
[hero]() { LOCPLINT->cb->sortBackpackArtifactsByCost(hero->id); }));
buttons.emplace_back(std::make_unique<CButton>(Point(), AnimationPath::builtin("ALTFILL.DEF"),
CButton::tooltipLocalized("vcmi.heroWindow.sortBackpackBySlot"),
[hero]() { LOCPLINT->cb->sortBackpackArtifactsBySlot(hero->id); }));
buttons.emplace_back(std::make_unique<CButton>(Point(), AnimationPath::builtin("ALTFILL.DEF"),
CButton::tooltipLocalized("vcmi.heroWindow.sortBackpackByClass"),
[hero]() { LOCPLINT->cb->sortBackpackArtifactsByClass(hero->id); }));
pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
pos.h = stretchedBackground->pos.h = arts->pos.h + buttons.back()->pos.h + 3 * windowMargin;
auto buttonPos = Point(pos.x + windowMargin, pos.y + arts->pos.h + 2 * windowMargin);
for(const auto & button : buttons)
{
button->moveTo(buttonPos);
buttonPos += Point(button->pos.w + 10, 0);
}
sortBySlot = std::make_shared<CButton>(Point(), AnimationPath::builtin("IOKAY32.def"), CButton::tooltip(""),
[hero]() { LOCPLINT->cb->sortBackpackArtifactsBySlot(hero->id); }, EShortcut::GLOBAL_RETURN);
sortBySlot->moveTo(Point(pos.x + windowMargin, quitButton->pos.y));
statusbar = CGStatusBar::create(0, pos.h, ImagePath::builtin("ADROLLVR.bmp"), pos.w);
pos.h += statusbar->pos.h;
addUsedEvents(LCLICK);
center();
}
void CHeroBackpackWindow::notFocusedClick()
{
close();
}
void CHeroBackpackWindow::showAll(Canvas & to)
{
CIntObject::showAll(to);

View File

@@ -17,11 +17,11 @@ class CHeroBackpackWindow : public CStatusbarWindow, public CWindowWithArtifacts
{
public:
CHeroBackpackWindow(const CGHeroInstance * hero, const std::vector<CArtifactsOfHeroPtr> & artsSets);
void notFocusedClick() override;
protected:
std::shared_ptr<CArtifactsOfHeroBackpack> arts;
std::shared_ptr<CButton> quitButton;
std::shared_ptr<CButton> sortBySlot;
std::vector<std::unique_ptr<CButton>> buttons;
std::shared_ptr<CFilledTexture> stretchedBackground;
const int windowMargin = 5;

View File

@@ -2670,10 +2670,14 @@ bool CGameHandler::manageBackpackArtifacts(const PlayerColor & player, const Obj
for(auto & [sortId, pack] : packsSorted)
{
// Each pack of artifacts is also sorted by ArtifactID
// Each pack of artifacts is also sorted by ArtifactID. Scrolls by SpellID
std::sort(pack.begin(), pack.end(), [artSet](const auto & slots0, const auto & slots1) -> bool
{
return artSet->getArt(slots0.srcPos)->getTypeId().num > artSet->getArt(slots1.srcPos)->getTypeId().num;
const auto art0 = artSet->getArt(slots0.srcPos);
const auto art1 = artSet->getArt(slots1.srcPos);
if(art0->isScroll() && art1->isScroll())
return art0->getScrollSpellID() > art1->getScrollSpellID();
return art0->getTypeId().num > art1->getTypeId().num;
});
bma.artsPack0.insert(bma.artsPack0.end(), pack.begin(), pack.end());
}