1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00

Merge pull request #2625 from dydzio0614/artifacts-backpack-gui

Artifacts backpack GUI
This commit is contained in:
Ivan Savenko 2023-08-28 19:59:11 +03:00 committed by GitHub
commit 5be87b30c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 78 additions and 18 deletions

View File

@ -0,0 +1,8 @@
{
"basepath" : "buttons/",
"images" :
[
{ "frame" : 0, "file" : "backpackNormal.png"},
{ "frame" : 1, "file" : "backpackPressed.png"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

View File

@ -173,6 +173,8 @@
"vcmi.heroWindow.openCommander.hover" : "Open commander info window",
"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.commanderWindow.artifactMessage" : "Do you want to return this artifact to the hero?",

View File

@ -173,6 +173,8 @@
"vcmi.heroWindow.openCommander.hover" : "Otwórz okno dowódcy",
"vcmi.heroWindow.openCommander.help" : "Wyświetla informacje o dowódcy przynależącym do tego bohatera",
"vcmi.heroWindow.openBackpack.hover" : "Otwórz okno sakwy",
"vcmi.heroWindow.openBackpack.help" : "Otwiera okno pozwalające łatwiej zarządzać artefaktami w sakwie",
"vcmi.commanderWindow.artifactMessage" : "Czy chcesz zwrócić ten artefakt bohaterowi?",

View File

@ -14,6 +14,7 @@
#include "../gui/Shortcut.h"
#include "Buttons.h"
#include "Images.h"
#include "GameSettings.h"
#include "IHandlerBase.h"
#include "ObjectLists.h"
@ -27,25 +28,37 @@ CArtifactsOfHeroBackpack::CArtifactsOfHeroBackpack(const Point & position)
{
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
pos += position;
setRedrawParent(true);
const auto backpackCap = VLC->settings()->getInteger(EGameSettings::HEROES_BACKPACK_CAP);
auto visibleCapasityMax = HERO_BACKPACK_WINDOW_SLOT_LINES * HERO_BACKPACK_WINDOW_SLOT_COLUMNS;
auto visibleCapacityMax = HERO_BACKPACK_WINDOW_SLOT_ROWS * HERO_BACKPACK_WINDOW_SLOT_COLUMNS;
if(backpackCap >= 0)
visibleCapasityMax = visibleCapasityMax > backpackCap ? backpackCap : visibleCapasityMax;
visibleCapacityMax = visibleCapacityMax > backpackCap ? backpackCap : visibleCapacityMax;
backpack.resize(visibleCapasityMax);
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(46 * (artPlaceIdx % HERO_BACKPACK_WINDOW_SLOT_COLUMNS), 46 * (artPlaceIdx / HERO_BACKPACK_WINDOW_SLOT_COLUMNS)));
Point(slotSizeWithMargin * (artPlaceIdx % HERO_BACKPACK_WINDOW_SLOT_COLUMNS), slotSizeWithMargin * (artPlaceIdx / HERO_BACKPACK_WINDOW_SLOT_COLUMNS)));
artPlace->setArtifact(nullptr);
artPlace->leftClickCallback = std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1);
artPlace->rightClickCallback = std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1);
artPlaceIdx++;
}
if(backpackCap < 0 || visibleCapasityMax < backpackCap)
if(backpackCap < 0 || visibleCapacityMax < backpackCap)
{
auto onCreate = [](size_t index) -> std::shared_ptr<CIntObject>
{
@ -56,8 +69,8 @@ CArtifactsOfHeroBackpack::CArtifactsOfHeroBackpack(const Point & position)
scrollBackpack(static_cast<int>(pos) * HERO_BACKPACK_WINDOW_SLOT_COLUMNS - backpackPos);
};
backpackListBox = std::make_shared<CListBoxWithCallback>(
posMoved, onCreate, Point(0, 0), Point(0, 0), HERO_BACKPACK_WINDOW_SLOT_LINES, 0, 0, 1,
Rect(HERO_BACKPACK_WINDOW_SLOT_COLUMNS * 46 + 10, 0, HERO_BACKPACK_WINDOW_SLOT_LINES * 46 - 5, 0));
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));
}
}

View File

@ -31,6 +31,7 @@ public:
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_LINES = 8;
const size_t HERO_BACKPACK_WINDOW_SLOT_ROWS = 8;
};

View File

