|
@@ -26,19 +26,20 @@
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
|
|
|
|
|
-CWindowWithArtifacts::~CWindowWithArtifacts()
|
|
|
|
-{
|
|
|
|
- CCS->curh->dragAndDropCursor(nullptr);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet)
|
|
void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet)
|
|
{
|
|
{
|
|
|
|
+ CArtifactsOfHeroBase::PutBackPickedArtCallback artPutBackHandler = []() -> void
|
|
|
|
+ {
|
|
|
|
+ CCS->curh->dragAndDropCursor(nullptr);
|
|
|
|
+ };
|
|
|
|
+
|
|
artSets.emplace_back(artSet);
|
|
artSets.emplace_back(artSet);
|
|
- std::visit([this](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);
|
|
artSet->rightClickCallback = std::bind(&CWindowWithArtifacts::rightClickArtPlaceHero, this, _1, _2);
|
|
artSet->rightClickCallback = std::bind(&CWindowWithArtifacts::rightClickArtPlaceHero, this, _1, _2);
|
|
|
|
+ artSet->setPutBackPickedArtifactCallback(artPutBackHandler);
|
|
}, artSet);
|
|
}, artSet);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -90,35 +91,37 @@ void CWindowWithArtifacts::leftClickArtPlaceHero(CArtifactsOfHeroBase & artsInst
|
|
{
|
|
{
|
|
const auto artSetPtr = artSetWeak.lock();
|
|
const auto artSetPtr = artSetWeak.lock();
|
|
|
|
|
|
- // Hero(Main, Exchange) window, Kingdom window, Altar window left click handler
|
|
|
|
|
|
+ // Hero(Main, Exchange) window, Kingdom window, Altar window, Backpack window left click handler
|
|
if constexpr(
|
|
if constexpr(
|
|
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroMain>> ||
|
|
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroMain>> ||
|
|
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>> ||
|
|
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>> ||
|
|
- std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroAltar>>)
|
|
|
|
|
|
+ std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroAltar>> ||
|
|
|
|
+ std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroBackpack>>)
|
|
{
|
|
{
|
|
const auto pickedArtInst = getPickedArtifact();
|
|
const auto pickedArtInst = getPickedArtifact();
|
|
const auto heroPickedArt = getHeroPickedArtifact();
|
|
const auto heroPickedArt = getHeroPickedArtifact();
|
|
const auto hero = artSetPtr->getHero();
|
|
const auto hero = artSetPtr->getHero();
|
|
|
|
+ auto isTransferAllowed = false;
|
|
|
|
+ std::string msg;
|
|
|
|
|
|
if(pickedArtInst)
|
|
if(pickedArtInst)
|
|
{
|
|
{
|
|
auto srcLoc = ArtifactLocation(heroPickedArt, ArtifactPosition::TRANSITION_POS);
|
|
auto srcLoc = ArtifactLocation(heroPickedArt, ArtifactPosition::TRANSITION_POS);
|
|
auto dstLoc = ArtifactLocation(hero, artPlace.slot);
|
|
auto dstLoc = ArtifactLocation(hero, artPlace.slot);
|
|
- auto isTransferAllowed = false;
|
|
|
|
|
|
|
|
if(ArtifactUtils::isSlotBackpack(artPlace.slot))
|
|
if(ArtifactUtils::isSlotBackpack(artPlace.slot))
|
|
{
|
|
{
|
|
if(pickedArtInst->artType->isBig())
|
|
if(pickedArtInst->artType->isBig())
|
|
{
|
|
{
|
|
// War machines cannot go to backpack
|
|
// War machines cannot go to backpack
|
|
- LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[153]) % pickedArtInst->artType->getNameTranslated()));
|
|
|
|
|
|
+ msg = boost::str(boost::format(CGI->generaltexth->allTexts[153]) % pickedArtInst->artType->getNameTranslated());
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
if(ArtifactUtils::isBackpackFreeSlots(heroPickedArt))
|
|
if(ArtifactUtils::isBackpackFreeSlots(heroPickedArt))
|
|
isTransferAllowed = true;
|
|
isTransferAllowed = true;
|
|
else
|
|
else
|
|
- LOCPLINT->showInfoDialog(CGI->generaltexth->translate("core.genrltxt.152"));
|
|
|
|
|
|
+ msg = CGI->generaltexth->translate("core.genrltxt.152");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Check if artifact transfer is possible
|
|
// Check if artifact transfer is possible
|
|
@@ -137,7 +140,7 @@ void CWindowWithArtifacts::leftClickArtPlaceHero(CArtifactsOfHeroBase & artsInst
|
|
else
|
|
else
|
|
{
|
|
{
|
|
if(artPlace.getArt())
|
|
if(artPlace.getArt())
|
|
- {
|
|
|
|
|
|
+ {
|
|
if(artSetPtr->getHero()->tempOwner == LOCPLINT->playerID)
|
|
if(artSetPtr->getHero()->tempOwner == LOCPLINT->playerID)
|
|
{
|
|
{
|
|
if(checkSpecialArts(hero, artPlace))
|
|
if(checkSpecialArts(hero, artPlace))
|
|
@@ -148,12 +151,23 @@ void CWindowWithArtifacts::leftClickArtPlaceHero(CArtifactsOfHeroBase & artsInst
|
|
for(const auto artSlot : ArtifactUtils::unmovableSlots())
|
|
for(const auto artSlot : ArtifactUtils::unmovableSlots())
|
|
if(artPlace.slot == artSlot)
|
|
if(artPlace.slot == artSlot)
|
|
{
|
|
{
|
|
- LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[21]);
|
|
|
|
|
|
+ msg = CGI->generaltexth->allTexts[21];
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if constexpr(std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroBackpack>>)
|
|
|
|
+ {
|
|
|
|
+ if(!isTransferAllowed)
|
|
|
|
+ artSetPtr->destroyThis();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if(!msg.empty())
|
|
|
|
+ LOCPLINT->showInfoDialog(msg);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
// Market window left click handler
|
|
// Market window left click handler
|
|
else if constexpr(std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroMarket>>)
|
|
else if constexpr(std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroMarket>>)
|
|
@@ -189,10 +203,11 @@ void CWindowWithArtifacts::rightClickArtPlaceHero(CArtifactsOfHeroBase & artsIns
|
|
{
|
|
{
|
|
const auto artSetPtr = artSetWeak.lock();
|
|
const auto artSetPtr = artSetWeak.lock();
|
|
|
|
|
|
- // Hero(Main, Exchange) window, Kingdom window right click handler
|
|
|
|
|
|
+ // Hero (Main, Exchange) window, Kingdom window, Backpack window right click handler
|
|
if constexpr(
|
|
if constexpr(
|
|
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroMain>> ||
|
|
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroMain>> ||
|
|
- std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>>)
|
|
|
|
|
|
+ std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>> ||
|
|
|
|
+ std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroBackpack>>)
|
|
{
|
|
{
|
|
if(artPlace.getArt())
|
|
if(artPlace.getArt())
|
|
{
|
|
{
|
|
@@ -244,19 +259,19 @@ void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const
|
|
if(artSetPtr)
|
|
if(artSetPtr)
|
|
{
|
|
{
|
|
const auto hero = artSetPtr->getHero();
|
|
const auto hero = artSetPtr->getHero();
|
|
- if(artSetPtr->isActive())
|
|
|
|
|
|
+ if(pickedArtInst)
|
|
{
|
|
{
|
|
- if(pickedArtInst)
|
|
|
|
|
|
+ if(artSetPtr->isActive())
|
|
{
|
|
{
|
|
CCS->curh->dragAndDropCursor("artifact", pickedArtInst->artType->getIconIndex());
|
|
CCS->curh->dragAndDropCursor("artifact", pickedArtInst->artType->getIconIndex());
|
|
if(srcLoc.isHolder(hero) || !std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>>)
|
|
if(srcLoc.isHolder(hero) || !std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>>)
|
|
artSetPtr->markPossibleSlots(pickedArtInst, hero->tempOwner == LOCPLINT->playerID);
|
|
artSetPtr->markPossibleSlots(pickedArtInst, hero->tempOwner == LOCPLINT->playerID);
|
|
}
|
|
}
|
|
- else
|
|
|
|
- {
|
|
|
|
- artSetPtr->unmarkSlots();
|
|
|
|
- CCS->curh->dragAndDropCursor(nullptr);
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ artSetPtr->unmarkSlots();
|
|
|
|
+ CCS->curh->dragAndDropCursor(nullptr);
|
|
}
|
|
}
|
|
if(withRedraw)
|
|
if(withRedraw)
|
|
{
|
|
{
|
|
@@ -321,19 +336,21 @@ void CWindowWithArtifacts::updateSlots(const ArtifactPosition & slot)
|
|
std::optional<std::tuple<const CGHeroInstance*, const CArtifactInstance*>> CWindowWithArtifacts::getState()
|
|
std::optional<std::tuple<const CGHeroInstance*, const CArtifactInstance*>> CWindowWithArtifacts::getState()
|
|
{
|
|
{
|
|
const CArtifactInstance * artInst = nullptr;
|
|
const CArtifactInstance * artInst = nullptr;
|
|
- const CGHeroInstance * hero = nullptr;
|
|
|
|
- size_t pickedCnt = 0;
|
|
|
|
|
|
+ std::map<const CGHeroInstance*, size_t> pickedCnt;
|
|
|
|
|
|
- auto getHeroArtBody = [&hero, &artInst, &pickedCnt](auto artSetWeak) -> void
|
|
|
|
|
|
+ auto getHeroArtBody = [&artInst, &pickedCnt](auto artSetWeak) -> void
|
|
{
|
|
{
|
|
auto artSetPtr = artSetWeak.lock();
|
|
auto artSetPtr = artSetWeak.lock();
|
|
if(artSetPtr)
|
|
if(artSetPtr)
|
|
{
|
|
{
|
|
if(const auto art = artSetPtr->getPickedArtifact())
|
|
if(const auto art = artSetPtr->getPickedArtifact())
|
|
{
|
|
{
|
|
- artInst = art;
|
|
|
|
- hero = artSetPtr->getHero();
|
|
|
|
- pickedCnt += hero->artifactsTransitionPos.size();
|
|
|
|
|
|
+ const auto hero = artSetPtr->getHero();
|
|
|
|
+ if(pickedCnt.count(hero) == 0)
|
|
|
|
+ {
|
|
|
|
+ pickedCnt.insert({ hero, hero->artifactsTransitionPos.size() });
|
|
|
|
+ artInst = art;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
};
|
|
@@ -343,10 +360,13 @@ std::optional<std::tuple<const CGHeroInstance*, const CArtifactInstance*>> CWind
|
|
// The state is possible when the hero has placed an artifact in the ArtifactPosition::TRANSITION_POS,
|
|
// The state is possible when the hero has placed an artifact in the ArtifactPosition::TRANSITION_POS,
|
|
// and the previous artifact has not yet removed from the ArtifactPosition::TRANSITION_POS.
|
|
// and the previous artifact has not yet removed from the ArtifactPosition::TRANSITION_POS.
|
|
// This is a transitional state. Then return nullopt.
|
|
// This is a transitional state. Then return nullopt.
|
|
- if(pickedCnt > 1)
|
|
|
|
|
|
+ if(std::accumulate(std::begin(pickedCnt), std::end(pickedCnt), 0, [](size_t accum, const auto & value)
|
|
|
|
+ {
|
|
|
|
+ return accum + value.second;
|
|
|
|
+ }) > 1)
|
|
return std::nullopt;
|
|
return std::nullopt;
|
|
else
|
|
else
|
|
- return std::make_tuple(hero, artInst);
|
|
|
|
|
|
+ return std::make_tuple(pickedCnt.begin()->first, artInst);
|
|
}
|
|
}
|
|
|
|
|
|
std::optional<CWindowWithArtifacts::CArtifactsOfHeroPtr> CWindowWithArtifacts::findAOHbyRef(CArtifactsOfHeroBase & artsInst)
|
|
std::optional<CWindowWithArtifacts::CArtifactsOfHeroPtr> CWindowWithArtifacts::findAOHbyRef(CArtifactsOfHeroBase & artsInst)
|