1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

backpack window cursor fix

This commit is contained in:
SoundSSGood 2024-04-16 17:45:31 +03:00
parent 9390825ee7
commit e8eb638bf1
16 changed files with 75 additions and 41 deletions

View File

@ -25,8 +25,7 @@
#include "../../lib/networkPacks/ArtifactLocation.h" #include "../../lib/networkPacks/ArtifactLocation.h"
CArtifactsOfHeroBase::CArtifactsOfHeroBase() CArtifactsOfHeroBase::CArtifactsOfHeroBase()
: curHero(nullptr), : curHero(nullptr)
putBackPickedArtCallback(nullptr)
{ {
} }
@ -45,13 +44,6 @@ void CArtifactsOfHeroBase::putBackPickedArtifact()
LOCPLINT->cb->swapArtifacts(ArtifactLocation(curHero->id, ArtifactPosition::TRANSITION_POS), ArtifactLocation(curHero->id, slot)); LOCPLINT->cb->swapArtifacts(ArtifactLocation(curHero->id, ArtifactPosition::TRANSITION_POS), ArtifactLocation(curHero->id, slot));
} }
} }
if(putBackPickedArtCallback)
putBackPickedArtCallback();
}
void CArtifactsOfHeroBase::setPutBackPickedArtifactCallback(PutBackPickedArtCallback callback)
{
putBackPickedArtCallback = callback;
} }
void CArtifactsOfHeroBase::init( void CArtifactsOfHeroBase::init(

View File

@ -22,7 +22,6 @@ protected:
public: public:
using ArtPlaceMap = std::map<ArtifactPosition, ArtPlacePtr>; using ArtPlaceMap = std::map<ArtifactPosition, ArtPlacePtr>;
using ClickFunctor = std::function<void(CArtifactsOfHeroBase&, CArtPlace&, const Point&)>; using ClickFunctor = std::function<void(CArtifactsOfHeroBase&, CArtPlace&, const Point&)>;
using PutBackPickedArtCallback = std::function<void()>;
ClickFunctor clickPressedCallback; ClickFunctor clickPressedCallback;
ClickFunctor showPopupCallback; ClickFunctor showPopupCallback;
@ -30,7 +29,6 @@ public:
CArtifactsOfHeroBase(); CArtifactsOfHeroBase();
virtual void putBackPickedArtifact(); virtual void putBackPickedArtifact();
virtual void setPutBackPickedArtifactCallback(PutBackPickedArtCallback callback);
virtual void clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition); virtual void clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition);
virtual void showPopupArtPlace(CArtPlace & artPlace, const Point & cursorPosition); virtual void showPopupArtPlace(CArtPlace & artPlace, const Point & cursorPosition);
virtual void gestureArtPlace(CArtPlace & artPlace, const Point & cursorPosition); virtual void gestureArtPlace(CArtPlace & artPlace, const Point & cursorPosition);
@ -52,7 +50,6 @@ protected:
std::vector<ArtPlacePtr> backpack; std::vector<ArtPlacePtr> backpack;
std::shared_ptr<CButton> leftBackpackRoll; std::shared_ptr<CButton> leftBackpackRoll;
std::shared_ptr<CButton> rightBackpackRoll; std::shared_ptr<CButton> rightBackpackRoll;
PutBackPickedArtCallback putBackPickedArtCallback;
const std::vector<Point> slotPos = const std::vector<Point> slotPos =
{ {

View File

@ -26,8 +26,7 @@ CArtifactsOfHeroMain::CArtifactsOfHeroMain(const Point & position)
addGestureCallback(std::bind(&CArtifactsOfHeroBase::gestureArtPlace, this, _1, _2)); addGestureCallback(std::bind(&CArtifactsOfHeroBase::gestureArtPlace, this, _1, _2));
} }
void CArtifactsOfHeroMain::deactivate() CArtifactsOfHeroMain::~CArtifactsOfHeroMain()
{ {
putBackPickedArtifact(); CArtifactsOfHeroBase::putBackPickedArtifact();
CArtifactsOfHeroBase::deactivate();
} }