@ -14,17 +14,33 @@
#include "../gui/Shortcut.h"
#include "../widgets/Buttons.h"
#include "../widgets/Images.h"
#include "CMessage.h"
#include "render/Canvas.h"
#include "CPlayerInterface.h"
CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero)
: CWindowObject(PLAYER_COLORED)
: CWindowObject((EOptions)0)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
arts = std::make_shared<CArtifactsOfHeroBackpack>(Point(-100, -170));
stretchedBackground = std::make_shared<CFilledTexture>("DIBOXBCK", Rect(0, 0, 410, 425));
pos.w = stretchedBackground->pos.w;
pos.h = stretchedBackground->pos.h;
center();
arts = std::make_shared<CArtifactsOfHeroBackpack>(/*Point(-100, -170)*/Point(10, 10));
arts->setHero(hero);
addSet(arts);
addCloseCallback(std::bind(&CHeroBackpackWindow::close, this));
quitButton = std::make_shared<CButton>(Point(242, 200), "hsbtns.def", CButton::tooltip(""), [this]() { close(); }, EShortcut::GLOBAL_RETURN);
quitButton = std::make_shared<CButton>(Point(173, 385), "IOKAY32.def", CButton::tooltip(""), [this]() { close(); }, EShortcut::GLOBAL_RETURN);
}
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);
}

View File

@ -12,6 +12,8 @@
#include "../widgets/CWindowWithArtifacts.h"
#include "CWindowObject.h"
class CFilledTexture;
class CHeroBackpackWindow : public CWindowObject, public CWindowWithArtifacts
{
public:
@ -20,4 +22,7 @@ public:
private:
std::shared_ptr<CArtifactsOfHeroBackpack> arts;
std::shared_ptr<CButton> quitButton;
std::shared_ptr<CFilledTexture> stretchedBackground;
void showAll(Canvas &to) override;
};

View File

@ -84,11 +84,19 @@ CHeroWindow::CHeroWindow(const CGHeroInstance * hero)
quitButton = std::make_shared<CButton>(Point(609, 516), "hsbtns.def", CButton::tooltip(heroscrn[17]), [=](){ close(); }, EShortcut::GLOBAL_RETURN);
dismissLabel = std::make_shared<CTextBox>(CGI->generaltexth->jktexts[8], Rect(370, 430, 65, 35), 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
dismissButton = std::make_shared<CButton>(Point(454, 429), "hsbtns2.def", CButton::tooltip(heroscrn[28]), [=](){ dismissCurrent(); }, EShortcut::HERO_DISMISS);
questlogLabel = std::make_shared<CTextBox>(CGI->generaltexth->jktexts[9], Rect(510, 430, 65, 35), 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
questlogButton = std::make_shared<CButton>(Point(314, 429), "hsbtns4.def", CButton::tooltip(heroscrn[0]), [=](){ LOCPLINT->showQuestLog(); }, EShortcut::ADVENTURE_QUEST_LOG);
if(settings["general"]["enableUiEnhancements"].Bool())
{
questlogButton = std::make_shared<CButton>(Point(314, 429), "hsbtns4.def", CButton::tooltip(heroscrn[0]), [=](){ LOCPLINT->showQuestLog(); }, EShortcut::ADVENTURE_QUEST_LOG);
backpackButton = std::make_shared<CButton>(Point(424, 429), "buttons/backpack", CButton::tooltipLocalized("vcmi.heroWindow.Backpack"), [=](){ createBackpackWindow(); }, EShortcut::HERO_BACKPACK);
dismissButton = std::make_shared<CButton>(Point(534, 429), "hsbtns2.def", CButton::tooltip(heroscrn[28]), [=](){ dismissCurrent(); }, EShortcut::HERO_DISMISS);
}
else
{
dismissLabel = std::make_shared<CTextBox>(CGI->generaltexth->jktexts[8], Rect(370, 430, 65, 35), 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
questlogLabel = std::make_shared<CTextBox>(CGI->generaltexth->jktexts[9], Rect(510, 430, 65, 35), 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
dismissButton = std::make_shared<CButton>(Point(454, 429), "hsbtns2.def", CButton::tooltip(heroscrn[28]), [=](){ dismissCurrent(); }, EShortcut::HERO_DISMISS);
questlogButton = std::make_shared<CButton>(Point(314, 429), "hsbtns4.def", CButton::tooltip(heroscrn[0]), [=](){ LOCPLINT->showQuestLog(); }, EShortcut::ADVENTURE_QUEST_LOG);
}
formations = std::make_shared<CToggleGroup>(0);
formations->addToggle(0, std::make_shared<CToggleButton>(Point(481, 483), "hsbtns6.def", std::make_pair(heroscrn[23], heroscrn[29]), 0, EShortcut::HERO_TIGHT_FORMATION));

View File

@ -38,7 +38,8 @@
"autosaveCountLimit",
"useSavePrefix",
"savePrefix",
"startTurnAutosave"
"startTurnAutosave",
"enableUiEnhancements"
],
"properties" : {
"playerName" : {
@ -126,6 +127,10 @@
"startTurnAutosave" : {
"type": "boolean",
"default": false
},
"enableUiEnhancements" : {
"type": "boolean",
"default": true
}
}
},