1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Quick Recruitment Window upgrade

Now is possible to switch by button between creatures upgrades.
Fixed small typo, rename from purhase to purchase.
This commit is contained in:
FeniksFire 2017-12-20 20:08:21 +01:00
parent 26a222ac62
commit f82fd41a14
5 changed files with 48 additions and 29 deletions

View File

@ -32,7 +32,7 @@ set(client_SRCS
windows/CAdvmapInterface.cpp
windows/CCastleInterface.cpp
windows/CCreatureWindow.cpp
windows/CreaturePurhaseCard.cpp
windows/CreaturePurchaseCard.cpp
windows/CHeroWindow.cpp
windows/CKingdomInterface.cpp
windows/CQuestLog.cpp
@ -90,7 +90,7 @@ set(client_HEADERS
windows/CAdvmapInterface.h
windows/CCastleInterface.h
windows/CCreatureWindow.h
windows/CreaturePurhaseCard.h
windows/CreaturePurchaseCard.h
windows/CHeroWindow.h
windows/CKingdomInterface.h
windows/CQuestLog.h

View File

@ -8,69 +8,88 @@
*
*/
#include "StdInc.h"
#include "CreaturePurhaseCard.h"
#include "CreaturePurchaseCard.h"
#include "CAdvmapInterface.h"
#include "CHeroWindow.h"
#include "../widgets/Buttons.h"
#include "../../CCallback.h"
#include "../CreatureCostBox.h"
#include "QuickRecruitmentWindow.h"
#include "../gui/CGuiHandler.h"
void CreaturePurhaseCard::initButtons()
void CreaturePurchaseCard::initButtons()
{
initMaxButton();
initMinButton();
initCreatureSwitcherButton();
}
void CreaturePurhaseCard::initMaxButton()
void CreaturePurchaseCard::initMaxButton()
{
maxButton = std::make_shared<CButton>(Point(pos.x + 52, pos.y + 178), "iam014.def", CButton::tooltip(), std::bind(&CSlider::moveToMax,slider), SDLK_m);
maxButton = std::make_shared<CButton>(Point(pos.x + 52, pos.y + 178), "iam014.def", CButton::tooltip(), std::bind(&CSlider::moveToMax,slider), SDLK_LSHIFT);
}
void CreaturePurhaseCard::initMinButton()
void CreaturePurchaseCard::initMinButton()
{
minButton = std::make_shared<CButton>(Point(pos.x, pos.y + 178), "iam015.def", CButton::tooltip(), std::bind(&CSlider::moveToMin,slider), SDLK_m);
minButton = std::make_shared<CButton>(Point(pos.x, pos.y + 178), "iam015.def", CButton::tooltip(), std::bind(&CSlider::moveToMin,slider), SDLK_LCTRL);
}
void CreaturePurhaseCard::initAmountInfo()
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()
{
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);
}
void CreaturePurhaseCard::updateAmountInfo(int value)
void CreaturePurchaseCard::updateAmountInfo(int value)
{
availableAmount->setText(boost::lexical_cast<std::string>(maxAmount-value));
purhaseAmount->setText(boost::lexical_cast<std::string>(value));
}
void CreaturePurhaseCard::initSlider()
void CreaturePurchaseCard::initSlider()
{
slider = std::make_shared<CSlider>(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurhaseCard::sliderMoved, this , _1), 0, maxAmount, 0);
slider = std::make_shared<CSlider>(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurchaseCard::sliderMoved, this , _1), 0, maxAmount, 0);
}
void CreaturePurhaseCard::initCostBox()
void CreaturePurchaseCard::initCostBox()
{
cost = std::make_shared<CreatureCostBox>(Rect(pos.x, pos.y + 194, 97, 74), "");
cost->createItems(creatureOnTheCard->cost);
}
void CreaturePurhaseCard::sliderMoved(int to)
void CreaturePurchaseCard::sliderMoved(int to)
{
updateAmountInfo(to);
cost->set(creatureOnTheCard->cost * to);
parent->updateAllSliders();
}
CreaturePurhaseCard::CreaturePurhaseCard(const CCreature * creature, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents) : creatureOnTheCard(creature), parent(parents), maxAmount(creaturesMaxAmount)
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 CreaturePurhaseCard::initView()
void CreaturePurchaseCard::initView()
{
picture = std::make_shared<CCreaturePic>(pos.x, pos.y, creatureOnTheCard);
initAmountInfo();

View File

@ -17,7 +17,7 @@ class CButton;
class CreatureCostBox;
class QuickRecruitmentWindow;
class CreaturePurhaseCard : public CIntObject
class CreaturePurchaseCard : public CIntObject
{
public:
const CCreature * creatureOnTheCard;
@ -25,14 +25,15 @@ public:
QuickRecruitmentWindow * parent;
int maxAmount;
void sliderMoved(int to);
CreaturePurhaseCard(const CCreature * creature, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents);
CreaturePurchaseCard(const std::vector<CreatureID> & creaturesID, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents);
private:
void initView();
void initButtons();
void initMaxButton();
void initMinButton();
void initCreatureSwitcherButton();
void switchCreatureLevel();
void initAmountInfo();
void updateAmountInfo(int value);
@ -41,9 +42,9 @@ private:
void initCostBox();
std::shared_ptr<CButton> maxButton, minButton;
std::shared_ptr<CButton> maxButton, minButton, creatureSwitcher;
std::shared_ptr<CLabel> availableAmount, purhaseAmount;
std::shared_ptr<CCreaturePic> picture;
std::shared_ptr<CreatureCostBox> cost;
const std::vector<CreatureID> & upgradesID;
};

View File

@ -16,7 +16,7 @@
#include "../../CCallback.h"
#include "../CreatureCostBox.h"
#include "../lib/ResourceSet.h"
#include "CreaturePurhaseCard.h"
#include "CreaturePurchaseCard.h"
void QuickRecruitmentWindow::setButtons()
@ -53,8 +53,7 @@ void QuickRecruitmentWindow::setCreaturePurhaseCards()
{
if(!town->town->creatures.at(i).empty() && !town->creatures.at(i).second.empty() && town->creatures[i].first)
{
CreatureID crid = town->creatures[i].second[town->creatures[i].second.size() - 1];
cards.push_back(std::make_shared<CreaturePurhaseCard>(VLC->creh->creatures[crid], position, town->creatures[i].first, this));
cards.push_back(std::make_shared<CreaturePurchaseCard>(town->creatures[i].second, position, town->creatures[i].first, this));
position.x += 108;
}
}
@ -76,7 +75,7 @@ void QuickRecruitmentWindow::initWindow(Rect startupPosition)
backgroundTexture = std::make_shared<CFilledTexture>("DIBOXBCK.pcx", Rect(0, 0, pos.w, pos.h));
}
void QuickRecruitmentWindow::maxAllCards(std::vector<std::shared_ptr<CreaturePurhaseCard> > cards)
void QuickRecruitmentWindow::maxAllCards(std::vector<std::shared_ptr<CreaturePurchaseCard> > cards)
{
auto allAvailableResources = LOCPLINT->cb->getResourceAmount();
for(auto i : boost::adaptors::reverse(cards))

View File

@ -13,7 +13,7 @@
class CButton;
class CreatureCostBox;
class CreaturePurhaseCard;
class CreaturePurchaseCard;
class CFilledTexture;
class QuickRecruitmentWindow : public CWindowObject
@ -33,13 +33,13 @@ private:
void setCreaturePurhaseCards();
void maxAllCards(std::vector<std::shared_ptr<CreaturePurhaseCard>> cards);
void maxAllSlidersAmount(std::vector<std::shared_ptr<CreaturePurhaseCard>> cards);
void maxAllCards(std::vector<std::shared_ptr<CreaturePurchaseCard>> cards);
void maxAllSlidersAmount(std::vector<std::shared_ptr<CreaturePurchaseCard>> cards);
void purhaseUnits();
const CGTownInstance * town;
std::shared_ptr<CButton> maxButton, buyButton, cancelButton;
std::shared_ptr<CreatureCostBox> totalCost;
std::vector<std::shared_ptr<CreaturePurhaseCard>> cards;
std::vector<std::shared_ptr<CreaturePurchaseCard>> cards;
std::shared_ptr<CFilledTexture> backgroundTexture;
};