From 3ea6f530adf42fc0efa3dfaf42cffd9e5194d4ce Mon Sep 17 00:00:00 2001 From: SoundSSGood <87084363+SoundSSGood@users.noreply.github.com> Date: Thu, 6 Jul 2023 21:37:18 +0300 Subject: [PATCH] backpack window initial --- client/widgets/CArtifactsOfHeroBase.cpp | 4 -- client/widgets/CArtifactsOfHeroBase.h | 2 +- client/widgets/CWindowWithArtifacts.cpp | 5 ++ client/widgets/CWindowWithArtifacts.h | 1 + client/windows/CTradeWindow.cpp | 62 +++++++++---------------- client/windows/CTradeWindow.h | 3 +- 6 files changed, 31 insertions(+), 46 deletions(-) diff --git a/client/widgets/CArtifactsOfHeroBase.cpp b/client/widgets/CArtifactsOfHeroBase.cpp index 8c9039770..38e9371f9 100644 --- a/client/widgets/CArtifactsOfHeroBase.cpp +++ b/client/widgets/CArtifactsOfHeroBase.cpp @@ -32,10 +32,6 @@ CArtifactsOfHeroBase::CArtifactsOfHeroBase() CArtifactsOfHeroBase::~CArtifactsOfHeroBase() { - // TODO: cursor handling is CWindowWithArtifacts level. Should be moved when trading, kingdom and hero window are reworked - // This will interfere with the implementation of a separate backpack window - CCS->curh->dragAndDropCursor(nullptr); - // Artifact located in artifactsTransitionPos should be returned if(getPickedArtifact()) { diff --git a/client/widgets/CArtifactsOfHeroBase.h b/client/widgets/CArtifactsOfHeroBase.h index d21e5983e..743a98254 100644 --- a/client/widgets/CArtifactsOfHeroBase.h +++ b/client/widgets/CArtifactsOfHeroBase.h @@ -21,7 +21,6 @@ public: using ArtPlaceMap = std::map; using ClickHandler = std::function; - const CGHeroInstance * curHero; ClickHandler leftClickCallback; ClickHandler rightClickCallback; @@ -42,6 +41,7 @@ public: virtual const CArtifactInstance * getPickedArtifact(); protected: + const CGHeroInstance * curHero; ArtPlaceMap artWorn; std::vector backpack; std::shared_ptr leftBackpackRoll; diff --git a/client/widgets/CWindowWithArtifacts.cpp b/client/widgets/CWindowWithArtifacts.cpp index b421ea769..45bcc7e54 100644 --- a/client/widgets/CWindowWithArtifacts.cpp +++ b/client/widgets/CWindowWithArtifacts.cpp @@ -26,6 +26,11 @@ #include "../../lib/CGeneralTextHandler.h" #include "../../lib/mapObjects/CGHeroInstance.h" +CWindowWithArtifacts::~CWindowWithArtifacts() +{ + CCS->curh->dragAndDropCursor(nullptr); +} + void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet) { artSets.emplace_back(artSet); diff --git a/client/widgets/CWindowWithArtifacts.h b/client/widgets/CWindowWithArtifacts.h index e7517d9be..51df78be4 100644 --- a/client/widgets/CWindowWithArtifacts.h +++ b/client/widgets/CWindowWithArtifacts.h @@ -24,6 +24,7 @@ public: std::weak_ptr, std::weak_ptr>; + virtual ~CWindowWithArtifacts(); void addSet(CArtifactsOfHeroPtr artSet); const CGHeroInstance * getHeroPickedArtifact(); const CArtifactInstance * getPickedArtifact(); diff --git a/client/windows/CTradeWindow.cpp b/client/windows/CTradeWindow.cpp index 4291f2bff..d52f3fbc3 100644 --- a/client/windows/CTradeWindow.cpp +++ b/client/windows/CTradeWindow.cpp @@ -180,24 +180,23 @@ void CTradeWindow::CTradeableItem::clickPressed(const Point & cursorPosition) CAltarWindow *aw = static_cast(mw); const auto pickedArtInst = aw->getPickedArtifact(); - auto artifactsOfHero = std::dynamic_pointer_cast(aw->arts); if(pickedArtInst) { - artifactsOfHero->pickedArtMoveToAltar(ArtifactPosition::TRANSITION_POS); + aw->arts->pickedArtMoveToAltar(ArtifactPosition::TRANSITION_POS); aw->moveArtToAltar(this->shared_from_this(), pickedArtInst); } else if(const CArtifactInstance *art = getArtInstance()) { - const auto hero = artifactsOfHero->getHero(); + const auto hero = aw->arts->getHero(); const auto slot = hero->getSlotByInstance(art); assert(slot != ArtifactPosition::PRE_FIRST); LOCPLINT->cb->swapArtifacts(ArtifactLocation(hero, slot), ArtifactLocation(hero, ArtifactPosition::TRANSITION_POS)); - artifactsOfHero->pickedArtFromSlot = slot; - artifactsOfHero->artifactsOnAltar.erase(art); + aw->arts->pickedArtFromSlot = slot; + aw->arts->artifactsOnAltar.erase(art); setID(-1); subtitle.clear(); - aw->deal->block(!artifactsOfHero->artifactsOnAltar.size()); + aw->deal->block(!aw->arts->artifactsOnAltar.size()); } aw->calcTotalExp(); @@ -374,34 +373,10 @@ void CTradeWindow::initItems(bool Left) int xOffset = 0, yOffset = 0; if(mode == EMarketMode::ARTIFACT_RESOURCE) { - xOffset = -361; - yOffset = +46; - auto item = std::make_shared(Point(137, 469), itemsType[Left], -1, 1, 0); item->recActions &= ~(UPDATE | SHOWALL); items[Left].push_back(item); } - else //ARTIFACT_EXP - { - xOffset = -365; - yOffset = -12; - } - - if(mode == EMarketMode::ARTIFACT_RESOURCE) - { - auto artifactsOfHero = std::make_shared(Point(xOffset, yOffset)); - artifactsOfHero->selectArtCallback = std::bind(&CTradeWindow::artifactSelected, this, _1); - artifactsOfHero->setHero(hero); - addSet(artifactsOfHero); - arts = artifactsOfHero; - } - else - { - auto artifactsOfHero = std::make_shared(Point(xOffset, yOffset)); - artifactsOfHero->setHero(hero); - addSet(artifactsOfHero); - arts = artifactsOfHero; - } } else { @@ -701,7 +676,13 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket * Market, const CGHeroInsta } titleLabel = std::make_shared(300, 27, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, title); - + if(mode == EMarketMode::ARTIFACT_RESOURCE) + { + arts = std::make_shared(Point(-361, 46)); + arts->selectArtCallback = std::bind(&CTradeWindow::artifactSelected, this, _1); + arts->setHero(hero); + addSet(arts); + } initItems(false); initItems(true); @@ -1133,6 +1114,10 @@ CAltarWindow::CAltarWindow(const IMarket * Market, const CGHeroInstance * Hero, sacrificeBackpack = std::make_shared(Point(147, 520), "ALTEMBK.DEF", CGI->generaltexth->zelp[570], std::bind(&CAltarWindow::SacrificeBackpack,this)); sacrificeBackpack->block(hero->artifactsInBackpack.empty()); + arts = std::make_shared(Point(-365, -12)); + arts->setHero(hero); + addSet(arts); + initItems(true); initItems(false); artIcon = std::make_shared("ARTIFACT", 0, 0, 281, 442); @@ -1234,15 +1219,14 @@ void CAltarWindow::makeDeal() else { std::vector positions; - auto artifactsOfHero = std::dynamic_pointer_cast(arts); - for(const CArtifactInstance * art : artifactsOfHero->artifactsOnAltar) + for(const CArtifactInstance * art : arts->artifactsOnAltar) { positions.push_back(hero->getSlotByInstance(art)); } std::sort(positions.begin(), positions.end(), std::greater<>()); LOCPLINT->cb->trade(market, mode, positions, {}, {}, hero); - artifactsOfHero->artifactsOnAltar.clear(); + arts->artifactsOnAltar.clear(); for(auto item : items[0]) { @@ -1279,13 +1263,12 @@ void CAltarWindow::SacrificeAll() } else { - auto artifactsOfHero = std::dynamic_pointer_cast(arts); - for(const auto & aw : artifactsOfHero->visibleArtSet.artifactsWorn) + for(const auto & aw : arts->visibleArtSet.artifactsWorn) { if(!aw.second.locked) moveArtToAltar(nullptr, aw.second.artifact); } - artifactsOfHero->updateWornSlots(); + arts->updateWornSlots(); SacrificeBackpack(); } redraw(); @@ -1501,9 +1484,8 @@ bool CAltarWindow::putOnAltar(std::shared_ptr altarSlot, const C market->getOffer(art->artType->getId(), 0, dmp, val, EMarketMode::ARTIFACT_EXP); val = static_cast(hero->calculateXp(val)); - auto artsAltar = std::dynamic_pointer_cast(arts); - artsAltar->artifactsOnAltar.insert(art); - artsAltar->deleteFromVisible(art); + arts->artifactsOnAltar.insert(art); + arts->deleteFromVisible(art); altarSlot->setArtInstance(art); altarSlot->subtitle = std::to_string(val); diff --git a/client/windows/CTradeWindow.h b/client/windows/CTradeWindow.h index c8343deb4..396b6e435 100644 --- a/client/windows/CTradeWindow.h +++ b/client/windows/CTradeWindow.h @@ -67,7 +67,6 @@ public: const IMarket * market; const CGHeroInstance * hero; - std::shared_ptr arts; //all indexes: 1 = left, 0 = right std::array>, 2> items; @@ -117,6 +116,7 @@ protected: class CMarketplaceWindow : public CTradeWindow { std::shared_ptr titleLabel; + std::shared_ptr arts; bool printButtonFor(EMarketMode::EMarketMode M) const; @@ -155,6 +155,7 @@ public: std::shared_ptr sacrificeBackpack; std::shared_ptr expToLevel; std::shared_ptr expOnAltar; + std::shared_ptr arts; CAltarWindow(const IMarket * Market, const CGHeroInstance * Hero, EMarketMode::EMarketMode Mode); ~CAltarWindow();