mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-30 23:18:08 +02:00
Artifacts market widget
This commit is contained in:
parent
4e0ea7355b
commit
bb7137545f
@ -60,6 +60,11 @@ CAltarCreatures::CAltarCreatures(const IMarket * market, const CGHeroInstance *
|
||||
rightTradePanel->moveTo(pos.topLeft() + Point(334, 110));
|
||||
rightTradePanel->selectedImage->moveTo(pos.topLeft() + Point(395, 422));
|
||||
rightTradePanel->selectedSubtitle->moveTo(pos.topLeft() + Point(426, 503));
|
||||
rightTradePanel->updateSlotsCallback = [this]()
|
||||
{
|
||||
for(const auto & altarSlot : rightTradePanel->slots)
|
||||
updateAltarSlot(altarSlot);
|
||||
};
|
||||
leftTradePanel->deleteSlotsCheck = rightTradePanel->deleteSlotsCheck = std::bind(&CCreaturesSelling::slotDeletingCheck, this, _1);
|
||||
|
||||
readExpValues();
|
||||
@ -69,7 +74,7 @@ CAltarCreatures::CAltarCreatures(const IMarket * market, const CGHeroInstance *
|
||||
void CAltarCreatures::readExpValues()
|
||||
{
|
||||
int bidQty = 0;
|
||||
for(auto heroSlot : leftTradePanel->slots)
|
||||
for(const auto & heroSlot : leftTradePanel->slots)
|
||||
{
|
||||
if(heroSlot->id >= 0)
|
||||
market->getOffer(heroSlot->id, 0, bidQty, expPerUnit[heroSlot->serial], EMarketMode::CREATURE_EXP);
|
||||
@ -138,10 +143,9 @@ void CAltarCreatures::updateSelected()
|
||||
|
||||
void CAltarCreatures::updateSlots()
|
||||
{
|
||||
rightTradePanel->deleteSlots();
|
||||
rightTradePanel->updateSlots();
|
||||
CCreaturesSelling::updateSlots();
|
||||
assert(leftTradePanel->slots.size() == rightTradePanel->slots.size());
|
||||
readExpValues();
|
||||
}
|
||||
|
||||
void CAltarCreatures::deselect()
|
||||
@ -211,14 +215,13 @@ void CAltarCreatures::sacrificeAll()
|
||||
|
||||
if(hRight)
|
||||
offerSlider->scrollTo(unitsOnAltar[hRight->serial]);
|
||||
for(auto altarSlot : rightTradePanel->slots)
|
||||
updateAltarSlot(altarSlot);
|
||||
rightTradePanel->updateSlots();
|
||||
updateSelected();
|
||||
|
||||
deal->block(calcExpAltarForHero() == 0);
|
||||
}
|
||||
|
||||
void CAltarCreatures::updateAltarSlot(std::shared_ptr<CTradeableItem> slot)
|
||||
void CAltarCreatures::updateAltarSlot(const std::shared_ptr<CTradeableItem> & slot)
|
||||
{
|
||||
auto units = unitsOnAltar[slot->serial];
|
||||
slot->setType(units > 0 ? EType::CREATURE : EType::CREATURE_PLACEHOLDER);
|
||||
|
@ -20,12 +20,12 @@ public:
|
||||
TExpType calcExpAltarForHero() override;
|
||||
void makeDeal() override;
|
||||
void sacrificeAll() override;
|
||||
void updateAltarSlot(std::shared_ptr<CTradeableItem> slot);
|
||||
|
||||
private:
|
||||
std::vector<int> unitsOnAltar;
|
||||
std::vector<int> expPerUnit;
|
||||
|
||||
void updateAltarSlot(const std::shared_ptr<CTradeableItem> & slot);
|
||||
void readExpValues();
|
||||
void updateControls();
|
||||
void updateSelected();
|
||||
|
120
client/widgets/markets/CArtifactsBuying.cpp
Normal file
120
client/widgets/markets/CArtifactsBuying.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* CArtifactsBuying.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 "CArtifactsBuying.h"
|
||||
|
||||
#include "../../gui/CGuiHandler.h"
|
||||
#include "../../widgets/Buttons.h"
|
||||
#include "../../widgets/Slider.h"
|
||||
#include "../../widgets/TextControls.h"
|
||||
|
||||
#include "../../CGameInfo.h"
|
||||
#include "../../CPlayerInterface.h"
|
||||
|
||||
#include "../../../CCallback.h"
|
||||
|
||||
#include "../../../lib/CGeneralTextHandler.h"
|
||||
#include "../../../lib/mapObjects/CGMarket.h"
|
||||
#include "../../../lib/mapObjects/CGTownInstance.h"
|
||||
|
||||
CArtifactsBuying::CArtifactsBuying(const IMarket * market, const CGHeroInstance * hero)
|
||||
: CTradeBase(market, hero)
|
||||
, CMarketMisc([this](){return CArtifactsBuying::getSelectionParams();})
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
|
||||
|
||||
assert(dynamic_cast<const CGTownInstance*>(market));
|
||||
labels.emplace_back(std::make_shared<CLabel>(299, 27, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW,
|
||||
(*CGI->townh)[dynamic_cast<const CGTownInstance*>(market)->getFaction()]->town->buildings[BuildingID::ARTIFACT_MERCHANT]->getNameTranslated()));
|
||||
deal = std::make_shared<CButton>(Point(270, 520), AnimationPath::builtin("TPMRKB.DEF"),
|
||||
CGI->generaltexth->zelp[595], [this]() {CArtifactsBuying::makeDeal(); });
|
||||
labels.emplace_back(std::make_shared<CLabel>(445, 148, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[168]));
|
||||
|
||||
// Player's resources
|
||||
assert(leftTradePanel);
|
||||
std::for_each(leftTradePanel->slots.cbegin(), leftTradePanel->slots.cend(), [this](auto & slot)
|
||||
{
|
||||
slot->clickPressedCallback = [this](const std::shared_ptr<CTradeableItem> & heroSlot)
|
||||
{
|
||||
CArtifactsBuying::onSlotClickPressed(heroSlot, hLeft);
|
||||
};
|
||||
});
|
||||
leftTradePanel->moveTo(pos.topLeft() + Point(39, 182));
|
||||
leftTradePanel->selectedImage->moveTo(pos.topLeft() + Point(141, 453));
|
||||
|
||||
// Artifacts panel
|
||||
rightTradePanel = std::make_shared<ArtifactsPanel>([this](const std::shared_ptr<CTradeableItem> & newSlot)
|
||||
{
|
||||
CArtifactsBuying::onSlotClickPressed(newSlot, hRight);
|
||||
|
||||
}, [this]()
|
||||
{
|
||||
// TODO move to parent
|
||||
if(hLeft)
|
||||
for(const auto & slot : rightTradePanel->slots)
|
||||
{
|
||||
int h1, h2; //hlp variables for getting offer
|
||||
this->market->getOffer(hLeft->id, slot->id, h1, h2, EMarketMode::RESOURCE_ARTIFACT);
|
||||
|
||||
rightTradePanel->updateOffer(*slot, h1, h2);
|
||||
}
|
||||
else
|
||||
rightTradePanel->clearSubtitles();
|
||||
}, market->availableItemsIds(EMarketMode::RESOURCE_ARTIFACT));
|
||||
rightTradePanel->deleteSlotsCheck = [this](const std::shared_ptr<CTradeableItem> & slot)
|
||||
{
|
||||
return vstd::contains(this->market->availableItemsIds(EMarketMode::RESOURCE_ARTIFACT), ArtifactID(slot->id)) ? false : true;
|
||||
};
|
||||
rightTradePanel->moveTo(pos.topLeft() + Point(328, 182));
|
||||
|
||||
CArtifactsBuying::updateSlots();
|
||||
CMarketMisc::deselect();
|
||||
}
|
||||
|
||||
void CArtifactsBuying::makeDeal()
|
||||
{
|
||||
LOCPLINT->cb->trade(market, EMarketMode::RESOURCE_ARTIFACT, GameResID(hLeft->id), ArtifactID(hRight->id), offerQty, hero);
|
||||
deselect();
|
||||
}
|
||||
|
||||
void CArtifactsBuying::updateSlots()
|
||||
{
|
||||
CResourcesSelling::updateSlots();
|
||||
rightTradePanel->updateSlots();
|
||||
}
|
||||
|
||||
CMarketMisc::SelectionParams CArtifactsBuying::getSelectionParams()
|
||||
{
|
||||
if(hLeft && hRight)
|
||||
return std::make_tuple(std::to_string(deal->isBlocked() ? 0 : bidQty),
|
||||
std::to_string(deal->isBlocked() ? 0 : offerQty), hLeft->id, CGI->artifacts()->getByIndex(hRight->id)->getIconIndex());
|
||||
else
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void CArtifactsBuying::onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot, std::shared_ptr<CTradeableItem> & hCurSlot)
|
||||
{
|
||||
if(newSlot == hCurSlot)
|
||||
return;
|
||||
|
||||
CTradeBase::onSlotClickPressed(newSlot, hCurSlot);
|
||||
if(hLeft)
|
||||
{
|
||||
if(hRight)
|
||||
{
|
||||
market->getOffer(hLeft->id, hRight->id, bidQty, offerQty, EMarketMode::RESOURCE_ARTIFACT);
|
||||
deal->block(LOCPLINT->cb->getResourceAmount(GameResID(hLeft->id)) >= bidQty ? false : true);
|
||||
}
|
||||
updateSelected();
|
||||
rightTradePanel->updateSlots();
|
||||
}
|
||||
redraw();
|
||||
}
|
24
client/widgets/markets/CArtifactsBuying.h
Normal file
24
client/widgets/markets/CArtifactsBuying.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* CArtifactsBuying.h, 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
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "CTradeBase.h"
|
||||
|
||||
class CArtifactsBuying : public CResourcesSelling, public CMarketMisc
|
||||
{
|
||||
public:
|
||||
CArtifactsBuying(const IMarket * market, const CGHeroInstance * hero);
|
||||
void makeDeal() override;
|
||||
void updateSlots() override;
|
||||
|
||||
private:
|
||||
CMarketMisc::SelectionParams getSelectionParams();
|
||||
void CArtifactsBuying::onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot, std::shared_ptr<CTradeableItem> & hCurSlot);
|
||||
};
|
@ -29,6 +29,7 @@
|
||||
CFreelancerGuild::CFreelancerGuild(const IMarket * market, const CGHeroInstance * hero)
|
||||
: CTradeBase(market, hero)
|
||||
, CResourcesBuying([this](){CResourcesBuying::updateSubtitles(EMarketMode::CREATURE_RESOURCE);})
|
||||
, CMarketMisc([this](){return CFreelancerGuild::getSelectionParams();})
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||
|
||||
@ -59,7 +60,6 @@ CFreelancerGuild::CFreelancerGuild(const IMarket * market, const CGHeroInstance
|
||||
|
||||
// Guild resources panel
|
||||
assert(rightTradePanel);
|
||||
rightTradePanel->moveBy(Point(327, 181));
|
||||
std::for_each(rightTradePanel->slots.cbegin(), rightTradePanel->slots.cend(), [this](auto & slot)
|
||||
{
|
||||
slot->clickPressedCallback = [this](const std::shared_ptr<CTradeableItem> & heroSlot)
|
||||
@ -68,28 +68,7 @@ CFreelancerGuild::CFreelancerGuild(const IMarket * market, const CGHeroInstance
|
||||
};
|
||||
});
|
||||
|
||||
CFreelancerGuild::deselect();
|
||||
}
|
||||
|
||||
void CFreelancerGuild::updateSelected()
|
||||
{
|
||||
std::optional<size_t> lImageIndex = std::nullopt;
|
||||
std::optional<size_t> rImageIndex = std::nullopt;
|
||||
|
||||
if(hLeft && hRight)
|
||||
{
|
||||
leftTradePanel->selectedSubtitle->setText(std::to_string(bidQty * offerSlider->getValue()));
|
||||
rightTradePanel->selectedSubtitle->setText(std::to_string(offerQty * offerSlider->getValue()));
|
||||
lImageIndex = CGI->creatures()->getByIndex(hLeft->id)->getIconIndex();
|
||||
rImageIndex = hRight->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
leftTradePanel->selectedSubtitle->setText("");
|
||||
rightTradePanel->selectedSubtitle->setText("");
|
||||
}
|
||||
leftTradePanel->setSelectedFrameIndex(lImageIndex);
|
||||
rightTradePanel->setSelectedFrameIndex(rImageIndex);
|
||||
CMarketMisc::deselect();
|
||||
}
|
||||
|
||||
void CFreelancerGuild::makeDeal()
|
||||
@ -101,10 +80,13 @@ void CFreelancerGuild::makeDeal()
|
||||
}
|
||||
}
|
||||
|
||||
void CFreelancerGuild::deselect()
|
||||
CMarketMisc::SelectionParams CFreelancerGuild::getSelectionParams()
|
||||
{
|
||||
CResourcesBuying::deselect();
|
||||
updateSelected();
|
||||
if(hLeft && hRight)
|
||||
return std::make_tuple(std::to_string(bidQty * offerSlider->getValue()), std::to_string(offerQty * offerSlider->getValue()),
|
||||
CGI->creatures()->getByIndex(hLeft->id)->getIconIndex(), hRight->id);
|
||||
else
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void CFreelancerGuild::onOfferSliderMoved(int newVal)
|
||||
|
@ -11,15 +11,14 @@
|
||||
|
||||
#include "CTradeBase.h"
|
||||
|
||||
class CFreelancerGuild : public CCreaturesSelling , public CResourcesBuying
|
||||
class CFreelancerGuild : public CCreaturesSelling , public CResourcesBuying, public CMarketMisc
|
||||
{
|
||||
public:
|
||||
CFreelancerGuild(const IMarket * market, const CGHeroInstance * hero);
|
||||
void makeDeal() override;
|
||||
void deselect() override;
|
||||
|
||||
private:
|
||||
void updateSelected();
|
||||
CMarketMisc::SelectionParams getSelectionParams();
|
||||
void onOfferSliderMoved(int newVal);
|
||||
void onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot, std::shared_ptr<CTradeableItem> & hCurSlot) override;
|
||||
};
|
||||
|
@ -22,12 +22,12 @@
|
||||
#include "../../../CCallback.h"
|
||||
|
||||
#include "../../../lib/CGeneralTextHandler.h"
|
||||
#include "../../../lib/mapObjects/CGHeroInstance.h"
|
||||
#include "../../../lib/mapObjects/CGMarket.h"
|
||||
|
||||
CMarketResources::CMarketResources(const IMarket * market, const CGHeroInstance * hero)
|
||||
: CTradeBase(market, hero)
|
||||
, CResourcesBuying([this](){CMarketResources::updateSubtitles();})
|
||||
, CMarketMisc([this](){return CMarketResources::getSelectionParams();})
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||
|
||||
@ -54,7 +54,6 @@ CMarketResources::CMarketResources(const IMarket * market, const CGHeroInstance
|
||||
|
||||
// Market resources panel
|
||||
assert(rightTradePanel);
|
||||
rightTradePanel->moveTo(pos.topLeft() + Point(327, 181));
|
||||
std::for_each(rightTradePanel->slots.cbegin(), rightTradePanel->slots.cend(), [this](auto & slot)
|
||||
{
|
||||
slot->clickPressedCallback = [this](const std::shared_ptr<CTradeableItem> & resSlot)
|
||||
@ -64,7 +63,7 @@ CMarketResources::CMarketResources(const IMarket * market, const CGHeroInstance
|
||||
});
|
||||
|
||||
CResourcesSelling::updateSlots();
|
||||
CMarketResources::deselect();
|
||||
CMarketMisc::deselect();
|
||||
}
|
||||
|
||||
void CMarketResources::makeDeal()
|
||||
@ -76,31 +75,13 @@ void CMarketResources::makeDeal()
|
||||
}
|
||||
}
|
||||
|
||||
void CMarketResources::deselect()
|
||||
CMarketMisc::SelectionParams CMarketResources::getSelectionParams()
|
||||
{
|
||||
CResourcesBuying::deselect();
|
||||
updateSelected();
|
||||
}
|
||||
|
||||
void CMarketResources::updateSelected()
|
||||
{
|
||||
std::optional<size_t> lImageIndex = std::nullopt;
|
||||
std::optional<size_t> rImageIndex = std::nullopt;
|
||||
|
||||
if(hLeft && hRight && hLeft->id != hRight->id)
|
||||
{
|
||||
leftTradePanel->selectedSubtitle->setText(std::to_string(bidQty * offerSlider->getValue()));
|
||||
rightTradePanel->selectedSubtitle->setText(std::to_string(offerQty * offerSlider->getValue()));
|
||||
lImageIndex = hLeft->id;
|
||||
rImageIndex = hRight->id;
|
||||
}
|
||||
return std::make_tuple(std::to_string(bidQty * offerSlider->getValue()),
|
||||
std::to_string(offerQty * offerSlider->getValue()), hLeft->id, hRight->id);
|
||||
else
|
||||
{
|
||||
leftTradePanel->selectedSubtitle->setText("");
|
||||
rightTradePanel->selectedSubtitle->setText("");
|
||||
}
|
||||
leftTradePanel->setSelectedFrameIndex(lImageIndex);
|
||||
rightTradePanel->setSelectedFrameIndex(rImageIndex);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void CMarketResources::onOfferSliderMoved(int newVal)
|
||||
|
@ -11,15 +11,14 @@
|
||||
|
||||
#include "CTradeBase.h"
|
||||
|
||||
class CMarketResources : public CResourcesSelling, public CResourcesBuying
|
||||
class CMarketResources : public CResourcesSelling, public CResourcesBuying, public CMarketMisc
|
||||
{
|
||||
public:
|
||||
CMarketResources(const IMarket * market, const CGHeroInstance * hero);
|
||||
void makeDeal() override;
|
||||
void deselect() override;
|
||||
|
||||
private:
|
||||
void updateSelected();
|
||||
CMarketMisc::SelectionParams getSelectionParams();
|
||||
void onOfferSliderMoved(int newVal);
|
||||
void onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot, std::shared_ptr<CTradeableItem> & hCurSlot);
|
||||
void updateSubtitles();
|
||||
|
@ -121,7 +121,6 @@ void CCreaturesSelling::updateSubtitle()
|
||||
|
||||
void CCreaturesSelling::updateSlots()
|
||||
{
|
||||
leftTradePanel->deleteSlots();
|
||||
leftTradePanel->updateSlots();
|
||||
}
|
||||
|
||||
@ -130,13 +129,12 @@ CResourcesBuying::CResourcesBuying(TradePanelBase::UpdateSlotsFunctor callback)
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||
|
||||
rightTradePanel = std::make_shared<ResourcesPanel>([](const std::shared_ptr<CTradeableItem>&) {}, callback);
|
||||
rightTradePanel->moveTo(pos.topLeft() + Point(327, 181));
|
||||
labels.emplace_back(std::make_shared<CLabel>(445, 148, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[168]));
|
||||
}
|
||||
|
||||
void CResourcesBuying::updateSubtitles(EMarketMode marketMode)
|
||||
{
|
||||
assert(marketMode == EMarketMode::RESOURCE_RESOURCE || marketMode == EMarketMode::CREATURE_RESOURCE || marketMode == EMarketMode::ARTIFACT_RESOURCE);
|
||||
|
||||
if(hLeft)
|
||||
for(const auto & slot : rightTradePanel->slots)
|
||||
{
|
||||
@ -149,13 +147,6 @@ void CResourcesBuying::updateSubtitles(EMarketMode marketMode)
|
||||
rightTradePanel->clearSubtitles();
|
||||
};
|
||||
|
||||
void CResourcesBuying::deselect()
|
||||
{
|
||||
CTradeBase::deselect();
|
||||
bidQty = 0;
|
||||
offerQty = 0;
|
||||
}
|
||||
|
||||
CResourcesSelling::CResourcesSelling()
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||
@ -172,3 +163,38 @@ void CResourcesSelling::updateSlots()
|
||||
{
|
||||
leftTradePanel->updateSlots();
|
||||
}
|
||||
|
||||
CMarketMisc::CMarketMisc(SelectionParamsFunctor callback)
|
||||
: selectionParamsCallback(callback)
|
||||
{
|
||||
}
|
||||
|
||||
void CMarketMisc::deselect()
|
||||
{
|
||||
CTradeBase::deselect();
|
||||
bidQty = 0;
|
||||
offerQty = 0;
|
||||
updateSelected();
|
||||
}
|
||||
|
||||
void CMarketMisc::updateSelected()
|
||||
{
|
||||
std::optional<size_t> lImageIndex = std::nullopt;
|
||||
std::optional<size_t> rImageIndex = std::nullopt;
|
||||
|
||||
assert(selectionParamsCallback);
|
||||
if(auto params = selectionParamsCallback())
|
||||
{
|
||||
leftTradePanel->selectedSubtitle->setText(std::get<0>(params.value()));
|
||||
rightTradePanel->selectedSubtitle->setText(std::get<1>(params.value()));
|
||||
lImageIndex = std::get<2>(params.value());
|
||||
rImageIndex = std::get<3>(params.value());
|
||||
}
|
||||
else
|
||||
{
|
||||
leftTradePanel->selectedSubtitle->setText("");
|
||||
rightTradePanel->selectedSubtitle->setText("");
|
||||
}
|
||||
leftTradePanel->setSelectedFrameIndex(lImageIndex);
|
||||
rightTradePanel->setSelectedFrameIndex(rImageIndex);
|
||||
}
|
||||
|
@ -80,11 +80,6 @@ class CResourcesBuying : virtual public CTradeBase, virtual public CIntObject
|
||||
public:
|
||||
CResourcesBuying(TradePanelBase::UpdateSlotsFunctor callback);
|
||||
void updateSubtitles(EMarketMode marketMode);
|
||||
void deselect() override;
|
||||
|
||||
protected:
|
||||
int bidQty;
|
||||
int offerQty;
|
||||
};
|
||||
|
||||
class CResourcesSelling : virtual public CTradeBase, virtual public CIntObject
|
||||
@ -93,3 +88,19 @@ public:
|
||||
CResourcesSelling();
|
||||
void updateSlots() override;
|
||||
};
|
||||
|
||||
class CMarketMisc : virtual public CTradeBase, virtual public CIntObject
|
||||
{
|
||||
public:
|
||||
using SelectionParams = std::optional<std::tuple<std::string, std::string, int, int>>;
|
||||
using SelectionParamsFunctor = std::function<SelectionParams()>;
|
||||
|
||||
CMarketMisc(SelectionParamsFunctor callback);
|
||||
void deselect() override;
|
||||
void updateSelected();
|
||||
|
||||
protected:
|
||||
int bidQty;
|
||||
int offerQty;
|
||||
SelectionParamsFunctor selectionParamsCallback;
|
||||
};
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
CTransferResources::CTransferResources(const IMarket * market, const CGHeroInstance * hero)
|
||||
: CTradeBase(market, hero)
|
||||
, CMarketMisc([this](){return CTransferResources::getSelectionParams();})
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||
|
||||
@ -70,31 +71,13 @@ void CTransferResources::makeDeal()
|
||||
}
|
||||
}
|
||||
|
||||
void CTransferResources::deselect()
|
||||
CMarketMisc::SelectionParams CTransferResources::getSelectionParams()
|
||||
{
|
||||
CTradeBase::deselect();
|
||||
updateSelected();
|
||||
}
|
||||
|
||||
void CTransferResources::updateSelected()
|
||||
{
|
||||
std::optional<size_t> lImageIndex = std::nullopt;
|
||||
std::optional<size_t> rImageIndex = std::nullopt;
|
||||
|
||||
if(hLeft && hRight)
|
||||
{
|
||||
leftTradePanel->selectedSubtitle->setText(std::to_string(offerSlider->getValue()));
|
||||
rightTradePanel->selectedSubtitle->setText(CGI->generaltexth->capColors[hRight->id]);
|
||||
lImageIndex = hLeft->id;
|
||||
rImageIndex = hRight->id;
|
||||
}
|
||||
return std::make_tuple(std::to_string(offerSlider->getValue()),
|
||||
CGI->generaltexth->capColors[hRight->id], hLeft->id, hRight->id);
|
||||
else
|
||||
{
|
||||
leftTradePanel->selectedSubtitle->setText("");
|
||||
rightTradePanel->selectedSubtitle->setText("");
|
||||
}
|
||||
leftTradePanel->setSelectedFrameIndex(lImageIndex);
|
||||
rightTradePanel->setSelectedFrameIndex(rImageIndex);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void CTransferResources::onOfferSliderMoved(int newVal)
|
||||
|
@ -11,15 +11,14 @@
|
||||
|
||||
#include "CTradeBase.h"
|
||||
|
||||
class CTransferResources : public CResourcesSelling
|
||||
class CTransferResources : public CResourcesSelling, public CMarketMisc
|
||||
{
|
||||
public:
|
||||
CTransferResources(const IMarket * market, const CGHeroInstance * hero);
|
||||
void makeDeal() override;
|
||||
void deselect() override;
|
||||
|
||||
private:
|
||||
void updateSelected();
|
||||
CMarketMisc::SelectionParams getSelectionParams();
|
||||
void onOfferSliderMoved(int newVal);
|
||||
void onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot, std::shared_ptr<CTradeableItem> & hCurSlot);
|
||||
};
|
||||
|
@ -273,6 +273,9 @@ void CTradeableItem::setArtInstance(const CArtifactInstance * art)
|
||||
|
||||
void TradePanelBase::updateSlots()
|
||||
{
|
||||
if(deleteSlotsCheck)
|
||||
slots.erase(std::remove_if(slots.begin(), slots.end(), deleteSlotsCheck), slots.end());
|
||||
|
||||
if(updateSlotsCallback)
|
||||
updateSlotsCallback();
|
||||
}
|
||||
@ -299,12 +302,6 @@ void TradePanelBase::updateOffer(CTradeableItem & slot, int cost, int qty)
|
||||
}
|
||||
}
|
||||
|
||||
void TradePanelBase::deleteSlots()
|
||||
{
|
||||
if(deleteSlotsCheck)
|
||||
slots.erase(std::remove_if(slots.begin(), slots.end(), deleteSlotsCheck), slots.end());
|
||||
}
|
||||
|
||||
void TradePanelBase::setSelectedFrameIndex(std::optional<size_t> index)
|
||||
{
|
||||
if(index.has_value())
|
||||
@ -355,6 +352,8 @@ ArtifactsPanel::ArtifactsPanel(CTradeableItem::ClickPressedFunctor clickPressedC
|
||||
}
|
||||
}
|
||||
updateSlotsCallback = updateSubtitles;
|
||||
selectedImage = std::make_shared<CAnimImage>(AnimationPath::builtin("artifact"), 0, 0, selectedImagePos.x, selectedImagePos.y);
|
||||
selectedSubtitle = std::make_shared<CLabel>(selectedSubtitlePos.x, selectedSubtitlePos.y, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
|
||||
}
|
||||
|
||||
PlayersPanel::PlayersPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback)
|
||||
|
@ -71,7 +71,6 @@ public:
|
||||
virtual void deselect();
|
||||
virtual void clearSubtitles();
|
||||
void updateOffer(CTradeableItem & slot, int, int);
|
||||
void deleteSlots();
|
||||
void setSelectedFrameIndex(std::optional<size_t> index);
|
||||
};
|
||||
|
||||
@ -90,7 +89,7 @@ class ResourcesPanel : public TradePanelBase
|
||||
Point(83, 158)
|
||||
};
|
||||
const Point slotDimension = Point(69, 66);
|
||||
const Point selectedImagePos = Point(102, 276);
|
||||
const Point selectedImagePos = Point(101, 276);
|
||||
const Point selectedSubtitlePos = Point(118, 324);
|
||||
|
||||
public:
|
||||
@ -101,12 +100,14 @@ class ArtifactsPanel : public TradePanelBase
|
||||
{
|
||||
const std::vector<Point> slotsPos =
|
||||
{
|
||||
Point(0, 0), Point(83, 0), Point(166, 0),
|
||||
Point(0, 79), Point(83, 79), Point(166, 79),
|
||||
Point(0, 0), Point(83, 0), Point(165, 0),
|
||||
Point(0, 79), Point(83, 79), Point(165, 79),
|
||||
Point(83, 158)
|
||||
};
|
||||
const size_t slotsForTrade = 7;
|
||||
const Point slotDimension = Point(69, 66);
|
||||
const Point selectedImagePos = Point(96, 266);
|
||||
const Point selectedSubtitlePos = Point(118, 324);
|
||||
|
||||
public:
|
||||
ArtifactsPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback, UpdateSlotsFunctor updateSubtitles,
|
||||
|
@ -59,13 +59,13 @@ CMarketWindow::CMarketWindow(const IMarket * market, const CGHeroInstance * hero
|
||||
|
||||
void CMarketWindow::artifactsChanged()
|
||||
{
|
||||
market->artifactsChanged(false);
|
||||
//market->artifactsChanged(false);
|
||||
if(artsBuy)
|
||||
artsBuy->updateSlots();
|
||||
}
|
||||
|
||||
void CMarketWindow::updateGarrisons()
|
||||
{
|
||||
CAltarWindow::updateGarrisons();
|
||||
|
||||
if(guild)
|
||||
guild->updateSlots();
|
||||
}
|
||||
@ -169,9 +169,6 @@ void CMarketWindow::createArtifactsBuying(const IMarket * market, const CGHeroIn
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
|
||||
|
||||
background = createBg(ImagePath::builtin("TPMRKABS.bmp"), PLAYER_COLORED);
|
||||
//this->market = std::make_shared<CMarketplaceWindow>(market, hero, []() {}, EMarketMode::RESOURCE_ARTIFACT);
|
||||
//createInternals(EMarketMode::RESOURCE_ARTIFACT, market, hero);
|
||||
|
||||
artsBuy = std::make_shared<CArtifactsBuying>(market, hero);
|
||||
|
||||
background->center();
|
||||
|
@ -449,12 +449,6 @@ void CMarketplaceWindow::updateGarrison()
|
||||
|
||||
void CMarketplaceWindow::artifactsChanged(bool Left)
|
||||
{
|
||||
assert(!Left);
|
||||
if(mode != EMarketMode::RESOURCE_ARTIFACT)
|
||||
return;
|
||||
|
||||
rightTradePanel->deleteSlots();
|
||||
redraw();
|
||||
}
|
||||
|
||||
std::string CMarketplaceWindow::updateSlotSubtitle(bool Left) const
|
||||
|
Loading…
Reference in New Issue
Block a user