1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Refactoring. Callbacks have been encapsulated. Added cursorPosition

This commit is contained in:
SoundSSGood 2023-11-13 17:43:02 +02:00
parent 29b61081f3
commit 21b02414bf
19 changed files with 73 additions and 62 deletions

View File

@ -139,7 +139,7 @@ void CCommanderArtPlace::clickPressed(const Point & cursorPosition)
LOCPLINT->showYesNoDialog(CGI->generaltexth->translate("vcmi.commanderWindow.artifactMessage"), [this]() { returnArtToHeroCallback(); }, []() {}); LOCPLINT->showYesNoDialog(CGI->generaltexth->translate("vcmi.commanderWindow.artifactMessage"), [this]() { returnArtToHeroCallback(); }, []() {});
} }
void CCommanderArtPlace::showPopupWindow(const Point & cursorPosition) void CCommanderArtPlace::showPopupWindow(const Point& cursorPosition)
{ {
if(ourArt && text.size()) if(ourArt && text.size())
CArtPlace::showPopupWindow(cursorPosition); CArtPlace::showPopupWindow(cursorPosition);
@ -180,16 +180,16 @@ bool CArtPlace::isSelected() const
return selection->visible; return selection->visible;
} }
void CHeroArtPlace::clickPressed(const Point & cursorPosition) void CArtPlace::clickPressed(const Point & cursorPosition)
{ {
if(leftClickCallback) if(clickPressedCallback)
leftClickCallback(*this); clickPressedCallback(*this, cursorPosition);
} }
void CHeroArtPlace::showPopupWindow(const Point & cursorPosition) void CArtPlace::showPopupWindow(const Point & cursorPosition)
{ {
if(showPopupCallback) if(showPopupCallback)
showPopupCallback(*this); showPopupCallback(*this, cursorPosition);
} }
void CArtPlace::showAll(Canvas & to) void CArtPlace::showAll(Canvas & to)
@ -216,6 +216,16 @@ void CArtPlace::setArtifact(const CArtifactInstance * art)
} }
} }
void CArtPlace::setClickPressedCallback(ClickFunctor callback)
{
clickPressedCallback = callback;
}
void CArtPlace::setShowPopupCallback(ClickFunctor callback)
{
showPopupCallback = callback;
}
void CHeroArtPlace::addCombinedArtInfo(std::map<const CArtifact*, int> & arts) void CHeroArtPlace::addCombinedArtInfo(std::map<const CArtifact*, int> & arts)
{ {
for(const auto & combinedArt : arts) for(const auto & combinedArt : arts)

View File

@ -32,14 +32,22 @@ public:
class CArtPlace : public LRClickableAreaWTextComp class CArtPlace : public LRClickableAreaWTextComp
{ {
public: public:
using ClickFunctor = std::function<void(CArtPlace&, const Point&)>;
ArtifactPosition slot;
CArtPlace(Point position, const CArtifactInstance * art = nullptr); CArtPlace(Point position, const CArtifactInstance * art = nullptr);
const CArtifactInstance* getArt(); const CArtifactInstance * getArt();
void lockSlot(bool on); void lockSlot(bool on);
bool isLocked() const; bool isLocked() const;
void selectSlot(bool on); void selectSlot(bool on);
bool isSelected() const; bool isSelected() const;
void showAll(Canvas & to) override; void showAll(Canvas & to) override;
void setArtifact(const CArtifactInstance * art); void setArtifact(const CArtifactInstance * art);
void setClickPressedCallback(ClickFunctor callback);
void setShowPopupCallback(ClickFunctor callback);
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
protected: protected:
std::shared_ptr<CAnimImage> image; std::shared_ptr<CAnimImage> image;
@ -47,6 +55,8 @@ protected:
int imageIndex; int imageIndex;
std::shared_ptr<CAnimImage> selection; std::shared_ptr<CAnimImage> selection;
bool locked; bool locked;
ClickFunctor clickPressedCallback;
ClickFunctor showPopupCallback;
void setInternals(const CArtifactInstance * artInst); void setInternals(const CArtifactInstance * artInst);
}; };
@ -68,15 +78,7 @@ public:
class CHeroArtPlace: public CArtPlace class CHeroArtPlace: public CArtPlace
{ {
public: public:
using ClickFunctor = std::function<void(CHeroArtPlace&)>;
ArtifactPosition slot;
ClickFunctor leftClickCallback;
ClickFunctor showPopupCallback;
CHeroArtPlace(Point position, const CArtifactInstance * art = nullptr); CHeroArtPlace(Point position, const CArtifactInstance * art = nullptr);
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
void addCombinedArtInfo(std::map<const CArtifact*, int> & arts); void addCombinedArtInfo(std::map<const CArtifact*, int> & arts);
}; };

View File

@ -23,8 +23,8 @@ CArtifactsOfHeroAltar::CArtifactsOfHeroAltar(const Point & position)
: visibleArtSet(ArtBearer::ArtBearer::HERO) : visibleArtSet(ArtBearer::ArtBearer::HERO)
{ {
init( init(
std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1), std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1, _2),
std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1), std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1, _2),
position, position,
std::bind(&CArtifactsOfHeroAltar::scrollBackpack, this, _1)); std::bind(&CArtifactsOfHeroAltar::scrollBackpack, this, _1));
pickedArtFromSlot = ArtifactPosition::PRE_FIRST; pickedArtFromSlot = ArtifactPosition::PRE_FIRST;
@ -69,7 +69,7 @@ void CArtifactsOfHeroAltar::scrollBackpack(int offset)
redraw(); redraw();
} }
void CArtifactsOfHeroAltar::pickUpArtifact(CHeroArtPlace & artPlace) void CArtifactsOfHeroAltar::pickUpArtifact(CArtPlace & artPlace)
{ {
if(const auto art = artPlace.getArt()) if(const auto art = artPlace.getArt())
{ {

View File

@ -26,7 +26,7 @@ public:
void updateWornSlots() override; void updateWornSlots() override;
void updateBackpackSlots() override; void updateBackpackSlots() override;
void scrollBackpack(int offset) override; void scrollBackpack(int offset) override;
void pickUpArtifact(CHeroArtPlace & artPlace); void pickUpArtifact(CArtPlace & artPlace);
void swapArtifacts(const ArtifactLocation & srcLoc, const ArtifactLocation & dstLoc); void swapArtifacts(const ArtifactLocation & srcLoc, const ArtifactLocation & dstLoc);
void pickedArtMoveToAltar(const ArtifactPosition & slot); void pickedArtMoveToAltar(const ArtifactPosition & slot);
void deleteFromVisible(const CArtifactInstance * artInst); void deleteFromVisible(const CArtifactInstance * artInst);

View File

@ -46,7 +46,7 @@ void CArtifactsOfHeroBackpack::swapArtifacts(const ArtifactLocation & srcLoc, co
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc); LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
} }
void CArtifactsOfHeroBackpack::pickUpArtifact(CHeroArtPlace & artPlace) void CArtifactsOfHeroBackpack::pickUpArtifact(CArtPlace & artPlace)
{ {
LOCPLINT->cb->swapArtifacts(ArtifactLocation(curHero->id, artPlace.slot), LOCPLINT->cb->swapArtifacts(ArtifactLocation(curHero->id, artPlace.slot),
ArtifactLocation(curHero->id, ArtifactPosition::TRANSITION_POS)); ArtifactLocation(curHero->id, ArtifactPosition::TRANSITION_POS));
@ -96,8 +96,8 @@ void CArtifactsOfHeroBackpack::initAOHbackpack(size_t slots, bool slider)
backpackSlotsBackgrounds.emplace_back(std::make_shared<CPicture>(ImagePath::builtin("heroWindow/artifactSlotEmpty"), pos)); backpackSlotsBackgrounds.emplace_back(std::make_shared<CPicture>(ImagePath::builtin("heroWindow/artifactSlotEmpty"), pos));
artPlace = std::make_shared<CHeroArtPlace>(pos); artPlace = std::make_shared<CHeroArtPlace>(pos);
artPlace->setArtifact(nullptr); artPlace->setArtifact(nullptr);
artPlace->leftClickCallback = std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1); artPlace->setClickPressedCallback(std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1, _2));
artPlace->showPopupCallback = std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1); artPlace->setShowPopupCallback(std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1, _2));
artPlaceIdx++; artPlaceIdx++;
} }

