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

136 lines
4.6 KiB
C++
Raw Normal View History

/*
* CTradeWindow.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
2023-11-05 00:53:37 +02:00
#include "../widgets/CTradeBase.h"
2023-04-23 14:10:35 +02:00
#include "../widgets/CWindowWithArtifacts.h"
#include "CWindowObject.h"
class CSlider;
class CGStatusBar;
2023-11-05 00:53:37 +02:00
class CTradeWindow : public CTradeBase, public CWindowObject, public CWindowWithArtifacts //base for markets and altar of sacrifice
{
public:
EType itemsType[2];
EMarketMode mode;
std::shared_ptr<CButton> ok;
std::shared_ptr<CButton> max;
std::shared_ptr<CSlider> slider; //for choosing amount to be exchanged
bool readyToTrade;
CTradeWindow(const ImagePath & bgName, const IMarket * Market, const CGHeroInstance * Hero, const std::function<void()> & onWindowClosed, EMarketMode Mode); //c
void showAll(Canvas & to) override;
2023-10-07 01:44:37 +02:00
void close() override;
void initSubs(bool Left);
void initTypes();
void initItems(bool Left);
std::vector<int> *getItemsIds(bool Left); //nullptr if default
void getPositionsFor(std::vector<Rect> &poss, bool Left, EType type) const;
void setMode(EMarketMode Mode); //mode setter
void artifactSelected(CHeroArtPlace *slot); //used when selling artifacts -> called when user clicked on artifact slot
virtual void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const = 0;
virtual void selectionChanged(bool side) = 0; //true == left
virtual Point selectionOffset(bool Left) const = 0;
virtual std::string selectionSubtitle(bool Left) const = 0;
virtual void garrisonChanged() = 0;
virtual void artifactsChanged(bool left) = 0;
protected:
std::function<void()> onWindowClosed;
std::shared_ptr<CGStatusBar> statusBar;
std::vector<std::shared_ptr<CLabel>> labels;
std::vector<std::shared_ptr<CPicture>> images;
std::vector<std::shared_ptr<CButton>> buttons;
std::vector<std::shared_ptr<CTextBox>> texts;
};
class CMarketplaceWindow : public CTradeWindow
{
std::shared_ptr<CLabel> titleLabel;
2023-07-06 20:37:18 +02:00
std::shared_ptr<CArtifactsOfHeroMarket> arts;
bool printButtonFor(EMarketMode M) const;
ImagePath getBackgroundForMode(EMarketMode mode);
public:
int r1, r2; //suggested amounts of traded resources
bool madeTransaction; //if player made at least one transaction
std::shared_ptr<CTextBox> traderText;
void setMax();
void sliderMoved(int to);
2023-11-05 00:53:37 +02:00
void makeDeal() override;
void selectionChanged(bool side) override; //true == left
CMarketplaceWindow(const IMarket * Market, const CGHeroInstance * Hero, const std::function<void()> & onWindowClosed, EMarketMode Mode);
2017-07-17 23:04:00 +02:00
~CMarketplaceWindow();
Point selectionOffset(bool Left) const override;
std::string selectionSubtitle(bool Left) const override;
void garrisonChanged() override; //removes creatures with count 0 from the list (apparently whole stack has been sold)
void artifactsChanged(bool left) override;
void resourceChanged();
void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const override;
void updateTraderText();
};
class CAltarWindow : public CTradeWindow
{
std::shared_ptr<CAnimImage> artIcon;
public:
std::vector<int> sacrificedUnits; //[slot_nr] -> how many creatures from that slot will be sacrificed
std::vector<int> expPerUnit;
std::shared_ptr<CButton> sacrificeAll;
std::shared_ptr<CButton> sacrificeBackpack;
std::shared_ptr<CLabel> expToLevel;
std::shared_ptr<CLabel> expOnAltar;
2023-07-06 20:37:18 +02:00
std::shared_ptr<CArtifactsOfHeroAltar> arts;
CAltarWindow(const IMarket * Market, const CGHeroInstance * Hero, const std::function<void()> & onWindowClosed, EMarketMode Mode);
~CAltarWindow();
void getExpValues();
void selectionChanged(bool side) override; //true == left
2017-08-01 17:17:46 +02:00
void selectOppositeItem(bool side);
void SacrificeAll();
void SacrificeBackpack();
void putOnAltar(int backpackIndex);
bool putOnAltar(std::shared_ptr<CTradeableItem> altarSlot, const CArtifactInstance * art);
2023-11-05 00:53:37 +02:00
void makeDeal() override;
void showAll(Canvas & to) override;
void blockTrade();
void sliderMoved(int to);
void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const override;
void mimicCres();
Point selectionOffset(bool Left) const override;
std::string selectionSubtitle(bool Left) const override;
void garrisonChanged() override;
void artifactsChanged(bool left) override;
void calcTotalExp();
void setExpToLevel();
void updateRight(std::shared_ptr<CTradeableItem> toUpdate);
void artifactPicked();
int firstFreeSlot();
2023-04-23 13:33:47 +02:00
void moveArtToAltar(std::shared_ptr<CTradeableItem>, const CArtifactInstance * art);
};