2024-02-03 22:59:05 +02:00
|
|
|
/*
|
|
|
|
* CFreelancerGuild.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 "CFreelancerGuild.h"
|
|
|
|
|
|
|
|
#include "../../gui/CGuiHandler.h"
|
2024-05-18 21:59:28 +02:00
|
|
|
#include "../../gui/Shortcut.h"
|
2024-02-03 22:59:05 +02:00
|
|
|
#include "../../widgets/Buttons.h"
|
|
|
|
#include "../../widgets/TextControls.h"
|
|
|
|
|
|
|
|
#include "../../CGameInfo.h"
|
|
|
|
#include "../../CPlayerInterface.h"
|
|
|
|
|
|
|
|
#include "../../../CCallback.h"
|
|
|
|
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../../../lib/texts/CGeneralTextHandler.h"
|
2024-02-03 22:59:05 +02:00
|
|
|
#include "../../../lib/mapObjects/CGHeroInstance.h"
|
2024-08-20 16:15:50 +02:00
|
|
|
#include "../../../lib/mapObjects/IMarket.h"
|
2024-02-03 22:59:05 +02:00
|
|
|
|
|
|
|
CFreelancerGuild::CFreelancerGuild(const IMarket * market, const CGHeroInstance * hero)
|
2024-03-20 13:28:19 +02:00
|
|
|
: CMarketBase(market, hero)
|
2024-02-27 13:39:50 +02:00
|
|
|
, CResourcesBuying(
|
2024-03-19 13:53:23 +02:00
|
|
|
[this](const std::shared_ptr<CTradeableItem> & heroSlot){CFreelancerGuild::onSlotClickPressed(heroSlot, offerTradePanel);},
|
2024-10-19 21:48:06 +02:00
|
|
|
[this](){CMarketBase::updateSubtitlesForBid(EMarketMode::CREATURE_RESOURCE, bidTradePanel->getHighlightedItemId());})
|
2024-03-02 20:30:29 +02:00
|
|
|
, CMarketSlider([this](int newVal){CMarketSlider::onOfferSliderMoved(newVal);})
|
2024-02-03 22:59:05 +02:00
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2024-02-03 22:59:05 +02:00
|
|
|
|
2024-03-02 20:30:29 +02:00
|
|
|
labels.emplace_back(std::make_shared<CLabel>(titlePos.x, titlePos.y, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW,
|
2024-03-20 13:28:19 +02:00
|
|
|
VLC->generaltexth->translate("object.core.freelancersGuild.name")));
|
2024-02-19 23:40:43 +02:00
|
|
|
labels.emplace_back(std::make_shared<CLabel>(155, 103, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE,
|
2024-02-03 22:59:05 +02:00
|
|
|
boost::str(boost::format(CGI->generaltexth->allTexts[272]) % hero->getNameTranslated())));
|
2024-03-02 20:30:29 +02:00
|
|
|
deal = std::make_shared<CButton>(dealButtonPosWithSlider, AnimationPath::builtin("TPMRKB.DEF"),
|
2024-05-18 21:59:28 +02:00
|
|
|
CGI->generaltexth->zelp[595], [this]() {CFreelancerGuild::makeDeal();}, EShortcut::MARKET_DEAL);
|
2024-03-02 20:30:29 +02:00
|
|
|
offerSlider->moveTo(pos.topLeft() + Point(232, 489));
|
2024-02-03 22:59:05 +02:00
|
|
|
|
|
|
|
// Hero creatures panel
|
2024-02-25 22:58:53 +02:00
|
|
|
assert(bidTradePanel);
|
|
|
|
bidTradePanel->moveTo(pos.topLeft() + Point(45, 123));
|
2024-03-19 13:53:23 +02:00
|
|
|
bidTradePanel->showcaseSlot->subtitle->moveBy(Point(0, -1));
|
2024-02-25 22:58:53 +02:00
|
|
|
bidTradePanel->deleteSlotsCheck = std::bind(&CCreaturesSelling::slotDeletingCheck, this, _1);
|
|
|
|
std::for_each(bidTradePanel->slots.cbegin(), bidTradePanel->slots.cend(), [this](auto & slot)
|
2024-02-03 22:59:05 +02:00
|
|
|
{
|
|
|
|
slot->clickPressedCallback = [this](const std::shared_ptr<CTradeableItem> & heroSlot)
|
|
|
|
{
|
2024-03-19 13:53:23 +02:00
|
|
|
CFreelancerGuild::onSlotClickPressed(heroSlot, bidTradePanel);
|
2024-02-03 22:59:05 +02:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2024-03-02 20:30:29 +02:00
|
|
|
CFreelancerGuild::deselect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFreelancerGuild::deselect()
|
|
|
|
{
|
|
|
|
CMarketBase::deselect();
|
|
|
|
CMarketSlider::deselect();
|
2024-03-20 13:28:19 +02:00
|
|
|
CMarketTraderText::deselect();
|
2024-02-03 22:59:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CFreelancerGuild::makeDeal()
|
|
|
|
{
|
2024-02-19 23:40:43 +02:00
|
|
|
if(auto toTrade = offerSlider->getValue(); toTrade != 0)
|
|
|
|
{
|
2024-10-19 21:48:06 +02:00
|
|
|
LOCPLINT->cb->trade(market->getObjInstanceID(), EMarketMode::CREATURE_RESOURCE, SlotID(bidTradePanel->highlightedSlot->serial), GameResID(offerTradePanel->getHighlightedItemId()), bidQty * toTrade, hero);
|
2024-03-20 13:28:19 +02:00
|
|
|
CMarketTraderText::makeDeal();
|
2024-02-19 23:40:43 +02:00
|
|
|
deselect();
|
|
|
|
}
|
2024-02-03 22:59:05 +02:00
|
|
|
}
|
|
|
|
|
2024-03-20 13:28:19 +02:00
|
|
|
CMarketBase::MarketShowcasesParams CFreelancerGuild::getShowcasesParams() const
|
2024-02-03 22:59:05 +02:00
|
|
|
{
|
2024-03-20 13:28:19 +02:00
|
|
|
if(bidTradePanel->isHighlighted() && offerTradePanel->isHighlighted())
|
2024-04-08 11:46:46 +02:00
|
|
|
return MarketShowcasesParams
|
|
|
|
{
|
2024-10-19 21:48:06 +02:00
|
|
|
ShowcaseParams {std::to_string(bidQty * offerSlider->getValue()), CGI->creatures()->getByIndex(bidTradePanel->getHighlightedItemId())->getIconIndex()},
|
|
|
|
ShowcaseParams {std::to_string(offerQty * offerSlider->getValue()), offerTradePanel->getHighlightedItemId()}
|
2024-04-08 11:46:46 +02:00
|
|
|
};
|
2024-02-22 22:49:30 +02:00
|
|
|
else
|
2024-04-08 11:46:46 +02:00
|
|
|
return MarketShowcasesParams {std::nullopt, std::nullopt};
|
2024-02-03 22:59:05 +02:00
|
|
|
}
|
|
|
|
|
2024-03-02 20:30:29 +02:00
|
|
|
void CFreelancerGuild::highlightingChanged()
|
2024-02-03 22:59:05 +02:00
|
|
|
{
|
2024-03-20 13:28:19 +02:00
|
|
|
if(bidTradePanel->isHighlighted() && offerTradePanel->isHighlighted())
|
2024-02-03 22:59:05 +02:00
|
|
|
{
|
2024-10-19 21:48:06 +02:00
|
|
|
market->getOffer(bidTradePanel->getHighlightedItemId(), offerTradePanel->getHighlightedItemId(), bidQty, offerQty, EMarketMode::CREATURE_RESOURCE);
|
2024-03-19 13:53:23 +02:00
|
|
|
offerSlider->setAmount((hero->getStackCount(SlotID(bidTradePanel->highlightedSlot->serial)) - (hero->stacksCount() == 1 && hero->needsLastStack() ? 1 : 0)) / bidQty);
|
|
|
|
offerSlider->scrollTo(0);
|
|
|
|
offerSlider->block(false);
|
|
|
|
maxAmount->block(false);
|
2024-04-28 14:58:54 +02:00
|
|
|
deal->block(!LOCPLINT->makingTurn);
|
2024-02-03 22:59:05 +02:00
|
|
|
}
|
2024-03-19 13:53:23 +02:00
|
|
|
CMarketBase::highlightingChanged();
|
2024-03-20 13:28:19 +02:00
|
|
|
CMarketTraderText::highlightingChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CFreelancerGuild::getTraderText()
|
|
|
|
{
|
|
|
|
if(bidTradePanel->isHighlighted() && offerTradePanel->isHighlighted())
|
|
|
|
{
|
2024-04-08 11:46:46 +02:00
|
|
|
MetaString message = MetaString::createFromTextID("core.genrltxt.269");
|
|
|
|
message.replaceNumber(offerQty);
|
|
|
|
message.replaceRawString(offerQty == 1 ? CGI->generaltexth->allTexts[161] : CGI->generaltexth->allTexts[160]);
|
2024-10-19 21:48:06 +02:00
|
|
|
message.replaceName(GameResID(offerTradePanel->getHighlightedItemId()));
|
2024-04-08 11:46:46 +02:00
|
|
|
message.replaceNumber(bidQty);
|
|
|
|
if(bidQty == 1)
|
2024-10-19 21:48:06 +02:00
|
|
|
message.replaceNameSingular(bidTradePanel->getHighlightedItemId());
|
2024-04-08 11:46:46 +02:00
|
|
|
else
|
2024-10-19 21:48:06 +02:00
|
|
|
message.replaceNamePlural(bidTradePanel->getHighlightedItemId());
|
2024-04-08 11:46:46 +02:00
|
|
|
return message.toString();
|
2024-03-20 13:28:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return madeTransaction ? CGI->generaltexth->allTexts[162] : CGI->generaltexth->allTexts[163];
|
|
|
|
}
|
2024-02-03 22:59:05 +02:00
|
|
|
}
|