2023-04-23 14:10:35 +02:00
|
|
|
/*
|
|
|
|
* CArtifactsOfHeroBase.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2024-10-20 14:27:21 +02:00
|
|
|
#include "CComponentHolder.h"
|
2024-06-11 18:00:51 +02:00
|
|
|
#include "Scrollable.h"
|
2023-04-23 14:10:35 +02:00
|
|
|
|
2024-05-20 11:47:25 +02:00
|
|
|
#include "../gui/Shortcut.h"
|
|
|
|
|
2023-11-04 22:15:03 +02:00
|
|
|
class CButton;
|
2024-06-11 18:00:51 +02:00
|
|
|
class BackpackScroller;
|
2023-11-04 22:15:03 +02:00
|
|
|
|
2024-05-20 11:47:25 +02:00
|
|
|
class CArtifactsOfHeroBase : virtual public CIntObject, public CKeyShortcut
|
2023-04-23 14:10:35 +02:00
|
|
|
{
|
|
|
|
protected:
|
2024-05-21 19:00:13 +02:00
|
|
|
using ArtPlacePtr = std::shared_ptr<CArtPlace>;
|
2023-09-17 17:40:14 +02:00
|
|
|
using BpackScrollFunctor = std::function<void(int)>;
|
2023-04-23 14:10:35 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
using ArtPlaceMap = std::map<ArtifactPosition, ArtPlacePtr>;
|
2024-05-02 00:49:17 +02:00
|
|
|
using ClickFunctor = std::function<void(CArtPlace&, const Point&)>;
|
2023-04-23 14:10:35 +02:00
|
|
|
|
2023-12-17 16:30:19 +02:00
|
|
|
ClickFunctor clickPressedCallback;
|
2023-09-17 17:40:14 +02:00
|
|
|
ClickFunctor showPopupCallback;
|
2023-12-17 16:30:19 +02:00
|
|
|
ClickFunctor gestureCallback;
|
2023-04-23 14:10:35 +02:00
|
|
|
|
|
|
|
CArtifactsOfHeroBase();
|
2023-07-06 21:14:12 +02:00
|
|
|
virtual void putBackPickedArtifact();
|
2024-10-28 14:30:19 +02:00
|
|
|
virtual void clickPressedArtPlace(CComponentHolder & artPlace, const Point & cursorPosition);
|
2024-10-20 14:27:21 +02:00
|
|
|
virtual void showPopupArtPlace(CComponentHolder & artPlace, const Point & cursorPosition);
|
|
|
|
virtual void gestureArtPlace(CComponentHolder & artPlace, const Point & cursorPosition);
|
2023-04-23 14:10:35 +02:00
|
|
|
virtual void setHero(const CGHeroInstance * hero);
|
|
|
|
virtual const CGHeroInstance * getHero() const;
|
2024-03-06 15:16:35 +02:00
|
|
|
virtual void scrollBackpack(bool left);
|
2024-09-06 16:59:40 +02:00
|
|
|
virtual void markPossibleSlots(const CArtifact * art, bool assumeDestRemoved = true);
|
2023-04-23 14:10:35 +02:00
|
|
|
virtual void unmarkSlots();
|
|
|
|
virtual ArtPlacePtr getArtPlace(const ArtifactPosition & slot);
|
2024-05-01 20:18:36 +02:00
|
|
|
virtual ArtPlacePtr getArtPlace(const Point & cursorPosition);
|
2023-04-23 14:10:35 +02:00
|
|
|
virtual void updateWornSlots();
|
|
|
|
virtual void updateBackpackSlots();
|
|
|
|
virtual void updateSlot(const ArtifactPosition & slot);
|
|
|
|
virtual const CArtifactInstance * getPickedArtifact();
|
2024-05-20 14:31:07 +02:00
|
|
|
void enableGesture();
|
2024-05-08 13:16:16 +02:00
|
|
|
const CArtifactInstance * getArt(const ArtifactPosition & slot) const;
|
2024-05-20 11:47:25 +02:00
|
|
|
void enableKeyboardShortcuts();
|
2024-10-28 14:30:19 +02:00
|
|
|
void setClickPressedArtPlacesCallback(const CArtPlace::ClickFunctor & callback) const;
|
2024-10-21 20:49:22 +02:00
|
|
|
void setShowPopupArtPlacesCallback(const CArtPlace::ClickFunctor & callback) const;
|
2023-04-23 14:10:35 +02:00
|
|
|
|
2023-07-06 20:37:18 +02:00
|
|
|
const CGHeroInstance * curHero;
|
2023-04-23 14:10:35 +02:00
|
|
|
ArtPlaceMap artWorn;
|
|
|
|
std::vector<ArtPlacePtr> backpack;
|
|
|
|
std::shared_ptr<CButton> leftBackpackRoll;
|
|
|
|
std::shared_ptr<CButton> rightBackpackRoll;
|
2024-06-11 18:00:51 +02:00
|
|
|
std::shared_ptr<BackpackScroller> backpackScroller;
|
2023-04-23 14:10:35 +02:00
|
|
|
|
|
|
|
const std::vector<Point> slotPos =
|
|
|
|
{
|
2023-11-06 14:13:10 +02:00
|
|
|
Point(509,30), Point(568,242), Point(509,80), //0-2
|
|
|
|
Point(383,69), Point(562,184), Point(509,131), //3-5
|
|
|
|
Point(431,69), Point(610,184), Point(515,295), //6-8
|
|
|
|
Point(383,143), Point(399,193), Point(415,244), //9-11
|
|
|
|
Point(431,295), Point(564,30), Point(610,30), //12-14
|
2023-04-23 14:10:35 +02:00
|
|
|
Point(610,76), Point(610,122), Point(610,310), //15-17
|
2023-11-06 14:13:10 +02:00
|
|
|
Point(381,295) //18
|
2023-04-23 14:10:35 +02:00
|
|
|
};
|
|
|
|
|
2024-05-20 14:31:07 +02:00
|
|
|
protected:
|
|
|
|
virtual void init(const Point & position, const BpackScrollFunctor & scrollCallback);
|
2023-04-23 14:10:35 +02:00
|
|
|
// Assigns an artifacts to an artifact place depending on it's new slot ID
|
2024-01-27 23:48:11 +02:00
|
|
|
virtual void setSlotData(ArtPlacePtr artPlace, const ArtifactPosition & slot);
|
2023-04-23 14:10:35 +02:00
|
|
|
};
|
2024-06-11 18:00:51 +02:00
|
|
|
|
|
|
|
class BackpackScroller : public Scrollable
|
|
|
|
{
|
|
|
|
CArtifactsOfHeroBase * owner;
|
|
|
|
|
|
|
|
void scrollBy(int distance) override;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BackpackScroller(CArtifactsOfHeroBase * owner, const Rect & dimensions);
|
|
|
|
};
|