1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-16 10:19:47 +02:00
vcmi/client/widgets/markets/CMarketBase.h

129 lines
3.4 KiB
C++
Raw Normal View History

2023-12-04 23:21:49 +02:00
/*
2024-03-02 20:30:29 +02:00
* CMarketBase.h, part of VCMI engine
2023-12-04 23:21:49 +02:00
*
* 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
#include "TradePanels.h"
2024-03-02 20:30:29 +02:00
#include "../../widgets/Slider.h"
2024-03-20 13:28:19 +02:00
#include "../../render/EFont.h"
#include "../../render/Colors.h"
2023-12-04 23:21:49 +02:00
VCMI_LIB_NAMESPACE_BEGIN
class IMarket;
VCMI_LIB_NAMESPACE_END
2024-03-02 20:30:29 +02:00
class CMarketBase : public CIntObject
2023-12-04 23:21:49 +02:00
{
public:
2024-03-20 13:28:19 +02:00
struct ShowcaseParams
2024-02-29 12:02:39 +02:00
{
std::string text;
int imageIndex;
};
2024-04-08 11:46:46 +02:00
struct MarketShowcasesParams
{
std::optional<const ShowcaseParams> bidParams;
std::optional<const ShowcaseParams> offerParams;
};
2024-03-20 13:28:19 +02:00
using ShowcasesParamsFunctor = std::function<const MarketShowcasesParams()>;
2024-02-29 12:02:39 +02:00
2023-12-04 23:21:49 +02:00
const IMarket * market;
const CGHeroInstance * hero;
2024-02-25 22:58:53 +02:00
std::shared_ptr<TradePanelBase> bidTradePanel;
std::shared_ptr<TradePanelBase> offerTradePanel;
2023-12-04 23:21:49 +02:00
std::shared_ptr<CButton> deal;
std::vector<std::shared_ptr<CLabel>> labels;
std::vector<std::shared_ptr<CTextBox>> texts;
2024-02-29 12:02:39 +02:00
int bidQty;
int offerQty;
2024-03-02 20:30:29 +02:00
const Point dealButtonPos = Point(270, 520);
const Point titlePos = Point(299, 27);
2023-12-04 23:21:49 +02:00
2024-03-20 13:28:19 +02:00
CMarketBase(const IMarket * market, const CGHeroInstance * hero);
2023-12-04 23:21:49 +02:00
virtual void makeDeal() = 0;
virtual void deselect();
2024-03-02 20:30:29 +02:00
virtual void update();
2024-02-29 12:02:39 +02:00
protected:
virtual void onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot, std::shared_ptr<TradePanelBase> & curPanel);
virtual void updateSubtitlesForBid(EMarketMode marketMode, int bidId);
virtual void updateShowcases();
2024-03-20 13:28:19 +02:00
virtual MarketShowcasesParams getShowcasesParams() const = 0;
virtual void highlightingChanged();
2023-12-04 23:21:49 +02:00
};
// Market subclasses
2024-03-02 20:30:29 +02:00
class CExperienceAltar : virtual public CMarketBase
2023-12-04 23:21:49 +02:00
{
public:
std::shared_ptr<CLabel> expToLevel;
std::shared_ptr<CLabel> expForHero;
std::shared_ptr<CButton> sacrificeAllButton;
CExperienceAltar();
2024-03-02 20:30:29 +02:00
void deselect() override;
void update() override;
2023-12-04 23:21:49 +02:00
virtual void sacrificeAll() = 0;
virtual TExpType calcExpAltarForHero() = 0;
};
2024-03-02 20:30:29 +02:00
class CCreaturesSelling : virtual public CMarketBase
2023-12-04 23:21:49 +02:00
{
public:
CCreaturesSelling();
bool slotDeletingCheck(const std::shared_ptr<CTradeableItem> & slot) const;
void updateSubtitles() const;
2024-02-03 22:59:05 +02:00
};
2024-03-02 20:30:29 +02:00
class CResourcesBuying : virtual public CMarketBase
2024-02-03 22:59:05 +02:00
{
public:
2024-02-27 13:39:50 +02:00
CResourcesBuying(const CTradeableItem::ClickPressedFunctor & clickPressedCallback,
const TradePanelBase::UpdateSlotsFunctor & updSlotsCallback);
2024-02-19 23:40:43 +02:00
};
2024-03-02 20:30:29 +02:00
class CResourcesSelling : virtual public CMarketBase
2024-02-19 23:40:43 +02:00
{
public:
explicit CResourcesSelling(const CTradeableItem::ClickPressedFunctor & clickPressedCallback);
void updateSubtitles() const;
2024-02-22 22:49:30 +02:00
};
2024-03-02 20:30:29 +02:00
class CMarketSlider : virtual public CMarketBase
{
public:
std::shared_ptr<CSlider> offerSlider;
std::shared_ptr<CButton> maxAmount;
const Point dealButtonPosWithSlider = Point(306, 520);
explicit CMarketSlider(const CSlider::SliderMovingFunctor & movingCallback);
2024-03-02 20:30:29 +02:00
void deselect() override;
virtual void onOfferSliderMoved(int newVal);
};
2024-03-20 13:28:19 +02:00
class CMarketTraderText : virtual public CMarketBase
{
public:
CMarketTraderText(const Point & pos = Point(316, 48), const EFonts & font = EFonts::FONT_SMALL, const ColorRGBA & Color = Colors::WHITE);
void deselect() override;
void makeDeal() override;
const Point traderTextDimensions = Point(260, 75);
std::shared_ptr<CTextBox> traderText;
bool madeTransaction;
protected:
void highlightingChanged() override;
virtual std::string getTraderText() = 0;
};