View File

@ -21,5 +21,5 @@ class CArtifactsOfHeroMain : public CArtifactsOfHeroBase
{ {
public: public:
CArtifactsOfHeroMain(const Point & position); CArtifactsOfHeroMain(const Point & position);
void deactivate() override; ~CArtifactsOfHeroMain() override;
}; };

View File

@ -35,6 +35,12 @@
#include "../../CCallback.h" #include "../../CCallback.h"
CWindowWithArtifacts::CWindowWithArtifacts(const std::vector<CArtifactsOfHeroPtr> * artSets)
{
if(artSets)
this->artSets.insert(this->artSets.end(), artSets->begin(), artSets->end());
}
void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet) void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet)
{ {
artSets.emplace_back(artSet); artSets.emplace_back(artSet);
@ -42,19 +48,13 @@ void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet)
void CWindowWithArtifacts::addSetAndCallbacks(CArtifactsOfHeroPtr artSet) void CWindowWithArtifacts::addSetAndCallbacks(CArtifactsOfHeroPtr artSet)
{ {
CArtifactsOfHeroBase::PutBackPickedArtCallback artPutBackFunctor = []() -> void
{
CCS->curh->dragAndDropCursor(nullptr);
};
addSet(artSet); addSet(artSet);
std::visit([this, artPutBackFunctor](auto artSetWeak) std::visit([this](auto artSetWeak)
{ {
auto artSet = artSetWeak.lock(); auto artSet = artSetWeak.lock();
artSet->clickPressedCallback = std::bind(&CWindowWithArtifacts::clickPressedArtPlaceHero, this, _1, _2, _3); artSet->clickPressedCallback = std::bind(&CWindowWithArtifacts::clickPressedArtPlaceHero, this, _1, _2, _3);
artSet->showPopupCallback = std::bind(&CWindowWithArtifacts::showPopupArtPlaceHero, this, _1, _2, _3); artSet->showPopupCallback = std::bind(&CWindowWithArtifacts::showPopupArtPlaceHero, this, _1, _2, _3);
artSet->gestureCallback = std::bind(&CWindowWithArtifacts::gestureArtPlaceHero, this, _1, _2, _3); artSet->gestureCallback = std::bind(&CWindowWithArtifacts::gestureArtPlaceHero, this, _1, _2, _3);
artSet->setPutBackPickedArtifactCallback(artPutBackFunctor);
}, artSet); }, artSet);
} }
@ -146,7 +146,7 @@ void CWindowWithArtifacts::clickPressedArtPlaceHero(CArtifactsOfHeroBase & artsI
{ {
if(checkSpecialArts(*art, hero, std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroAltar>> ? true : false)) if(checkSpecialArts(*art, hero, std::is_same_v<decltype(artSetWeak), std::weak_ptr<CArtifactsOfHeroAltar>> ? true : false))
{ {
assert(artSetPtr->getHero()->getSlotByInstance(art)); assert(artSetPtr->getHero()->getSlotByInstance(art) != ArtifactPosition::PRE_FIRST);
LOCPLINT->cb->swapArtifacts(ArtifactLocation(artSetPtr->getHero()->id, artSetPtr->getHero()->getSlotByInstance(art)), LOCPLINT->cb->swapArtifacts(ArtifactLocation(artSetPtr->getHero()->id, artSetPtr->getHero()->getSlotByInstance(art)),
ArtifactLocation(artSetPtr->getHero()->id, ArtifactPosition::TRANSITION_POS)); ArtifactLocation(artSetPtr->getHero()->id, ArtifactPosition::TRANSITION_POS));
} }
@ -296,17 +296,7 @@ void CWindowWithArtifacts::artifactMoved(const ArtifactLocation & srcLoc, const
const auto hero = artSetPtr->getHero(); const auto hero = artSetPtr->getHero();
if(pickedArtInst) if(pickedArtInst)
{ {
markPossibleSlots(); setCursorAnimation(*pickedArtInst);
if(pickedArtInst->getTypeId() == ArtifactID::SPELL_SCROLL && pickedArtInst->getScrollSpellID().num >= 0 && settings["general"]["enableUiEnhancements"].Bool())
{
auto anim = GH.renderHandler().loadAnimation(AnimationPath::builtin("spellscr"));
anim->load(pickedArtInst->getScrollSpellID().num);
std::shared_ptr<IImage> img = anim->getImage(pickedArtInst->getScrollSpellID().num);
CCS->curh->dragAndDropCursor(img->scaleFast(Point(44, 34)));
}
else
CCS->curh->dragAndDropCursor(AnimationPath::builtin("artifact"), pickedArtInst->artType->getIconIndex());
} }
else else
{ {
@ -476,3 +466,19 @@ bool CWindowWithArtifacts::checkSpecialArts(const CArtifactInstance & artInst, c
} }
return true; return true;
} }
void CWindowWithArtifacts::setCursorAnimation(const CArtifactInstance & artInst)
{
markPossibleSlots();
if(artInst.isScroll() && settings["general"]["enableUiEnhancements"].Bool())
{
assert(artInst.getScrollSpellID().num >= 0);
const auto animation = GH.renderHandler().loadAnimation(AnimationPath::builtin("spellscr"));
animation->load(artInst.getScrollSpellID().num);
CCS->curh->dragAndDropCursor(animation->getImage(artInst.getScrollSpellID().num)->scaleFast(Point(44, 34)));
}
else
{
CCS->curh->dragAndDropCursor(AnimationPath::builtin("artifact"), artInst.artType->getIconIndex());
}
}

View File

@ -28,6 +28,7 @@ public:
std::weak_ptr<CArtifactsOfHeroQuickBackpack>>; std::weak_ptr<CArtifactsOfHeroQuickBackpack>>;
using CloseCallback = std::function<void()>; using CloseCallback = std::function<void()>;
explicit CWindowWithArtifacts(const std::vector<CArtifactsOfHeroPtr> * artSets = nullptr);
void addSet(CArtifactsOfHeroPtr artSet); void addSet(CArtifactsOfHeroPtr artSet);
void addSetAndCallbacks(CArtifactsOfHeroPtr artSet); void addSetAndCallbacks(CArtifactsOfHeroPtr artSet);
void addCloseCallback(CloseCallback callback); void addCloseCallback(CloseCallback callback);
@ -51,4 +52,5 @@ protected:
std::optional<CArtifactsOfHeroPtr> findAOHbyRef(CArtifactsOfHeroBase & artsInst); std::optional<CArtifactsOfHeroPtr> findAOHbyRef(CArtifactsOfHeroBase & artsInst);
void markPossibleSlots(); void markPossibleSlots();
bool checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance * hero, bool isTrade); bool checkSpecialArts(const CArtifactInstance & artInst, const CGHeroInstance * hero, bool isTrade);
void setCursorAnimation(const CArtifactInstance & artInst);
}; };

View File

@ -20,8 +20,9 @@
#include "render/Canvas.h" #include "render/Canvas.h"
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero) CHeroBackpackWindow::CHeroBackpackWindow(const CGHeroInstance * hero, const std::vector<CArtifactsOfHeroPtr> & artsSets)
: CStatusbarWindow(0) : CStatusbarWindow(0)
, CWindowWithArtifacts(&artsSets)
{ {
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE); OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
@ -48,6 +49,13 @@ void CHeroBackpackWindow::showAll(Canvas & to)
CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to, pos.w+28, pos.h+29, pos.x-14, pos.y-15); CMessage::drawBorder(PlayerColor(LOCPLINT->playerID), to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
} }
void CHeroBackpackWindow::activate()
{
if(const auto art = getPickedArtifact())
setCursorAnimation(*art);
CIntObject::activate();
}
CHeroQuickBackpackWindow::CHeroQuickBackpackWindow(const CGHeroInstance * hero, ArtifactPosition targetSlot) CHeroQuickBackpackWindow::CHeroQuickBackpackWindow(const CGHeroInstance * hero, ArtifactPosition targetSlot)
: CWindowObject(0) : CWindowObject(0)
{ {

View File

@ -17,7 +17,7 @@ class CFilledTexture;
class CHeroBackpackWindow : public CStatusbarWindow, public CWindowWithArtifacts class CHeroBackpackWindow : public CStatusbarWindow, public CWindowWithArtifacts
{ {
public: public:
CHeroBackpackWindow(const CGHeroInstance * hero); CHeroBackpackWindow(const CGHeroInstance * hero, const std::vector<CArtifactsOfHeroPtr> & artsSets);
protected: protected:
std::shared_ptr<CArtifactsOfHeroBackpack> arts; std::shared_ptr<CArtifactsOfHeroBackpack> arts;
@ -26,6 +26,7 @@ protected:
const int windowMargin = 5; const int windowMargin = 5;
void showAll(Canvas & to) override; void showAll(Canvas & to) override;
void activate() override;
}; };
class CHeroQuickBackpackWindow : public CWindowObject, public CWindowWithArtifacts class CHeroQuickBackpackWindow : public CWindowObject, public CWindowWithArtifacts

View File

@ -19,6 +19,7 @@
#include "../CPlayerInterface.h" #include "../CPlayerInterface.h"
#include "../gui/CGuiHandler.h" #include "../gui/CGuiHandler.h"
#include "../gui/CursorHandler.h"
#include "../gui/TextAlignment.h" #include "../gui/TextAlignment.h"
#include "../gui/Shortcut.h" #include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h" #include "../gui/WindowHandler.h"
@ -325,7 +326,7 @@ void CHeroWindow::dismissCurrent()
void CHeroWindow::createBackpackWindow() void CHeroWindow::createBackpackWindow()
{ {
GH.windows().createAndPushWindow<CHeroBackpackWindow>(curHero); GH.windows().createAndPushWindow<CHeroBackpackWindow>(curHero, artSets);
} }
void CHeroWindow::commanderWindow() void CHeroWindow::commanderWindow()
@ -359,3 +360,9 @@ bool CHeroWindow::holdsGarrison(const CArmedInstance * army)
{ {
return army == curHero; return army == curHero;
} }
void CHeroWindow::deactivate()
{
CCS->curh->dragAndDropCursor(nullptr);
CIntObject::deactivate();
}

View File

@ -108,6 +108,7 @@ public:
void switchHero(); //changes displayed hero void switchHero(); //changes displayed hero
void updateGarrisons() override; void updateGarrisons() override;
bool holdsGarrison(const CArmedInstance * army) override; bool holdsGarrison(const CArmedInstance * army) override;
void deactivate() override;
void createBackpackWindow(); void createBackpackWindow();
//friends //friends

View File

@ -18,6 +18,7 @@
#include "../PlayerLocalState.h" #include "../PlayerLocalState.h"
#include "../adventureMap/CResDataBar.h" #include "../adventureMap/CResDataBar.h"
#include "../gui/CGuiHandler.h" #include "../gui/CGuiHandler.h"
#include "../gui/CursorHandler.h"
#include "../gui/Shortcut.h" #include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h" #include "../gui/WindowHandler.h"
#include "../widgets/CComponent.h" #include "../widgets/CComponent.h"
@ -723,6 +724,12 @@ bool CKingdHeroList::holdsGarrison(const CArmedInstance * army)
return false; return false;
} }
void CKingdHeroList::deactivate()
{
CCS->curh->dragAndDropCursor(nullptr);
CIntObject::deactivate();
}
std::shared_ptr<CIntObject> CKingdHeroList::createHeroItem(size_t index) std::shared_ptr<CIntObject> CKingdHeroList::createHeroItem(size_t index)
{ {
ui32 picCount = 4; // OVSLOT contains 4 images ui32 picCount = 4; // OVSLOT contains 4 images

View File

@ -344,6 +344,7 @@ public:
void updateGarrisons() override; void updateGarrisons() override;
bool holdsGarrison(const CArmedInstance * army) override; bool holdsGarrison(const CArmedInstance * army) override;
void deactivate() override;
}; };
/// Tab with all town-specific data /// Tab with all town-specific data

