1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/client/windows/CWindowWithArtifacts.cpp

567 lines
17 KiB
C++
Raw Normal View History

2023-04-23 14:10:35 +02:00
/*
* CWindowWithArtifacts.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "CWindowWithArtifacts.h"
#include "../gui/CGuiHandler.h"
#include "../gui/CursorHandler.h"
#include "../gui/WindowHandler.h"
2023-04-23 14:10:35 +02:00
2023-09-25 22:58:59 +02:00
#include "../render/IRenderHandler.h"
#include "../render/CAnimation.h"
#include "../render/IImage.h"
2024-04-23 15:21:45 +02:00
#include "../widgets/CComponent.h"
2023-04-23 14:10:35 +02:00
#include "../windows/CHeroWindow.h"
#include "../windows/CSpellWindow.h"
#include "../windows/GUIClasses.h"
2023-12-17 16:30:19 +02:00
#include "../windows/CHeroBackpackWindow.h"
2023-04-23 14:10:35 +02:00
#include "../CPlayerInterface.h"
#include "../CGameInfo.h"
2023-05-17 15:52:16 +02:00
#include "../../lib/ArtifactUtils.h"
2023-04-23 14:10:35 +02:00
#include "../../lib/CGeneralTextHandler.h"
#include "../../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/networkPacks/ArtifactLocation.h"
2023-09-25 23:02:16 +02:00
#include "../../lib/CConfigHandler.h"
2023-04-23 14:10:35 +02:00
2024-01-27 23:48:11 +02:00
#include "../../CCallback.h"
2024-04-16 16:45:31 +02:00
CWindowWithArtifacts::CWindowWithArtifacts(const std::vector<CArtifactsOfHeroPtr> * artSets)
{
if(artSets)
this->artSets.insert(this->artSets.end(), artSets->begin(), artSets->end());
}
2024-04-23 19:26:21 +02:00
void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr newArtSet)
2023-09-18 21:58:08 +02:00
{
2024-04-23 19:26:21 +02:00
artSets.emplace_back(newArtSet);
2023-09-18 21:58:08 +02:00
}
2024-04-23 19:26:21 +02:00
void CWindowWithArtifacts::addSetAndCallbacks(CArtifactsOfHeroPtr newArtSet)
2023-04-23 14:10:35 +02:00
{
2024-04-23 19:26:21 +02:00
addSet(newArtSet);
2024-04-16 16:45:31 +02:00
std::visit([this](auto artSetWeak)
2023-04-23 14:10:35 +02:00
{
auto artSet = artSetWeak.lock();
2023-12-17 16:30:19 +02:00
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);
2024-04-23 19:26:21 +02:00
}, newArtSet);
2023-04-23 14:10:35 +02:00
}
2024-04-23 19:26:21 +02:00
void CWindowWithArtifacts::addCloseCallback(const CloseCallback & callback)
2023-07-16 20:16:12 +02:00
{
closeCallback = callback;
}
2023-04-23 14:10:35 +02:00
const CGHeroInstance * CWindowWithArtifacts::getHeroPickedArtifact()
{
auto res = getState();
if(res.has_value())
return std::get<const CGHeroInstance*>(res.value());
else
return nullptr;
}
const CArtifactInstance * CWindowWithArtifacts::getPickedArtifact()
{
auto res = getState();
if(res.has_value())
return std::get<const CArtifactInstance*>(res.value());
else
return nullptr;
}
2024-04-23 19:26:21 +02:00
void CWindowWithArtifacts::clickPressedArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
2023-04-23 14:10:35 +02:00
{
2024-04-23 19:26:21 +02:00
const auto currentArtSet = findAOHbyRef(artsInst);
assert(currentArtSet.has_value());
2023-04-23 14:10:35 +02:00
if(artPlace.isLocked())
return;
if (!LOCPLINT->makingTurn)
return;
2023-04-23 14:10:35 +02:00
std::visit(
2024-01-27 23:48:11 +02:00
[this, &artPlace](auto artSetWeak) -> void
2023-04-23 14:10:35 +02:00
{
const auto artSetPtr = artSetWeak.lock();
2023-07-06 21:14:12 +02:00
// Hero(Main, Exchange) window, Kingdom window, Altar window, Backpack window left click handler
2023-04-23 14:10:35 +02:00
if constexpr(
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroMain>> ||
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>> ||
2023-07-06 21:14:12 +02:00
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroAltar>> ||
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroBackpack>>)
2023-04-23 14:10:35 +02:00
{
const auto pickedArtInst = getPickedArtifact();
const auto heroPickedArt = getHeroPickedArtifact();
const auto hero = artSetPtr->getHero();
2023-07-06 21:14:12 +02:00
auto isTransferAllowed = false;
std::string msg;
2023-04-23 14:10:35 +02:00
if(pickedArtInst)
{
auto srcLoc = ArtifactLocation(heroPickedArt->id, ArtifactPosition::TRANSITION_POS);
auto dstLoc = ArtifactLocation(hero->id, artPlace.slot);
2023-04-23 14:10:35 +02:00
if(ArtifactUtils::isSlotBackpack(artPlace.slot))
{
if(pickedArtInst->artType->isBig())
{
// War machines cannot go to backpack
2023-07-06 21:14:12 +02:00
msg = boost::str(boost::format(CGI->generaltexth->allTexts[153]) % pickedArtInst->artType->getNameTranslated());
2023-04-23 14:10:35 +02:00
}
else
{
if(ArtifactUtils::isBackpackFreeSlots(heroPickedArt))
isTransferAllowed = true;
else
2023-07-06 21:14:12 +02:00
msg = CGI->generaltexth->translate("core.genrltxt.152");
2023-04-23 14:10:35 +02:00
}
}
// Check if artifact transfer is possible
else if(pickedArtInst->canBePutAt(hero, artPlace.slot, true) && (!artPlace.getArt() || hero->tempOwner == LOCPLINT->playerID))
2023-04-23 14:10:35 +02:00
{
isTransferAllowed = true;
}
if constexpr(std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>>)
{
if(hero != heroPickedArt)
isTransferAllowed = false;
}
if(isTransferAllowed)
2024-01-27 23:48:11 +02:00
LOCPLINT->cb->swapArtifacts(srcLoc, dstLoc);
2023-04-23 14:10:35 +02:00
}
2024-01-16 21:54:00 +02:00
else if(auto art = artPlace.getArt())
2023-04-23 14:10:35 +02:00
{
2024-02-01 10:43:16 +02:00
if(artSetPtr->getHero()->getOwner() == LOCPLINT->playerID)
2023-07-06 21:14:12 +02:00
{
2024-01-27 23:48:11 +02:00
if(checkSpecialArts(*art, hero, std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroAltar>> ? true : false))
2024-03-06 15:16:35 +02:00
{
2024-04-16 16:45:31 +02:00
assert(artSetPtr->getHero()->getSlotByInstance(art) != ArtifactPosition::PRE_FIRST);
if(GH.isKeyboardCmdDown())
{
std::shared_ptr<CArtifactsOfHeroMain> anotherHeroEquipmentPointer = nullptr;
for(auto set : artSets)
{
if(std::holds_alternative<std::weak_ptr<CArtifactsOfHeroMain>>(set))
{
std::shared_ptr<CArtifactsOfHeroMain> heroEquipmentPointer = std::get<std::weak_ptr<CArtifactsOfHeroMain>>(set).lock();
if(heroEquipmentPointer->getHero()->id != artSetPtr->getHero()->id)
{
anotherHeroEquipmentPointer = heroEquipmentPointer;
break;
}
}
}
if(anotherHeroEquipmentPointer != nullptr)
{
ArtifactPosition availablePosition = ArtifactUtils::getArtAnyPosition(anotherHeroEquipmentPointer->getHero(), art->getTypeId());
if(availablePosition != ArtifactPosition::PRE_FIRST)
{
LOCPLINT->cb->swapArtifacts(ArtifactLocation(artSetPtr->getHero()->id, artSetPtr->getHero()->getSlotByInstance(art)),
ArtifactLocation(anotherHeroEquipmentPointer->getHero()->id, availablePosition));
}
}
}
else if(GH.isKeyboardAltDown())
{
ArtifactPosition destinationPosition = ArtifactPosition::PRE_FIRST;
if(ArtifactUtils::isSlotEquipment(artPlace.slot))
{
ArtifactPosition availablePosition = ArtifactUtils::getArtBackpackPosition(artSetPtr->getHero(), art->getTypeId());
if(availablePosition != ArtifactPosition::PRE_FIRST)
{
destinationPosition = availablePosition;
}
}
else if(ArtifactUtils::isSlotBackpack(artPlace.slot))
{
ArtifactPosition availablePosition = ArtifactUtils::getArtAnyPosition(artSetPtr->getHero(), art->getTypeId());
if(availablePosition != ArtifactPosition::PRE_FIRST && availablePosition != ArtifactPosition::BACKPACK_START)
{
destinationPosition = availablePosition;
}
}
if(destinationPosition != ArtifactPosition::PRE_FIRST)
{
LOCPLINT->cb->swapArtifacts(ArtifactLocation(artSetPtr->getHero()->id, artPlace.slot),
ArtifactLocation(artSetPtr->getHero()->id, destinationPosition));
}
}
else
{
LOCPLINT->cb->swapArtifacts(ArtifactLocation(artSetPtr->getHero()->id, artPlace.slot),
ArtifactLocation(artSetPtr->getHero()->id, ArtifactPosition::TRANSITION_POS));
}
2024-03-06 15:16:35 +02:00
}
2024-01-16 21:54:00 +02:00
}
else
{
for(const auto artSlot : ArtifactUtils::unmovableSlots())
if(artPlace.slot == artSlot)
{
msg = CGI->generaltexth->allTexts[21];
break;
}
2023-04-23 14:10:35 +02:00
}
}
2023-07-06 21:14:12 +02:00
if constexpr(std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroBackpack>>)
{
2024-04-23 19:26:21 +02:00
if(!isTransferAllowed && artPlace.getArt() && closeCallback)
closeCallback();
2023-07-06 21:14:12 +02:00
}
else
{
if(!msg.empty())
LOCPLINT->showInfoDialog(msg);
}
2023-04-23 14:10:35 +02:00
}
// Market window left click handler
else if constexpr(std::is_same_v<decltype(artSetWeak), std::weak_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]);
}
}
}
2023-11-07 14:17:34 +02:00
else if constexpr(std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroQuickBackpack>>)
{
const auto hero = artSetPtr->getHero();
2024-01-27 23:48:11 +02:00
LOCPLINT->cb->swapArtifacts(ArtifactLocation(hero->id, artPlace.slot), ArtifactLocation(hero->id, artSetPtr->getFilterSlot()));
2023-11-07 14:17:34 +02:00
if(closeCallback)
closeCallback();
}
2024-04-23 19:26:21 +02:00
}, currentArtSet.value());
2023-04-23 14:10:35 +02:00
}
2024-04-23 19:26:21 +02:00
void CWindowWithArtifacts::showPopupArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
2023-04-23 14:10:35 +02:00
{
2024-04-23 19:26:21 +02:00
const auto currentArtSet = findAOHbyRef(artsInst);
assert(currentArtSet.has_value());
2023-04-23 14:10:35 +02:00
if(artPlace.isLocked())
return;
std::visit(
[&artPlace, &cursorPosition](auto artSetWeak) -> void
2023-04-23 14:10:35 +02:00
{
const auto artSetPtr = artSetWeak.lock();
2023-07-06 21:14:12 +02:00
// Hero (Main, Exchange) window, Kingdom window, Backpack window right click handler
2023-04-23 14:10:35 +02:00
if constexpr(
2024-01-16 21:54:00 +02:00
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroAltar>> ||
2023-04-23 14:10:35 +02:00
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroMain>> ||
2023-07-06 21:14:12 +02:00
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>> ||
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroBackpack>>)
2023-04-23 14:10:35 +02:00
{
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);
2023-04-23 14:10:35 +02:00
}
}
// Altar window, Market window right click handler
else if constexpr(
2023-11-07 14:17:34 +02:00
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroMarket>> ||
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroQuickBackpack>>)
2023-04-23 14:10:35 +02:00
{
if(artPlace.getArt() && artPlace.text.size())
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
2023-04-23 14:10:35 +02:00
}
2024-04-23 19:26:21 +02:00
}, currentArtSet.value());
2023-04-23 14:10:35 +02:00
}
2024-04-23 19:26:21 +02:00
void CWindowWithArtifacts::gestureArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
2023-12-17 16:30:19 +02:00
{
2024-04-23 19:26:21 +02:00
const auto currentArtSet = findAOHbyRef(artsInst);
assert(currentArtSet.has_value());
2023-12-17 16:30:19 +02:00
if(artPlace.isLocked())
return;
std::visit(
[&artPlace, cursorPosition](auto artSetWeak) -> void
{
const auto artSetPtr = artSetWeak.lock();
if constexpr(
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroMain>> ||
std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>>)
{
2024-01-18 13:42:52 +02:00
if(!settings["general"]["enableUiEnhancements"].Bool())
return;
2023-12-17 16:30:19 +02:00
GH.windows().createAndPushWindow<CHeroQuickBackpackWindow>(artSetPtr->getHero(), artPlace.slot);
auto backpackWindow = GH.windows().topWindow<CHeroQuickBackpackWindow>();
backpackWindow->moveTo(cursorPosition - Point(1, 1));
backpackWindow->fitToScreen(15);
}
2024-04-23 19:26:21 +02:00
}, currentArtSet.value());
2023-12-17 16:30:19 +02:00
}
2024-04-23 15:21:45 +02:00
void CWindowWithArtifacts::activate()
{
if(const auto art = getPickedArtifact())
setCursorAnimation(*art);
CWindowObject::activate();
}
void CWindowWithArtifacts::deactivate()
{
CCS->curh->dragAndDropCursor(nullptr);
CWindowObject::deactivate();
}
void CWindowWithArtifacts::enableArtifactsCostumeSwitcher() const
2024-04-19 16:14:41 +02:00
{
for(auto artSet : artSets)
std::visit(
[](auto artSetWeak)
{
if constexpr(std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroMain>>)
{
const auto artSetPtr = artSetWeak.lock();
artSetPtr->enableArtifactsCostumeSwitcher();
}
}, artSet);
}
2023-04-23 14:10:35 +02:00
void CWindowWithArtifacts::artifactRemoved(const ArtifactLocation & artLoc)
{
2024-04-23 19:26:21 +02:00
update();
2023-04-23 14:10:35 +02:00
}
void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc, bool withRedraw)
{
auto curState = getState();
if(!curState.has_value())
// Transition state. Nothing to do here. Just skip. Need to wait for final state.
return;
auto pickedArtInst = std::get<const CArtifactInstance*>(curState.value());
2023-09-03 20:41:00 +02:00
auto artifactMovedBody = [this, withRedraw, &destLoc, &pickedArtInst](auto artSetWeak) -> void
2023-04-23 14:10:35 +02:00
{
auto artSetPtr = artSetWeak.lock();
if(artSetPtr)
{
const auto hero = artSetPtr->getHero();
2023-07-06 21:14:12 +02:00
if(pickedArtInst)
2023-04-23 14:10:35 +02:00
{
2024-04-16 16:45:31 +02:00
setCursorAnimation(*pickedArtInst);
2023-07-06 21:14:12 +02:00
}
else
{
artSetPtr->unmarkSlots();
CCS->curh->dragAndDropCursor(nullptr);
2023-04-23 14:10:35 +02:00
}
if(withRedraw)
{
artSetPtr->updateWornSlots();
artSetPtr->updateBackpackSlots();
// Update arts bonuses on window.
// TODO rework this part when CHeroWindow and CExchangeWindow are reworked
if(auto * chw = dynamic_cast<CHeroWindow*>(this))
{
chw->update(hero, true);
}
else if(auto * cew = dynamic_cast<CExchangeWindow*>(this))
{
cew->updateWidgets();
}
2023-09-03 20:41:00 +02:00
artSetPtr->redraw();
2023-04-23 14:10:35 +02:00
}
// Make sure the status bar is updated so it does not display old text
if(destLoc.artHolder == hero->id)
2023-04-23 14:10:35 +02:00
{
if(auto artPlace = artSetPtr->getArtPlace(destLoc.slot))
artPlace->hover(true);
}
}
};
for(auto artSetWeak : artSets)
std::visit(artifactMovedBody, artSetWeak);
}
void CWindowWithArtifacts::artifactDisassembled(const ArtifactLocation & artLoc)
{
2024-04-23 19:26:21 +02:00
update();
2023-04-23 14:10:35 +02:00
}
void CWindowWithArtifacts::artifactAssembled(const ArtifactLocation & artLoc)
{
2023-09-03 20:41:00 +02:00
markPossibleSlots();
2024-04-23 19:26:21 +02:00
update();
2023-04-23 14:10:35 +02:00
}
2024-04-23 19:26:21 +02:00
void CWindowWithArtifacts::update() const
2023-04-23 14:10:35 +02:00
{
2023-09-12 17:30:48 +02:00
auto updateSlotBody = [](auto artSetWeak) -> void
2023-04-23 14:10:35 +02:00
{
if(const auto artSetPtr = artSetWeak.lock())
{
2023-09-12 17:30:48 +02:00
artSetPtr->updateWornSlots();
artSetPtr->updateBackpackSlots();
2023-09-03 20:41:00 +02:00
artSetPtr->redraw();
2023-04-23 14:10:35 +02:00
}
};
for(auto artSetWeak : artSets)
std::visit(updateSlotBody, artSetWeak);
}
std::optional<std::tuple<const CGHeroInstance*, const CArtifactInstance*>> CWindowWithArtifacts::getState()
{
const CArtifactInstance * artInst = nullptr;
2023-07-06 21:14:12 +02:00
std::map<const CGHeroInstance*, size_t> pickedCnt;
2023-04-23 14:10:35 +02:00
2023-07-06 21:14:12 +02:00
auto getHeroArtBody = [&artInst, &pickedCnt](auto artSetWeak) -> void
2023-04-23 14:10:35 +02:00
{
auto artSetPtr = artSetWeak.lock();
if(artSetPtr)
{
if(const auto art = artSetPtr->getPickedArtifact())
{
2023-07-06 21:14:12 +02:00
const auto hero = artSetPtr->getHero();
if(pickedCnt.count(hero) == 0)
{
pickedCnt.insert({ hero, hero->artifactsTransitionPos.size() });
artInst = art;
}
2023-04-23 14:10:35 +02:00
}
}
};
for(auto artSetWeak : artSets)
std::visit(getHeroArtBody, artSetWeak);
// 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.
// This is a transitional state. Then return nullopt.
2023-07-06 21:14:12 +02:00
if(std::accumulate(std::begin(pickedCnt), std::end(pickedCnt), 0, [](size_t accum, const auto & value)
{
return accum + value.second;
}) > 1)
2023-04-23 14:10:35 +02:00
return std::nullopt;
else
2023-07-06 21:14:12 +02:00
return std::make_tuple(pickedCnt.begin()->first, artInst);
2023-04-23 14:10:35 +02:00
}
2024-04-23 19:26:21 +02:00
std::optional<CWindowWithArtifacts::CArtifactsOfHeroPtr> CWindowWithArtifacts::findAOHbyRef(const CArtifactsOfHeroBase & artsInst)
2023-04-23 14:10:35 +02:00
{
std::optional<CArtifactsOfHeroPtr> res;
auto findAOHBody = [&res, &artsInst](auto & artSetWeak) -> void
{
if(&artsInst == artSetWeak.lock().get())
res = artSetWeak;
};
for(auto artSetWeak : artSets)
{
std::visit(findAOHBody, artSetWeak);
if(res.has_value())
return res;
}
return res;
}
2023-09-03 20:41:00 +02:00
void CWindowWithArtifacts::markPossibleSlots()
{
if(const auto pickedArtInst = getPickedArtifact())
{
const auto heroArtOwner = getHeroPickedArtifact();
auto artifactAssembledBody = [&pickedArtInst, &heroArtOwner](auto artSetWeak) -> void
{
if(auto artSetPtr = artSetWeak.lock())
{
if(artSetPtr->isActive())
{
const auto hero = artSetPtr->getHero();
if(heroArtOwner == hero || !std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>>)
artSetPtr->markPossibleSlots(pickedArtInst, hero->tempOwner == LOCPLINT->playerID);
}
}
};
for(auto artSetWeak : artSets)
std::visit(artifactAssembledBody, artSetWeak);
}
}
2024-01-27 23:48:11 +02:00
2024-04-23 19:26:21 +02:00
bool CWindowWithArtifacts::checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance * hero, bool isTrade) const
2024-01-27 23:48:11 +02:00
{
const auto artId = artInst.getTypeId();
if(artId == ArtifactID::SPELLBOOK)
{
GH.windows().createAndPushWindow<CSpellWindow>(hero, LOCPLINT, LOCPLINT->battleInt.get());
return false;
}
if(artId == ArtifactID::CATAPULT)
{
// The Catapult must be equipped
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[312],
std::vector<std::shared_ptr<CComponent>>(1, std::make_shared<CComponent>(ComponentType::ARTIFACT, ArtifactID(ArtifactID::CATAPULT))));
return false;
}
2024-04-23 19:26:21 +02:00
if(isTrade && !artInst.artType->isTradable())
2024-01-27 23:48:11 +02:00
{
2024-04-23 19:26:21 +02:00
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[21],
std::vector<std::shared_ptr<CComponent>>(1, std::make_shared<CComponent>(ComponentType::ARTIFACT, artId)));
return false;
2024-01-27 23:48:11 +02:00
}
return true;
}
2024-04-16 16:45:31 +02:00
void CWindowWithArtifacts::setCursorAnimation(const CArtifactInstance & artInst)
{
markPossibleSlots();
if(artInst.isScroll() && settings["general"]["enableUiEnhancements"].Bool())
{
assert(artInst.getScrollSpellID().num >= 0);
const auto animation = GH.renderHandler().loadAnimation(AnimationPath::builtin("spellscr"));
animation->load(artInst.getScrollSpellID().num);
CCS->curh->dragAndDropCursor(animation->getImage(artInst.getScrollSpellID().num)->scaleFast(Point(44, 34)));
}
else
{
CCS->curh->dragAndDropCursor(AnimationPath::builtin("artifact"), artInst.artType->getIconIndex());
}
}