|
|
|
@ -29,7 +29,6 @@
|
|
|
|
|
|
|
|
|
|
#include "../../lib/ArtifactUtils.h"
|
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
|
|
|
|
#include "../../lib/networkPacks/ArtifactLocation.h"
|
|
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
|
|
|
|
|
@ -51,9 +50,65 @@ void CWindowWithArtifacts::addSetAndCallbacks(ArtifactsOfHeroVar newArtSet)
|
|
|
|
|
addSet(newArtSet);
|
|
|
|
|
std::visit([this](auto artSet)
|
|
|
|
|
{
|
|
|
|
|
artSet->clickPressedCallback = std::bind(&CWindowWithArtifacts::clickPressedArtPlaceHero, this, _1, _2, _3);
|
|
|
|
|
artSet->showPopupCallback = std::bind(&CWindowWithArtifacts::showPopupArtPlaceHero, this, _1, _2, _3);
|
|
|
|
|
artSet->gestureCallback = std::bind(&CWindowWithArtifacts::gestureArtPlaceHero, this, _1, _2, _3);
|
|
|
|
|
if constexpr(std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroMarket>>)
|
|
|
|
|
{
|
|
|
|
|
artSet->clickPressedCallback = [artSet](CArtPlace & artPlace, const Point & cursorPosition)
|
|
|
|
|
{
|
|
|
|
|
artSet->onClickPrassedArtPlace(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, 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)
|
|
|
|
|
{
|
|
|
|
|
showQuickBackpackWindow(*artSet, artPlace, cursorPosition);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}, newArtSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -94,218 +149,104 @@ const CArtifactInstance * CWindowWithArtifacts::getPickedArtifact()
|
|
|
|
|
return art;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWindowWithArtifacts::clickPressedArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
|
|
|
|
|
void CWindowWithArtifacts::clickPressedOnArtPlace(const CGHeroInstance & hero, const ArtifactPosition & slot,
|
|
|
|
|
bool allowExchange, bool altarTrading, bool closeWindow)
|
|
|
|
|
{
|
|
|
|
|
const auto currentArtSet = findAOHbyRef(artsInst);
|
|
|
|
|
assert(currentArtSet.has_value());
|
|
|
|
|
|
|
|
|
|
if(artPlace.isLocked())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(!LOCPLINT->makingTurn)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::visit(
|
|
|
|
|
[this, &artPlace](auto artSetPtr)
|
|
|
|
|
if(const auto heroArtOwner = getHeroPickedArtifact())
|
|
|
|
|
{
|
|
|
|
|
if(allowExchange || hero.id == heroArtOwner->id)
|
|
|
|
|
putPickedArtifact(hero, slot);
|
|
|
|
|
}
|
|
|
|
|
else if(auto art = hero.getArt(slot))
|
|
|
|
|
{
|
|
|
|
|
if(hero.getOwner() == LOCPLINT->playerID)
|
|
|
|
|
{
|
|
|
|
|
// Hero(Main, Exchange) window, Kingdom window, Altar window, Backpack window left click handler
|
|
|
|
|
if constexpr(
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroMain>> ||
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroKingdom>> ||
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroAltar>> ||
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroBackpack>>)
|
|
|
|
|
if(checkSpecialArts(*art, hero, altarTrading))
|
|
|
|
|
{
|
|
|
|
|
const auto pickedArtInst = getPickedArtifact();
|
|
|
|
|
const auto heroPickedArt = getHeroPickedArtifact();
|
|
|
|
|
const auto hero = artSetPtr->getHero();
|
|
|
|
|
auto isTransferAllowed = false;
|
|
|
|
|
std::string msg;
|
|
|
|
|
assert(hero.getArt(slot));
|
|
|
|
|
auto srcLoc = ArtifactLocation(hero.id, slot);
|
|
|
|
|
auto dstLoc = ArtifactLocation(hero.id, ArtifactPosition::TRANSITION_POS);
|
|
|
|
|
|
|
|
|
|
if(pickedArtInst)
|
|
|
|
|
if(GH.isKeyboardCtrlDown())
|
|
|
|
|
{
|
|
|
|
|
auto srcLoc = ArtifactLocation(heroPickedArt->id, ArtifactPosition::TRANSITION_POS);
|
|
|
|
|
auto dstLoc = ArtifactLocation(hero->id, artPlace.slot);
|
|
|
|
|
|
|
|
|
|
if(ArtifactUtils::isSlotBackpack(artPlace.slot))
|
|
|
|
|
{
|
|
|
|
|
if(pickedArtInst->artType->isBig())
|
|
|
|
|
for(auto & anotherSet : artSets)
|
|
|
|
|
if(std::holds_alternative<std::shared_ptr<CArtifactsOfHeroMain>>(anotherSet))
|
|
|
|
|
{
|
|
|
|
|
// War machines cannot go to backpack
|
|
|
|
|
msg = boost::str(boost::format(CGI->generaltexth->allTexts[153]) % pickedArtInst->artType->getNameTranslated());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(ArtifactUtils::isBackpackFreeSlots(heroPickedArt))
|
|
|
|
|
isTransferAllowed = true;
|
|
|
|
|
else
|
|
|
|
|
msg = CGI->generaltexth->translate("core.genrltxt.152");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Check if artifact transfer is possible
|
|
|
|
|
else if(pickedArtInst->canBePutAt(hero, artPlace.slot, true) && (!artPlace.getArt() || hero->tempOwner == LOCPLINT->playerID))
|
|
|
|
|
{
|
|
|
|
|
isTransferAllowed = true;
|
|
|
|
|
}
|
|
|
|
|
if constexpr(std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroKingdom>>)
|
|
|
|
|
{
|
|
|
|
|
if(hero != heroPickedArt)
|
|
|
|
|
isTransferAllowed = false;
|
|
|
|
|
}
|
|
|
|
|
if(isTransferAllowed)
|
|
|
|
|
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
|
|
|
|
|
}
|
|
|
|
|
else if(auto art = artPlace.getArt())
|
|
|
|
|
{
|
|
|
|
|
if(artSetPtr->getHero()->getOwner() == LOCPLINT->playerID)
|
|
|
|
|
{
|
|
|
|
|
if(checkSpecialArts(*art, hero, std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroAltar>> ? true : false))
|
|
|
|
|
{
|
|
|
|
|
assert(artSetPtr->getHero()->getSlotByInstance(art) != ArtifactPosition::PRE_FIRST);
|
|
|
|
|
|
|
|
|
|
auto srcLoc = ArtifactLocation(hero->id, artPlace.slot);
|
|
|
|
|
auto dstLoc = ArtifactLocation(hero->id, ArtifactPosition::TRANSITION_POS);
|
|
|
|
|
|
|
|
|
|
if(GH.isKeyboardCtrlDown())
|
|
|
|
|
const auto anotherHeroEquipment = std::get<std::shared_ptr<CArtifactsOfHeroMain>>(anotherSet);
|
|
|
|
|
if(hero.id != anotherHeroEquipment->getHero()->id)
|
|
|
|
|
{
|
|
|
|
|
for(auto & anotherSet : artSets)
|
|
|
|
|
if(std::holds_alternative<std::shared_ptr<CArtifactsOfHeroMain>>(anotherSet))
|
|
|
|
|
{
|
|
|
|
|
auto anotherHeroEquipment = std::get<std::shared_ptr<CArtifactsOfHeroMain>>(anotherSet);
|
|
|
|
|
if(hero->id != anotherHeroEquipment->getHero()->id)
|
|
|
|
|
{
|
|
|
|
|
dstLoc.slot = ArtifactPosition::FIRST_AVAILABLE;
|
|
|
|
|
dstLoc.artHolder = anotherHeroEquipment->getHero()->id;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(GH.isKeyboardAltDown())
|
|
|
|
|
{
|
|
|
|
|
if(ArtifactUtils::isSlotEquipment(artPlace.slot))
|
|
|
|
|
dstLoc.slot = ArtifactUtils::getArtBackpackPosition(artSetPtr->getHero(), art->getTypeId());
|
|
|
|
|
else if(ArtifactUtils::isSlotBackpack(artPlace.slot))
|
|
|
|
|
dstLoc.slot = ArtifactUtils::getArtEquippedPosition(artSetPtr->getHero(), art->getTypeId());
|
|
|
|
|
}
|
|
|
|
|
if(dstLoc.slot != ArtifactPosition::PRE_FIRST)
|
|
|
|
|
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(const auto & artSlot : ArtifactUtils::unmovableSlots())
|
|
|
|
|
if(artPlace.slot == artSlot)
|
|
|
|
|
{
|
|
|
|
|
msg = CGI->generaltexth->allTexts[21];
|
|
|
|
|
dstLoc.slot = ArtifactPosition::FIRST_AVAILABLE;
|
|
|
|
|
dstLoc.artHolder = anotherHeroEquipment->getHero()->id;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if constexpr(std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroBackpack>>)
|
|
|
|
|
else if(GH.isKeyboardAltDown())
|
|
|
|
|
{
|
|
|
|
|
if(!isTransferAllowed && artPlace.getArt() && !GH.isKeyboardCtrlDown() && !GH.isKeyboardAltDown() && closeCallback)
|
|
|
|
|
closeCallback();
|
|
|
|
|
const auto artId = hero.getArt(slot)->getTypeId();
|
|
|
|
|
if(ArtifactUtils::isSlotEquipment(slot))
|
|
|
|
|
dstLoc.slot = ArtifactUtils::getArtBackpackPosition(&hero, artId);
|
|
|
|
|
else if(ArtifactUtils::isSlotBackpack(slot))
|
|
|
|
|
dstLoc.slot = ArtifactUtils::getArtEquippedPosition(&hero, artId);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
else if(closeWindow && closeCallback)
|
|
|
|
|
{
|
|
|
|
|
if(!msg.empty())
|
|
|
|
|
LOCPLINT->showInfoDialog(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Market window left click handler
|
|
|
|
|
else if constexpr(std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroMarket>>)
|
|
|
|
|
{
|
|
|
|
|
if(artSetPtr->selectArtCallback && artPlace.getArt())
|
|
|
|
|
{
|
|
|
|
|
if(artPlace.getArt()->artType->isTradable())
|
|
|
|
|
{
|
|
|
|
|
artSetPtr->unmarkSlots();
|
|
|
|
|
artPlace.selectSlot(true);
|
|
|
|
|
artSetPtr->selectArtCallback(&artPlace);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// This item can't be traded
|
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[21]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if constexpr(std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroQuickBackpack>>)
|
|
|
|
|
{
|
|
|
|
|
const auto hero = artSetPtr->getHero();
|
|
|
|
|
LOCPLINT->cb->swapArtifacts(ArtifactLocation(hero->id, artPlace.slot), ArtifactLocation(hero->id, artSetPtr->getFilterSlot()));
|
|
|
|
|
if(closeCallback)
|
|
|
|
|
closeCallback();
|
|
|
|
|
}
|
|
|
|
|
}, currentArtSet.value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWindowWithArtifacts::showPopupArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
|
|
|
|
|
{
|
|
|
|
|
const auto currentArtSet = findAOHbyRef(artsInst);
|
|
|
|
|
assert(currentArtSet.has_value());
|
|
|
|
|
|
|
|
|
|
if(artPlace.isLocked())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::visit(
|
|
|
|
|
[&artPlace, &cursorPosition](auto artSetPtr)
|
|
|
|
|
{
|
|
|
|
|
// Hero (Main, Exchange) window, Kingdom window, Backpack window right click handler
|
|
|
|
|
if constexpr(
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroAltar>> ||
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroMain>> ||
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroKingdom>> ||
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroBackpack>>)
|
|
|
|
|
{
|
|
|
|
|
if(artPlace.getArt())
|
|
|
|
|
{
|
|
|
|
|
if(ArtifactUtilsClient::askToDisassemble(artSetPtr->getHero(), artPlace.slot))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(ArtifactUtilsClient::askToAssemble(artSetPtr->getHero(), artPlace.slot))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(artPlace.text.size())
|
|
|
|
|
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
|
|
|
|
|
}
|
|
|
|
|
if(dstLoc.slot != ArtifactPosition::PRE_FIRST)
|
|
|
|
|
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
|
|
|
|
|
}
|
|
|
|
|
// Altar window, Market window right click handler
|
|
|
|
|
else if constexpr(
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::weak_ptr<CArtifactsOfHeroMarket>> ||
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::weak_ptr<CArtifactsOfHeroQuickBackpack>>)
|
|
|
|
|
{
|
|
|
|
|
if(artPlace.getArt() && artPlace.text.size())
|
|
|
|
|
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
|
|
|
|
|
}
|
|
|
|
|
}, currentArtSet.value());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(const auto & artSlot : ArtifactUtils::unmovableSlots())
|
|
|
|
|
if(slot == artSlot)
|
|
|
|
|
{
|
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[21]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWindowWithArtifacts::gestureArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
|
|
|
|
|
void CWindowWithArtifacts::swapArtifactAndClose(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const ArtifactLocation & dstLoc)
|
|
|
|
|
{
|
|
|
|
|
const auto currentArtSet = findAOHbyRef(artsInst);
|
|
|
|
|
assert(currentArtSet.has_value());
|
|
|
|
|
if(artPlace.isLocked())
|
|
|
|
|
LOCPLINT->cb->swapArtifacts(ArtifactLocation(artsInst.getHero()->id, artPlace.slot), dstLoc);
|
|
|
|
|
if(closeCallback)
|
|
|
|
|
closeCallback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWindowWithArtifacts::showArtifactAssembling(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
|
|
|
|
|
{
|
|
|
|
|
if(artPlace.getArt())
|
|
|
|
|
{
|
|
|
|
|
if(ArtifactUtilsClient::askToDisassemble(artsInst.getHero(), artPlace.slot))
|
|
|
|
|
return;
|
|
|
|
|
if(ArtifactUtilsClient::askToAssemble(artsInst.getHero(), artPlace.slot))
|
|
|
|
|
return;
|
|
|
|
|
if(artPlace.text.size())
|
|
|
|
|
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWindowWithArtifacts::showArifactInfo(CArtPlace & artPlace, const Point & cursorPosition)
|
|
|
|
|
{
|
|
|
|
|
if(artPlace.getArt() && artPlace.text.size())
|
|
|
|
|
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWindowWithArtifacts::showQuickBackpackWindow(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
|
|
|
|
|
{
|
|
|
|
|
if(!settings["general"]["enableUiEnhancements"].Bool())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::visit(
|
|
|
|
|
[&artPlace, cursorPosition](auto artSetPtr)
|
|
|
|
|
{
|
|
|
|
|
if constexpr(
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroMain>> ||
|
|
|
|
|
std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroKingdom>>)
|
|
|
|
|
{
|
|
|
|
|
if(!settings["general"]["enableUiEnhancements"].Bool())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
GH.windows().createAndPushWindow<CHeroQuickBackpackWindow>(artSetPtr->getHero(), artPlace.slot);
|
|
|
|
|
auto backpackWindow = GH.windows().topWindow<CHeroQuickBackpackWindow>();
|
|
|
|
|
backpackWindow->moveTo(cursorPosition - Point(1, 1));
|
|
|
|
|
backpackWindow->fitToScreen(15);
|
|
|
|
|
}
|
|
|
|
|
}, currentArtSet.value());
|
|
|
|
|
GH.windows().createAndPushWindow<CHeroQuickBackpackWindow>(artsInst.getHero(), artPlace.slot);
|
|
|
|
|
auto backpackWindow = GH.windows().topWindow<CHeroQuickBackpackWindow>();
|
|
|
|
|
backpackWindow->moveTo(cursorPosition - Point(1, 1));
|
|
|
|
|
backpackWindow->fitToScreen(15);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWindowWithArtifacts::activate()
|
|
|
|
@ -397,22 +338,6 @@ void CWindowWithArtifacts::update()
|
|
|
|
|
}, artSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<CWindowWithArtifacts::ArtifactsOfHeroVar> CWindowWithArtifacts::findAOHbyRef(const CArtifactsOfHeroBase & artsInst)
|
|
|
|
|
{
|
|
|
|
|
std::optional<ArtifactsOfHeroVar> res;
|
|
|
|
|
for(auto & artSet : artSets)
|
|
|
|
|
{
|
|
|
|
|
std::visit([&res, &artsInst](auto & artSetPtr)
|
|
|
|
|
{
|
|
|
|
|
if(&artsInst == artSetPtr.get())
|
|
|
|
|
res = artSetPtr;
|
|
|
|
|
}, artSet);
|
|
|
|
|
if(res.has_value())
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWindowWithArtifacts::markPossibleSlots()
|
|
|
|
|
{
|
|
|
|
|
if(const auto pickedArtInst = getPickedArtifact())
|
|
|
|
@ -423,23 +348,23 @@ void CWindowWithArtifacts::markPossibleSlots()
|
|
|
|
|
if(artSetPtr->isActive())
|
|
|
|
|
{
|
|
|
|
|
const auto hero = artSetPtr->getHero();
|
|
|
|
|
if(heroArtOwner == hero || !std::is_same_v<decltype(artSetPtr), std::weak_ptr<CArtifactsOfHeroKingdom>>)
|
|
|
|
|
if(heroArtOwner == hero || !std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroKingdom>>)
|
|
|
|
|
artSetPtr->markPossibleSlots(pickedArtInst, hero->tempOwner == LOCPLINT->playerID);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for(auto & artSetWeak : artSets)
|
|
|
|
|
std::visit(artifactAssembledBody, artSetWeak);
|
|
|
|
|
for(auto & artSet : artSets)
|
|
|
|
|
std::visit(artifactAssembledBody, artSet);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CWindowWithArtifacts::checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance * hero, bool isTrade) const
|
|
|
|
|
bool CWindowWithArtifacts::checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance & hero, bool isTrade) const
|
|
|
|
|
{
|
|
|
|
|
const auto artId = artInst.getTypeId();
|
|
|
|
|
|
|
|
|
|
if(artId == ArtifactID::SPELLBOOK)
|
|
|
|
|
{
|
|
|
|
|
GH.windows().createAndPushWindow<CSpellWindow>(hero, LOCPLINT, LOCPLINT->battleInt.get());
|
|
|
|
|
GH.windows().createAndPushWindow<CSpellWindow>(&hero, LOCPLINT, LOCPLINT->battleInt.get());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(artId == ArtifactID::CATAPULT)
|
|
|
|
@ -473,3 +398,32 @@ void CWindowWithArtifacts::setCursorAnimation(const CArtifactInstance & artInst)
|
|
|
|
|
CCS->curh->dragAndDropCursor(AnimationPath::builtin("artifact"), artInst.artType->getIconIndex());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWindowWithArtifacts::putPickedArtifact(const CGHeroInstance & curHero, const ArtifactPosition & targetSlot)
|
|
|
|
|
{
|
|
|
|
|
const auto heroArtOwner = getHeroPickedArtifact();
|
|
|
|
|
const auto pickedArt = getPickedArtifact();
|
|
|
|
|
auto srcLoc = ArtifactLocation(heroArtOwner->id, ArtifactPosition::TRANSITION_POS);
|
|
|
|
|
auto dstLoc = ArtifactLocation(curHero.id, targetSlot);
|
|
|
|
|
|
|
|
|
|
if(ArtifactUtils::isSlotBackpack(dstLoc.slot))
|
|
|
|
|
{
|
|
|
|
|
if(pickedArt->artType->isBig())
|
|
|
|
|
{
|
|
|
|
|
// War machines cannot go to backpack
|
|
|
|
|
LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[153]) % pickedArt->artType->getNameTranslated()));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(ArtifactUtils::isBackpackFreeSlots(heroArtOwner))
|
|
|
|
|
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
|
|
|
|
|
else
|
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->translate("core.genrltxt.152"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Check if artifact transfer is possible
|
|
|
|
|
else if(pickedArt->canBePutAt(&curHero, dstLoc.slot, true) && (!curHero.getArt(targetSlot) || curHero.tempOwner == LOCPLINT->playerID))
|
|
|
|
|
{
|
|
|
|
|
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|