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"
|
2023-02-01 20:42:06 +02:00
|
|
|
|
2017-11-01 15:58:49 +02:00
|
|
|
#include "CHeroWindow.h"
|
|
|
|
#include "QuickRecruitmentWindow.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "CCreatureWindow.h"
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-04-27 19:21:06 +02:00
|
|
|
#include "../gui/Shortcut.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../gui/TextAlignment.h"
|
2023-05-16 14:10:26 +02:00
|
|
|
#include "../gui/WindowHandler.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../widgets/Buttons.h"
|
2023-05-30 16:31:45 +02:00
|
|
|
#include "../widgets/Slider.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../widgets/TextControls.h"
|
|
|
|
#include "../widgets/CreatureCostBox.h"
|
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "../../lib/CCreatureHandler.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
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
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);
|
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
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
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);
|
2017-11-01 15:58:49 +02:00
|
|
|
}
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::initCreatureSwitcherButton()
|
|
|
|
{
|
2024-05-18 21:59:28 +02:00
|
|
|
creatureSwitcher = std::make_shared<CButton>(Point(pos.x + 18, pos.y-37), AnimationPath::builtin("iDv6432.def"), CButton::tooltip(), [&](){ switchCreatureLevel(); }, EShortcut::RECRUITMENT_SWITCH_LEVEL);
|
2017-12-20 21:08:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreaturePurchaseCard::switchCreatureLevel()
|
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2023-04-05 02:26:29 +02:00
|
|
|
auto index = vstd::find_pos(upgradesID, creatureOnTheCard->getId());
|
2017-12-20 21:08:21 +02:00
|
|
|
auto nextCreatureId = vstd::circularAt(upgradesID, ++index);
|
|
|
|
creatureOnTheCard = nextCreatureId.toCreature();
|
2024-11-15 04:25:16 +02:00
|
|
|
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);
|
2017-12-20 21:08:21 +02:00
|
|
|
parent->updateAllSliders();
|
2023-04-05 02:26:29 +02:00
|
|
|
cost->set(creatureOnTheCard->getFullRecruitCost() * slider->getValue());
|
2017-12-20 21:08:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreaturePurchaseCard::initAmountInfo()
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2022-11-26 23:12:20 +02:00
|
|
|
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);
|
2017-11-01 15:58:49 +02:00
|
|
|
updateAmountInfo(0);
|
|
|
|
}
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::updateAmountInfo(int value)
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2023-03-09 15:36:46 +02:00
|
|
|
availableAmount->setText(std::to_string(maxAmount-value));
|
|
|
|
purchaseAmount->setText(std::to_string(value));
|
2017-11-01 15:58:49 +02:00
|
|
|
}
|
|
|
|
|
2017-12-20 21:08:21 +02:00
|
|
|
void CreaturePurchaseCard::initSlider()
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2023-06-22 22:49:38 +02:00
|
|
|
slider = std::make_shared<CSlider>(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurchaseCard::sliderMoved, this, _1), 0, maxAmount, 0, Orientation::HORIZONTAL);
|
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
|
|
|
{
|
2017-12-22 21:52:13 +02:00
|
|
|
cost = std::make_shared<CreatureCostBox>(Rect(pos.x+2, pos.y + 194, 97, 74), "");
|
2023-04-05 02:26:29 +02:00
|
|
|
cost->createItems(creatureOnTheCard->getFullRecruitCost());
|
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);
|
2023-04-05 02:26:29 +02:00
|
|
|
cost->set(creatureOnTheCard->getFullRecruitCost() * 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);
|
2023-08-23 14:07:50 +02:00
|
|
|
background = std::make_shared<CPicture>(ImagePath::builtin("QuickRecruitmentWindow/CreaturePurchaseCard.png"), pos.x-4, pos.y-50);
|
2022-10-04 20:30:18 +02:00
|
|
|
creatureClickArea = std::make_shared<CCreatureClickArea>(Point(pos.x, pos.y), picture, creatureOnTheCard);
|
2022-09-19 07:45:30 +02:00
|
|
|
|
2017-11-01 15:58:49 +02:00
|
|
|
initAmountInfo();
|
|
|
|
initSlider();
|
2022-10-04 20:30:18 +02:00
|
|
|
initButtons(); // order important! buttons need slider!
|
2017-11-01 15:58:49 +02:00
|
|
|
initCostBox();
|
|
|
|
}
|
2022-09-19 07:45:30 +02:00
|
|
|
|
|
|
|
CreaturePurchaseCard::CCreatureClickArea::CCreatureClickArea(const Point & position, const std::shared_ptr<CCreaturePic> creaturePic, const CCreature * creatureOnTheCard)
|
2023-06-13 18:33:35 +02:00
|
|
|
: CIntObject(SHOW_POPUP),
|
2022-09-19 07:45:30 +02:00
|
|
|
creatureOnTheCard(creatureOnTheCard)
|
|
|
|
{
|
2022-10-04 20:30:18 +02:00
|
|
|
pos.x += position.x;
|
|
|
|
pos.y += position.y;
|
2022-09-19 07:45:30 +02:00
|
|
|
pos.w = CREATURE_WIDTH;
|
|
|
|
pos.h = CREATURE_HEIGHT;
|
|
|
|
}
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void CreaturePurchaseCard::CCreatureClickArea::showPopupWindow(const Point & cursorPosition)
|
2022-09-19 07:45:30 +02:00
|
|
|
{
|
2023-06-11 17:20:10 +02:00
|
|
|
GH.windows().createAndPushWindow<CStackWindow>(creatureOnTheCard, true);
|
2022-09-19 07:45:30 +02:00
|
|
|
}
|