Browse Source

askToAssemble, askToDisassemble

SoundSSGood 2 years ago
parent
commit
177523d972

+ 1 - 1
client/CPlayerInterface.cpp

@@ -1925,7 +1925,7 @@ void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
 							 al.slot.num);
 			return;
 		}
-		CHeroArtPlace::askToAssemble(hero, al.slot);
+		ArtifactUtils::askToAssemble(hero, al.slot);
 	}
 }
 

+ 41 - 0
client/widgets/CArtifactHolder.cpp

@@ -1056,3 +1056,44 @@ std::optional<CWindowWithArtifacts::CArtifactsOfHeroPtr> CWindowWithArtifacts::f
 	}
 	return res;
 }
+
+bool ArtifactUtils::askToAssemble(const CGHeroInstance * hero, const ArtifactPosition & slot)
+{
+	assert(hero);
+	const auto art = hero->getArt(slot);
+	assert(art);
+	auto assemblyPossibilities = ArtifactUtils::assemblyPossibilities(hero, art->getTypeId(), ArtifactUtils::isSlotEquipment(slot));
+
+	for(const auto combinedArt : assemblyPossibilities)
+	{
+		LOCPLINT->showArtifactAssemblyDialog(
+			art->artType,
+			combinedArt,
+			std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), hero, slot, true, combinedArt->getId()));
+
+		if(assemblyPossibilities.size() > 2)
+			logGlobal->warn("More than one possibility of assembling on %s... taking only first", art->artType->getNameTranslated());
+		return true;
+	}
+	return false;
+}
+
+bool ArtifactUtils::askToDisassemble(const CGHeroInstance * hero, const ArtifactPosition & slot)
+{
+	assert(hero);
+	const auto art = hero->getArt(slot);
+	assert(art);
+
+	if(art->canBeDisassembled())
+	{
+		if(ArtifactUtils::isSlotBackpack(slot) && !ArtifactUtils::isBackpackFreeSlots(hero, art->artType->constituents->size() - 1))
+			return false;
+
+		LOCPLINT->showArtifactAssemblyDialog(
+			art->artType,
+			nullptr,
+			std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), hero, slot, false, ArtifactID()));
+		return true;
+	}
+	return false;
+}

+ 6 - 0
client/widgets/CArtifactHolder.h

@@ -220,3 +220,9 @@ private:
 	std::optional<std::tuple<const CGHeroInstance*, const CArtifactInstance*>> getState();
 	std::optional<CArtifactsOfHeroPtr> findAOHbyRef(CArtifactsOfHeroBase & artsInst);
 };
+
+namespace ArtifactUtils
+{
+	bool askToAssemble(const CGHeroInstance* hero, const ArtifactPosition& slot);
+	bool askToDisassemble(const CGHeroInstance* hero, const ArtifactPosition& slot);
+}