Browse Source

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

Artifacts backpack GUI
Ivan Savenko 2 years ago
parent
commit
5be87b30c1

+ 8 - 0
Mods/vcmi/Sprites/buttons/backpack.json

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

BIN
Mods/vcmi/Sprites/buttons/backpackNormal.png


BIN
Mods/vcmi/Sprites/buttons/backpackPressed.png


BIN
Mods/vcmi/Sprites/heroWindow/artifactSlotEmpty.png


+ 2 - 0
Mods/vcmi/config/vcmi/english.json

@@ -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?",
 

+ 2 - 0
Mods/vcmi/config/vcmi/polish.json

@@ -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?",
 

+ 20 - 7
client/widgets/CArtifactsOfHeroBackpack.cpp

@@ -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));
 	}
 }
 

+ 2 - 1
client/widgets/CArtifactsOfHeroBackpack.h

@@ -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;
 };

+ 20 - 4
client/windows/CHeroBackpackWindow.cpp

@@ -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);
 }

+ 5 - 0
client/windows/CHeroBackpackWindow.h

@@ -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;
 };

+ 13 - 5
client/windows/CHeroWindow.cpp

@@ -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));

+ 6 - 1
config/schemas/settings.json

@@ -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
 				}
 			}
 		},