1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-21 00:19:29 +02:00

Merge pull request #3739 from SoundSSGood/fixes

Fixes for found regressions
This commit is contained in:
Ivan Savenko
2024-04-11 19:30:55 +03:00
committed by GitHub
6 changed files with 25 additions and 17 deletions

View File

@ -287,13 +287,7 @@ void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const
// Transition state. Nothing to do here. Just skip. Need to wait for final state. // Transition state. Nothing to do here. Just skip. Need to wait for final state.
return; return;
// 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.
auto pickedArtInst = std::get<const CArtifactInstance*>(curState.value()); auto pickedArtInst = std::get<const CArtifactInstance*>(curState.value());
assert(!pickedArtInst || destLoc.artHolder == std::get<const CGHeroInstance*>(curState.value())->id);
auto artifactMovedBody = [this, withRedraw, &destLoc, &pickedArtInst](auto artSetWeak) -> void auto artifactMovedBody = [this, withRedraw, &destLoc, &pickedArtInst](auto artSetWeak) -> void
{ {
auto artSetPtr = artSetWeak.lock(); auto artSetPtr = artSetWeak.lock();

View File

@ -34,8 +34,13 @@ CArtifactsSelling::CArtifactsSelling(const IMarket * market, const CGHeroInstanc
{ {
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE); OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
labels.emplace_back(std::make_shared<CLabel>(titlePos.x, titlePos.y, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, std::string title;
(*CGI->townh)[dynamic_cast<const CGTownInstance*>(market)->getFaction()]->town->buildings[BuildingID::ARTIFACT_MERCHANT]->getNameTranslated())); if(const auto townMarket = dynamic_cast<const CGTownInstance*>(market))
title = (*CGI->townh)[townMarket->getFaction()]->town->buildings[BuildingID::ARTIFACT_MERCHANT]->getNameTranslated();
else if(const auto mapMarket = dynamic_cast<const CGMarket*>(market))
title = mapMarket->title;
labels.emplace_back(std::make_shared<CLabel>(titlePos.x, titlePos.y, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, title));
labels.push_back(std::make_shared<CLabel>(155, 56, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, boost::str(boost::format(CGI->generaltexth->allTexts[271]) % hero->getNameTranslated()))); labels.push_back(std::make_shared<CLabel>(155, 56, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, boost::str(boost::format(CGI->generaltexth->allTexts[271]) % hero->getNameTranslated())));
deal = std::make_shared<CButton>(dealButtonPos, AnimationPath::builtin("TPMRKB.DEF"), deal = std::make_shared<CButton>(dealButtonPos, AnimationPath::builtin("TPMRKB.DEF"),
CGI->generaltexth->zelp[595], [this](){CArtifactsSelling::makeDeal();}); CGI->generaltexth->zelp[595], [this](){CArtifactsSelling::makeDeal();});

View File

@ -202,12 +202,13 @@ void CMarketWindow::createArtifactsSelling(const IMarket * market, const CGHeroI
background = createBg(ImagePath::builtin("TPMRKASS.bmp"), PLAYER_COLORED); background = createBg(ImagePath::builtin("TPMRKASS.bmp"), PLAYER_COLORED);
// Create image that copies part of background containing slot MISC_1 into position of slot MISC_5 // Create image that copies part of background containing slot MISC_1 into position of slot MISC_5
artSlotBack = std::make_shared<CPicture>(background->getSurface(), Rect(20, 187, 47, 47), 18, 339); artSlotBack = std::make_shared<CPicture>(background->getSurface(), Rect(20, 187, 47, 47), 0, 0);
artSlotBack->moveTo(Point(358, 443));
auto artsSellingMarket = std::make_shared<CArtifactsSelling>(market, hero); auto artsSellingMarket = std::make_shared<CArtifactsSelling>(market, hero);
artSets.clear(); artSets.clear();
addSetAndCallbacks(artsSellingMarket->getAOHset()); addSetAndCallbacks(artsSellingMarket->getAOHset());
marketWidget = artsSellingMarket; marketWidget = artsSellingMarket;
initWidgetInternals(EMarketMode::ARTIFACT_RESOURCE, CGI->generaltexth->zelp[600]); initWidgetInternals(EMarketMode::ARTIFACT_RESOURCE, CGI->generaltexth->zelp[600]);
} }
void CMarketWindow::createMarketResources(const IMarket * market, const CGHeroInstance * hero) void CMarketWindow::createMarketResources(const IMarket * market, const CGHeroInstance * hero)

View File

@ -840,15 +840,18 @@ CArtifactSet::ArtPlacementMap CArtifactSet::putArtifact(ArtifactPosition slot, C
void CArtifactSet::removeArtifact(ArtifactPosition slot) void CArtifactSet::removeArtifact(ArtifactPosition slot)
{ {
auto art = getArt(slot, false); if(const auto art = getArt(slot, false))
if(art)
{ {
if(art->isCombined()) if(art->isCombined())
{ {
for(auto & part : art->getPartsInfo()) for(const auto & part : art->getPartsInfo())
{ {
if(getArt(part.slot, false)) if(part.slot != ArtifactPosition::PRE_FIRST)
eraseArtSlot(part.slot); {
assert(getArt(part.slot, false));
assert(getArt(part.slot, false) == part.art);
}
eraseArtSlot(part.slot);
} }
} }
eraseArtSlot(slot); eraseArtSlot(slot);

View File

@ -757,6 +757,9 @@ bool CGTownInstance::allowsTrade(EMarketMode mode) const
case EMarketMode::RESOURCE_SKILL: case EMarketMode::RESOURCE_SKILL:
return hasBuilt(BuildingSubID::MAGIC_UNIVERSITY); return hasBuilt(BuildingSubID::MAGIC_UNIVERSITY);
case EMarketMode::CREATURE_EXP:
case EMarketMode::ARTIFACT_EXP:
return false;
default: default:
assert(0); assert(0);
return false; return false;

View File

@ -2706,7 +2706,8 @@ bool CGameHandler::moveArtifact(const PlayerColor & player, const ArtifactLocati
COMPLAIN_RET("That heroes cannot make any exchange!"); COMPLAIN_RET("That heroes cannot make any exchange!");
const auto srcArtifact = srcArtSet->getArt(src.slot); const auto srcArtifact = srcArtSet->getArt(src.slot);
const bool isDstSlotOccupied = dstArtSet->bearerType() == ArtBearer::ALTAR ? false : dstArtSet->getArt(dst.slot) != nullptr; const auto dstArtifact = dstArtSet->getArt(dst.slot);
const bool isDstSlotOccupied = dstArtSet->bearerType() == ArtBearer::ALTAR ? false : dstArtifact != nullptr;
const bool isDstSlotBackpack = dstArtSet->bearerType() == ArtBearer::HERO ? ArtifactUtils::isSlotBackpack(dst.slot) : false; const bool isDstSlotBackpack = dstArtSet->bearerType() == ArtBearer::HERO ? ArtifactUtils::isSlotBackpack(dst.slot) : false;
if(srcArtifact == nullptr) if(srcArtifact == nullptr)
@ -2744,7 +2745,8 @@ bool CGameHandler::moveArtifact(const PlayerColor & player, const ArtifactLocati
// Check if dst slot is occupied // Check if dst slot is occupied
if(!isDstSlotBackpack && isDstSlotOccupied) if(!isDstSlotBackpack && isDstSlotOccupied)
{ {
// Previous artifact must be removed // Previous artifact must be swapped
COMPLAIN_RET_FALSE_IF(!dstArtifact->canBePutAt(srcArtSet, src.slot, true), "Cannot swap artifacts!");
ma.artsPack1.push_back(BulkMoveArtifacts::LinkedSlots(dstSlot, src.slot)); ma.artsPack1.push_back(BulkMoveArtifacts::LinkedSlots(dstSlot, src.slot));
ma.swap = true; ma.swap = true;
} }