From 03b4733c64d452a6a90e60c2e7b64095a57574cd Mon Sep 17 00:00:00 2001 From: SoundSSGood <87084363+SoundSSGood@users.noreply.github.com> Date: Sun, 20 Oct 2024 15:27:21 +0300 Subject: [PATCH] CSecSkillPlace --- client/CMakeLists.txt | 4 +- client/widgets/CArtifactsOfHeroBase.cpp | 47 ++++---- client/widgets/CArtifactsOfHeroBase.h | 8 +- client/widgets/CArtifactsOfHeroMarket.cpp | 11 +- client/widgets/CArtifactsOfHeroMarket.h | 2 +- .../{CArtPlace.cpp => CComponentHolder.cpp} | 100 +++++++++++------- .../{CArtPlace.h => CComponentHolder.h} | 44 +++++--- client/windows/CCreatureWindow.cpp | 4 +- 8 files changed, 131 insertions(+), 89 deletions(-) rename client/widgets/{CArtPlace.cpp => CComponentHolder.cpp} (83%) rename client/widgets/{CArtPlace.h => CComponentHolder.h} (75%) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 991aba090..5de831a28 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -116,8 +116,8 @@ set(vcmiclientcommon_SRCS globalLobby/GlobalLobbyWindow.cpp widgets/Buttons.cpp - widgets/CArtPlace.cpp widgets/CComponent.cpp + widgets/CComponentHolder.cpp widgets/CExchangeController.cpp widgets/CGarrisonInt.cpp widgets/CreatureCostBox.cpp @@ -327,8 +327,8 @@ set(vcmiclientcommon_HEADERS globalLobby/GlobalLobbyWindow.h widgets/Buttons.h - widgets/CArtPlace.h widgets/CComponent.h + widgets/CComponentHolder.h widgets/CExchangeController.h widgets/CGarrisonInt.h widgets/CreatureCostBox.h diff --git a/client/widgets/CArtifactsOfHeroBase.cpp b/client/widgets/CArtifactsOfHeroBase.cpp index 9ccd9248e..5941e90dd 100644 --- a/client/widgets/CArtifactsOfHeroBase.cpp +++ b/client/widgets/CArtifactsOfHeroBase.cpp @@ -89,31 +89,40 @@ void CArtifactsOfHeroBase::init( setRedrawParent(true); } -void CArtifactsOfHeroBase::clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition) +void CArtifactsOfHeroBase::clickPrassedArtPlace(CComponentHolder & artPlace, const Point & cursorPosition) { - if(artPlace.isLocked()) + auto ownedPlace = getArtPlace(cursorPosition); + assert(ownedPlace != nullptr); + + if(ownedPlace->isLocked()) return; if(clickPressedCallback) - clickPressedCallback(artPlace, cursorPosition); + clickPressedCallback(*ownedPlace, cursorPosition); } -void CArtifactsOfHeroBase::showPopupArtPlace(CArtPlace & artPlace, const Point & cursorPosition) +void CArtifactsOfHeroBase::showPopupArtPlace(CComponentHolder & artPlace, const Point & cursorPosition) { - if(artPlace.isLocked()) + auto ownedPlace = getArtPlace(cursorPosition); + assert(ownedPlace != nullptr); + + if(ownedPlace->isLocked()) return; if(showPopupCallback) - showPopupCallback(artPlace, cursorPosition); + showPopupCallback(*ownedPlace, cursorPosition); } -void CArtifactsOfHeroBase::gestureArtPlace(CArtPlace & artPlace, const Point & cursorPosition) +void CArtifactsOfHeroBase::gestureArtPlace(CComponentHolder & artPlace, const Point & cursorPosition) { - if(artPlace.isLocked()) + auto ownedPlace = getArtPlace(cursorPosition); + assert(ownedPlace != nullptr); + + if(ownedPlace->isLocked()) return; if(gestureCallback) - gestureCallback(artPlace, cursorPosition); + gestureCallback(*ownedPlace, cursorPosition); } void CArtifactsOfHeroBase::setHero(const CGHeroInstance * hero) @@ -156,24 +165,16 @@ CArtifactsOfHeroBase::ArtPlacePtr CArtifactsOfHeroBase::getArtPlace(const Artifa { if(ArtifactUtils::isSlotEquipment(slot)) { - if(artWorn.find(slot) == artWorn.end()) - { - logGlobal->error("CArtifactsOfHero::getArtPlace: invalid slot %d", slot); - return nullptr; - } - return artWorn[slot]; + if(artWorn.find(slot) != artWorn.end()) + return artWorn[slot]; } if(ArtifactUtils::isSlotBackpack(slot)) { - for(ArtPlacePtr artPlace : backpack) - if(artPlace->slot == slot) - return artPlace; - return nullptr; - } - else - { - return nullptr; + if(slot - ArtifactPosition::BACKPACK_START < backpack.size()) + return(backpack[slot - ArtifactPosition::BACKPACK_START]); } + logGlobal->error("CArtifactsOfHero::getArtPlace: invalid slot %d", slot); + return nullptr; } CArtifactsOfHeroBase::ArtPlacePtr CArtifactsOfHeroBase::getArtPlace(const Point & cursorPosition) diff --git a/client/widgets/CArtifactsOfHeroBase.h b/client/widgets/CArtifactsOfHeroBase.h index 7aaaf5ce3..df4b02a0d 100644 --- a/client/widgets/CArtifactsOfHeroBase.h +++ b/client/widgets/CArtifactsOfHeroBase.h @@ -9,7 +9,7 @@ */ #pragma once -#include "CArtPlace.h" +#include "CComponentHolder.h" #include "Scrollable.h" #include "../gui/Shortcut.h" @@ -33,9 +33,9 @@ public: CArtifactsOfHeroBase(); virtual void putBackPickedArtifact(); - virtual void clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition); - virtual void showPopupArtPlace(CArtPlace & artPlace, const Point & cursorPosition); - virtual void gestureArtPlace(CArtPlace & artPlace, const Point & cursorPosition); + virtual void clickPrassedArtPlace(CComponentHolder & artPlace, const Point & cursorPosition); + virtual void showPopupArtPlace(CComponentHolder & artPlace, const Point & cursorPosition); + virtual void gestureArtPlace(CComponentHolder & artPlace, const Point & cursorPosition); virtual void setHero(const CGHeroInstance * hero); virtual const CGHeroInstance * getHero() const; virtual void scrollBackpack(bool left); diff --git a/client/widgets/CArtifactsOfHeroMarket.cpp b/client/widgets/CArtifactsOfHeroMarket.cpp index 7158d0371..0b7dacc3c 100644 --- a/client/widgets/CArtifactsOfHeroMarket.cpp +++ b/client/widgets/CArtifactsOfHeroMarket.cpp @@ -22,18 +22,21 @@ CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position, const int artPlace->setSelectionWidth(selectionWidth); }; -void CArtifactsOfHeroMarket::clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition) +void CArtifactsOfHeroMarket::clickPrassedArtPlace(CComponentHolder & artPlace, const Point & cursorPosition) { - if(artPlace.isLocked()) + auto ownedPlace = getArtPlace(cursorPosition); + assert(ownedPlace != nullptr); + + if(ownedPlace->isLocked()) return; - if(const auto art = getArt(artPlace.slot)) + if(const auto art = getArt(ownedPlace->slot)) { if(onSelectArtCallback && art->artType->isTradable()) { unmarkSlots(); artPlace.selectSlot(true); - onSelectArtCallback(&artPlace); + onSelectArtCallback(ownedPlace.get()); } else { diff --git a/client/widgets/CArtifactsOfHeroMarket.h b/client/widgets/CArtifactsOfHeroMarket.h index 87334c0d7..5fd88b9ca 100644 --- a/client/widgets/CArtifactsOfHeroMarket.h +++ b/client/widgets/CArtifactsOfHeroMarket.h @@ -18,5 +18,5 @@ public: std::function onClickNotTradableCallback; CArtifactsOfHeroMarket(const Point & position, const int selectionWidth); - void clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition) override; + void clickPrassedArtPlace(CComponentHolder & artPlace, const Point & cursorPosition) override; }; diff --git a/client/widgets/CArtPlace.cpp b/client/widgets/CComponentHolder.cpp similarity index 83% rename from client/widgets/CArtPlace.cpp rename to client/widgets/CComponentHolder.cpp index 0444ef77d..81a9cdfd3 100644 --- a/client/widgets/CArtPlace.cpp +++ b/client/widgets/CComponentHolder.cpp @@ -1,5 +1,5 @@ /* - * CArtPlace.cpp, part of VCMI engine + * CComponentHolder.cpp, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * @@ -8,14 +8,14 @@ * */ #include "StdInc.h" -#include "CArtPlace.h" +#include "CComponentHolder.h" #include "../gui/CGuiHandler.h" #include "../gui/Shortcut.h" #include "CComponent.h" +#include "Images.h" -#include "../windows/GUIClasses.h" #include "../render/Canvas.h" #include "../render/Colors.h" #include "../render/IRenderHandler.h" @@ -28,9 +28,51 @@ #include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/networkPacks/ArtifactLocation.h" #include "../../lib/CConfigHandler.h" +#include "../../lib/CSkillHandler.h" + +CComponentHolder::CComponentHolder(const Rect & area, const Point & selectionOversize) + : SelectableSlot(area, selectionOversize) +{ +} + +void CComponentHolder::setClickPressedCallback(const ClickFunctor & callback) +{ + clickPressedCallback = callback; +} + +void CComponentHolder::setShowPopupCallback(const ClickFunctor & callback) +{ + showPopupCallback = callback; +} + +void CComponentHolder::setGestureCallback(const ClickFunctor & callback) +{ + gestureCallback = callback; +} + +void CComponentHolder::clickPressed(const Point & cursorPosition) +{ + if(clickPressedCallback) + clickPressedCallback(*this, cursorPosition); +} + +void CComponentHolder::showPopupWindow(const Point & cursorPosition) +{ + if(showPopupCallback) + showPopupCallback(*this, cursorPosition); +} + +void CComponentHolder::gesture(bool on, const Point & initialPosition, const Point & finalPosition) +{ + if(!on) + return; + + if(gestureCallback) + gestureCallback(*this, initialPosition); +} CArtPlace::CArtPlace(Point position, const ArtifactID & artId, const SpellID & spellId) - : SelectableSlot(Rect(position, Point(44, 44)), Point(1, 1)) + : CComponentHolder(Rect(position, Point(44, 44)), Point(1, 1)) , locked(false) , imageIndex(0) { @@ -171,42 +213,6 @@ bool CArtPlace::isLocked() const return locked; } -void CArtPlace::clickPressed(const Point & cursorPosition) -{ - if(clickPressedCallback) - clickPressedCallback(*this, cursorPosition); -} - -void CArtPlace::showPopupWindow(const Point & cursorPosition) -{ - if(showPopupCallback) - showPopupCallback(*this, cursorPosition); -} - -void CArtPlace::gesture(bool on, const Point & initialPosition, const Point & finalPosition) -{ - if(!on) - return; - - if(gestureCallback) - gestureCallback(*this, initialPosition); -} - -void CArtPlace::setClickPressedCallback(const ClickFunctor & callback) -{ - clickPressedCallback = callback; -} - -void CArtPlace::setShowPopupCallback(const ClickFunctor & callback) -{ - showPopupCallback = callback; -} - -void CArtPlace::setGestureCallback(const ClickFunctor & callback) -{ - gestureCallback = callback; -} - void CArtPlace::addCombinedArtInfo(const std::map> & arts) { for(auto [combinedId, availableArts] : arts) @@ -244,3 +250,17 @@ void CArtPlace::addCombinedArtInfo(const std::map(AnimationPath::builtin("SECSKILL"), 0); + setSkill(skillId); +} + +void CSecSkillPlace::setSkill(const SecondarySkill & skillId) +{ + //skillId.toSkill()->getIconIndex(); +} diff --git a/client/widgets/CArtPlace.h b/client/widgets/CComponentHolder.h similarity index 75% rename from client/widgets/CArtPlace.h rename to client/widgets/CComponentHolder.h index 645a57e5a..dd49e4bae 100644 --- a/client/widgets/CArtPlace.h +++ b/client/widgets/CComponentHolder.h @@ -1,5 +1,5 @@ /* - * CArtPlace.h, part of VCMI engine + * CComponentHolder.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * @@ -13,11 +13,29 @@ class CAnimImage; -class CArtPlace : public SelectableSlot +class CComponentHolder : public SelectableSlot { public: - using ClickFunctor = std::function; + using ClickFunctor = std::function; + ClickFunctor clickPressedCallback; + ClickFunctor showPopupCallback; + ClickFunctor gestureCallback; + std::shared_ptr image; + + CComponentHolder(const Rect & area, const Point & selectionOversize); + void setClickPressedCallback(const ClickFunctor & callback); + void setShowPopupCallback(const ClickFunctor & callback); + void setGestureCallback(const ClickFunctor & callback); + void clickPressed(const Point & cursorPosition) override; + void showPopupWindow(const Point & cursorPosition) override; + void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override; + virtual ~CComponentHolder() = default; +}; + +class CArtPlace : public CComponentHolder +{ +public: ArtifactPosition slot; CArtPlace(Point position, const ArtifactID & artId = ArtifactID::NONE, const SpellID & spellId = SpellID::NONE); @@ -26,12 +44,6 @@ public: ArtifactID getArtifactId() const; void lockSlot(bool on); bool isLocked() const; - void setClickPressedCallback(const ClickFunctor & callback); - void setShowPopupCallback(const ClickFunctor & callback); - void setGestureCallback(const ClickFunctor & callback); - void clickPressed(const Point & cursorPosition) override; - void showPopupWindow(const Point & cursorPosition) override; - void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override; void addCombinedArtInfo(const std::map> & arts); private: @@ -39,10 +51,6 @@ private: SpellID spellId; bool locked; int32_t imageIndex; - std::shared_ptr image; - ClickFunctor clickPressedCallback; - ClickFunctor showPopupCallback; - ClickFunctor gestureCallback; }; class CCommanderArtPlace : public CArtPlace @@ -59,3 +67,13 @@ public: void clickPressed(const Point & cursorPosition) override; void showPopupWindow(const Point & cursorPosition) override; }; + +class CSecSkillPlace : public CComponentHolder +{ +public: + CSecSkillPlace(const Point & position, const SecondarySkill & skillId = SecondarySkill::NONE); + void setSkill(const SecondarySkill & skillId); + +private: + SecondarySkill skillId; +}; diff --git a/client/windows/CCreatureWindow.cpp b/client/windows/CCreatureWindow.cpp index 28f0b7b92..79726ea26 100644 --- a/client/windows/CCreatureWindow.cpp +++ b/client/windows/CCreatureWindow.cpp @@ -17,8 +17,8 @@ #include "../CPlayerInterface.h" #include "../render/Canvas.h" #include "../widgets/Buttons.h" -#include "../widgets/CArtPlace.h" #include "../widgets/CComponent.h" +#include "../widgets/CComponentHolder.h" #include "../widgets/Images.h" #include "../widgets/TextControls.h" #include "../widgets/ObjectLists.h" @@ -619,7 +619,7 @@ CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool s if(art) { parent->stackArtifact = std::make_shared(pos, art->getTypeId()); - parent->stackArtifact->setShowPopupCallback([](CArtPlace & artPlace, const Point & cursorPosition) + parent->stackArtifact->setShowPopupCallback([](CComponentHolder & artPlace, const Point & cursorPosition) { artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition); });