1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
/*
* 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"
#include "../gui/Shortcut.h"
#include "../widgets/Buttons.h"
#include "../widgets/Images.h"
#include "../widgets/TextControls.h"
#include "CMessage.h"
#include "render/Canvas.h"
#include "CPlayerInterface.h"
#include "../../CCallback.h"
#include "../../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/networkPacks/ArtifactLocation.h"
CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std::vector<CArtifactsOfHeroPtr> & artsSets)
: CWindowWithArtifacts(&artsSets)
{
OBJECT_CONSTRUCTION;
stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
arts = std::make_shared<CArtifactsOfHeroBackpack>();
arts->moveBy(Point(windowMargin, windowMargin));
arts->clickPressedCallback = [this](const CArtPlace & artPlace, const Point & cursorPosition)
{
clickPressedOnArtPlace(arts->getHero(), artPlace.slot, true, false, true, cursorPosition);
};
arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
{
showArtifactAssembling(*arts, artPlace, cursorPosition);
};
addSet(arts);
arts->setHero(hero);
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);
}
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);
CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
}
CHeroQuickBackpackWindow::CHeroQuickBackpackWindow(const CGHeroInstance * hero, ArtifactPosition targetSlot)
{
OBJECT_CONSTRUCTION;
stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
arts = std::make_shared<CArtifactsOfHeroQuickBackpack>(targetSlot);
arts->moveBy(Point(windowMargin, windowMargin));
arts->clickPressedCallback = [this](const CArtPlace & artPlace, const Point & cursorPosition)
{
if(const auto curHero = arts->getHero())
swapArtifactAndClose(*arts, artPlace.slot, ArtifactLocation(curHero->id, arts->getFilterSlot()));
};
addSet(arts);
arts->setHero(hero);
addUsedEvents(GESTURE);
addUsedEvents(LCLICK);
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();
}
void CHeroQuickBackpackWindow::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
{
arts->selectSlotAt(currentPosition);
redraw();
}
void CHeroQuickBackpackWindow::notFocusedClick()
{
close();
}
void CHeroQuickBackpackWindow::showAll(Canvas & to)
{
if(arts->getSlotsNum() == 0)
{
// Dirty solution for closing that window
close();
return;
}
CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to, pos.w + 28, pos.h + 29, pos.x - 14, pos.y - 15);
CIntObject::showAll(to);
}
|