mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
fixed highlighting slots
This commit is contained in:
parent
bef97889e9
commit
3675d88730
@ -58,7 +58,7 @@ void CArtifactsOfHeroAltar::updateBackpackSlots()
|
||||
void CArtifactsOfHeroAltar::scrollBackpack(int offset)
|
||||
{
|
||||
CArtifactsOfHeroBase::scrollBackpackForArtSet(offset, visibleArtSet);
|
||||
safeRedraw();
|
||||
redraw();
|
||||
}
|
||||
|
||||
void CArtifactsOfHeroAltar::pickUpArtifact(CHeroArtPlace & artPlace)
|
||||
|
@ -90,6 +90,8 @@ void CArtifactsOfHeroBase::init(
|
||||
rightBackpackRoll = std::make_shared<CButton>(Point(632, 364), AnimationPath::builtin("hsbtns5.def"), CButton::tooltip(), [scrollHandler]() { scrollHandler(+1); }, EShortcut::MOVE_RIGHT);
|
||||
leftBackpackRoll->block(true);
|
||||
rightBackpackRoll->block(true);
|
||||
|
||||
setRedrawParent(true);
|
||||
}
|
||||
|
||||
void CArtifactsOfHeroBase::leftClickArtPlace(CHeroArtPlace & artPlace)
|
||||
@ -127,7 +129,7 @@ const CGHeroInstance * CArtifactsOfHeroBase::getHero() const
|
||||
void CArtifactsOfHeroBase::scrollBackpack(int offset)
|
||||
{
|
||||
scrollBackpackForArtSet(offset, *curHero);
|
||||
safeRedraw();
|
||||
redraw();
|
||||
}
|
||||
|
||||
void CArtifactsOfHeroBase::scrollBackpackForArtSet(int offset, const CArtifactSet & artSet)
|
||||
@ -172,17 +174,6 @@ void CArtifactsOfHeroBase::scrollBackpackForArtSet(int offset, const CArtifactSe
|
||||
rightBackpackRoll->block(!scrollingPossible);
|
||||
}
|
||||
|
||||
void CArtifactsOfHeroBase::safeRedraw()
|
||||
{
|
||||
if(isActive())
|
||||
{
|
||||
if(parent)
|
||||
parent->redraw();
|
||||
else
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
void CArtifactsOfHeroBase::markPossibleSlots(const CArtifactInstance * art, bool assumeDestRemoved)
|
||||
{
|
||||
for(auto artPlace : artWorn)
|
||||
|
@ -33,7 +33,6 @@ public:
|
||||
virtual void setHero(const CGHeroInstance * hero);
|
||||
virtual const CGHeroInstance * getHero() const;
|
||||
virtual void scrollBackpack(int offset);
|
||||
virtual void safeRedraw();
|
||||
virtual void markPossibleSlots(const CArtifactInstance * art, bool assumeDestRemoved = true);
|
||||
virtual void unmarkSlots();
|
||||
virtual ArtPlacePtr getArtPlace(const ArtifactPosition & slot);
|
||||
|
@ -39,6 +39,8 @@ CArtifactsOfHeroKingdom::CArtifactsOfHeroKingdom(ArtPlaceMap ArtWorn, std::vecto
|
||||
}
|
||||
leftBackpackRoll->addCallback(std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, -1));
|
||||
rightBackpackRoll->addCallback(std::bind(&CArtifactsOfHeroBase::scrollBackpack, this, +1));
|
||||
|
||||
setRedrawParent(true);
|
||||
}
|
||||
|
||||
CArtifactsOfHeroKingdom::~CArtifactsOfHeroKingdom()
|
||||
|
@ -37,5 +37,5 @@ void CArtifactsOfHeroMarket::scrollBackpack(int offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
safeRedraw();
|
||||
redraw();
|
||||
}
|
@ -261,7 +261,7 @@ void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const
|
||||
auto pickedArtInst = std::get<const CArtifactInstance*>(curState.value());
|
||||
assert(!pickedArtInst || destLoc.isHolder(std::get<const CGHeroInstance*>(curState.value())));
|
||||
|
||||
auto artifactMovedBody = [this, withRedraw, &srcLoc, &destLoc, &pickedArtInst](auto artSetWeak) -> void
|
||||
auto artifactMovedBody = [this, withRedraw, &destLoc, &pickedArtInst](auto artSetWeak) -> void
|
||||
{
|
||||
auto artSetPtr = artSetWeak.lock();
|
||||
if(artSetPtr)
|
||||
@ -269,12 +269,8 @@ void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const
|
||||
const auto hero = artSetPtr->getHero();
|
||||
if(pickedArtInst)
|
||||
{
|
||||
if(artSetPtr->isActive())
|
||||
{
|
||||
CCS->curh->dragAndDropCursor(AnimationPath::builtin("artifact"), pickedArtInst->artType->getIconIndex());
|
||||
if(srcLoc.isHolder(hero) || !std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroKingdom>>)
|
||||
artSetPtr->markPossibleSlots(pickedArtInst, hero->tempOwner == LOCPLINT->playerID);
|
||||
}
|
||||
markPossibleSlots();
|
||||
CCS->curh->dragAndDropCursor(AnimationPath::builtin("artifact"), pickedArtInst->artType->getIconIndex());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -296,7 +292,7 @@ void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const
|
||||
{
|
||||
cew->updateWidgets();
|
||||
}
|
||||
artSetPtr->safeRedraw();
|
||||
artSetPtr->redraw();
|
||||
}
|
||||
|
||||
// Make sure the status bar is updated so it does not display old text
|
||||
@ -319,6 +315,7 @@ void CWindowWithArtifacts::artifactDisassembled(const ArtifactLocation & artLoc)
|
||||
|
||||
void CWindowWithArtifacts::artifactAssembled(const ArtifactLocation & artLoc)
|
||||
{
|
||||
markPossibleSlots();
|
||||
updateSlots(artLoc.slot);
|
||||
}
|
||||
|
||||
@ -333,7 +330,7 @@ void CWindowWithArtifacts::updateSlots(const ArtifactPosition & slot)
|
||||
else if(ArtifactUtils::isSlotBackpack(slot))
|
||||
artSetPtr->updateBackpackSlots();
|
||||
|
||||
artSetPtr->safeRedraw();
|
||||
artSetPtr->redraw();
|
||||
}
|
||||
};
|
||||
|
||||
@ -395,3 +392,26 @@ std::optional<CWindowWithArtifacts::CArtifactsOfHeroPtr> CWindowWithArtifacts::f
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,5 @@ private:
|
||||
void updateSlots(const ArtifactPosition & slot);
|
||||
std::optional<std::tuple<const CGHeroInstance*, const CArtifactInstance*>> getState();
|
||||
std::optional<CArtifactsOfHeroPtr> findAOHbyRef(CArtifactsOfHeroBase & artsInst);
|
||||
void markPossibleSlots();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user