mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Sonarcloud warnings
This commit is contained in:
parent
20471c9c2f
commit
c9a8f8e855
@ -92,7 +92,7 @@ CArtPlace::CArtPlace(Point position, const CArtifactInstance * art)
|
||||
image->disable();
|
||||
}
|
||||
|
||||
const CArtifactInstance * CArtPlace::getArt()
|
||||
const CArtifactInstance * CArtPlace::getArt() const
|
||||
{
|
||||
return ourArt;
|
||||
}
|
||||
@ -108,7 +108,7 @@ CCommanderArtPlace::CCommanderArtPlace(Point position, const CGHeroInstance * co
|
||||
void CCommanderArtPlace::returnArtToHeroCallback()
|
||||
{
|
||||
ArtifactPosition artifactPos = commanderSlotID;
|
||||
ArtifactPosition freeSlot = ArtifactUtils::getArtBackpackPosition(commanderOwner, ourArt->getTypeId());
|
||||
ArtifactPosition freeSlot = ArtifactUtils::getArtBackpackPosition(commanderOwner, getArt()->getTypeId());
|
||||
if(freeSlot == ArtifactPosition::PRE_FIRST)
|
||||
{
|
||||
LOCPLINT->showInfoDialog(CGI->generaltexth->translate("core.genrltxt.152"));
|
||||
@ -119,7 +119,7 @@ void CCommanderArtPlace::returnArtToHeroCallback()
|
||||
src.creature = SlotID::COMMANDER_SLOT_PLACEHOLDER;
|
||||
ArtifactLocation dst(commanderOwner->id, freeSlot);
|
||||
|
||||
if(ourArt->canBePutAt(commanderOwner, freeSlot, true))
|
||||
if(getArt()->canBePutAt(commanderOwner, freeSlot, true))
|
||||
{
|
||||
LOCPLINT->cb->swapArtifacts(src, dst);
|
||||
setArtifact(nullptr);
|
||||
@ -130,13 +130,13 @@ void CCommanderArtPlace::returnArtToHeroCallback()
|
||||
|
||||
void CCommanderArtPlace::clickPressed(const Point & cursorPosition)
|
||||
{
|
||||
if(ourArt && text.size())
|
||||
if(getArt() && text.size())
|
||||
LOCPLINT->showYesNoDialog(CGI->generaltexth->translate("vcmi.commanderWindow.artifactMessage"), [this]() { returnArtToHeroCallback(); }, []() {});
|
||||
}
|
||||
|
||||
void CCommanderArtPlace::showPopupWindow(const Point& cursorPosition)
|
||||
void CCommanderArtPlace::showPopupWindow(const Point & cursorPosition)
|
||||
{
|
||||
if(ourArt && text.size())
|
||||
if(getArt() && text.size())
|
||||
CArtPlace::showPopupWindow(cursorPosition);
|
||||
}
|
||||
|
||||
@ -204,22 +204,22 @@ void CArtPlace::setArtifact(const CArtifactInstance * art)
|
||||
}
|
||||
}
|
||||
|
||||
void CArtPlace::setClickPressedCallback(ClickFunctor callback)
|
||||
void CArtPlace::setClickPressedCallback(const ClickFunctor & callback)
|
||||
{
|
||||
clickPressedCallback = callback;
|
||||
}
|
||||
|
||||
void CArtPlace::setShowPopupCallback(ClickFunctor callback)
|
||||
void CArtPlace::setShowPopupCallback(const ClickFunctor & callback)
|
||||
{
|
||||
showPopupCallback = callback;
|
||||
}
|
||||
|
||||
void CArtPlace::setGestureCallback(ClickFunctor callback)
|
||||
void CArtPlace::setGestureCallback(const ClickFunctor & callback)
|
||||
{
|
||||
gestureCallback = callback;
|
||||
}
|
||||
|
||||
void CHeroArtPlace::addCombinedArtInfo(std::map<const CArtifact*, int> & arts)
|
||||
void CHeroArtPlace::addCombinedArtInfo(const std::map<const CArtifact*, int> & arts)
|
||||
{
|
||||
for(const auto & combinedArt : arts)
|
||||
{
|
||||
|
@ -19,34 +19,35 @@ public:
|
||||
using ClickFunctor = std::function<void(CArtPlace&, const Point&)>;
|
||||
|
||||
ArtifactPosition slot;
|
||||
|
||||
|
||||
CArtPlace(Point position, const CArtifactInstance * art = nullptr);
|
||||
const CArtifactInstance * getArt();
|
||||
const CArtifactInstance * getArt() const;
|
||||
void lockSlot(bool on);
|
||||
bool isLocked() const;
|
||||
void setArtifact(const CArtifactInstance * art);
|
||||
void setClickPressedCallback(ClickFunctor callback);
|
||||
void setShowPopupCallback(ClickFunctor callback);
|
||||
void setGestureCallback(ClickFunctor callback);
|
||||
void setClickPressedCallback(const ClickFunctor & callback);
|
||||
void setShowPopupCallback(const ClickFunctor & callback);
|
||||
void setGestureCallback(const ClickFunctor & callback);
|
||||
void clickPressed(const Point & cursorPosition) override;
|
||||
void showPopupWindow(const Point & cursorPosition) override;
|
||||
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<CAnimImage> image;
|
||||
private:
|
||||
const CArtifactInstance * ourArt;
|
||||
int imageIndex;
|
||||
bool locked;
|
||||
int imageIndex;
|
||||
std::shared_ptr<CAnimImage> image;
|
||||
ClickFunctor clickPressedCallback;
|
||||
ClickFunctor showPopupCallback;
|
||||
ClickFunctor gestureCallback;
|
||||
|
||||
protected:
|
||||
void setInternals(const CArtifactInstance * artInst);
|
||||
};
|
||||
|
||||
class CCommanderArtPlace : public CArtPlace
|
||||
{
|
||||
protected:
|
||||
private:
|
||||
const CGHeroInstance * commanderOwner;
|
||||
ArtifactPosition commanderSlotID;
|
||||
|
||||
@ -62,7 +63,7 @@ class CHeroArtPlace: public CArtPlace
|
||||
{
|
||||
public:
|
||||
CHeroArtPlace(Point position, const CArtifactInstance * art = nullptr);
|
||||
void addCombinedArtInfo(std::map<const CArtifact*, int> & arts);
|
||||
void addCombinedArtInfo(const std::map<const CArtifact*, int> & arts);
|
||||
};
|
||||
|
||||
namespace ArtifactUtilsClient
|
||||
|
@ -41,24 +41,24 @@ CWindowWithArtifacts::CWindowWithArtifacts(const std::vector<CArtifactsOfHeroPtr
|
||||
this->artSets.insert(this->artSets.end(), artSets->begin(), artSets->end());
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet)
|
||||
void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr newArtSet)
|
||||
{
|
||||
artSets.emplace_back(artSet);
|
||||
artSets.emplace_back(newArtSet);
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::addSetAndCallbacks(CArtifactsOfHeroPtr artSet)
|
||||
void CWindowWithArtifacts::addSetAndCallbacks(CArtifactsOfHeroPtr newArtSet)
|
||||
{
|
||||
addSet(artSet);
|
||||
addSet(newArtSet);
|
||||
std::visit([this](auto artSetWeak)
|
||||
{
|
||||
auto artSet = artSetWeak.lock();
|
||||
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);
|
||||
}, artSet);
|
||||
}, newArtSet);
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::addCloseCallback(CloseCallback callback)
|
||||
void CWindowWithArtifacts::addCloseCallback(const CloseCallback & callback)
|
||||
{
|
||||
closeCallback = callback;
|
||||
}
|
||||
@ -81,10 +81,10 @@ const CArtifactInstance * CWindowWithArtifacts::getPickedArtifact()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::clickPressedArtPlaceHero(CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
|
||||
void CWindowWithArtifacts::clickPressedArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
const auto artSet = findAOHbyRef(artsInst);
|
||||
assert(artSet.has_value());
|
||||
const auto currentArtSet = findAOHbyRef(artsInst);
|
||||
assert(currentArtSet.has_value());
|
||||
|
||||
if(artPlace.isLocked())
|
||||
return;
|
||||
@ -222,11 +222,8 @@ void CWindowWithArtifacts::clickPressedArtPlaceHero(CArtifactsOfHeroBase & artsI
|
||||
|
||||
if constexpr(std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroBackpack>>)
|
||||
{
|
||||
if(!isTransferAllowed && artPlace.getArt())
|
||||
{
|
||||
if(closeCallback)
|
||||
closeCallback();
|
||||
}
|
||||
if(!isTransferAllowed && artPlace.getArt() && closeCallback)
|
||||
closeCallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -259,13 +256,13 @@ void CWindowWithArtifacts::clickPressedArtPlaceHero(CArtifactsOfHeroBase & artsI
|
||||
if(closeCallback)
|
||||
closeCallback();
|
||||
}
|
||||
}, artSet.value());
|
||||
}, currentArtSet.value());
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::showPopupArtPlaceHero(CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
|
||||
void CWindowWithArtifacts::showPopupArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
const auto artSetWeak = findAOHbyRef(artsInst);
|
||||
assert(artSetWeak.has_value());
|
||||
const auto currentArtSet = findAOHbyRef(artsInst);
|
||||
assert(currentArtSet.has_value());
|
||||
|
||||
if(artPlace.isLocked())
|
||||
return;
|
||||
@ -304,13 +301,13 @@ void CWindowWithArtifacts::showPopupArtPlaceHero(CArtifactsOfHeroBase & artsInst
|
||||
if(artPlace.getArt() && artPlace.text.size())
|
||||
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
|
||||
}
|
||||
}, artSetWeak.value());
|
||||
}, currentArtSet.value());
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::gestureArtPlaceHero(CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
|
||||
void CWindowWithArtifacts::gestureArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition)
|
||||
{
|
||||
const auto artSetWeak = findAOHbyRef(artsInst);
|
||||
assert(artSetWeak.has_value());
|
||||
const auto currentArtSet = findAOHbyRef(artsInst);
|
||||
assert(currentArtSet.has_value());
|
||||
if(artPlace.isLocked())
|
||||
return;
|
||||
|
||||
@ -330,7 +327,7 @@ void CWindowWithArtifacts::gestureArtPlaceHero(CArtifactsOfHeroBase & artsInst,
|
||||
backpackWindow->moveTo(cursorPosition - Point(1, 1));
|
||||
backpackWindow->fitToScreen(15);
|
||||
}
|
||||
}, artSetWeak.value());
|
||||
}, currentArtSet.value());
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::activate()
|
||||
@ -348,7 +345,7 @@ void CWindowWithArtifacts::deactivate()
|
||||
|
||||
void CWindowWithArtifacts::artifactRemoved(const ArtifactLocation & artLoc)
|
||||
{
|
||||
updateSlots();
|
||||
update();
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc, bool withRedraw)
|
||||
@ -407,16 +404,16 @@ void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const
|
||||
|
||||
void CWindowWithArtifacts::artifactDisassembled(const ArtifactLocation & artLoc)
|
||||
{
|
||||
updateSlots();
|
||||
update();
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::artifactAssembled(const ArtifactLocation & artLoc)
|
||||
{
|
||||
markPossibleSlots();
|
||||
updateSlots();
|
||||
update();
|
||||
}
|
||||
|
||||
void CWindowWithArtifacts::updateSlots()
|
||||
void CWindowWithArtifacts::update() const
|
||||
{
|
||||
auto updateSlotBody = [](auto artSetWeak) -> void
|
||||
{
|
||||
@ -468,7 +465,7 @@ std::optional<std::tuple<const CGHeroInstance*, const CArtifactInstance*>> CWind
|
||||
return std::make_tuple(pickedCnt.begin()->first, artInst);
|
||||
}
|
||||
|
||||
std::optional<CWindowWithArtifacts::CArtifactsOfHeroPtr> CWindowWithArtifacts::findAOHbyRef(CArtifactsOfHeroBase & artsInst)
|
||||
std::optional<CWindowWithArtifacts::CArtifactsOfHeroPtr> CWindowWithArtifacts::findAOHbyRef(const CArtifactsOfHeroBase & artsInst)
|
||||
{
|
||||
std::optional<CArtifactsOfHeroPtr> res;
|
||||
|
||||
@ -510,7 +507,7 @@ void CWindowWithArtifacts::markPossibleSlots()
|
||||
}
|
||||
}
|
||||
|
||||
bool CWindowWithArtifacts::checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance * hero, bool isTrade)
|
||||
bool CWindowWithArtifacts::checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance * hero, bool isTrade) const
|
||||
{
|
||||
const auto artId = artInst.getTypeId();
|
||||
|
||||
@ -526,14 +523,11 @@ bool CWindowWithArtifacts::checkSpecialArts(const CArtifactInstance & artInst, c
|
||||
std::vector<std::shared_ptr<CComponent>>(1, std::make_shared<CComponent>(ComponentType::ARTIFACT, ArtifactID(ArtifactID::CATAPULT))));
|
||||
return false;
|
||||
}
|
||||
if(isTrade)
|
||||
if(isTrade && !artInst.artType->isTradable())
|
||||
{
|
||||
if(!artInst.artType->isTradable())
|
||||
{
|
||||
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[21],
|
||||
std::vector<std::shared_ptr<CComponent>>(1, std::make_shared<CComponent>(ComponentType::ARTIFACT, artId)));
|
||||
return false;
|
||||
}
|
||||
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[21],
|
||||
std::vector<std::shared_ptr<CComponent>>(1, std::make_shared<CComponent>(ComponentType::ARTIFACT, artId)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -28,15 +28,18 @@ public:
|
||||
std::weak_ptr<CArtifactsOfHeroQuickBackpack>>;
|
||||
using CloseCallback = std::function<void()>;
|
||||
|
||||
std::vector<CArtifactsOfHeroPtr> artSets;
|
||||
CloseCallback closeCallback;
|
||||
|
||||
explicit CWindowWithArtifacts(const std::vector<CArtifactsOfHeroPtr> * artSets = nullptr);
|
||||
void addSet(CArtifactsOfHeroPtr artSet);
|
||||
void addSetAndCallbacks(CArtifactsOfHeroPtr artSet);
|
||||
void addCloseCallback(CloseCallback callback);
|
||||
void addSet(CArtifactsOfHeroPtr newArtSet);
|
||||
void addSetAndCallbacks(CArtifactsOfHeroPtr newArtSet);
|
||||
void addCloseCallback(const CloseCallback & callback);
|
||||
const CGHeroInstance * getHeroPickedArtifact();
|
||||
const CArtifactInstance * getPickedArtifact();
|
||||
void clickPressedArtPlaceHero(CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
||||
void showPopupArtPlaceHero(CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
||||
void gestureArtPlaceHero(CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
||||
void clickPressedArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
||||
void showPopupArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
||||
void gestureArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
||||
void activate() override;
|
||||
void deactivate() override;
|
||||
|
||||
@ -46,13 +49,10 @@ public:
|
||||
virtual void artifactAssembled(const ArtifactLocation & artLoc);
|
||||
|
||||
protected:
|
||||
std::vector<CArtifactsOfHeroPtr> artSets;
|
||||
CloseCallback closeCallback;
|
||||
|
||||
void updateSlots();
|
||||
void update() const;
|
||||
std::optional<std::tuple<const CGHeroInstance*, const CArtifactInstance*>> getState();
|
||||
std::optional<CArtifactsOfHeroPtr> findAOHbyRef(CArtifactsOfHeroBase & artsInst);
|
||||
std::optional<CArtifactsOfHeroPtr> findAOHbyRef(const CArtifactsOfHeroBase & artsInst);
|
||||
void markPossibleSlots();
|
||||
bool checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance * hero, bool isTrade);
|
||||
bool checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance * hero, bool isTrade) const;
|
||||
void setCursorAnimation(const CArtifactInstance & artInst);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user