2023-12-04 23:21:49 +02:00
|
|
|
/*
|
|
|
|
* CTradeBase.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
|
|
|
|
|
|
|
|
#include "TradePanels.h"
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class IMarket;
|
|
|
|
class CGHeroInstance;
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
|
|
|
class CButton;
|
|
|
|
class CSlider;
|
|
|
|
|
2024-02-27 13:39:50 +02:00
|
|
|
class CTradeBase : public CIntObject
|
2023-12-04 23:21:49 +02:00
|
|
|
{
|
|
|
|
public:
|
2024-02-29 12:02:39 +02:00
|
|
|
struct SelectionParamOneSide
|
|
|
|
{
|
|
|
|
std::string text;
|
|
|
|
int imageIndex;
|
|
|
|
};
|
|
|
|
using SelectionParams = std::tuple<std::optional<const SelectionParamOneSide>, std::optional<const SelectionParamOneSide>>;
|
|
|
|
using SelectionParamsFunctor = std::function<const SelectionParams()>;
|
|
|
|
|
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
|
|
|
|
2024-02-29 12:02:39 +02:00
|
|
|
// Highlighted trade slots (nullptr if no highlight)
|
2023-12-04 23:21:49 +02:00
|
|
|
std::shared_ptr<CTradeableItem> hLeft;
|
|
|
|
std::shared_ptr<CTradeableItem> hRight;
|
|
|
|
std::shared_ptr<CButton> deal;
|
|
|
|
std::shared_ptr<CSlider> offerSlider;
|
2024-02-19 23:40:43 +02:00
|
|
|
std::shared_ptr<CButton> maxAmount;
|
2023-12-04 23:21:49 +02:00
|
|
|
std::vector<std::shared_ptr<CLabel>> labels;
|
|
|
|
std::vector<std::shared_ptr<CTextBox>> texts;
|
2024-02-29 12:02:39 +02:00
|
|
|
SelectionParamsFunctor selectionParamsCallback;
|
|
|
|
int bidQty;
|
|
|
|
int offerQty;
|
2023-12-04 23:21:49 +02:00
|
|
|
|
2024-02-29 12:02:39 +02:00
|
|
|
CTradeBase(const IMarket * market, const CGHeroInstance * hero, const SelectionParamsFunctor & getParamsCallback);
|
2023-12-04 23:21:49 +02:00
|
|
|
virtual void makeDeal() = 0;
|
|
|
|
virtual void deselect();
|
2024-02-27 13:39:50 +02:00
|
|
|
virtual void updateSlots();
|
2024-02-29 12:02:39 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot, std::shared_ptr<CTradeableItem> & hCurSlot);
|
2024-02-27 13:39:50 +02:00
|
|
|
virtual void updateSubtitles(EMarketMode marketMode);
|
2024-02-29 12:02:39 +02:00
|
|
|
virtual void updateSelected();
|
|
|
|
virtual CTradeBase::SelectionParams getSelectionParams() const = 0;
|
2023-12-04 23:21:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Market subclasses
|
2024-02-27 13:39:50 +02:00
|
|
|
class CExperienceAltar : virtual public CTradeBase
|
2023-12-04 23:21:49 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::shared_ptr<CLabel> expToLevel;
|
|
|
|
std::shared_ptr<CLabel> expForHero;
|
|
|
|
std::shared_ptr<CButton> sacrificeAllButton;
|
|
|
|
const Point dealButtonPos = Point(269, 520);
|
|
|
|
|
|
|
|
CExperienceAltar();
|
2024-02-29 22:33:12 +02:00
|
|
|
void updateSlots() override;
|
2023-12-04 23:21:49 +02:00
|
|
|
virtual void sacrificeAll() = 0;
|
|
|
|
virtual TExpType calcExpAltarForHero() = 0;
|
|
|
|
};
|
|
|
|
|
2024-02-27 13:39:50 +02:00
|
|
|
class CCreaturesSelling : virtual public CTradeBase
|
2023-12-04 23:21:49 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCreaturesSelling();
|
|
|
|
bool slotDeletingCheck(const std::shared_ptr<CTradeableItem> & slot);
|
2024-02-29 12:02:39 +02:00
|
|
|
void updateSubtitles();
|
2024-02-03 22:59:05 +02:00
|
|
|
};
|
|
|
|
|
2024-02-27 13:39:50 +02:00
|
|
|
class CResourcesBuying : virtual public CTradeBase
|
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-02-27 13:39:50 +02:00
|
|
|
class CResourcesSelling : virtual public CTradeBase
|
2024-02-19 23:40:43 +02:00
|
|
|
{
|
|
|
|
public:
|
2024-02-27 13:39:50 +02:00
|
|
|
CResourcesSelling(const CTradeableItem::ClickPressedFunctor & clickPressedCallback);
|
2024-02-29 12:02:39 +02:00
|
|
|
void updateSubtitles();
|
2024-02-22 22:49:30 +02:00
|
|
|
};
|