1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-12 10:03:53 +02:00
vcmi/client/windows/CHeroBackpackWindow.cpp

82 lines
2.4 KiB
C++
Raw Normal View History

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"
#include "../widgets/Images.h"
#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
2023-11-07 14:17:34 +02:00
CHeroBackpackWindow::CHeroBackpackWindow()
: CWindowObject((EOptions)0)
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-11-07 14:17:34 +02:00
CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero)
: CHeroBackpackWindow()
{
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
arts = std::make_shared<CArtifactsOfHeroBackpack>(Point(windowMargin, windowMargin));
2023-09-18 21:58:08 +02:00
addSetAndCallbacks(arts);
2023-11-07 14:17:34 +02:00
arts->setHero(hero);
2023-07-16 20:16:12 +02:00
addCloseCallback(std::bind(&CHeroBackpackWindow::close, this));
2023-07-17 18:42:55 +02:00
2023-11-07 14:17:34 +02:00
init();
center();
2023-11-07 14:17:34 +02:00
}
2023-11-07 14:17:34 +02:00
void CHeroBackpackWindow::init()
{
quitButton = std::make_shared<CButton>(Point(), AnimationPath::builtin("IOKAY32.def"), CButton::tooltip(""), [this]() { 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));
}
void CHeroBackpackWindow::showAll(Canvas & to)
{
CIntObject::showAll(to);
2023-08-21 17:08:15 +02:00
CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to.getInternalSurface(), 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)
: CHeroBackpackWindow()
{
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
auto artsQuickBp = std::make_shared<CArtifactsOfHeroQuickBackpack>(Point(windowMargin, windowMargin), targetSlot);
addSetAndCallbacks(static_cast<std::weak_ptr<CArtifactsOfHeroQuickBackpack>>(artsQuickBp));
arts = artsQuickBp;
arts->setHero(hero);
addCloseCallback(std::bind(&CHeroQuickBackpackWindow::close, this));
init();
}
void CHeroQuickBackpackWindow::showAll(Canvas & to)
{
if(arts->getSlotsNum() == 0)
{
close();
return;
}
CHeroBackpackWindow::showAll(to);
}