2024-02-25 22:58:53 +02:00
|
|
|
/*
|
|
|
|
* CArtifactsSelling.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 "CArtifactsSelling.h"
|
|
|
|
|
|
|
|
#include "../../gui/CGuiHandler.h"
|
|
|
|
#include "../../widgets/Buttons.h"
|
|
|
|
#include "../../widgets/Slider.h"
|
|
|
|
#include "../../widgets/TextControls.h"
|
|
|
|
|
|
|
|
#include "../../CGameInfo.h"
|
|
|
|
|
|
|
|
#include "../../../lib/CArtifactInstance.h"
|
|
|
|
#include "../../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../../lib/mapObjects/CGMarket.h"
|
|
|
|
|
|
|
|
CArtifactsSelling::CArtifactsSelling(const IMarket * market, const CGHeroInstance * hero)
|
2024-02-29 12:02:39 +02:00
|
|
|
: CTradeBase(market, hero, [this](){return CArtifactsSelling::getSelectionParams();})
|
2024-02-27 13:39:50 +02:00
|
|
|
, CResourcesBuying(
|
|
|
|
[this](const std::shared_ptr<CTradeableItem> & resSlot){CArtifactsSelling::onSlotClickPressed(resSlot, hRight);},
|
|
|
|
[this](){CTradeBase::updateSubtitles(EMarketMode::ARTIFACT_RESOURCE);})
|
2024-02-25 22:58:53 +02:00
|
|
|
{
|
|
|
|
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
|
|
|
|
|
|
|
|
deal = std::make_shared<CButton>(Point(270, 520), AnimationPath::builtin("TPMRKB.DEF"),
|
|
|
|
CGI->generaltexth->zelp[595], [this](){CArtifactsSelling::makeDeal();});
|
2024-02-27 13:39:50 +02:00
|
|
|
bidSelectedSlot = std::make_shared<CTradeableItem>(Rect(Point(123, 470), Point(69, 66)), EType::ARTIFACT_TYPE, 0, 0);
|
2024-02-25 22:58:53 +02:00
|
|
|
|
|
|
|
// Hero's artifacts
|
|
|
|
heroArts = std::make_shared<CArtifactsOfHeroMarket>(Point(-361, 46));
|
|
|
|
heroArts->setHero(hero);
|
|
|
|
heroArts->selectArtCallback = [this](CArtPlace * artPlace)
|
|
|
|
{
|
|
|
|
assert(artPlace);
|
2024-02-27 13:39:50 +02:00
|
|
|
const auto artForTrade = artPlace->getArt();
|
|
|
|
assert(artForTrade);
|
|
|
|
bidSelectedSlot->setID(artForTrade->getTypeId().num);
|
|
|
|
hLeft = bidSelectedSlot;
|
2024-02-25 22:58:53 +02:00
|
|
|
if(hRight)
|
2024-02-27 13:39:50 +02:00
|
|
|
{ // dublicate
|
|
|
|
this->market->getOffer(hLeft->id, hRight->id, bidQty, offerQty, EMarketMode::ARTIFACT_RESOURCE);
|
2024-02-25 22:58:53 +02:00
|
|
|
deal->block(false);
|
|
|
|
}
|
|
|
|
CArtifactsSelling::updateSelected();
|
|
|
|
offerTradePanel->updateSlots();
|
|
|
|
redraw();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Market resources panel
|
|
|
|
assert(offerTradePanel);
|
2024-02-27 13:39:50 +02:00
|
|
|
offerTradePanel->moveTo(pos.topLeft() + Point(326, 184));
|
|
|
|
offerTradePanel->selectedSlot->moveTo(pos.topLeft() + Point(409, 473));
|
2024-02-25 22:58:53 +02:00
|
|
|
|
|
|
|
CArtifactsSelling::updateSelected();
|
2024-02-29 12:02:39 +02:00
|
|
|
CTradeBase::deselect();
|
2024-02-25 22:58:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactsSelling::makeDeal()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactsSelling::updateSelected()
|
|
|
|
{
|
2024-02-29 12:02:39 +02:00
|
|
|
CTradeBase::updateSelected();
|
2024-02-25 22:58:53 +02:00
|
|
|
|
2024-02-27 13:39:50 +02:00
|
|
|
if(hLeft && hRight)
|
2024-02-25 22:58:53 +02:00
|
|
|
{
|
2024-02-27 13:39:50 +02:00
|
|
|
bidSelectedSlot->image->enable();
|
|
|
|
bidSelectedSlot->image->setFrame(CGI->artifacts()->getByIndex(hLeft->id)->getIconIndex());
|
|
|
|
bidSelectedSlot->subtitle->setText(std::to_string(bidQty));
|
2024-02-25 22:58:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-27 13:39:50 +02:00
|
|
|
bidSelectedSlot->image->disable();
|
|
|
|
bidSelectedSlot->image->setFrame(0);
|
|
|
|
bidSelectedSlot->subtitle->clear();
|
2024-02-25 22:58:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<CArtifactsOfHeroMarket> CArtifactsSelling::getAOHset() const
|
|
|
|
{
|
|
|
|
return heroArts;
|
|
|
|
}
|
|
|
|
|
2024-02-29 12:02:39 +02:00
|
|
|
CTradeBase::SelectionParams CArtifactsSelling::getSelectionParams() const
|
2024-02-25 22:58:53 +02:00
|
|
|
{
|
2024-02-27 13:39:50 +02:00
|
|
|
if(hLeft && hRight)
|
2024-02-25 22:58:53 +02:00
|
|
|
return std::make_tuple(
|
|
|
|
std::nullopt,
|
|
|
|
SelectionParamOneSide {std::to_string(offerQty), GameResID(hRight->id)}
|
|
|
|
);
|
|
|
|
else
|
|
|
|
return std::make_tuple(std::nullopt, std::nullopt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CArtifactsSelling::onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot, std::shared_ptr<CTradeableItem> & hCurSlot)
|
|
|
|
{
|
|
|
|
assert(newSlot);
|
|
|
|
if(newSlot == hCurSlot)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CTradeBase::onSlotClickPressed(newSlot, hCurSlot);
|
2024-02-27 13:39:50 +02:00
|
|
|
if(hLeft)
|
2024-02-25 22:58:53 +02:00
|
|
|
{
|
|
|
|
if(hRight)
|
|
|
|
{
|
2024-02-27 13:39:50 +02:00
|
|
|
market->getOffer(hLeft->id, hRight->id, bidQty, offerQty, EMarketMode::ARTIFACT_RESOURCE);
|
2024-02-25 22:58:53 +02:00
|
|
|
deal->block(false);
|
|
|
|
}
|
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
redraw();
|
|
|
|
}
|