2023-07-06 21:14:12 +02:00
|
|
|
/*
|
|
|
|
* CHeroBackpackWindow.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CHeroBackpackWindow.h"
|
|
|
|
|
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-07-17 18:42:55 +02:00
|
|
|
#include "../gui/Shortcut.h"
|
|
|
|
|
|
|
|
#include "../widgets/Buttons.h"
|
2023-08-20 00:52:03 +02:00
|
|
|
#include "../widgets/Images.h"
|
2024-01-18 13:42:52 +02:00
|
|
|
#include "../widgets/TextControls.h"
|
2023-08-20 00:52:03 +02:00
|
|
|
#include "CMessage.h"
|
|
|
|
#include "render/Canvas.h"
|
2023-08-21 17:08:15 +02:00
|
|
|
#include "CPlayerInterface.h"
|
2023-07-06 21:14:12 +02:00
|
|
|
|
2024-05-20 11:47:25 +02:00
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
|
|
|
#include "../../lib/networkPacks/ArtifactLocation.h"
|
|
|
|
|
|
|
|
CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std::vector<CArtifactsOfHeroPtr> & artsSets)
|
2024-04-23 15:21:45 +02:00
|
|
|
: CWindowWithArtifacts(&artsSets)
|
2023-07-06 21:14:12 +02:00
|
|
|
{
|
2023-11-07 14:17:34 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
|
|
|
|
|
|
|
stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
|
2023-12-17 16:30:19 +02:00
|
|
|
arts = std::make_shared<CArtifactsOfHeroBackpack>();
|
|
|
|
arts->moveBy(Point(windowMargin, windowMargin));
|
2024-05-20 14:31:07 +02:00
|
|
|
arts->clickPressedCallback = [this](const CArtPlace & artPlace, const Point & cursorPosition)
|
2024-05-20 11:47:25 +02:00
|
|
|
{
|
|
|
|
clickPressedOnArtPlace(arts->getHero(), artPlace.slot, true, false, true);
|
|
|
|
};
|
|
|
|
arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
|
|
|
{
|
|
|
|
showArtifactAssembling(*arts, artPlace, cursorPosition);
|
|
|
|
};
|
|
|
|
addSet(arts);
|
2023-11-07 14:17:34 +02:00
|
|
|
arts->setHero(hero);
|
2024-01-18 13:42:52 +02:00
|
|
|
quitButton = std::make_shared<CButton>(Point(), AnimationPath::builtin("IOKAY32.def"), CButton::tooltip(""),
|
|
|
|
[this]() { WindowBase::close(); }, EShortcut::GLOBAL_RETURN);
|
2023-11-07 14:17:34 +02:00
|
|
|
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));
|
2024-01-18 13:42:52 +02:00
|
|
|
statusbar = CGStatusBar::create(0, pos.h, ImagePath::builtin("ADROLLVR.bmp"), pos.w);
|
|
|
|
pos.h += statusbar->pos.h;
|
|
|
|
|
2023-12-17 16:30:19 +02:00
|
|
|
center();
|
2023-08-20 00:52:03 +02:00
|
|
|
}
|
|
|
|
|
2023-08-31 21:27:32 +02:00
|
|
|
void CHeroBackpackWindow::showAll(Canvas & to)
|
2023-08-20 00:52:03 +02:00
|
|
|
{
|
|
|
|
CIntObject::showAll(to);
|
2024-02-26 18:32:15 +02:00
|
|
|
CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
|
2023-07-16 20:16:12 +02:00
|
|
|
}
|
2023-11-07 14:17:34 +02:00
|
|
|
|
|
|
|
CHeroQuickBackpackWindow::CHeroQuickBackpackWindow(const CGHeroInstance * hero, ArtifactPosition targetSlot)
|
|
|
|
{
|
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
|
|
|
|
2023-12-17 16:30:19 +02:00
|
|
|
stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
|
|
|
|
arts = std::make_shared<CArtifactsOfHeroQuickBackpack>(targetSlot);
|
|
|
|
arts->moveBy(Point(windowMargin, windowMargin));
|
2024-05-20 14:31:07 +02:00
|
|
|
arts->clickPressedCallback = [this](const CArtPlace & artPlace, const Point & cursorPosition)
|
2024-05-20 11:47:25 +02:00
|
|
|
{
|
|
|
|
if(const auto curHero = arts->getHero())
|
|
|
|
swapArtifactAndClose(*arts, artPlace.slot, ArtifactLocation(curHero->id, arts->getFilterSlot()));
|
|
|
|
};
|
|
|
|
arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
|
|
|
{
|
2024-05-20 14:31:07 +02:00
|
|
|
showArifactInfo(*arts, artPlace, cursorPosition);
|
2024-05-20 11:47:25 +02:00
|
|
|
};
|
|
|
|
addSet(arts);
|
2023-11-07 14:17:34 +02:00
|
|
|
arts->setHero(hero);
|
2023-12-17 16:30:19 +02:00
|
|
|
addUsedEvents(GESTURE);
|
|
|
|
pos.w = stretchedBackground->pos.w = arts->pos.w + 2 * windowMargin;
|
|
|
|
pos.h = stretchedBackground->pos.h = arts->pos.h + windowMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroQuickBackpackWindow::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
|
|
|
|
{
|
|
|
|
if(on)
|
|
|
|
return;
|
|
|
|
|
|
|
|
arts->swapSelected();
|
|
|
|
close();
|
|
|
|
}
|
2023-11-07 14:17:34 +02:00
|
|
|
|
2023-12-17 16:30:19 +02:00
|
|
|
void CHeroQuickBackpackWindow::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
|
|
|
|
{
|
|
|
|
arts->selectSlotAt(currentPosition);
|
|
|
|
redraw();
|
2023-11-07 14:17:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroQuickBackpackWindow::showAll(Canvas & to)
|
|
|
|
{
|
|
|
|
if(arts->getSlotsNum() == 0)
|
|
|
|
{
|
2023-12-17 16:30:19 +02:00
|
|
|
// Dirty solution for closing that window
|
2023-11-07 14:17:34 +02:00
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
2024-02-26 18:32:15 +02:00
|
|
|
CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to, pos.w + 28, pos.h + 29, pos.x - 14, pos.y - 15);
|
2023-12-17 16:30:19 +02:00
|
|
|
CIntObject::showAll(to);
|
2023-11-07 14:17:34 +02:00
|
|
|
}
|