View File

@ -25,7 +25,7 @@ public:
CArtifactsOfHeroBackpack(); CArtifactsOfHeroBackpack();
CArtifactsOfHeroBackpack(const Point & position); CArtifactsOfHeroBackpack(const Point & position);
void swapArtifacts(const ArtifactLocation & srcLoc, const ArtifactLocation & dstLoc); void swapArtifacts(const ArtifactLocation & srcLoc, const ArtifactLocation & dstLoc);
void pickUpArtifact(CHeroArtPlace & artPlace); void pickUpArtifact(CArtPlace & artPlace);
void scrollBackpack(int offset) override; void scrollBackpack(int offset) override;
void updateBackpackSlots() override; void updateBackpackSlots() override;
size_t getActiveSlotRowsNum(); size_t getActiveSlotRowsNum();

View File

@ -56,8 +56,8 @@ void CArtifactsOfHeroBase::setPutBackPickedArtifactCallback(PutBackPickedArtCall
} }
void CArtifactsOfHeroBase::init( void CArtifactsOfHeroBase::init(
CHeroArtPlace::ClickFunctor lClickCallback, CArtPlace::ClickFunctor lClickCallback,
CHeroArtPlace::ClickFunctor showPopupCallback, CArtPlace::ClickFunctor showPopupCallback,
const Point & position, const Point & position,
BpackScrollFunctor scrollCallback) BpackScrollFunctor scrollCallback)
{ {
@ -78,14 +78,14 @@ void CArtifactsOfHeroBase::init(
{ {
artPlace.second->slot = artPlace.first; artPlace.second->slot = artPlace.first;
artPlace.second->setArtifact(nullptr); artPlace.second->setArtifact(nullptr);
artPlace.second->leftClickCallback = lClickCallback; artPlace.second->setClickPressedCallback(lClickCallback);
artPlace.second->showPopupCallback = showPopupCallback; artPlace.second->setShowPopupCallback(showPopupCallback);
} }
for(auto artPlace : backpack) for(auto artPlace : backpack)
{ {
artPlace->setArtifact(nullptr); artPlace->setArtifact(nullptr);
artPlace->leftClickCallback = lClickCallback; artPlace->setClickPressedCallback(lClickCallback);
artPlace->showPopupCallback = showPopupCallback; artPlace->setShowPopupCallback(showPopupCallback);
} }
leftBackpackRoll = std::make_shared<CButton>(Point(379, 364), AnimationPath::builtin("hsbtns3.def"), CButton::tooltip(), [scrollCallback]() {scrollCallback(-1);}, EShortcut::MOVE_LEFT); leftBackpackRoll = std::make_shared<CButton>(Point(379, 364), AnimationPath::builtin("hsbtns3.def"), CButton::tooltip(), [scrollCallback]() {scrollCallback(-1);}, EShortcut::MOVE_LEFT);
rightBackpackRoll = std::make_shared<CButton>(Point(632, 364), AnimationPath::builtin("hsbtns5.def"), CButton::tooltip(), [scrollCallback]() {scrollCallback(+1);}, EShortcut::MOVE_RIGHT); rightBackpackRoll = std::make_shared<CButton>(Point(632, 364), AnimationPath::builtin("hsbtns5.def"), CButton::tooltip(), [scrollCallback]() {scrollCallback(+1);}, EShortcut::MOVE_RIGHT);
@ -95,16 +95,16 @@ void CArtifactsOfHeroBase::init(
setRedrawParent(true); setRedrawParent(true);
} }
void CArtifactsOfHeroBase::leftClickArtPlace(CHeroArtPlace & artPlace) void CArtifactsOfHeroBase::leftClickArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
{ {
if(leftClickCallback) if(leftClickCallback)
leftClickCallback(*this, artPlace); leftClickCallback(*this, artPlace, cursorPosition);
} }
void CArtifactsOfHeroBase::rightClickArtPlace(CHeroArtPlace & artPlace) void CArtifactsOfHeroBase::rightClickArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
{ {
if(showPopupCallback) if(showPopupCallback)
showPopupCallback(*this, artPlace); showPopupCallback(*this, artPlace, cursorPosition);
} }
void CArtifactsOfHeroBase::setHero(const CGHeroInstance * hero) void CArtifactsOfHeroBase::setHero(const CGHeroInstance * hero)

View File

@ -21,7 +21,7 @@ protected:
public: public:
using ArtPlaceMap = std::map<ArtifactPosition, ArtPlacePtr>; using ArtPlaceMap = std::map<ArtifactPosition, ArtPlacePtr>;
using ClickFunctor = std::function<void(CArtifactsOfHeroBase&, CHeroArtPlace&)>; using ClickFunctor = std::function<void(CArtifactsOfHeroBase&, CArtPlace&, const Point&)>;
using PutBackPickedArtCallback = std::function<void()>; using PutBackPickedArtCallback = std::function<void()>;
ClickFunctor leftClickCallback; ClickFunctor leftClickCallback;
@ -30,8 +30,8 @@ public:
CArtifactsOfHeroBase(); CArtifactsOfHeroBase();
virtual void putBackPickedArtifact(); virtual void putBackPickedArtifact();
virtual void setPutBackPickedArtifactCallback(PutBackPickedArtCallback callback); virtual void setPutBackPickedArtifactCallback(PutBackPickedArtCallback callback);
virtual void leftClickArtPlace(CHeroArtPlace & artPlace); virtual void leftClickArtPlace(CArtPlace & artPlace, const Point & cursorPosition);
virtual void rightClickArtPlace(CHeroArtPlace & artPlace); virtual void rightClickArtPlace(CArtPlace & artPlace, const Point & cursorPosition);
virtual void setHero(const CGHeroInstance * hero); virtual void setHero(const CGHeroInstance * hero);
virtual const CGHeroInstance * getHero() const; virtual const CGHeroInstance * getHero() const;
virtual void scrollBackpack(int offset); virtual void scrollBackpack(int offset);

View File

@ -30,14 +30,14 @@ CArtifactsOfHeroKingdom::CArtifactsOfHeroKingdom(ArtPlaceMap ArtWorn, std::vecto
{ {
artPlace.second->slot = artPlace.first; artPlace.second->slot = artPlace.first;
artPlace.second->setArtifact(nullptr); artPlace.second->setArtifact(nullptr);
artPlace.second->leftClickCallback = std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1); artPlace.second->setClickPressedCallback(std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1, _2));
artPlace.second->showPopupCallback = std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1); artPlace.second->setShowPopupCallback(std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1, _2));
} }
for(auto artPlace : backpack) for(auto artPlace : backpack)
{ {
artPlace->setArtifact(nullptr); artPlace->setArtifact(nullptr);
artPlace->leftClickCallback = std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1); artPlace->setClickPressedCallback(std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1, _2));
artPlace->showPopupCallback = std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1); artPlace->setShowPopupCallback(std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1, _2));
} }
leftBackpackRoll->addCallback(std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, -1)); leftBackpackRoll->addCallback(std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, -1));
rightBackpackRoll->addCallback(std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, +1)); rightBackpackRoll->addCallback(std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, +1));
@ -55,7 +55,7 @@ void CArtifactsOfHeroKingdom::swapArtifacts(const ArtifactLocation & srcLoc, con
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc); LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
} }
void CArtifactsOfHeroKingdom::pickUpArtifact(CHeroArtPlace & artPlace) void CArtifactsOfHeroKingdom::pickUpArtifact(CArtPlace & artPlace)
{ {
LOCPLINT->cb->swapArtifacts(ArtifactLocation(curHero->id, artPlace.slot), LOCPLINT->cb->swapArtifacts(ArtifactLocation(curHero->id, artPlace.slot),
ArtifactLocation(curHero->id, ArtifactPosition::TRANSITION_POS)); ArtifactLocation(curHero->id, ArtifactPosition::TRANSITION_POS));

View File

@ -24,5 +24,5 @@ public:
std::shared_ptr<CButton> leftScroll, std::shared_ptr<CButton> rightScroll); std::shared_ptr<CButton> leftScroll, std::shared_ptr<CButton> rightScroll);
~CArtifactsOfHeroKingdom(); ~CArtifactsOfHeroKingdom();
void swapArtifacts(const ArtifactLocation & srcLoc, const ArtifactLocation & dstLoc); void swapArtifacts(const ArtifactLocation & srcLoc, const ArtifactLocation & dstLoc);
void pickUpArtifact(CHeroArtPlace & artPlace); void pickUpArtifact(CArtPlace & artPlace);
}; };

