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;
|
|
|
|
|
|
|
|
class CTradeBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const IMarket * market;
|
|
|
|
const CGHeroInstance * hero;
|
|
|
|
|
|
|
|
//all indexes: 1 = left, 0 = right
|
|
|
|
std::array<std::vector<std::shared_ptr<CTradeableItem>>, 2> items;
|
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
|
|
|
|
|
|
|
//highlighted items (nullptr if no highlight)
|
|
|
|
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;
|
|
|
|
|
|
|
|
CTradeBase(const IMarket * market, const CGHeroInstance * hero);
|
|
|
|
void removeItems(const std::set<std::shared_ptr<CTradeableItem>> & toRemove);
|
|
|
|
void removeItem(std::shared_ptr<CTradeableItem> item);
|
|
|
|
void getEmptySlots(std::set<std::shared_ptr<CTradeableItem>> & toRemove);
|
|
|
|
virtual void makeDeal() = 0;
|
|
|
|
virtual void deselect();
|
|
|
|
virtual void onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot, std::shared_ptr<CTradeableItem> & hCurSlot);
|
2024-02-03 22:59:05 +02:00
|
|
|
virtual void updateSlots() {}; // TODO make pure virtual
|
2023-12-04 23:21:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Market subclasses
|
|
|
|
class CExperienceAltar : virtual public CTradeBase, virtual public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::shared_ptr<CLabel> expToLevel;
|
|
|
|
std::shared_ptr<CLabel> expForHero;
|
|
|
|
std::shared_ptr<CButton> sacrificeAllButton;
|
|
|
|
const Point dealButtonPos = Point(269, 520);
|
|
|
|
|
|
|
|
CExperienceAltar();
|
|
|
|
virtual void sacrificeAll() = 0;
|
|
|
|
virtual TExpType calcExpAltarForHero() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CCreaturesSelling : virtual public CTradeBase, virtual public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCreaturesSelling();
|
|
|
|
bool slotDeletingCheck(const std::shared_ptr<CTradeableItem> & slot);
|
|
|
|
void updateSubtitle();
|
2024-02-03 22:59:05 +02:00
|
|
|
void updateSlots() override;
|
|
|
|
};
|
|
|
|
|
2024-02-21 20:48:14 +02:00
|
|
|
class CResourcesBuying : virtual public CTradeBase, virtual public CIntObject
|
2024-02-03 22:59:05 +02:00
|
|
|
{
|
|
|
|
public:
|
2024-02-21 20:48:14 +02:00
|
|
|
CResourcesBuying(TradePanelBase::UpdateSlotsFunctor callback);
|
2024-02-03 22:59:05 +02:00
|
|
|
void updateSubtitles(EMarketMode marketMode);
|
2024-02-19 23:40:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CResourcesSelling : virtual public CTradeBase, virtual public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CResourcesSelling();
|
|
|
|
void updateSlots() override;
|
2023-12-04 23:21:49 +02:00
|
|
|
};
|
2024-02-22 22:49:30 +02:00
|
|
|
|
|
|
|
class CMarketMisc : virtual public CTradeBase, virtual public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
2024-02-25 22:58:53 +02:00
|
|
|
struct SelectionParamOneSide
|
|
|
|
{
|
|
|
|
std::string text;
|
|
|
|
int imageIndex;
|
|
|
|
};
|
|
|
|
using SelectionParams = std::tuple<std::optional<const SelectionParamOneSide>, std::optional<const SelectionParamOneSide>>;
|
2024-02-22 22:49:30 +02:00
|
|
|
using SelectionParamsFunctor = std::function<SelectionParams()>;
|
|
|
|
|
|
|
|
CMarketMisc(SelectionParamsFunctor callback);
|
|
|
|
void deselect() override;
|
|
|
|
void updateSelected();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int bidQty;
|
|
|
|
int offerQty;
|
|
|
|
SelectionParamsFunctor selectionParamsCallback;
|
|
|
|
};
|