2017-11-01 15:58:49 +02:00
|
|
|
/*
|
2017-12-21 20:27:39 +02:00
|
|
|
* CreaturePurchaseCard.cpp, part of VCMI engine
|
2017-11-01 15:58:49 +02:00
|
|
|
*
|
|
|
|
* 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"
|
2017-12-20 21:08:21 +02:00
|
|
|
#include "CreaturePurchaseCard.h"
|
2017-11-01 15:58:49 +02:00
|
|
|
#include "CAdvmapInterface.h"
|
|
|
|
#include "CHeroWindow.h"
|
|
|
|
#include "../widgets/Buttons.h"
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
#include "../CreatureCostBox.h"
|
|
|
|
#include "QuickRecruitmentWindow.h"
|
2017-12-20 21:08:21 +02:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2017-11-01 15:58:49 +02:00
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::initButtons()
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
|
|
|
initMaxButton();
|
|
|
|
initMinButton();
|
2017-12-20 21:08:21 +02:00
|
|
|
initCreatureSwitcherButton();
|
2017-11-01 15:58:49 +02:00
|
|
|
}
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::initMaxButton()
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2017-12-20 21:08:21 +02:00
|
|
|
maxButton = std::make_shared<CButton>(Point(pos.x + 52, pos.y + 178), "iam014.def", CButton::tooltip(), std::bind(&CSlider::moveToMax,slider), SDLK_LSHIFT);
|
2017-11-01 15:58:49 +02:00
|
|
|
}
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::initMinButton()
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2017-12-20 21:08:21 +02:00
|
|
|
minButton = std::make_shared<CButton>(Point(pos.x, pos.y + 178), "iam015.def", CButton::tooltip(), std::bind(&CSlider::moveToMin,slider), SDLK_LCTRL);
|
2017-11-01 15:58:49 +02:00
|
|
|
}
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::initCreatureSwitcherButton()
|
|
|
|
{
|
|
|
|
creatureSwitcher = std::make_shared<CButton>(Point(pos.x + 20, pos.y-33), "iDv6432.def", CButton::tooltip(), [&](){ switchCreatureLevel(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreaturePurchaseCard::switchCreatureLevel()
|
|
|
|
{
|
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(ACTIVATE + DEACTIVATE + UPDATE + SHOWALL + SHARE_POS);
|
|
|
|
auto index = vstd::find_pos(upgradesID, creatureOnTheCard->idNumber);
|
|
|
|
auto nextCreatureId = vstd::circularAt(upgradesID, ++index);
|
|
|
|
creatureOnTheCard = nextCreatureId.toCreature();
|
|
|
|
picture = std::make_shared<CCreaturePic>(parent->pos.x, parent->pos.y, creatureOnTheCard);
|
|
|
|
parent->updateAllSliders();
|
|
|
|
cost->set(creatureOnTheCard->cost * slider->getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreaturePurchaseCard::initAmountInfo()
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
|
|
|
availableAmount = std::make_shared<CLabel>(pos.x + 27, pos.y + 146, FONT_SMALL, CENTER, Colors::YELLOW);
|
|
|
|
purhaseAmount = std::make_shared<CLabel>(pos.x + 77, pos.y + 146, FONT_SMALL, CENTER, Colors::WHITE);
|
|
|
|
updateAmountInfo(0);
|
|
|
|
}
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::updateAmountInfo(int value)
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2017-11-15 20:44:54 +02:00
|
|
|
availableAmount->setText(boost::lexical_cast<std::string>(maxAmount-value));
|
2017-11-01 15:58:49 +02:00
|
|
|
purhaseAmount->setText(boost::lexical_cast<std::string>(value));
|
|
|
|
}
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::initSlider()
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2017-12-20 21:08:21 +02:00
|
|
|
slider = std::make_shared<CSlider>(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurchaseCard::sliderMoved, this , _1), 0, maxAmount, 0);
|
2017-11-01 15:58:49 +02:00
|
|
|
}
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::initCostBox()
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
|
|
|
cost = std::make_shared<CreatureCostBox>(Rect(pos.x, pos.y + 194, 97, 74), "");
|
2017-11-15 20:44:54 +02:00
|
|
|
cost->createItems(creatureOnTheCard->cost);
|
2017-11-01 15:58:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::sliderMoved(int to)
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
|
|
|
updateAmountInfo(to);
|
2017-11-15 20:44:54 +02:00
|
|
|
cost->set(creatureOnTheCard->cost * to);
|
2017-11-01 15:58:49 +02:00
|
|
|
parent->updateAllSliders();
|
|
|
|
}
|
|
|
|
|
2017-12-21 20:27:39 +02:00
|
|
|
CreaturePurchaseCard::CreaturePurchaseCard(const std::vector<CreatureID> & creaturesID, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents)
|
|
|
|
: upgradesID(creaturesID),
|
|
|
|
parent(parents),
|
|
|
|
maxAmount(creaturesMaxAmount)
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2017-12-20 21:08:21 +02:00
|
|
|
creatureOnTheCard = upgradesID.back().toCreature();
|
2017-11-15 20:44:54 +02:00
|
|
|
moveTo(Point(position.x, position.y));
|
2017-11-01 15:58:49 +02:00
|
|
|
initView();
|
|
|
|
}
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::initView()
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2017-11-15 20:44:54 +02:00
|
|
|
picture = std::make_shared<CCreaturePic>(pos.x, pos.y, creatureOnTheCard);
|
2017-11-01 15:58:49 +02:00
|
|
|
initAmountInfo();
|
|
|
|
initSlider();
|
|
|
|
initButtons();
|
|
|
|
initCostBox();
|
|
|
|
}
|