View File

@ -19,8 +19,8 @@
CArtifactsOfHeroMain::CArtifactsOfHeroMain(const Point & position) CArtifactsOfHeroMain::CArtifactsOfHeroMain(const Point & position)
{ {
init( init(
std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1), std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1, _2),
std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1), std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1, _2),
position, position,
std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1)); std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, _1));
} }
@ -35,7 +35,7 @@ void CArtifactsOfHeroMain::swapArtifacts(const ArtifactLocation & srcLoc, const
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc); LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
} }
void CArtifactsOfHeroMain::pickUpArtifact(CHeroArtPlace & artPlace) void CArtifactsOfHeroMain::pickUpArtifact(CArtPlace & artPlace)
{ {
LOCPLINT->cb->swapArtifacts(ArtifactLocation(curHero->id, artPlace.slot), LOCPLINT->cb->swapArtifacts(ArtifactLocation(curHero->id, artPlace.slot),
ArtifactLocation(curHero->id, ArtifactPosition::TRANSITION_POS)); ArtifactLocation(curHero->id, ArtifactPosition::TRANSITION_POS));

View File

@ -23,5 +23,5 @@ public:
CArtifactsOfHeroMain(const Point & position); CArtifactsOfHeroMain(const Point & position);
~CArtifactsOfHeroMain(); ~CArtifactsOfHeroMain();
void swapArtifacts(const ArtifactLocation & srcLoc, const ArtifactLocation & dstLoc); void swapArtifacts(const ArtifactLocation & srcLoc, const ArtifactLocation & dstLoc);
void pickUpArtifact(CHeroArtPlace & artPlace); void pickUpArtifact(CArtPlace & artPlace);
}; };

