1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Hero backpack can now be scrolled via mouse wheel / swipe

This commit is contained in:
Ivan Savenko 2024-06-11 16:00:51 +00:00
parent fc1a20239e
commit 0a03b333f0
2 changed files with 32 additions and 0 deletions

View File

@ -85,6 +85,9 @@ void CArtifactsOfHeroBase::init(
leftBackpackRoll->block(true);
rightBackpackRoll->block(true);
backpackScroller = std::make_shared<BackpackScroller>(this, Rect(380, 30, 278, 382));
backpackScroller->setScrollingEnabled(false);
setRedrawParent(true);
}
@ -186,6 +189,8 @@ void CArtifactsOfHeroBase::updateBackpackSlots()
leftBackpackRoll->block(!scrollingPossible);
if(rightBackpackRoll)
rightBackpackRoll->block(!scrollingPossible);
if (backpackScroller)
backpackScroller->setScrollingEnabled(scrollingPossible);
}
void CArtifactsOfHeroBase::updateSlot(const ArtifactPosition & slot)
@ -245,3 +250,17 @@ void CArtifactsOfHeroBase::setSlotData(ArtPlacePtr artPlace, const ArtifactPosit
artPlace->setArtifact(nullptr);
}
}
BackpackScroller::BackpackScroller(CArtifactsOfHeroBase * owner, const Rect & dimensions)
: Scrollable(0, Point(), Orientation::HORIZONTAL)
, owner(owner)
{
pos = dimensions + pos.topLeft();
setPanningStep(46);
}
void BackpackScroller::scrollBy(int distance)
{
if (distance != 0)
owner->scrollBackpack(distance < 0);
}

View File

@ -10,8 +10,10 @@
#pragma once
#include "CArtPlace.h"
#include "Scrollable.h"
class CButton;
class BackpackScroller;
class CArtifactsOfHeroBase : virtual public CIntObject
{
@ -50,6 +52,7 @@ protected:
std::vector<ArtPlacePtr> backpack;
std::shared_ptr<CButton> leftBackpackRoll;
std::shared_ptr<CButton> rightBackpackRoll;
std::shared_ptr<BackpackScroller> backpackScroller;
const std::vector<Point> slotPos =
{
@ -67,3 +70,13 @@ protected:
// Assigns an artifacts to an artifact place depending on it's new slot ID
virtual void setSlotData(ArtPlacePtr artPlace, const ArtifactPosition & slot);
};
class BackpackScroller : public Scrollable
{
CArtifactsOfHeroBase * owner;
void scrollBy(int distance) override;
public:
BackpackScroller(CArtifactsOfHeroBase * owner, const Rect & dimensions);
};