mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
CWindowWithArtifacts remove std::variant
This commit is contained in:
parent
0501073d4c
commit
03aaf849f0
@ -240,6 +240,11 @@ const CArtifactInstance * CArtifactsOfHeroBase::getArt(const ArtifactPosition &
|
||||
return curHero ? curHero->getArt(slot) : nullptr;
|
||||
}
|
||||
|
||||
void CArtifactsOfHeroBase::enableKeyboardShortcuts()
|
||||
{
|
||||
addUsedEvents(AEventsReceiver::KEYBOARD);
|
||||
}
|
||||
|
||||
void CArtifactsOfHeroBase::setSlotData(ArtPlacePtr artPlace, const ArtifactPosition & slot)
|
||||
{
|
||||
// Spurious call from artifactMoved in attempt to update hidden backpack slot
|
||||
|
@ -11,9 +11,11 @@
|
||||
|
||||
#include "CArtPlace.h"
|
||||
|
||||
#include "../gui/Shortcut.h"
|
||||
|
||||
class CButton;
|
||||
|
||||
class CArtifactsOfHeroBase : virtual public CIntObject
|
||||
class CArtifactsOfHeroBase : virtual public CIntObject, public CKeyShortcut
|
||||
{
|
||||
protected:
|
||||
using ArtPlacePtr = std::shared_ptr<CHeroArtPlace>;
|
||||
@ -45,6 +47,7 @@ public:
|
||||
virtual const CArtifactInstance * getPickedArtifact();
|
||||
void addGestureCallback(CArtPlace::ClickFunctor callback);
|
||||
const CArtifactInstance * getArt(const ArtifactPosition & slot) const;
|
||||
void enableKeyboardShortcuts();
|
||||
|
||||
protected:
|
||||
const CGHeroInstance * curHero;
|
||||
|
@ -33,11 +33,6 @@ CArtifactsOfHeroMain::~CArtifactsOfHeroMain()
|
||||
CArtifactsOfHeroBase::putBackPickedArtifact();
|
||||
}
|
||||
|
||||
void CArtifactsOfHeroMain::enableArtifactsCostumeSwitcher()
|
||||
{
|
||||
addUsedEvents(AEventsReceiver::KEYBOARD);
|
||||
}
|
||||
|
||||
void CArtifactsOfHeroMain::keyPressed(EShortcut key)
|
||||
{
|
||||
if(!shortcutPressed)
|
||||
|
@ -11,14 +11,11 @@
|
||||
|
||||
#include "CArtifactsOfHeroBase.h"
|
||||
|
||||
#include "../gui/Shortcut.h"
|
||||
|
||||
class CArtifactsOfHeroMain : public CArtifactsOfHeroBase, public CKeyShortcut
|
||||
class CArtifactsOfHeroMain : public CArtifactsOfHeroBase
|
||||
{
|
||||
public:
|
||||
CArtifactsOfHeroMain(const Point & position);
|
||||
~CArtifactsOfHeroMain() override;
|
||||
void enableArtifactsCostumeSwitcher();
|
||||
void keyPressed(EShortcut key) override;
|
||||
void keyReleased(EShortcut key) override;
|
||||
|
||||
|
@ -20,7 +20,10 @@
|
||||
#include "render/Canvas.h"
|
||||
#include "CPlayerInterface.h"
|
||||
|
||||
CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std::vector<ArtifactsOfHeroVar> & artsSets)
|
||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||
#include "../../lib/networkPacks/ArtifactLocation.h"
|
||||
|
||||
CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std::vector<CArtifactsOfHeroPtr> & artsSets)
|
||||
: CWindowWithArtifacts(&artsSets)
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||
@ -28,7 +31,15 @@ CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std:
|
||||
stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
|
||||
arts = std::make_shared<CArtifactsOfHeroBackpack>();
|
||||
arts->moveBy(Point(windowMargin, windowMargin));
|
||||
addSetAndCallbacks(arts);
|
||||
arts->clickPressedCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
clickPressedOnArtPlace(arts->getHero(), artPlace.slot, true, false, true);
|
||||
};
|
||||
arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showArtifactAssembling(*arts, artPlace, cursorPosition);
|
||||
};
|
||||
addSet(arts);
|
||||
arts->setHero(hero);
|
||||
addCloseCallback(std::bind(&CHeroBackpackWindow::close, this));
|
||||
quitButton = std::make_shared<CButton>(Point(), AnimationPath::builtin("IOKAY32.def"), CButton::tooltip(""),
|
||||
@ -55,7 +66,16 @@ CHeroQuickBackpackWindow::CHeroQuickBackpackWindow(const CGHeroInstance * hero,
|
||||
stretchedBackground = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, 0, 0));
|
||||
arts = std::make_shared<CArtifactsOfHeroQuickBackpack>(targetSlot);
|
||||
arts->moveBy(Point(windowMargin, windowMargin));
|
||||
addSetAndCallbacks(static_cast<std::shared_ptr<CArtifactsOfHeroQuickBackpack>>(arts));
|
||||
arts->clickPressedCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
if(const auto curHero = arts->getHero())
|
||||
swapArtifactAndClose(*arts, artPlace.slot, ArtifactLocation(curHero->id, arts->getFilterSlot()));
|
||||
};
|
||||
arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showArifactInfo(artPlace, cursorPosition);
|
||||
};
|
||||
addSet(arts);
|
||||
arts->setHero(hero);
|
||||
addCloseCallback(std::bind(&CHeroQuickBackpackWindow::close, this));
|
||||
addUsedEvents(GESTURE);
|
||||
|
@ -16,7 +16,7 @@ class CFilledTexture;
|
||||
class CHeroBackpackWindow : public CStatusbarWindow, public CWindowWithArtifacts
|
||||
{
|
||||
public:
|
||||
CHeroBackpackWindow(const CGHeroInstance * hero, const std::vector<ArtifactsOfHeroVar> & artsSets);
|
||||
CHeroBackpackWindow(const CGHeroInstance * hero, const std::vector<CArtifactsOfHeroPtr> & artsSets);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<CArtifactsOfHeroBackpack> arts;
|
||||
|
@ -214,8 +214,20 @@ void CHeroWindow::update()
|
||||
{
|
||||
arts = std::make_shared<CArtifactsOfHeroMain>(Point(-65, -8));
|
||||
arts->setHero(curHero);
|
||||
addSetAndCallbacks(arts);
|
||||
enableArtifactsCostumeSwitcher();
|
||||
arts->clickPressedCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
clickPressedOnArtPlace(arts->getHero(), artPlace.slot, true, false, false);
|
||||
};
|
||||
arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showArtifactAssembling(*arts, artPlace, cursorPosition);
|
||||
};
|
||||
arts->gestureCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showQuickBackpackWindow(arts->getHero(), artPlace.slot, cursorPosition);
|
||||
};
|
||||
addSet(arts);
|
||||
enableKeyboardShortcuts();
|
||||
}
|
||||
|
||||
int serial = LOCPLINT->cb->getHeroSerial(curHero, false);
|
||||
|
@ -548,9 +548,21 @@ std::shared_ptr<CIntObject> CKingdomInterface::createMainTab(size_t index)
|
||||
switch(index)
|
||||
{
|
||||
case 0:
|
||||
return std::make_shared<CKingdHeroList>(size, [this](const CWindowWithArtifacts::ArtifactsOfHeroVar & newHeroSet)
|
||||
return std::make_shared<CKingdHeroList>(size, [this](const CWindowWithArtifacts::CArtifactsOfHeroPtr & newHeroSet)
|
||||
{
|
||||
addSetAndCallbacks(newHeroSet);
|
||||
newHeroSet->clickPressedCallback = [this, newHeroSet](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
clickPressedOnArtPlace(newHeroSet->getHero(), artPlace.slot, false, false, false);
|
||||
};
|
||||
newHeroSet->showPopupCallback = [this, newHeroSet](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showArtifactAssembling(*newHeroSet, artPlace, cursorPosition);
|
||||
};
|
||||
newHeroSet->gestureCallback = [this, newHeroSet](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showQuickBackpackWindow(newHeroSet->getHero(), artPlace.slot, cursorPosition);
|
||||
};
|
||||
addSet(newHeroSet);
|
||||
});
|
||||
case 1:
|
||||
return std::make_shared<CKingdTownList>(size);
|
||||
|
@ -334,7 +334,7 @@ private:
|
||||
std::shared_ptr<CLabel> skillsLabel;
|
||||
|
||||
public:
|
||||
using CreateHeroItemFunctor = std::function<void(const CWindowWithArtifacts::ArtifactsOfHeroVar)>;
|
||||
using CreateHeroItemFunctor = std::function<void(const CWindowWithArtifacts::CArtifactsOfHeroPtr)>;
|
||||
|
||||
CKingdHeroList(size_t maxSize, const CreateHeroItemFunctor & onCreateHeroItemCallback);
|
||||
void updateGarrisons() override;
|
||||
|
@ -194,7 +194,16 @@ void CMarketWindow::createArtifactsSelling(const IMarket * market, const CGHeroI
|
||||
artSlotBack->moveTo(pos.topLeft() + Point(18, 339));
|
||||
auto artsSellingMarket = std::make_shared<CArtifactsSelling>(market, hero);
|
||||
artSets.clear();
|
||||
addSetAndCallbacks(artsSellingMarket->getAOHset());
|
||||
const auto heroArts = artsSellingMarket->getAOHset();
|
||||
heroArts->clickPressedCallback = [heroArts](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
heroArts->onClickPressedArtPlace(artPlace);
|
||||
};
|
||||
heroArts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showArifactInfo(artPlace, cursorPosition);
|
||||
};
|
||||
addSet(heroArts);
|
||||
marketWidget = artsSellingMarket;
|
||||
initWidgetInternals(EMarketMode::ARTIFACT_RESOURCE, CGI->generaltexth->zelp[600]);
|
||||
}
|
||||
@ -234,7 +243,20 @@ void CMarketWindow::createAltarArtifacts(const IMarket * market, const CGHeroIns
|
||||
auto altarArtifacts = std::make_shared<CAltarArtifacts>(market, hero);
|
||||
marketWidget = altarArtifacts;
|
||||
artSets.clear();
|
||||
addSetAndCallbacks(altarArtifacts->getAOHset());
|
||||
const auto heroArts = altarArtifacts->getAOHset();
|
||||
heroArts->clickPressedCallback = [this, heroArts](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
clickPressedOnArtPlace(heroArts->getHero(), artPlace.slot, true, true, false);
|
||||
};
|
||||
heroArts->showPopupCallback = [this, heroArts](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showArtifactAssembling(*heroArts, artPlace, cursorPosition);
|
||||
};
|
||||
heroArts->gestureCallback = [this, heroArts](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showQuickBackpackWindow(heroArts->getHero(), artPlace.slot, cursorPosition);
|
||||
};
|
||||
addSet(heroArts);
|
||||
initWidgetInternals(EMarketMode::ARTIFACT_EXP, CGI->generaltexth->zelp[568]);
|
||||
updateHero();
|
||||
quitButton->addCallback([altarArtifacts](){altarArtifacts->putBackArtifacts();});
|
||||
|
@ -33,85 +33,17 @@
|
||||
|
||||
#include "../../CCallback.h"
|
||||
|
||||
CWindowWithArtifacts::CWindowWithArtifacts(const std::vector<ArtifactsOfHeroVar> * artSets)
|
||||
CWindowWithArtifacts::CWindowWithArtifacts(const std::vector<CArtifactsOfHeroPtr> * artSets)
|
||||
{
|
||||
if(artSets)
|
||||
this->artSets.insert(this->artSets.end(), artSets->begin(), artSets->end());
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::addSet(ArtifactsOfHeroVar newArtSet)
|
||||
void CWindowWithArtifacts::addSet(const std::shared_ptr<CArtifactsOfHeroBase> & newArtSet)
|
||||
{
|
||||
artSets.emplace_back(newArtSet);
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::addSetAndCallbacks(ArtifactsOfHeroVar newArtSet)
|
||||
{
|
||||
addSet(newArtSet);
|
||||
std::visit([this](auto artSet)
|
||||
{
|
||||
if constexpr(std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroMarket>>)
|
||||
{
|
||||
artSet->clickPressedCallback = [artSet](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
artSet->onClickPressedArtPlace(artPlace);
|
||||
};
|
||||
}
|
||||
if constexpr(std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroQuickBackpack>>)
|
||||
{
|
||||
artSet->clickPressedCallback = [this, artSet](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
if(const auto curHero = artSet->getHero())
|
||||
swapArtifactAndClose(*artSet, artPlace.slot, ArtifactLocation(curHero->id, artSet->getFilterSlot()));
|
||||
};
|
||||
}
|
||||
if constexpr(
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroMain>> ||
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroKingdom>> ||
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroAltar>> ||
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroBackpack>>)
|
||||
{
|
||||
artSet->clickPressedCallback = [this, artSet](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
if(const auto curHero = artSet->getHero())
|
||||
clickPressedOnArtPlace(*curHero, artPlace.slot,
|
||||
!std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroKingdom>>,
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroAltar>>,
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroBackpack>>);
|
||||
};
|
||||
}
|
||||
if constexpr(
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroMarket>> ||
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroQuickBackpack>>)
|
||||
{
|
||||
artSet->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showArifactInfo(artPlace, cursorPosition);
|
||||
};
|
||||
}
|
||||
if constexpr(
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroMain>> ||
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroKingdom>> ||
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroAltar>> ||
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroBackpack>>)
|
||||
{
|
||||
artSet->showPopupCallback = [this, artSet](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showArtifactAssembling(*artSet, artPlace, cursorPosition);
|
||||
};
|
||||
}
|
||||
if constexpr(
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroMain>> ||
|
||||
std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroKingdom>>)
|
||||
{
|
||||
artSet->gestureCallback = [this, artSet](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
if(const auto curHero = artSet->getHero())
|
||||
showQuickBackpackWindow(*curHero, artPlace.slot, cursorPosition);
|
||||
};
|
||||
}
|
||||
}, newArtSet);
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::addCloseCallback(const CloseCallback & callback)
|
||||
{
|
||||
closeCallback = callback;
|
||||
@ -122,14 +54,11 @@ const CGHeroInstance * CWindowWithArtifacts::getHeroPickedArtifact()
|
||||
const CGHeroInstance * hero = nullptr;
|
||||
|
||||
for(auto & artSet : artSets)
|
||||
std::visit([&hero](auto artSetPtr)
|
||||
{
|
||||
if(const auto pickedArt = artSetPtr->getHero()->getArt(ArtifactPosition::TRANSITION_POS))
|
||||
{
|
||||
hero = artSetPtr->getHero();
|
||||
return;
|
||||
}
|
||||
}, artSet);
|
||||
if(const auto pickedArt = artSet->getHero()->getArt(ArtifactPosition::TRANSITION_POS))
|
||||
{
|
||||
hero = artSet->getHero();
|
||||
break;
|
||||
}
|
||||
return hero;
|
||||
}
|
||||
|
||||
@ -138,34 +67,33 @@ const CArtifactInstance * CWindowWithArtifacts::getPickedArtifact()
|
||||
const CArtifactInstance * art = nullptr;
|
||||
|
||||
for(auto & artSet : artSets)
|
||||
std::visit([&art](auto artSetPtr)
|
||||
{
|
||||
if(const auto pickedArt = artSetPtr->getHero()->getArt(ArtifactPosition::TRANSITION_POS))
|
||||
{
|
||||
art = pickedArt;
|
||||
return;
|
||||
}
|
||||
}, artSet);
|
||||
if(const auto pickedArt = artSet->getHero()->getArt(ArtifactPosition::TRANSITION_POS))
|
||||
{
|
||||
art = pickedArt;
|
||||
break;
|
||||
}
|
||||
return art;
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::clickPressedOnArtPlace(const CGHeroInstance & hero, const ArtifactPosition & slot,
|
||||
void CWindowWithArtifacts::clickPressedOnArtPlace(const CGHeroInstance * hero, const ArtifactPosition & slot,
|
||||
bool allowExchange, bool altarTrading, bool closeWindow)
|
||||
{
|
||||
if(!LOCPLINT->makingTurn)
|
||||
return;
|
||||
if(hero == nullptr)
|
||||
return;
|
||||
|
||||
if(const auto heroArtOwner = getHeroPickedArtifact())
|
||||
{
|
||||
if(allowExchange || hero.id == heroArtOwner->id)
|
||||
putPickedArtifact(hero, slot);
|
||||
if(allowExchange || hero->id == heroArtOwner->id)
|
||||
putPickedArtifact(*hero, slot);
|
||||
}
|
||||
else if(auto art = hero.getArt(slot))
|
||||
else if(auto art = hero->getArt(slot))
|
||||
{
|
||||
if(hero.getOwner() == LOCPLINT->playerID)
|
||||
if(hero->getOwner() == LOCPLINT->playerID)
|
||||
{
|
||||
if(checkSpecialArts(*art, hero, altarTrading))
|
||||
onClickPressedCommonArtifact(hero, slot, closeWindow);
|
||||
if(checkSpecialArts(*art, *hero, altarTrading))
|
||||
onClickPressedCommonArtifact(*hero, slot, closeWindow);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -207,13 +135,13 @@ void CWindowWithArtifacts::showArifactInfo(CArtPlace & artPlace, const Point & c
|
||||
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::showQuickBackpackWindow(const CGHeroInstance & hero, const ArtifactPosition & slot,
|
||||
void CWindowWithArtifacts::showQuickBackpackWindow(const CGHeroInstance * hero, const ArtifactPosition & slot,
|
||||
const Point & cursorPosition) const
|
||||
{
|
||||
if(!settings["general"]["enableUiEnhancements"].Bool())
|
||||
return;
|
||||
|
||||
GH.windows().createAndPushWindow<CHeroQuickBackpackWindow>(&hero, slot);
|
||||
GH.windows().createAndPushWindow<CHeroQuickBackpackWindow>(hero, slot);
|
||||
auto backpackWindow = GH.windows().topWindow<CHeroQuickBackpackWindow>();
|
||||
backpackWindow->moveTo(cursorPosition - Point(1, 1));
|
||||
backpackWindow->fitToScreen(15);
|
||||
@ -235,15 +163,10 @@ void CWindowWithArtifacts::deactivate()
|
||||
CWindowObject::deactivate();
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::enableArtifactsCostumeSwitcher() const
|
||||
void CWindowWithArtifacts::enableKeyboardShortcuts() const
|
||||
{
|
||||
for(auto & artSet : artSets)
|
||||
std::visit(
|
||||
[](auto artSetPtr)
|
||||
{
|
||||
if constexpr(std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroMain>>)
|
||||
artSetPtr->enableArtifactsCostumeSwitcher();
|
||||
}, artSet);
|
||||
artSet->enableKeyboardShortcuts();
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::artifactRemoved(const ArtifactLocation & artLoc)
|
||||
@ -254,19 +177,16 @@ void CWindowWithArtifacts::artifactRemoved(const ArtifactLocation & artLoc)
|
||||
void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc)
|
||||
{
|
||||
for(auto & artSet : artSets)
|
||||
std::visit([this](auto artSetPtr)
|
||||
{
|
||||
if(const auto pickedArtInst = getPickedArtifact())
|
||||
{
|
||||
markPossibleSlots();
|
||||
setCursorAnimation(*pickedArtInst);
|
||||
}
|
||||
else
|
||||
{
|
||||
artSetPtr->unmarkSlots();
|
||||
CCS->curh->dragAndDropCursor(nullptr);
|
||||
}
|
||||
}, artSet);
|
||||
if(const auto pickedArtInst = getPickedArtifact())
|
||||
{
|
||||
markPossibleSlots();
|
||||
setCursorAnimation(*pickedArtInst);
|
||||
}
|
||||
else
|
||||
{
|
||||
artSet->unmarkSlots();
|
||||
CCS->curh->dragAndDropCursor(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::artifactDisassembled(const ArtifactLocation & artLoc)
|
||||
@ -283,15 +203,14 @@ void CWindowWithArtifacts::artifactAssembled(const ArtifactLocation & artLoc)
|
||||
void CWindowWithArtifacts::update()
|
||||
{
|
||||
for(auto & artSet : artSets)
|
||||
std::visit([](auto artSetPtr)
|
||||
{
|
||||
artSetPtr->updateWornSlots();
|
||||
artSetPtr->updateBackpackSlots();
|
||||
{
|
||||
artSet->updateWornSlots();
|
||||
artSet->updateBackpackSlots();
|
||||
|
||||
// Make sure the status bar is updated so it does not display old text
|
||||
if(auto artPlace = artSetPtr->getArtPlace(GH.getCursorPosition()))
|
||||
artPlace->hover(true);
|
||||
}, artSet);
|
||||
// Make sure the status bar is updated so it does not display old text
|
||||
if(auto artPlace = artSet->getArtPlace(GH.getCursorPosition()))
|
||||
artPlace->hover(true);
|
||||
}
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::markPossibleSlots()
|
||||
@ -299,18 +218,15 @@ void CWindowWithArtifacts::markPossibleSlots()
|
||||
if(const auto pickedArtInst = getPickedArtifact())
|
||||
{
|
||||
const auto heroArtOwner = getHeroPickedArtifact();
|
||||
auto artifactAssembledBody = [&pickedArtInst, &heroArtOwner](auto artSetPtr)
|
||||
for(auto & artSet : artSets)
|
||||
{
|
||||
if(artSetPtr->isActive())
|
||||
if(artSet->isActive())
|
||||
{
|
||||
const auto hero = artSetPtr->getHero();
|
||||
if(heroArtOwner == hero || !std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroKingdom>>)
|
||||
artSetPtr->markPossibleSlots(pickedArtInst, hero->tempOwner == LOCPLINT->playerID);
|
||||
const auto hero = artSet->getHero();
|
||||
if(heroArtOwner == hero || !std::dynamic_pointer_cast<CArtifactsOfHeroKingdom>(artSet))
|
||||
artSet->markPossibleSlots(pickedArtInst, hero->tempOwner == LOCPLINT->playerID);
|
||||
}
|
||||
};
|
||||
|
||||
for(auto & artSet : artSets)
|
||||
std::visit(artifactAssembledBody, artSet);
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,21 +309,19 @@ void CWindowWithArtifacts::onClickPressedCommonArtifact(const CGHeroInstance & c
|
||||
{
|
||||
for(auto & anotherSet : artSets)
|
||||
{
|
||||
if(std::holds_alternative<std::shared_ptr<CArtifactsOfHeroMain>>(anotherSet))
|
||||
if(std::dynamic_pointer_cast<CArtifactsOfHeroMain>(anotherSet))
|
||||
{
|
||||
const auto anotherHeroEquipment = std::get<std::shared_ptr<CArtifactsOfHeroMain>>(anotherSet);
|
||||
if(curHero.id != anotherHeroEquipment->getHero()->id)
|
||||
if(curHero.id != anotherSet->getHero()->id)
|
||||
{
|
||||
dstLoc.slot = ArtifactPosition::FIRST_AVAILABLE;
|
||||
dstLoc.artHolder = anotherHeroEquipment->getHero()->id;
|
||||
dstLoc.artHolder = anotherSet->getHero()->id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(std::holds_alternative<std::shared_ptr<CArtifactsOfHeroAltar>>(anotherSet))
|
||||
if(const auto heroSetAltar = std::dynamic_pointer_cast<CArtifactsOfHeroAltar>(anotherSet))
|
||||
{
|
||||
const auto heroEquipment = std::get<std::shared_ptr<CArtifactsOfHeroAltar>>(anotherSet);
|
||||
dstLoc.slot = ArtifactPosition::FIRST_AVAILABLE;
|
||||
dstLoc.artHolder = heroEquipment->altarId;
|
||||
dstLoc.artHolder = heroSetAltar->altarId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -19,33 +19,26 @@
|
||||
class CWindowWithArtifacts : virtual public CWindowObject
|
||||
{
|
||||
public:
|
||||
using ArtifactsOfHeroVar = std::variant<
|
||||
std::shared_ptr<CArtifactsOfHeroMarket>,
|
||||
std::shared_ptr<CArtifactsOfHeroAltar>,
|
||||
std::shared_ptr<CArtifactsOfHeroKingdom>,
|
||||
std::shared_ptr<CArtifactsOfHeroMain>,
|
||||
std::shared_ptr<CArtifactsOfHeroBackpack>,
|
||||
std::shared_ptr<CArtifactsOfHeroQuickBackpack>>;
|
||||
using CArtifactsOfHeroPtr = std::shared_ptr<CArtifactsOfHeroBase>;
|
||||
using CloseCallback = std::function<void()>;
|
||||
|
||||
std::vector<ArtifactsOfHeroVar> artSets;
|
||||
std::vector<CArtifactsOfHeroPtr> artSets;
|
||||
CloseCallback closeCallback;
|
||||
|
||||
explicit CWindowWithArtifacts(const std::vector<ArtifactsOfHeroVar> * artSets = nullptr);
|
||||
void addSet(ArtifactsOfHeroVar newArtSet);
|
||||
void addSetAndCallbacks(ArtifactsOfHeroVar newArtSet);
|
||||
explicit CWindowWithArtifacts(const std::vector<CArtifactsOfHeroPtr> * artSets = nullptr);
|
||||
void addSet(const std::shared_ptr<CArtifactsOfHeroBase> & newArtSet);
|
||||
void addCloseCallback(const CloseCallback & callback);
|
||||
const CGHeroInstance * getHeroPickedArtifact();
|
||||
const CArtifactInstance * getPickedArtifact();
|
||||
void clickPressedOnArtPlace(const CGHeroInstance & hero, const ArtifactPosition & slot,
|
||||
void clickPressedOnArtPlace(const CGHeroInstance * hero, const ArtifactPosition & slot,
|
||||
bool allowExchange, bool altarTrading, bool closeWindow);
|
||||
void swapArtifactAndClose(const CArtifactsOfHeroBase & artsInst, const ArtifactPosition & slot, const ArtifactLocation & dstLoc) const;
|
||||
void showArtifactAssembling(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition) const;
|
||||
void showArifactInfo(CArtPlace & artPlace, const Point & cursorPosition) const;
|
||||
void showQuickBackpackWindow(const CGHeroInstance & hero, const ArtifactPosition & slot, const Point & cursorPosition) const;
|
||||
void showQuickBackpackWindow(const CGHeroInstance * hero, const ArtifactPosition & slot, const Point & cursorPosition) const;
|
||||
void activate() override;
|
||||
void deactivate() override;
|
||||
void enableArtifactsCostumeSwitcher() const;
|
||||
void enableKeyboardShortcuts() const;
|
||||
|
||||
virtual void artifactRemoved(const ArtifactLocation & artLoc);
|
||||
virtual void artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc);
|
||||
|
@ -763,8 +763,33 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
||||
artifs[1] = std::make_shared<CArtifactsOfHeroMain>(Point(98, 151));
|
||||
artifs[1]->setHero(heroInst[1]);
|
||||
|
||||
addSetAndCallbacks(artifs[0]);
|
||||
addSetAndCallbacks(artifs[1]);
|
||||
artifs[0]->clickPressedCallback = [this, heroArts = artifs[0]](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
clickPressedOnArtPlace(heroArts->getHero(), artPlace.slot, true, false, false);
|
||||
};
|
||||
artifs[0]->showPopupCallback = [this, heroArts = artifs[0]](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showArtifactAssembling(*heroArts, artPlace, cursorPosition);
|
||||
};
|
||||
artifs[0]->gestureCallback = [this, heroArts = artifs[0]](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showQuickBackpackWindow(heroArts->getHero(), artPlace.slot, cursorPosition);
|
||||
};
|
||||
artifs[1]->clickPressedCallback = [this, heroArts = artifs[1]](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
clickPressedOnArtPlace(heroArts->getHero(), artPlace.slot, true, false, false);
|
||||
};
|
||||
artifs[1]->showPopupCallback = [this, heroArts = artifs[1]](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showArtifactAssembling(*heroArts, artPlace, cursorPosition);
|
||||
};
|
||||
artifs[1]->gestureCallback = [this, heroArts = artifs[1]](CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
showQuickBackpackWindow(heroArts->getHero(), artPlace.slot, cursorPosition);
|
||||
};
|
||||
|
||||
addSet(artifs[0]);
|
||||
addSet(artifs[1]);
|
||||
|
||||
for(int g=0; g<4; ++g)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user