View File

@ -15,8 +15,8 @@
CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position) CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position)
{ {
init( init(
std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1), std::bind(&CArtifactsOfHeroBase::leftClickArtPlace, this, _1, _2),
std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1), std::bind(&CArtifactsOfHeroBase::rightClickArtPlace, this, _1, _2),
position, position,
std::bind(&CArtifactsOfHeroMarket::scrollBackpack, this, _1)); std::bind(&CArtifactsOfHeroMarket::scrollBackpack, this, _1));
}; };

View File

@ -14,7 +14,7 @@
class CArtifactsOfHeroMarket : public CArtifactsOfHeroBase class CArtifactsOfHeroMarket : public CArtifactsOfHeroBase
{ {
public: public:
std::function<void(CHeroArtPlace*)> selectArtCallback; std::function<void(CArtPlace*)> selectArtCallback;
CArtifactsOfHeroMarket(const Point & position); CArtifactsOfHeroMarket(const Point & position);
void scrollBackpack(int offset) override; void scrollBackpack(int offset) override;

View File

@ -48,8 +48,8 @@ void CWindowWithArtifacts::addSetAndCallbacks(CArtifactsOfHeroPtr artSet)
std::visit([this, artPutBackHandler](auto artSetWeak) std::visit([this, artPutBackHandler](auto artSetWeak)
{ {
auto artSet = artSetWeak.lock(); auto artSet = artSetWeak.lock();
artSet->leftClickCallback = std::bind(&CWindowWithArtifacts::leftClickArtPlaceHero, this, _1, _2); artSet->leftClickCallback = std::bind(&CWindowWithArtifacts::leftClickArtPlaceHero, this, _1, _2, _3);
artSet->showPopupCallback = std::bind(&CWindowWithArtifacts::rightClickArtPlaceHero, this, _1, _2); artSet->showPopupCallback = std::bind(&CWindowWithArtifacts::rightClickArtPlaceHero, this, _1, _2, _3);
artSet->setPutBackPickedArtifactCallback(artPutBackHandler); artSet->setPutBackPickedArtifactCallback(artPutBackHandler);
}, artSet); }, artSet);
} }
@ -77,7 +77,7 @@ const CArtifactInstance * CWindowWithArtifacts::getPickedArtifact()
return nullptr; return nullptr;
} }
void CWindowWithArtifacts::leftClickArtPlaceHero(CArtifactsOfHeroBase & artsInst, CHeroArtPlace & artPlace) void CWindowWithArtifacts::leftClickArtPlaceHero(CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
{ {
const auto artSetWeak = findAOHbyRef(artsInst); const auto artSetWeak = findAOHbyRef(artsInst);
assert(artSetWeak.has_value()); assert(artSetWeak.has_value());
@ -85,7 +85,7 @@ void CWindowWithArtifacts::leftClickArtPlaceHero(CArtifactsOfHeroBase & artsInst
if(artPlace.isLocked()) if(artPlace.isLocked())
return; return;
const auto checkSpecialArts = [](const CGHeroInstance * hero, CHeroArtPlace & artPlace) -> bool const auto checkSpecialArts = [](const CGHeroInstance * hero, CArtPlace & artPlace) -> bool
{ {
if(artPlace.getArt()->getTypeId() == ArtifactID::SPELLBOOK) if(artPlace.getArt()->getTypeId() == ArtifactID::SPELLBOOK)
{ {
@ -217,7 +217,7 @@ void CWindowWithArtifacts::leftClickArtPlaceHero(CArtifactsOfHeroBase & artsInst
}, artSetWeak.value()); }, artSetWeak.value());
} }
void CWindowWithArtifacts::rightClickArtPlaceHero(CArtifactsOfHeroBase & artsInst, CHeroArtPlace & artPlace) void CWindowWithArtifacts::rightClickArtPlaceHero(CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
{ {
const auto artSetWeak = findAOHbyRef(artsInst); const auto artSetWeak = findAOHbyRef(artsInst);
assert(artSetWeak.has_value()); assert(artSetWeak.has_value());
@ -226,7 +226,7 @@ void CWindowWithArtifacts::rightClickArtPlaceHero(CArtifactsOfHeroBase & artsIns
return; return;
std::visit( std::visit(
[&artPlace](auto artSetWeak) -> void [&artPlace, &cursorPosition](auto artSetWeak) -> void
{ {
const auto artSetPtr = artSetWeak.lock(); const auto artSetPtr = artSetWeak.lock();
@ -247,7 +247,7 @@ void CWindowWithArtifacts::rightClickArtPlaceHero(CArtifactsOfHeroBase & artsIns
return; return;
} }
if(artPlace.text.size()) if(artPlace.text.size())
artPlace.LRClickableAreaWTextComp::showPopupWindow(GH.getCursorPosition()); artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
} }
} }
// Altar window, Market window right click handler // Altar window, Market window right click handler
@ -257,7 +257,7 @@ void CWindowWithArtifacts::rightClickArtPlaceHero(CArtifactsOfHeroBase & artsIns
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroQuickBackpack>>) std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroQuickBackpack>>)
{ {
if(artPlace.getArt() && artPlace.text.size()) if(artPlace.getArt() && artPlace.text.size())
artPlace.LRClickableAreaWTextComp::showPopupWindow(GH.getCursorPosition()); artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
} }
}, artSetWeak.value()); }, artSetWeak.value());
} }

