mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-21 21:17:49 +02:00
refactoring
This commit is contained in:
parent
6a1a6b6864
commit
09bb9895ce
@ -90,20 +90,29 @@ void CArtifactsOfHeroBase::init(
|
|||||||
|
|
||||||
void CArtifactsOfHeroBase::clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
|
void CArtifactsOfHeroBase::clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
|
if(artPlace.isLocked())
|
||||||
|
return;
|
||||||
|
|
||||||
if(clickPressedCallback)
|
if(clickPressedCallback)
|
||||||
clickPressedCallback(*this, artPlace, cursorPosition);
|
clickPressedCallback(artPlace, cursorPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactsOfHeroBase::showPopupArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
|
void CArtifactsOfHeroBase::showPopupArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
|
if(artPlace.isLocked())
|
||||||
|
return;
|
||||||
|
|
||||||
if(showPopupCallback)
|
if(showPopupCallback)
|
||||||
showPopupCallback(*this, artPlace, cursorPosition);
|
showPopupCallback(artPlace, cursorPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactsOfHeroBase::gestureArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
|
void CArtifactsOfHeroBase::gestureArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
|
if(artPlace.isLocked())
|
||||||
|
return;
|
||||||
|
|
||||||
if(gestureCallback)
|
if(gestureCallback)
|
||||||
gestureCallback(*this, artPlace, cursorPosition);
|
gestureCallback(artPlace, cursorPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactsOfHeroBase::setHero(const CGHeroInstance * hero)
|
void CArtifactsOfHeroBase::setHero(const CGHeroInstance * hero)
|
||||||
@ -226,6 +235,11 @@ void CArtifactsOfHeroBase::addGestureCallback(CArtPlace::ClickFunctor callback)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CArtifactInstance * CArtifactsOfHeroBase::getArt(const ArtifactPosition & slot)
|
||||||
|
{
|
||||||
|
return curHero ? curHero->getArt(slot) : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void CArtifactsOfHeroBase::setSlotData(ArtPlacePtr artPlace, const ArtifactPosition & slot)
|
void CArtifactsOfHeroBase::setSlotData(ArtPlacePtr artPlace, const ArtifactPosition & slot)
|
||||||
{
|
{
|
||||||
// Spurious call from artifactMoved in attempt to update hidden backpack slot
|
// Spurious call from artifactMoved in attempt to update hidden backpack slot
|
||||||
|
@ -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&, CArtPlace&, const Point&)>;
|
using ClickFunctor = std::function<void(CArtPlace&, const Point&)>;
|
||||||
|
|
||||||
ClickFunctor clickPressedCallback;
|
ClickFunctor clickPressedCallback;
|
||||||
ClickFunctor showPopupCallback;
|
ClickFunctor showPopupCallback;
|
||||||
@ -44,6 +44,7 @@ public:
|
|||||||
virtual void updateSlot(const ArtifactPosition & slot);
|
virtual void updateSlot(const ArtifactPosition & slot);
|
||||||
virtual const CArtifactInstance * getPickedArtifact();
|
virtual const CArtifactInstance * getPickedArtifact();
|
||||||
void addGestureCallback(CArtPlace::ClickFunctor callback);
|
void addGestureCallback(CArtPlace::ClickFunctor callback);
|
||||||
|
const CArtifactInstance * getArt(const ArtifactPosition & slot);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const CGHeroInstance * curHero;
|
const CGHeroInstance * curHero;
|
||||||
|
@ -25,3 +25,21 @@ CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position, const int
|
|||||||
for(auto artPlace : backpack)
|
for(auto artPlace : backpack)
|
||||||
artPlace->setSelectionWidth(selectionWidth);
|
artPlace->setSelectionWidth(selectionWidth);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void CArtifactsOfHeroMarket::onClickPrassedArtPlace(CArtPlace & artPlace)
|
||||||
|
{
|
||||||
|
if(const auto art = getArt(artPlace.slot))
|
||||||
|
{
|
||||||
|
if(onSelectArtCallback && art->artType->isTradable())
|
||||||
|
{
|
||||||
|
unmarkSlots();
|
||||||
|
artPlace.selectSlot(true);
|
||||||
|
onSelectArtCallback(&artPlace);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(onClickNotTradableCallback)
|
||||||
|
onClickNotTradableCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
class CArtifactsOfHeroMarket : public CArtifactsOfHeroBase
|
class CArtifactsOfHeroMarket : public CArtifactsOfHeroBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::function<void(const CArtPlace*)> selectArtCallback;
|
std::function<void(const CArtPlace*)> onSelectArtCallback;
|
||||||
|
std::function<void()> onClickNotTradableCallback;
|
||||||
|
|
||||||
CArtifactsOfHeroMarket(const Point & position, const int selectionWidth);
|
CArtifactsOfHeroMarket(const Point & position, const int selectionWidth);
|
||||||
|
void onClickPrassedArtPlace(CArtPlace & artPlace);
|
||||||
};
|
};
|
||||||
|
@ -55,14 +55,18 @@ CArtifactsSelling::CArtifactsSelling(const IMarket * market, const CGHeroInstanc
|
|||||||
// Hero's artifacts
|
// Hero's artifacts
|
||||||
heroArts = std::make_shared<CArtifactsOfHeroMarket>(Point(-361, 46), offerTradePanel->selectionWidth);
|
heroArts = std::make_shared<CArtifactsOfHeroMarket>(Point(-361, 46), offerTradePanel->selectionWidth);
|
||||||
heroArts->setHero(hero);
|
heroArts->setHero(hero);
|
||||||
heroArts->selectArtCallback = [this](const CArtPlace * artPlace)
|
heroArts->onSelectArtCallback = [this](const CArtPlace * artPlace)
|
||||||
{
|
{
|
||||||
assert(artPlace);
|
assert(artPlace);
|
||||||
selectedHeroSlot = artPlace->slot;
|
selectedHeroSlot = artPlace->slot;
|
||||||
CArtifactsSelling::highlightingChanged();
|
CArtifactsSelling::highlightingChanged();
|
||||||
CIntObject::redraw();
|
CIntObject::redraw();
|
||||||
};
|
};
|
||||||
|
heroArts->onClickNotTradableCallback = []()
|
||||||
|
{
|
||||||
|
// This item can't be traded
|
||||||
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[21]);
|
||||||
|
};
|
||||||
CArtifactsSelling::updateShowcases();
|
CArtifactsSelling::updateShowcases();
|
||||||
CArtifactsSelling::deselect();
|
CArtifactsSelling::deselect();
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include "../../lib/ArtifactUtils.h"
|
#include "../../lib/ArtifactUtils.h"
|
||||||
#include "../../lib/CGeneralTextHandler.h"
|
#include "../../lib/CGeneralTextHandler.h"
|
||||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
|
||||||
#include "../../lib/networkPacks/ArtifactLocation.h"
|
#include "../../lib/networkPacks/ArtifactLocation.h"
|
||||||
#include "../../lib/CConfigHandler.h"
|
#include "../../lib/CConfigHandler.h"
|
||||||
|
|
||||||
@ -51,9 +50,65 @@ void CWindowWithArtifacts::addSetAndCallbacks(ArtifactsOfHeroVar newArtSet)
|
|||||||
addSet(newArtSet);
|
addSet(newArtSet);
|
||||||
std::visit([this](auto artSet)
|
std::visit([this](auto artSet)
|
||||||
{
|
{
|
||||||
artSet->clickPressedCallback = std::bind(&CWindowWithArtifacts::clickPressedArtPlaceHero, this, _1, _2, _3);
|
if constexpr(std::is_same_v<decltype(artSet), std::shared_ptr<CArtifactsOfHeroMarket>>)
|
||||||
artSet->showPopupCallback = std::bind(&CWindowWithArtifacts::showPopupArtPlaceHero, this, _1, _2, _3);
|
{
|
||||||
artSet->gestureCallback = std::bind(&CWindowWithArtifacts::gestureArtPlaceHero, this, _1, _2, _3);
|
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);
|
}, newArtSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,218 +149,104 @@ const CArtifactInstance * CWindowWithArtifacts::getPickedArtifact()
|
|||||||
return art;
|
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)
|
if(!LOCPLINT->makingTurn)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::visit(
|
if(const auto heroArtOwner = getHeroPickedArtifact())
|
||||||
[this, &artPlace](auto artSetPtr)
|
{
|
||||||
|
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(checkSpecialArts(*art, hero, altarTrading))
|
||||||
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>>)
|
|
||||||
{
|
{
|
||||||
const auto pickedArtInst = getPickedArtifact();
|
assert(hero.getArt(slot));
|
||||||
const auto heroPickedArt = getHeroPickedArtifact();
|
auto srcLoc = ArtifactLocation(hero.id, slot);
|
||||||
const auto hero = artSetPtr->getHero();
|
auto dstLoc = ArtifactLocation(hero.id, ArtifactPosition::TRANSITION_POS);
|
||||||
auto isTransferAllowed = false;
|
|
||||||
std::string msg;
|
|
||||||
|
|
||||||
if(pickedArtInst)
|
if(GH.isKeyboardCtrlDown())
|
||||||
{
|
{
|
||||||
auto srcLoc = ArtifactLocation(heroPickedArt->id, ArtifactPosition::TRANSITION_POS);
|
for(auto & anotherSet : artSets)
|
||||||
auto dstLoc = ArtifactLocation(hero->id, artPlace.slot);
|
if(std::holds_alternative<std::shared_ptr<CArtifactsOfHeroMain>>(anotherSet))
|
||||||
|
|
||||||
if(ArtifactUtils::isSlotBackpack(artPlace.slot))
|
|
||||||
{
|
|
||||||
if(pickedArtInst->artType->isBig())
|
|
||||||
{
|
{
|
||||||
// War machines cannot go to backpack
|
const auto anotherHeroEquipment = std::get<std::shared_ptr<CArtifactsOfHeroMain>>(anotherSet);
|
||||||
msg = boost::str(boost::format(CGI->generaltexth->allTexts[153]) % pickedArtInst->artType->getNameTranslated());
|
if(hero.id != anotherHeroEquipment->getHero()->id)
|
||||||
}
|
|
||||||
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())
|
|
||||||
{
|
{
|
||||||
for(auto & anotherSet : artSets)
|
dstLoc.slot = ArtifactPosition::FIRST_AVAILABLE;
|
||||||
if(std::holds_alternative<std::shared_ptr<CArtifactsOfHeroMain>>(anotherSet))
|
dstLoc.artHolder = anotherHeroEquipment->getHero()->id;
|
||||||
{
|
|
||||||
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];
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(GH.isKeyboardAltDown())
|
||||||
if constexpr(std::is_same_v<decltype(artSetPtr), std::shared_ptr<CArtifactsOfHeroBackpack>>)
|
|
||||||
{
|
{
|
||||||
if(!isTransferAllowed && artPlace.getArt() && !GH.isKeyboardCtrlDown() && !GH.isKeyboardAltDown() && closeCallback)
|
const auto artId = hero.getArt(slot)->getTypeId();
|
||||||
closeCallback();
|
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();
|
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(
|
else
|
||||||
std::is_same_v<decltype(artSetPtr), std::weak_ptr<CArtifactsOfHeroMarket>> ||
|
{
|
||||||
std::is_same_v<decltype(artSetPtr), std::weak_ptr<CArtifactsOfHeroQuickBackpack>>)
|
for(const auto & artSlot : ArtifactUtils::unmovableSlots())
|
||||||
{
|
if(slot == artSlot)
|
||||||
if(artPlace.getArt() && artPlace.text.size())
|
{
|
||||||
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[21]);
|
||||||
}
|
break;
|
||||||
}, currentArtSet.value());
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
LOCPLINT->cb->swapArtifacts(ArtifactLocation(artsInst.getHero()->id, artPlace.slot), dstLoc);
|
||||||
assert(currentArtSet.has_value());
|
if(closeCallback)
|
||||||
if(artPlace.isLocked())
|
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;
|
return;
|
||||||
|
|
||||||
std::visit(
|
GH.windows().createAndPushWindow<CHeroQuickBackpackWindow>(artsInst.getHero(), artPlace.slot);
|
||||||
[&artPlace, cursorPosition](auto artSetPtr)
|
auto backpackWindow = GH.windows().topWindow<CHeroQuickBackpackWindow>();
|
||||||
{
|
backpackWindow->moveTo(cursorPosition - Point(1, 1));
|
||||||
if constexpr(
|
backpackWindow->fitToScreen(15);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWindowWithArtifacts::activate()
|
void CWindowWithArtifacts::activate()
|
||||||
@ -397,22 +338,6 @@ void CWindowWithArtifacts::update()
|
|||||||
}, artSet);
|
}, 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()
|
void CWindowWithArtifacts::markPossibleSlots()
|
||||||
{
|
{
|
||||||
if(const auto pickedArtInst = getPickedArtifact())
|
if(const auto pickedArtInst = getPickedArtifact())
|
||||||
@ -423,23 +348,23 @@ void CWindowWithArtifacts::markPossibleSlots()
|
|||||||
if(artSetPtr->isActive())
|
if(artSetPtr->isActive())
|
||||||
{
|
{
|
||||||
const auto hero = artSetPtr->getHero();
|
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);
|
artSetPtr->markPossibleSlots(pickedArtInst, hero->tempOwner == LOCPLINT->playerID);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for(auto & artSetWeak : artSets)
|
for(auto & artSet : artSets)
|
||||||
std::visit(artifactAssembledBody, artSetWeak);
|
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();
|
const auto artId = artInst.getTypeId();
|
||||||
|
|
||||||
if(artId == ArtifactID::SPELLBOOK)
|
if(artId == ArtifactID::SPELLBOOK)
|
||||||
{
|
{
|
||||||
GH.windows().createAndPushWindow<CSpellWindow>(hero, LOCPLINT, LOCPLINT->battleInt.get());
|
GH.windows().createAndPushWindow<CSpellWindow>(&hero, LOCPLINT, LOCPLINT->battleInt.get());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(artId == ArtifactID::CATAPULT)
|
if(artId == ArtifactID::CATAPULT)
|
||||||
@ -473,3 +398,32 @@ void CWindowWithArtifacts::setCursorAnimation(const CArtifactInstance & artInst)
|
|||||||
CCS->curh->dragAndDropCursor(AnimationPath::builtin("artifact"), artInst.artType->getIconIndex());
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -37,9 +37,12 @@ public:
|
|||||||
void addCloseCallback(const CloseCallback & callback);
|
void addCloseCallback(const CloseCallback & callback);
|
||||||
const CGHeroInstance * getHeroPickedArtifact();
|
const CGHeroInstance * getHeroPickedArtifact();
|
||||||
const CArtifactInstance * getPickedArtifact();
|
const CArtifactInstance * getPickedArtifact();
|
||||||
void clickPressedArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
void clickPressedOnArtPlace(const CGHeroInstance & hero, const ArtifactPosition & slot,
|
||||||
void showPopupArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
bool allowExchange, bool altarTrading, bool closeWindow);
|
||||||
void gestureArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
void swapArtifactAndClose(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const ArtifactLocation & dstLoc);
|
||||||
|
void showArtifactAssembling(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
||||||
|
void showArifactInfo(CArtPlace & artPlace, const Point & cursorPosition);
|
||||||
|
void showQuickBackpackWindow(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
||||||
void activate() override;
|
void activate() override;
|
||||||
void deactivate() override;
|
void deactivate() override;
|
||||||
void enableArtifactsCostumeSwitcher() const;
|
void enableArtifactsCostumeSwitcher() const;
|
||||||
@ -51,8 +54,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void update();
|
void update();
|
||||||
std::optional<ArtifactsOfHeroVar> findAOHbyRef(const CArtifactsOfHeroBase & artsInst);
|
|
||||||
void markPossibleSlots();
|
void markPossibleSlots();
|
||||||
bool checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance * hero, bool isTrade) const;
|
bool checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance & hero, bool isTrade) const;
|
||||||
void setCursorAnimation(const CArtifactInstance & artInst);
|
void setCursorAnimation(const CArtifactInstance & artInst);
|
||||||
|
void putPickedArtifact(const CGHeroInstance & curHero, const ArtifactPosition & targetSlot);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user