mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
CArtifactsOfHero::artifactMoved updated
This commit is contained in:
parent
6b7ce798d0
commit
c706b4d419
@ -716,31 +716,40 @@ void CArtifactsOfHero::realizeCurrentTransaction()
|
|||||||
ArtifactLocation(commonInfo->dst.AOH->curHero, commonInfo->dst.slotID));
|
ArtifactLocation(commonInfo->dst.AOH->curHero, commonInfo->dst.slotID));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactsOfHero::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst)
|
void CArtifactsOfHero::artifactMoved(const ArtifactLocation & src, const ArtifactLocation & dst)
|
||||||
{
|
{
|
||||||
bool isCurHeroSrc = src.isHolder(curHero),
|
bool isCurHeroSrc = src.isHolder(curHero),
|
||||||
isCurHeroDst = dst.isHolder(curHero);
|
isCurHeroDst = dst.isHolder(curHero);
|
||||||
if(isCurHeroSrc && src.slot >= GameConstants::BACKPACK_START)
|
if(isCurHeroSrc && ArtifactUtils::isSlotBackpack(src.slot))
|
||||||
updateSlot(src.slot);
|
updateSlot(src.slot);
|
||||||
if(isCurHeroDst && dst.slot >= GameConstants::BACKPACK_START)
|
if(isCurHeroDst && ArtifactUtils::isSlotBackpack(dst.slot))
|
||||||
updateSlot(dst.slot);
|
updateSlot(dst.slot);
|
||||||
if(isCurHeroSrc || isCurHeroDst) //we need to update all slots, artifact might be combined and affect more slots
|
// We need to update all slots, artifact might be combined and affect more slots
|
||||||
|
if(isCurHeroSrc || isCurHeroDst)
|
||||||
updateWornSlots(false);
|
updateWornSlots(false);
|
||||||
|
|
||||||
if (!src.isHolder(curHero) && !isCurHeroDst)
|
if(!src.isHolder(curHero) && !isCurHeroDst)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(commonInfo->src == src) //artifact was taken from us
|
// When moving one artifact onto another it leads to two art movements: dst->TRANSITION_POS; src->dst
|
||||||
|
// however after first movement we pick the art from TRANSITION_POS and the second movement coming when
|
||||||
|
// we have a different artifact may look surprising... but it's valid.
|
||||||
|
|
||||||
|
// Artifact was taken from us
|
||||||
|
if(commonInfo->src == src)
|
||||||
{
|
{
|
||||||
assert(commonInfo->dst == dst //expected movement from slot ot slot
|
// Expected movement from slot ot slot
|
||||||
|| dst.slot == dst.getHolderArtSet()->artifactsInBackpack.size() + GameConstants::BACKPACK_START //artifact moved back to backpack (eg. to make place for art we are moving)
|
assert(commonInfo->dst == dst
|
||||||
|
// Artifact moved back to backpack (eg. to make place for art we are moving)
|
||||||
|
|| dst.slot == dst.getHolderArtSet()->artifactsInBackpack.size() + GameConstants::BACKPACK_START
|
||||||
|| dst.getHolderArtSet()->bearerType() != ArtBearer::HERO);
|
|| dst.getHolderArtSet()->bearerType() != ArtBearer::HERO);
|
||||||
commonInfo->reset();
|
commonInfo->reset();
|
||||||
unmarkSlots();
|
unmarkSlots();
|
||||||
}
|
}
|
||||||
else if(commonInfo->dst == src) //the dest artifact was moved -> we are picking it
|
// The dest artifact was moved -> we are picking it
|
||||||
|
else if(commonInfo->dst == src)
|
||||||
{
|
{
|
||||||
assert(ArtifactUtils::isSlotBackpack(dst.slot));
|
assert(dst.slot == ArtifactPosition::TRANSITION_POS);
|
||||||
commonInfo->reset();
|
commonInfo->reset();
|
||||||
|
|
||||||
CArtifactsOfHero::ArtPlacePtr ap;
|
CArtifactsOfHero::ArtPlacePtr ap;
|
||||||
@ -749,52 +758,28 @@ void CArtifactsOfHero::artifactMoved(const ArtifactLocation &src, const Artifact
|
|||||||
if(dst.isHolder(aoh->curHero))
|
if(dst.isHolder(aoh->curHero))
|
||||||
{
|
{
|
||||||
commonInfo->src.AOH = aoh;
|
commonInfo->src.AOH = aoh;
|
||||||
if((ap = aoh->getArtPlace(dst.slot)))//getArtPlace may return null
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ap)
|
commonInfo->src.art = dst.getArt();
|
||||||
{
|
commonInfo->src.slotID = dst.slot;
|
||||||
ap->select();
|
assert(commonInfo->src.AOH);
|
||||||
}
|
CCS->curh->dragAndDropCursor(make_unique<CAnimImage>("artifact", dst.getArt()->artType->getIconIndex()));
|
||||||
else
|
markPossibleSlots(dst.getArt());
|
||||||
{
|
|
||||||
commonInfo->src.art = dst.getArt();
|
|
||||||
commonInfo->src.slotID = dst.slot;
|
|
||||||
assert(commonInfo->src.AOH);
|
|
||||||
CCS->curh->dragAndDropCursor(std::make_unique<CAnimImage>("artifact", dst.getArt()->artType->getIconIndex()));
|
|
||||||
markPossibleSlots(dst.getArt());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(src.slot >= GameConstants::BACKPACK_START &&
|
|
||||||
src.slot < commonInfo->src.slotID &&
|
|
||||||
src.isHolder(commonInfo->src.AOH->curHero)) //artifact taken from before currently picked one
|
|
||||||
{
|
|
||||||
//int fixedSlot = src.hero->getArtPos(commonInfo->src.art);
|
|
||||||
vstd::advance(commonInfo->src.slotID, -1);
|
|
||||||
assert(commonInfo->src.valid());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//when moving one artifact onto another it leads to two art movements: dst->backapck; src->dst
|
|
||||||
// however after first movement we pick the art from backpack and the second movement coming when
|
|
||||||
// we have a different artifact may look surprising... but it's valid.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateParentWindow();
|
updateParentWindow();
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
// if(dst.slot >= Arts::BACKPACK_START && dst.slot - Arts::BACKPACK_START < backpackPos)
|
if(!ArtifactUtils::isSlotBackpack(src.slot) && dst.slot - GameConstants::BACKPACK_START < backpackPos)
|
||||||
// shift++;
|
|
||||||
//
|
|
||||||
if(src.slot < GameConstants::BACKPACK_START && dst.slot - GameConstants::BACKPACK_START < backpackPos)
|
|
||||||
shift++;
|
shift++;
|
||||||
if(dst.slot < GameConstants::BACKPACK_START && src.slot - GameConstants::BACKPACK_START < backpackPos)
|
if(!ArtifactUtils::isSlotBackpack(dst.slot) && src.slot - GameConstants::BACKPACK_START < backpackPos)
|
||||||
shift--;
|
shift--;
|
||||||
|
|
||||||
if( (isCurHeroSrc && src.slot >= GameConstants::BACKPACK_START)
|
// If backpack is changed, update it
|
||||||
|| (isCurHeroDst && dst.slot >= GameConstants::BACKPACK_START) )
|
if((isCurHeroSrc && ArtifactUtils::isSlotBackpack(src.slot))
|
||||||
scrollBackpack(shift); //update backpack slots
|
|| (isCurHeroDst && ArtifactUtils::isSlotBackpack(dst.slot)))
|
||||||
|
scrollBackpack(shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CArtifactsOfHero::artifactRemoved(const ArtifactLocation &al)
|
void CArtifactsOfHero::artifactRemoved(const ArtifactLocation &al)
|
||||||
|
Loading…
Reference in New Issue
Block a user