View File

@ -33,8 +33,8 @@ public:
void addCloseCallback(CloseCallback callback); void addCloseCallback(CloseCallback callback);
const CGHeroInstance * getHeroPickedArtifact(); const CGHeroInstance * getHeroPickedArtifact();
const CArtifactInstance * getPickedArtifact(); const CArtifactInstance * getPickedArtifact();
void leftClickArtPlaceHero(CArtifactsOfHeroBase & artsInst, CHeroArtPlace & artPlace); void leftClickArtPlaceHero(CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
void rightClickArtPlaceHero(CArtifactsOfHeroBase & artsInst, CHeroArtPlace & artPlace); void rightClickArtPlaceHero(CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
void artifactRemoved(const ArtifactLocation & artLoc) override; void artifactRemoved(const ArtifactLocation & artLoc) override;
void artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc, bool withRedraw) override; void artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc, bool withRedraw) override;

View File

@ -111,6 +111,5 @@ public:
void createBackpackWindow(); void createBackpackWindow();
//friends //friends
friend void CHeroArtPlace::clickPressed(const Point & cursorPosition);
friend class CPlayerInterface; friend class CPlayerInterface;
}; };

View File

@ -331,7 +331,7 @@ void CTradeWindow::setMode(EMarketMode Mode)
} }
} }
void CTradeWindow::artifactSelected(CHeroArtPlace *slot) void CTradeWindow::artifactSelected(CArtPlace * slot)
{ {
assert(mode == EMarketMode::ARTIFACT_RESOURCE); assert(mode == EMarketMode::ARTIFACT_RESOURCE);
items[1][0]->setArtInstance(slot->getArt()); items[1][0]->setArtInstance(slot->getArt());

View File

@ -40,7 +40,7 @@ public:
void getPositionsFor(std::vector<Rect> &poss, bool Left, EType type) const; void getPositionsFor(std::vector<Rect> &poss, bool Left, EType type) const;
void setMode(EMarketMode Mode); //mode setter void setMode(EMarketMode Mode); //mode setter
void artifactSelected(CHeroArtPlace *slot); //used when selling artifacts -> called when user clicked on artifact slot void artifactSelected(CArtPlace * slot); //used when selling artifacts -> called when user clicked on artifact slot
virtual void selectionChanged(bool side) = 0; //true == left virtual void selectionChanged(bool side) = 0; //true == left
virtual Point selectionOffset(bool Left) const = 0; virtual Point selectionOffset(bool Left) const = 0;
virtual std::string updateSlotSubtitle(bool Left) const = 0; virtual std::string updateSlotSubtitle(bool Left) const = 0;