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
|
/*
* CreaturePurchaseCard.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 "CreaturePurchaseCard.h"
#include "CHeroWindow.h"
#include "QuickRecruitmentWindow.h"
#include "CCreatureWindow.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/TextAlignment.h"
#include "../gui/WindowHandler.h"
#include "../widgets/Buttons.h"
#include "../widgets/Slider.h"
#include "../widgets/TextControls.h"
#include "../widgets/CreatureCostBox.h"
#include "../../CCallback.h"
#include "../../lib/CCreatureHandler.h"
void CreaturePurchaseCard::initButtons()
{
initMaxButton();
initMinButton();
initCreatureSwitcherButton();
}
void CreaturePurchaseCard::initMaxButton()
{
maxButton = std::make_shared<CButton>(Point(pos.x + 52, pos.y + 180), AnimationPath::builtin("QuickRecruitmentWindow/QuickRecruitmentAllButton.def"), CButton::tooltip(), std::bind(&CSlider::scrollToMax,slider), EShortcut::RECRUITMENT_MAX);
}
void CreaturePurchaseCard::initMinButton()
{
minButton = std::make_shared<CButton>(Point(pos.x, pos.y + 180), AnimationPath::builtin("QuickRecruitmentWindow/QuickRecruitmentNoneButton.def"), CButton::tooltip(), std::bind(&CSlider::scrollToMin,slider), EShortcut::RECRUITMENT_MIN);
}
void CreaturePurchaseCard::initCreatureSwitcherButton()
{
creatureSwitcher = std::make_shared<CButton>(Point(pos.x + 18, pos.y-37), AnimationPath::builtin("iDv6432.def"), CButton::tooltip(), [&](){ switchCreatureLevel(); }, EShortcut::RECRUITMENT_SWITCH_LEVEL);
}
void CreaturePurchaseCard::switchCreatureLevel()
{
OBJECT_CONSTRUCTION;
auto index = vstd::find_pos(upgradesID, creatureOnTheCard->getId());
auto nextCreatureId = vstd::circularAt(upgradesID, ++index);
creatureOnTheCard = nextCreatureId.toCreature();
picture = std::make_shared<CCreaturePic>(picture->pos.x - pos.x, picture->pos.y - pos.y, creatureOnTheCard);
creatureClickArea = std::make_shared<CCreatureClickArea>(Point(picture->pos.x - pos.x, picture->pos.y - pos.y), picture, creatureOnTheCard);
parent->updateAllSliders();
cost->set(creatureOnTheCard->getFullRecruitCost() * slider->getValue());
}
void CreaturePurchaseCard::initAmountInfo()
{
availableAmount = std::make_shared<CLabel>(pos.x + 25, pos.y + 146, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW);
purchaseAmount = std::make_shared<CLabel>(pos.x + 76, pos.y + 146, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
updateAmountInfo(0);
}
void CreaturePurchaseCard::updateAmountInfo(int value)
{
availableAmount->setText(std::to_string(maxAmount-value));
purchaseAmount->setText(std::to_string(value));
}
void CreaturePurchaseCard::initSlider()
{
slider = std::make_shared<CSlider>(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurchaseCard::sliderMoved, this, _1), 0, maxAmount, 0, Orientation::HORIZONTAL);
}
void CreaturePurchaseCard::initCostBox()
{
cost = std::make_shared<CreatureCostBox>(Rect(pos.x+2, pos.y + 194, 97, 74), "");
cost->createItems(creatureOnTheCard->getFullRecruitCost());
}
void CreaturePurchaseCard::sliderMoved(int to)
{
updateAmountInfo(to);
cost->set(creatureOnTheCard->getFullRecruitCost() * to);
parent->updateAllSliders();
}
CreaturePurchaseCard::CreaturePurchaseCard(const std::vector<CreatureID> & creaturesID, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents)
: upgradesID(creaturesID),
parent(parents),
maxAmount(creaturesMaxAmount)
{
creatureOnTheCard = upgradesID.back().toCreature();
moveTo(Point(position.x, position.y));
initView();
}
void CreaturePurchaseCard::initView()
{
picture = std::make_shared<CCreaturePic>(pos.x, pos.y, creatureOnTheCard);
background = std::make_shared<CPicture>(ImagePath::builtin("QuickRecruitmentWindow/CreaturePurchaseCard.png"), pos.x-4, pos.y-50);
creatureClickArea = std::make_shared<CCreatureClickArea>(Point(pos.x, pos.y), picture, creatureOnTheCard);
initAmountInfo();
initSlider();
initButtons(); // order important! buttons need slider!
initCostBox();
}
CreaturePurchaseCard::CCreatureClickArea::CCreatureClickArea(const Point & position, const std::shared_ptr<CCreaturePic> creaturePic, const CCreature * creatureOnTheCard)
: CIntObject(SHOW_POPUP),
creatureOnTheCard(creatureOnTheCard)
{
pos.x += position.x;
pos.y += position.y;
pos.w = CREATURE_WIDTH;
pos.h = CREATURE_HEIGHT;
}
void CreaturePurchaseCard::CCreatureClickArea::showPopupWindow(const Point & cursorPosition)
{
GH.windows().createAndPushWindow<CStackWindow>(creatureOnTheCard, true);
}
|