Ver Fonte

suggestions

SoundSSGood há 1 ano atrás
pai
commit
ff5ddd76b7

+ 12 - 7
client/ArtifactsUIController.cpp

@@ -23,7 +23,12 @@
 #include "widgets/CComponent.h"
 #include "windows/CWindowWithArtifacts.h"
 
-bool ArtifactsUIController::askToAssemble(const ArtifactLocation & al, const bool onlyEquipped, std::set<ArtifactID> * ignoredArtifacts)
+ArtifactsUIController::ArtifactsUIController()
+{
+	numOfMovedArts = 0;
+}
+
+bool ArtifactsUIController::askToAssemble(const ArtifactLocation & al, const bool onlyEquipped, const bool checkIgnored)
 {
 	if(auto hero = LOCPLINT->cb->getHero(al.artHolder))
 	{
@@ -32,13 +37,13 @@ bool ArtifactsUIController::askToAssemble(const ArtifactLocation & al, const boo
 			logGlobal->error("artifact location %d points to nothing", al.slot.num);
 			return false;
 		}
-		return askToAssemble(hero, al.slot, onlyEquipped, ignoredArtifacts);
+		return askToAssemble(hero, al.slot, onlyEquipped, checkIgnored);
 	}
 	return false;
 }
 
 bool ArtifactsUIController::askToAssemble(const CGHeroInstance * hero, const ArtifactPosition & slot,
-	const bool onlyEquipped, std::set<ArtifactID> * ignoredArtifacts)
+	const bool onlyEquipped, const bool checkIgnored)
 {
 	assert(hero);
 	const auto art = hero->getArt(slot);
@@ -52,17 +57,17 @@ bool ArtifactsUIController::askToAssemble(const CGHeroInstance * hero, const Art
 	auto assemblyPossibilities = ArtifactUtils::assemblyPossibilities(hero, art->getTypeId(), onlyEquipped);
 	if(!assemblyPossibilities.empty())
 	{
-		auto askThread = new boost::thread([this, hero, art, slot, assemblyPossibilities, ignoredArtifacts]() -> void
+		auto askThread = new boost::thread([this, hero, art, slot, assemblyPossibilities, checkIgnored]() -> void
 			{
 				boost::mutex::scoped_lock askLock(askAssembleArtifactMutex);
 				for(const auto combinedArt : assemblyPossibilities)
 				{
 					boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
-					if(ignoredArtifacts)
+					if(checkIgnored)
 					{
-						if(vstd::contains(*ignoredArtifacts, combinedArt->getId()))
+						if(vstd::contains(ignoredArtifacts, combinedArt->getId()))
 							continue;
-						ignoredArtifacts->emplace(combinedArt->getId());
+						ignoredArtifacts.emplace(combinedArt->getId());
 					}
 
 					bool assembleConfirmed = false;

+ 4 - 3
client/ArtifactsUIController.h

@@ -20,16 +20,17 @@ VCMI_LIB_NAMESPACE_END
 
 class ArtifactsUIController
 {
-public:
 	size_t numOfMovedArts;
 	size_t numOfArtsAskAssembleSession;
 	std::set<ArtifactID> ignoredArtifacts;
 
 	boost::mutex askAssembleArtifactMutex;
 
-	bool askToAssemble(const ArtifactLocation & al, const bool onlyEquipped = false, std::set<ArtifactID> * ignoredArtifacts = nullptr);
+public:
+	ArtifactsUIController();
+	bool askToAssemble(const ArtifactLocation & al, const bool onlyEquipped = false, const bool checkIgnored = false);
 	bool askToAssemble(const CGHeroInstance * hero, const ArtifactPosition & slot, const bool onlyEquipped = false,
-		std::set<ArtifactID> * ignoredArtifacts = nullptr);
+		const bool checkIgnored = false);
 	bool askToDisassemble(const CGHeroInstance * hero, const ArtifactPosition & slot);
 
 	void artifactRemoved();

+ 9 - 8
client/CPlayerInterface.cpp

@@ -131,7 +131,9 @@ struct HeroObjectRetriever
 
 CPlayerInterface::CPlayerInterface(PlayerColor Player):
 	localState(std::make_unique<PlayerLocalState>(*this)),
-	movementController(std::make_unique<HeroMovementController>())
+	movementController(std::make_unique<HeroMovementController>()),
+	artifactController(std::make_unique<ArtifactsUIController>())
+	
 {
 	logGlobal->trace("\tHuman player interface for player %s being constructed", Player.toString());
 	GH.defActionsDef = 0;
@@ -147,7 +149,6 @@ CPlayerInterface::CPlayerInterface(PlayerColor Player):
 	isAutoFightOn = false;
 	isAutoFightEndBattle = false;
 	ignoreEvents = false;
-	numOfMovedArts = 0;
 }
 
 CPlayerInterface::~CPlayerInterface()
@@ -1707,7 +1708,7 @@ void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj)
 
 void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
 {
-	ArtifactsUIController::askToAssemble(al, true, &ignoredArtifacts);
+	artifactController->askToAssemble(al, true, true);
 }
 
 void CPlayerInterface::artifactPut(const ArtifactLocation &al)
@@ -1720,33 +1721,33 @@ void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	adventureInt->onHeroChanged(cb->getHero(al.artHolder));
-	ArtifactsUIController::artifactRemoved();
+	artifactController->artifactRemoved();
 }
 
 void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	adventureInt->onHeroChanged(cb->getHero(dst.artHolder));
-	ArtifactsUIController::artifactMoved();
+	artifactController->artifactMoved();
 }
 
 void CPlayerInterface::bulkArtMovementStart(size_t totalNumOfArts, size_t possibleAssemblyNumOfArts)
 {
-	ArtifactsUIController::bulkArtMovementStart(totalNumOfArts, possibleAssemblyNumOfArts);
+	artifactController->bulkArtMovementStart(totalNumOfArts, possibleAssemblyNumOfArts);
 }
 
 void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	adventureInt->onHeroChanged(cb->getHero(al.artHolder));
-	ArtifactsUIController::artifactAssembled();
+	artifactController->artifactAssembled();
 }
 
 void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	adventureInt->onHeroChanged(cb->getHero(al.artHolder));
-	ArtifactsUIController::artifactDisassembled();
+	artifactController->artifactDisassembled();
 }
 
 void CPlayerInterface::waitForAllDialogs()

+ 2 - 1
client/CPlayerInterface.h

@@ -56,7 +56,7 @@ namespace boost
 }
 
 /// Central class for managing user interface logic
-class CPlayerInterface : public CGameInterface, public IUpdateable, public ArtifactsUIController
+class CPlayerInterface : public CGameInterface, public IUpdateable
 {
 	bool ignoreEvents;
 	int autosaveCount;
@@ -65,6 +65,7 @@ class CPlayerInterface : public CGameInterface, public IUpdateable, public Artif
 
 	std::unique_ptr<HeroMovementController> movementController;
 public: // TODO: make private
+	std::unique_ptr<ArtifactsUIController> artifactController;
 	std::shared_ptr<Environment> env;
 
 	std::unique_ptr<PlayerLocalState> localState;

+ 2 - 2
client/windows/CWindowWithArtifacts.cpp

@@ -117,9 +117,9 @@ void CWindowWithArtifacts::showArtifactAssembling(const CArtifactsOfHeroBase & a
 {
 	if(artsInst.getArt(artPlace.slot))
 	{
-		if(LOCPLINT->askToDisassemble(artsInst.getHero(), artPlace.slot))
+		if(LOCPLINT->artifactController->askToDisassemble(artsInst.getHero(), artPlace.slot))
 			return;
-		if(LOCPLINT->askToAssemble(artsInst.getHero(), artPlace.slot))
+		if(LOCPLINT->artifactController->askToAssemble(artsInst.getHero(), artPlace.slot))
 			return;
 		if(artPlace.text.size())
 			artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);