1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Merge pull request #1245 from IvanSavenko/artifact_assembly_fix

Artifact assembly fix
This commit is contained in:
Andrii Danylchenko
2022-12-19 10:24:29 +02:00
committed by GitHub
4 changed files with 37 additions and 12 deletions

View File

@@ -67,6 +67,8 @@ void CCursorHandler::initCursor()
void CCursorHandler::changeGraphic(ECursor::ECursorTypes type, int index) void CCursorHandler::changeGraphic(ECursor::ECursorTypes type, int index)
{ {
assert(dndObject == nullptr);
if(type != this->type) if(type != this->type)
{ {
this->type = type; this->type = type;

View File

@@ -254,6 +254,22 @@ void CHeroArtPlace::clickRight(tribool down, bool previousState)
} }
} }
void CArtifactsOfHero::activate()
{
if (commonInfo->src.AOH == this && commonInfo->src.art)
CCS->curh->dragAndDropCursor(make_unique<CAnimImage>("artifact", commonInfo->src.art->artType->getIconIndex()));
CIntObject::activate();
}
void CArtifactsOfHero::deactivate()
{
if (commonInfo->src.AOH == this && commonInfo->src.art)
CCS->curh->dragAndDropCursor(nullptr);
CIntObject::deactivate();
}
/** /**
* Selects artifact slot so that the containing artifact looks like it's picked up. * Selects artifact slot so that the containing artifact looks like it's picked up.
*/ */
@@ -675,10 +691,8 @@ void CArtifactsOfHero::updateParentWindow()
if(!updateState) if(!updateState)
{ {
cew->deactivate();
cew->updateWidgets(); cew->updateWidgets();
cew->redraw(); cew->redraw();
cew->activate();
} }
} }
} }

View File

@@ -148,6 +148,9 @@ public:
void dispose(); //free resources not needed after closing windows and reset state void dispose(); //free resources not needed after closing windows and reset state
void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right
void activate() override;
void deactivate() override;
void safeRedraw(); void safeRedraw();
void markPossibleSlots(const CArtifactInstance* art); void markPossibleSlots(const CArtifactInstance* art);
void unmarkSlots(bool withRedraw = true); //unmarks slots in all visible AOHs void unmarkSlots(bool withRedraw = true); //unmarks slots in all visible AOHs

View File

@@ -861,8 +861,6 @@ void CArtifactInstance::removeFrom(ArtifactLocation al)
al.getHolderArtSet()->eraseArtSlot(al.slot); al.getHolderArtSet()->eraseArtSlot(al.slot);
if(!ArtifactUtils::isSlotBackpack(al.slot)) if(!ArtifactUtils::isSlotBackpack(al.slot))
al.getHolderNode()->detachFrom(*this); al.getHolderNode()->detachFrom(*this);
//TODO delete me?
} }
bool CArtifactInstance::canBeDisassembled() const bool CArtifactInstance::canBeDisassembled() const
@@ -1062,7 +1060,9 @@ void CCombinedArtifactInstance::createConstituents()
void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance *art, ArtifactPosition slot) void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance *art, ArtifactPosition slot)
{ {
assert(vstd::contains(*artType->constituents, art->artType.get())); assert(vstd::contains_if(*artType->constituents, [=](const CArtifact * constituent){
return constituent->id == art->artType->id;
}));
assert(art->getParentNodes().size() == 1 && art->getParentNodes().front() == art->artType); assert(art->getParentNodes().size() == 1 && art->getParentNodes().front() == art->artType);
constituentsInfo.push_back(ConstituentInfo(art, slot)); constituentsInfo.push_back(ConstituentInfo(art, slot));
attachTo(*art); attachTo(*art);
@@ -1354,11 +1354,16 @@ bool CArtifactSet::isPositionFree(ArtifactPosition pos, bool onlyLockCheck) cons
ArtSlotInfo & CArtifactSet::retrieveNewArtSlot(ArtifactPosition slot) ArtSlotInfo & CArtifactSet::retrieveNewArtSlot(ArtifactPosition slot)
{ {
assert(!vstd::contains(artifactsWorn, slot)); assert(!vstd::contains(artifactsWorn, slot));
ArtSlotInfo &ret = !ArtifactUtils::isSlotBackpack(slot)
? artifactsWorn[slot]
: *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::BACKPACK_START), ArtSlotInfo());
return ret; if (!ArtifactUtils::isSlotBackpack(slot))
return artifactsWorn[slot];
ArtSlotInfo newSlot;
size_t index = slot - GameConstants::BACKPACK_START;
auto position = artifactsInBackpack.begin() + index;
auto inserted = artifactsInBackpack.insert(position, newSlot);
return *inserted;
} }
void CArtifactSet::setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art, bool locked) void CArtifactSet::setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art, bool locked)
@@ -1372,9 +1377,10 @@ void CArtifactSet::eraseArtSlot(ArtifactPosition slot)
{ {
if(ArtifactUtils::isSlotBackpack(slot)) if(ArtifactUtils::isSlotBackpack(slot))
{ {
assert(artifactsInBackpack.begin() + slot < artifactsInBackpack.end()); auto backpackSlot = ArtifactPosition(slot - GameConstants::BACKPACK_START);
slot = ArtifactPosition(slot - GameConstants::BACKPACK_START);
artifactsInBackpack.erase(artifactsInBackpack.begin() + slot); assert(artifactsInBackpack.begin() + backpackSlot < artifactsInBackpack.end());
artifactsInBackpack.erase(artifactsInBackpack.begin() + backpackSlot);
} }
else else
{ {