1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/client/widgets/markets/TradePanels.h

142 lines
4.2 KiB
C++
Raw Normal View History

2023-12-04 23:21:49 +02:00
/*
* TradePanels.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-01-10 18:01:34 +02:00
#include "../MiscWidgets.h"
2023-12-04 23:21:49 +02:00
#include "../Images.h"
#include "../../../lib/networkPacks/TradeItem.h"
enum class EType
{
RESOURCE, PLAYER, ARTIFACT_TYPE, CREATURE, CREATURE_PLACEHOLDER, ARTIFACT_PLACEHOLDER, ARTIFACT_INSTANCE
};
2024-01-10 18:01:34 +02:00
class CTradeableItem : public SelectableSlot, public std::enable_shared_from_this<CTradeableItem>
2023-12-04 23:21:49 +02:00
{
public:
std::shared_ptr<CAnimImage> image;
AnimationPath getFilename();
int getIndex();
using ClickPressedFunctor = std::function<void(const std::shared_ptr<CTradeableItem>&)>;
2024-01-10 18:01:34 +02:00
const CArtifactInstance * artInstance; //holds ptr to artifact instance id type artifact
2023-12-04 23:21:49 +02:00
EType type;
int id;
const int serial;
2024-02-27 13:39:50 +02:00
std::shared_ptr<CLabel> subtitle;
2023-12-04 23:21:49 +02:00
ClickPressedFunctor clickPressedCallback;
void setType(EType newType);
void setID(int newID);
const CArtifactInstance * getArtInstance() const;
void setArtInstance(const CArtifactInstance * art);
void showPopupWindow(const Point & cursorPosition) override;
void hover(bool on) override;
void clickPressed(const Point & cursorPosition) override;
2024-02-27 13:39:50 +02:00
CTradeableItem(const Rect & area, EType Type, int ID, int Serial);
2023-12-04 23:21:49 +02:00
};
class TradePanelBase : public CIntObject
{
public:
using UpdateSlotsFunctor = std::function<void()>;
using DeleteSlotsCheck = std::function<bool(const std::shared_ptr<CTradeableItem>&)>;
std::vector<std::shared_ptr<CTradeableItem>> slots;
UpdateSlotsFunctor updateSlotsCallback;
DeleteSlotsCheck deleteSlotsCheck;
std::shared_ptr<CTradeableItem> selected;
const int selectionWidth = 2;
2024-02-27 13:39:50 +02:00
std::shared_ptr<CTradeableItem> selectedSlot;
2023-12-04 23:21:49 +02:00
virtual void updateSlots();
virtual void deselect();
virtual void clearSubtitles();
void updateOffer(CTradeableItem & slot, int, int);
2024-02-27 13:39:50 +02:00
void setSelectedFrameIndex(const std::optional<size_t> & index);
void setSelectedSubtitleText(const std::string & text);
void clearSelectedSubtitleText();
2023-12-04 23:21:49 +02:00
};
class ResourcesPanel : public TradePanelBase
{
const std::vector<GameResID> resourcesForTrade =
{
GameResID::WOOD, GameResID::MERCURY, GameResID::ORE,
GameResID::SULFUR, GameResID::CRYSTAL, GameResID::GEMS,
GameResID::GOLD
};
const std::vector<Point> slotsPos =
{
Point(0, 0), Point(83, 0), Point(166, 0),
Point(0, 79), Point(83, 79), Point(166, 79),
Point(83, 158)
};
2024-01-10 18:01:34 +02:00
const Point slotDimension = Point(69, 66);
2024-02-27 13:39:50 +02:00
const Point selectedPos = Point(83, 267);
2023-12-04 23:21:49 +02:00
public:
2024-02-27 13:39:50 +02:00
ResourcesPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback, const UpdateSlotsFunctor & updateSubtitles);
2023-12-04 23:21:49 +02:00
};
class ArtifactsPanel : public TradePanelBase
{
const std::vector<Point> slotsPos =
{
2024-02-22 22:49:30 +02:00
Point(0, 0), Point(83, 0), Point(165, 0),
Point(0, 79), Point(83, 79), Point(165, 79),
2023-12-04 23:21:49 +02:00
Point(83, 158)
};
const size_t slotsForTrade = 7;
2024-01-10 18:01:34 +02:00
const Point slotDimension = Point(69, 66);
2024-02-27 13:39:50 +02:00
const Point selectedPos = Point(83, 266);
2023-12-04 23:21:49 +02:00
public:
2024-02-27 13:39:50 +02:00
ArtifactsPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback,
const UpdateSlotsFunctor & updateSubtitles, const std::vector<TradeItemBuy> & arts);
2023-12-04 23:21:49 +02:00
};
class PlayersPanel : public TradePanelBase
{
const std::vector<Point> slotsPos =
{
Point(0, 0), Point(83, 0), Point(166, 0),
Point(0, 118), Point(83, 118), Point(166, 118),
Point(83, 236)
};
2024-01-10 18:01:34 +02:00
const Point slotDimension = Point(58, 64);
2024-02-27 13:39:50 +02:00
const Point selectedPos = Point(83, 367);
2023-12-04 23:21:49 +02:00
public:
2024-02-27 13:39:50 +02:00
explicit PlayersPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback);
2023-12-04 23:21:49 +02:00
};
class CreaturesPanel : public TradePanelBase
{
const std::vector<Point> slotsPos =
{
Point(0, 0), Point(83, 0), Point(166, 0),
Point(0, 98), Point(83, 98), Point(166, 98),
Point(83, 196)
};
2024-02-27 13:39:50 +02:00
const Point slotDimension = Point(59, 64);
const Point selectedPos = Point(83, 327);
2023-12-04 23:21:49 +02:00
public:
using slotsData = std::vector<std::tuple<CreatureID, SlotID, int>>;
2024-02-27 13:39:50 +02:00
CreaturesPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback, const slotsData & initialSlots);
CreaturesPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback,
2023-12-04 23:21:49 +02:00
const std::vector<std::shared_ptr<CTradeableItem>> & srcSlots, bool emptySlots = true);
};