diff --git a/client/ArtifactsUIController.cpp b/client/ArtifactsUIController.cpp index 617e36d16..da41f5282 100644 --- a/client/ArtifactsUIController.cpp +++ b/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()) diff --git a/client/gui/EventDispatcher.cpp b/client/gui/EventDispatcher.cpp index 5a2373c47..048f03eb3 100644 --- a/client/gui/EventDispatcher.cpp +++ b/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) diff --git a/client/widgets/CComponentHolder.cpp b/client/widgets/CComponentHolder.cpp index 1cc5ccd7d..ab962d5aa 100644 --- a/client/widgets/CComponentHolder.cpp +++ b/client/widgets/CComponentHolder.cpp @@ -53,6 +53,11 @@ void CComponentHolder::setShowPopupCallback(const ClickFunctor & callback) showPopupCallback = callback; } +void CComponentHolder::setClosePopupWindowCallback(const std::function & 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) diff --git a/client/widgets/CComponentHolder.h b/client/widgets/CComponentHolder.h index 63aae897b..33aa4b827 100644 --- a/client/widgets/CComponentHolder.h +++ b/client/widgets/CComponentHolder.h @@ -20,15 +20,18 @@ public: ClickFunctor clickPressedCallback; ClickFunctor showPopupCallback; + std::function closePopupWindowCallback; ClickFunctor gestureCallback; std::shared_ptr image; CComponentHolder(const Rect & area, const Point & selectionOversize); void setClickPressedCallback(const ClickFunctor & callback); void setShowPopupCallback(const ClickFunctor & callback); + void setClosePopupWindowCallback(const std::function & 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; }; diff --git a/client/windows/CExchangeWindow.cpp b/client/windows/CExchangeWindow.cpp index 96ded2530..183a902a1 100644 --- a/client/windows/CExchangeWindow.cpp +++ b/client/windows/CExchangeWindow.cpp @@ -96,12 +96,12 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, artifs[0] = std::make_shared(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(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]); diff --git a/client/windows/CHeroBackpackWindow.cpp b/client/windows/CHeroBackpackWindow.cpp index d54e90e95..7e64be742 100644 --- a/client/windows/CHeroBackpackWindow.cpp +++ b/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); diff --git a/client/windows/CHeroWindow.cpp b/client/windows/CHeroWindow.cpp index 68ca35d0e..16e52b7c7 100644 --- a/client/windows/CHeroWindow.cpp +++ b/client/windows/CHeroWindow.cpp @@ -223,7 +223,7 @@ void CHeroWindow::updateArtifacts() { arts = std::make_shared(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); diff --git a/client/windows/CKingdomInterface.cpp b/client/windows/CKingdomInterface.cpp index dbceba00c..2023613c4 100644 --- a/client/windows/CKingdomInterface.cpp +++ b/client/windows/CKingdomInterface.cpp @@ -563,7 +563,7 @@ std::shared_ptr 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) { diff --git a/client/windows/CMarketWindow.cpp b/client/windows/CMarketWindow.cpp index dbd4ae4c5..95b567905 100644 --- a/client/windows/CMarketWindow.cpp +++ b/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) { diff --git a/client/windows/CWindowWithArtifacts.cpp b/client/windows/CWindowWithArtifacts.cpp index 3a091d51e..5c8ebfbb3 100644 --- a/client/windows/CWindowWithArtifacts.cpp +++ b/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([](){}); + }); + } } } diff --git a/client/windows/CWindowWithArtifacts.h b/client/windows/CWindowWithArtifacts.h index 72b184cc5..1febad78d 100644 --- a/client/windows/CWindowWithArtifacts.h +++ b/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;