View File

@ -12,6 +12,7 @@
#include "CMarketWindow.h" #include "CMarketWindow.h"
#include "../gui/CGuiHandler.h" #include "../gui/CGuiHandler.h"
#include "../gui/CursorHandler.h"
#include "../gui/Shortcut.h" #include "../gui/Shortcut.h"
#include "../widgets/Buttons.h" #include "../widgets/Buttons.h"
@ -261,3 +262,9 @@ void CMarketWindow::createAltarCreatures(const IMarket * market, const CGHeroIns
initWidgetInternals(EMarketMode::CREATURE_EXP, CGI->generaltexth->zelp[568]); initWidgetInternals(EMarketMode::CREATURE_EXP, CGI->generaltexth->zelp[568]);
updateHero(); updateHero();
} }
void CMarketWindow::deactivate()
{
CCS->curh->dragAndDropCursor(nullptr);
CIntObject::deactivate();
}

View File

@ -25,6 +25,7 @@ public:
bool holdsGarrison(const CArmedInstance * army) override; bool holdsGarrison(const CArmedInstance * army) override;
void artifactRemoved(const ArtifactLocation & artLoc) override; void artifactRemoved(const ArtifactLocation & artLoc) override;
void artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc, bool withRedraw) override; void artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc, bool withRedraw) override;
void deactivate() override;
private: private:
void createChangeModeButtons(EMarketMode currentMode, const IMarket * market, const CGHeroInstance * hero); void createChangeModeButtons(EMarketMode currentMode, const IMarket * market, const CGHeroInstance * hero);

