Selaa lähdekoodia

assembling art qol

SoundSSGood 2 kuukautta sitten
vanhempi
sitoutus
04ed758c41

+ 2 - 2
client/ArtifactsUIController.cpp

@@ -60,7 +60,7 @@ bool ArtifactsUIController::askToAssemble(const CGHeroInstance * hero, const Art
 	auto assemblyPossibilities = ArtifactUtils::assemblyPossibilities(hero, art->getTypeId(), onlyEquipped);
 	if(!assemblyPossibilities.empty())
 	{
-		auto askThread = new std::thread([this, hero, art, slot, assemblyPossibilities, checkIgnored]() -> void
+		auto askThread = new std::thread([this, hero, slot, assemblyPossibilities, checkIgnored]() -> void
 			{
 				std::scoped_lock interfaceLock(ENGINE->interfaceMutex);
 				for(const auto combinedArt : assemblyPossibilities)
@@ -73,7 +73,7 @@ bool ArtifactsUIController::askToAssemble(const CGHeroInstance * hero, const Art
 					}
 
 					bool assembleConfirmed = false;
-					MetaString message = MetaString::createFromTextID(art->getType()->getDescriptionTextID());
+					MetaString message = MetaString::createFromTextID(combinedArt->getDescriptionTextID());
 					message.appendEOL();
 					message.appendEOL();
 					if(combinedArt->isFused())

+ 5 - 3
client/gui/EventDispatcher.cpp

@@ -220,6 +220,11 @@ void EventDispatcher::dispatchClosePopup(const Point & position)
 {
 	bool popupOpen = ENGINE->windows().isTopWindowPopup(); // popup can already be closed for mouse dragging with RMB
 
+	if(popupOpen)
+	{
+		ENGINE->windows().popWindows(1);
+	}
+
 	auto hlp = rclickable;
 
 	for(auto & i : hlp)
@@ -229,9 +234,6 @@ void EventDispatcher::dispatchClosePopup(const Point & position)
 
 		i->closePopupWindow(!popupOpen);
 	}
-
-	if(popupOpen)
-		ENGINE->windows().popWindows(1);
 }
 
 void EventDispatcher::handleLeftButtonClick(const Point & position, int tolerance, bool isPressed)

+ 11 - 0
client/widgets/CComponentHolder.cpp

@@ -53,6 +53,11 @@ void CComponentHolder::setShowPopupCallback(const ClickFunctor & callback)
 	showPopupCallback = callback;
 }
 
+void CComponentHolder::setClosePopupWindowCallback(const std::function<void()> & callback)
+{
+    closePopupWindowCallback = callback;
+}
+
 void CComponentHolder::setGestureCallback(const ClickFunctor & callback)
 {
 	gestureCallback = callback;
@@ -70,6 +75,12 @@ void CComponentHolder::showPopupWindow(const Point & cursorPosition)
 		showPopupCallback(*this, cursorPosition);
 }
 
+void CComponentHolder::closePopupWindow(bool alreadyClosed)
+{
+    if(closePopupWindowCallback)
+        closePopupWindowCallback();
+}
+
 void CComponentHolder::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
 {
 	if(!on)

+ 3 - 0
client/widgets/CComponentHolder.h

@@ -20,15 +20,18 @@ public:
 
 	ClickFunctor clickPressedCallback;
 	ClickFunctor showPopupCallback;
+	std::function<void()> closePopupWindowCallback;
 	ClickFunctor gestureCallback;
 	std::shared_ptr<CAnimImage> image;
 
 	CComponentHolder(const Rect & area, const Point & selectionOversize);
 	void setClickPressedCallback(const ClickFunctor & callback);
 	void setShowPopupCallback(const ClickFunctor & callback);
+	void setClosePopupWindowCallback(const std::function<void()> & callback);
 	void setGestureCallback(const ClickFunctor & callback);
 	void clickPressed(const Point & cursorPosition) override;
 	void showPopupWindow(const Point & cursorPosition) override;
+	void closePopupWindow(bool alreadyClosed) override;
 	void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
 };
 

+ 2 - 2
client/windows/CExchangeWindow.cpp

@@ -96,12 +96,12 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
 
 	artifs[0] = std::make_shared<CArtifactsOfHeroMain>(Point(-334, 151));
 	artifs[0]->clickPressedCallback = [this, hero = heroInst[0]](const CArtPlace & artPlace, const Point & cursorPosition){clickPressedOnArtPlace(hero, artPlace.slot, true, false, false, cursorPosition);};
-	artifs[0]->showPopupCallback = [this, heroArts = artifs[0]](CArtPlace & artPlace, const Point & cursorPosition){showArtifactAssembling(*heroArts, artPlace, cursorPosition);};
+	artifs[0]->showPopupCallback = [this, heroArts = artifs[0]](CArtPlace & artPlace, const Point & cursorPosition){showArtifactPopup(*heroArts, artPlace, cursorPosition);};
 	artifs[0]->gestureCallback = [this, hero = heroInst[0]](const CArtPlace & artPlace, const Point & cursorPosition){showQuickBackpackWindow(hero, artPlace.slot, cursorPosition);};
 	artifs[0]->setHero(heroInst[0]);
 	artifs[1] = std::make_shared<CArtifactsOfHeroMain>(Point(98, 151));
 	artifs[1]->clickPressedCallback = [this, hero = heroInst[1]](const CArtPlace & artPlace, const Point & cursorPosition){clickPressedOnArtPlace(hero, artPlace.slot, true, false, false, cursorPosition);};
-	artifs[1]->showPopupCallback = [this, heroArts = artifs[1]](CArtPlace & artPlace, const Point & cursorPosition){showArtifactAssembling(*heroArts, artPlace, cursorPosition);};
+	artifs[1]->showPopupCallback = [this, heroArts = artifs[1]](CArtPlace & artPlace, const Point & cursorPosition){showArtifactPopup(*heroArts, artPlace, cursorPosition);};
 	artifs[1]->gestureCallback = [this, hero = heroInst[1]](const CArtPlace & artPlace, const Point & cursorPosition){showQuickBackpackWindow(hero, artPlace.slot, cursorPosition);};
 	artifs[1]->setHero(heroInst[1]);
 

+ 1 - 1
client/windows/CHeroBackpackWindow.cpp

@@ -41,7 +41,7 @@ CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std:
 	};
 	arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition)
 	{
-		showArtifactAssembling(*arts, artPlace, cursorPosition);
+		showArtifactPopup(*arts, artPlace, cursorPosition);
 	};
 	addSet(arts);
 	arts->setHero(hero);

+ 1 - 1
client/windows/CHeroWindow.cpp

@@ -223,7 +223,7 @@ void CHeroWindow::updateArtifacts()
 		{
 			arts = std::make_shared<CArtifactsOfHeroMain>(Point(-65, -8));
 			arts->clickPressedCallback = [this](const CArtPlace & artPlace, const Point & cursorPosition){clickPressedOnArtPlace(curHero, artPlace.slot, true, false, false, cursorPosition);};
-			arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition){showArtifactAssembling(*arts, artPlace, cursorPosition);};
+			arts->showPopupCallback = [this](CArtPlace & artPlace, const Point & cursorPosition){showArtifactPopup(*arts, artPlace, cursorPosition);};
 			arts->gestureCallback = [this](const CArtPlace & artPlace, const Point & cursorPosition){showQuickBackpackWindow(curHero, artPlace.slot, cursorPosition);};
 			arts->setHero(curHero);
 			addSet(arts);

+ 1 - 1
client/windows/CKingdomInterface.cpp

@@ -563,7 +563,7 @@ std::shared_ptr<CIntObject> CKingdomInterface::createMainTab(size_t index)
 				};
 				newHeroSet->showPopupCallback = [this, newHeroSet](CArtPlace & artPlace, const Point & cursorPosition)
 				{
-					showArtifactAssembling(*newHeroSet, artPlace, cursorPosition);
+					showArtifactPopup(*newHeroSet, artPlace, cursorPosition);
 				};
 				newHeroSet->gestureCallback = [this, newHeroSet](const CArtPlace & artPlace, const Point & cursorPosition)
 				{

+ 1 - 1
client/windows/CMarketWindow.cpp

@@ -267,7 +267,7 @@ void CMarketWindow::createAltarArtifacts(const IMarket * market, const CGHeroIns
 	};
 	heroArts->showPopupCallback = [this, heroArts](CArtPlace & artPlace, const Point & cursorPosition)
 	{
-		showArtifactAssembling(*heroArts, artPlace, cursorPosition);
+		showArtifactPopup(*heroArts, artPlace, cursorPosition);
 	};
 	heroArts->gestureCallback = [this, heroArts](const CArtPlace & artPlace, const Point & cursorPosition)
 	{

+ 9 - 4
client/windows/CWindowWithArtifacts.cpp

@@ -113,17 +113,22 @@ void CWindowWithArtifacts::swapArtifactAndClose(const CArtifactsOfHeroBase & art
 	close();
 }
 
-void CWindowWithArtifacts::showArtifactAssembling(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace,
+void CWindowWithArtifacts::showArtifactPopup(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace,
 	const Point & cursorPosition) const
 {
 	if(artsInst.getArt(artPlace.slot))
 	{
 		if(GAME->interface()->artifactController->askToDisassemble(artsInst.getHero(), artPlace.slot))
 			return;
-		if(GAME->interface()->artifactController->askToAssemble(artsInst.getHero(), artPlace.slot))
-			return;
-		if(artPlace.text.size())
+		if(!artPlace.text.empty())
+		{
 			artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
+			artPlace.setClosePopupWindowCallback([hero = artsInst.getHero(), artPlacePtr = &artPlace]()
+			{
+				GAME->interface()->artifactController->askToAssemble(hero, artPlacePtr->slot);
+				artPlacePtr->setClosePopupWindowCallback([](){});
+			});
+		}
 	}
 }
 

+ 1 - 1
client/windows/CWindowWithArtifacts.h

@@ -30,7 +30,7 @@ public:
 	void clickPressedOnArtPlace(const CGHeroInstance * hero, const ArtifactPosition & slot,
 		bool allowExchange, bool altarTrading, bool closeWindow, const Point & cursorPosition);
 	void swapArtifactAndClose(const CArtifactsOfHeroBase & artsInst, const ArtifactPosition & slot, const ArtifactLocation & dstLoc);
-	void showArtifactAssembling(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition) const;
+	void showArtifactPopup(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition) const;
 	void showQuickBackpackWindow(const CGHeroInstance * hero, const ArtifactPosition & slot, const Point & cursorPosition) const;
 	void activate() override;
 	void deactivate() override;