|
@@ -13,7 +13,6 @@
|
|
|
|
|
|
#include "../../gui/CGuiHandler.h"
|
|
|
#include "../../widgets/Buttons.h"
|
|
|
-#include "../../widgets/Slider.h"
|
|
|
#include "../../widgets/TextControls.h"
|
|
|
|
|
|
#include "../../CGameInfo.h"
|
|
@@ -25,21 +24,31 @@
|
|
|
#include "../../../lib/CGeneralTextHandler.h"
|
|
|
#include "../../../lib/mapObjects/CGHeroInstance.h"
|
|
|
#include "../../../lib/mapObjects/CGMarket.h"
|
|
|
+#include "../../../lib/mapObjects/CGTownInstance.h"
|
|
|
|
|
|
CArtifactsSelling::CArtifactsSelling(const IMarket * market, const CGHeroInstance * hero)
|
|
|
- : CTradeBase(market, hero, [this](){return CArtifactsSelling::getSelectionParams();})
|
|
|
+ : CMarketBase(market, hero, [this](){return CArtifactsSelling::getSelectionParams();})
|
|
|
, CResourcesBuying(
|
|
|
[this](const std::shared_ptr<CTradeableItem> & resSlot){CArtifactsSelling::onSlotClickPressed(resSlot, hRight);},
|
|
|
- [this](){CTradeBase::updateSubtitles(EMarketMode::ARTIFACT_RESOURCE);})
|
|
|
+ [this](){CMarketBase::updateSubtitles(EMarketMode::ARTIFACT_RESOURCE);})
|
|
|
{
|
|
|
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
|
|
|
|
|
|
- deal = std::make_shared<CButton>(Point(270, 520), AnimationPath::builtin("TPMRKB.DEF"),
|
|
|
+ labels.emplace_back(std::make_shared<CLabel>(titlePos.x, titlePos.y, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW,
|
|
|
+ (*CGI->townh)[dynamic_cast<const CGTownInstance*>(market)->getFaction()]->town->buildings[BuildingID::ARTIFACT_MERCHANT]->getNameTranslated()));
|
|
|
+ labels.push_back(std::make_shared<CLabel>(155, 56, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, boost::str(boost::format(CGI->generaltexth->allTexts[271]) % hero->getNameTranslated())));
|
|
|
+ deal = std::make_shared<CButton>(dealButtonPos, AnimationPath::builtin("TPMRKB.DEF"),
|
|
|
CGI->generaltexth->zelp[595], [this](){CArtifactsSelling::makeDeal();});
|
|
|
bidSelectedSlot = std::make_shared<CTradeableItem>(Rect(Point(123, 470), Point(69, 66)), EType::ARTIFACT_TYPE, 0, 0);
|
|
|
|
|
|
+ // Market resources panel
|
|
|
+ assert(offerTradePanel);
|
|
|
+ offerTradePanel->moveTo(pos.topLeft() + Point(326, 184));
|
|
|
+ offerTradePanel->selectedSlot->moveTo(pos.topLeft() + Point(409, 473));
|
|
|
+ offerTradePanel->selectedSlot->subtitle->moveBy(Point(0, 1));
|
|
|
+
|
|
|
// Hero's artifacts
|
|
|
- heroArts = std::make_shared<CArtifactsOfHeroMarket>(Point(-361, 46));
|
|
|
+ heroArts = std::make_shared<CArtifactsOfHeroMarket>(Point(-361, 46), offerTradePanel->selectionWidth);
|
|
|
heroArts->setHero(hero);
|
|
|
heroArts->selectArtCallback = [this](CArtPlace * artPlace)
|
|
|
{
|
|
@@ -49,29 +58,18 @@ CArtifactsSelling::CArtifactsSelling(const IMarket * market, const CGHeroInstanc
|
|
|
bidSelectedSlot->setID(artForTrade->getTypeId().num);
|
|
|
hLeft = bidSelectedSlot;
|
|
|
selectedHeroSlot = artPlace->slot;
|
|
|
- if(hRight)
|
|
|
- { // dublicate
|
|
|
- this->market->getOffer(hLeft->id, hRight->id, bidQty, offerQty, EMarketMode::ARTIFACT_RESOURCE);
|
|
|
- deal->block(false);
|
|
|
- }
|
|
|
- CArtifactsSelling::updateSelected();
|
|
|
- offerTradePanel->updateSlots();
|
|
|
+ CArtifactsSelling::highlightingChanged();
|
|
|
+ offerTradePanel->update();
|
|
|
redraw();
|
|
|
};
|
|
|
|
|
|
- // Market resources panel
|
|
|
- assert(offerTradePanel);
|
|
|
- offerTradePanel->moveTo(pos.topLeft() + Point(326, 184));
|
|
|
- offerTradePanel->selectedSlot->moveTo(pos.topLeft() + Point(409, 473));
|
|
|
- offerTradePanel->selectedSlot->subtitle->moveBy(Point(0, 1));
|
|
|
-
|
|
|
CArtifactsSelling::updateSelected();
|
|
|
CArtifactsSelling::deselect();
|
|
|
}
|
|
|
|
|
|
void CArtifactsSelling::deselect()
|
|
|
{
|
|
|
- CTradeBase::deselect();
|
|
|
+ CMarketBase::deselect();
|
|
|
selectedHeroSlot = ArtifactPosition::PRE_FIRST;
|
|
|
heroArts->unmarkSlots();
|
|
|
}
|
|
@@ -85,7 +83,7 @@ void CArtifactsSelling::makeDeal()
|
|
|
|
|
|
void CArtifactsSelling::updateSelected()
|
|
|
{
|
|
|
- CTradeBase::updateSelected();
|
|
|
+ CMarketBase::updateSelected();
|
|
|
|
|
|
if(hLeft && hRight)
|
|
|
{
|
|
@@ -101,11 +99,16 @@ void CArtifactsSelling::updateSelected()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void CArtifactsSelling::updateSlots()
|
|
|
+void CArtifactsSelling::update()
|
|
|
{
|
|
|
- CTradeBase::updateSlots();
|
|
|
+ CMarketBase::update();
|
|
|
if(selectedHeroSlot != ArtifactPosition::PRE_FIRST)
|
|
|
{
|
|
|
+ if(selectedHeroSlot.num >= ArtifactPosition::BACKPACK_START + hero->artifactsInBackpack.size())
|
|
|
+ {
|
|
|
+ selectedHeroSlot = ArtifactPosition::BACKPACK_START;
|
|
|
+ deselect();
|
|
|
+ }
|
|
|
if(hero->getArt(selectedHeroSlot) == nullptr)
|
|
|
deselect();
|
|
|
}
|
|
@@ -116,7 +119,7 @@ std::shared_ptr<CArtifactsOfHeroMarket> CArtifactsSelling::getAOHset() const
|
|
|
return heroArts;
|
|
|
}
|
|
|
|
|
|
-CTradeBase::SelectionParams CArtifactsSelling::getSelectionParams() const
|
|
|
+CMarketBase::SelectionParams CArtifactsSelling::getSelectionParams() const
|
|
|
{
|
|
|
if(hLeft && hRight)
|
|
|
return std::make_tuple(
|
|
@@ -127,21 +130,23 @@ CTradeBase::SelectionParams CArtifactsSelling::getSelectionParams() const
|
|
|
return std::make_tuple(std::nullopt, std::nullopt);
|
|
|
}
|
|
|
|
|
|
+void CArtifactsSelling::highlightingChanged()
|
|
|
+{
|
|
|
+ if(hLeft && hRight)
|
|
|
+ {
|
|
|
+ market->getOffer(hLeft->id, hRight->id, bidQty, offerQty, EMarketMode::ARTIFACT_RESOURCE);
|
|
|
+ deal->block(false);
|
|
|
+ }
|
|
|
+ updateSelected();
|
|
|
+}
|
|
|
+
|
|
|
void CArtifactsSelling::onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot, std::shared_ptr<CTradeableItem> & hCurSlot)
|
|
|
{
|
|
|
assert(newSlot);
|
|
|
if(newSlot == hCurSlot)
|
|
|
return;
|
|
|
|
|
|
- CTradeBase::onSlotClickPressed(newSlot, hCurSlot);
|
|
|
- if(hLeft)
|
|
|
- {
|
|
|
- if(hRight)
|
|
|
- {
|
|
|
- market->getOffer(hLeft->id, hRight->id, bidQty, offerQty, EMarketMode::ARTIFACT_RESOURCE);
|
|
|
- deal->block(false);
|
|
|
- }
|
|
|
- updateSelected();
|
|
|
- }
|
|
|
+ CMarketBase::onSlotClickPressed(newSlot, hCurSlot);
|
|
|
+ highlightingChanged();
|
|
|
redraw();
|
|
|
}
|