View File

@ -861,9 +861,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
auto openBackpack = [this](const CGHeroInstance * hero) -> void auto openBackpack = [this](const CGHeroInstance * hero) -> void
{ {
GH.windows().createAndPushWindow<CHeroBackpackWindow>(hero); GH.windows().createAndPushWindow<CHeroBackpackWindow>(hero, artSets);
for(auto artSet : artSets)
GH.windows().topWindow<CHeroBackpackWindow>()->addSet(artSet);
}; };
moveAllGarrButtonLeft = std::make_shared<CButton>(Point(325, 118), AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/armRight.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[1]), moveAllGarrButtonLeft = std::make_shared<CButton>(Point(325, 118), AnimationPath::builtin(QUICK_EXCHANGE_MOD_PREFIX + "/armRight.DEF"), CButton::tooltip(CGI->generaltexth->qeModCommands[1]),
@ -936,6 +934,12 @@ bool CExchangeWindow::holdsGarrison(const CArmedInstance * army)
return garr->upperArmy() == army || garr->lowerArmy() == army; return garr->upperArmy() == army || garr->lowerArmy() == army;
} }
void CExchangeWindow::deactivate()
{
CCS->curh->dragAndDropCursor(nullptr);
CIntObject::deactivate();
}
void CExchangeWindow::questlog(int whichHero) void CExchangeWindow::questlog(int whichHero)
{ {
CCS->curh->dragAndDropCursor(nullptr); CCS->curh->dragAndDropCursor(nullptr);

View File

@ -325,6 +325,7 @@ public:
void updateGarrisons() override; void updateGarrisons() override;
bool holdsGarrison(const CArmedInstance * army) override; bool holdsGarrison(const CArmedInstance * army) override;
void deactivate() override;
void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right