1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/client/windows/CreaturePurchaseCard.cpp

130 lines
4.5 KiB
C++
Raw Normal View History

/*
2017-12-21 20:27:39 +02:00
* 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"
2023-05-30 16:31:45 +02:00
#include "../widgets/Slider.h"
#include "../widgets/TextControls.h"
#include "../widgets/CreatureCostBox.h"
#include "../../CCallback.h"
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
#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;
2023-04-05 02:26:29 +02:00
auto index = vstd::find_pos(upgradesID, creatureOnTheCard->getId());
auto nextCreatureId = vstd::circularAt(upgradesID, ++index);
creatureOnTheCard = nextCreatureId.toCreature();
picture = std::make_shared<CCreaturePic>(parent->pos.x, parent->pos.y, creatureOnTheCard);
2022-10-04 20:30:18 +02:00
creatureClickArea = std::make_shared<CCreatureClickArea>(Point(parent->pos.x, parent->pos.y), picture, creatureOnTheCard);
parent->updateAllSliders();
2023-04-05 02:26:29 +02:00
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)
{
2023-03-09 15:36:46 +02:00
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), "");
2023-04-05 02:26:29 +02:00
cost->createItems(creatureOnTheCard->getFullRecruitCost());
}
void CreaturePurchaseCard::sliderMoved(int to)
{
updateAmountInfo(to);
2023-04-05 02:26:29 +02:00
cost->set(creatureOnTheCard->getFullRecruitCost() * to);
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)
{
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);
2022-10-04 20:30:18 +02:00
creatureClickArea = std::make_shared<CCreatureClickArea>(Point(pos.x, pos.y), picture, creatureOnTheCard);
initAmountInfo();
initSlider();
2022-10-04 20:30:18 +02:00
initButtons(); // order important! buttons need slider!
initCostBox();
}
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),
creatureOnTheCard(creatureOnTheCard)
{
2022-10-04 20:30:18 +02:00
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);
}