2014-07-13 16:31:00 +03:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../widgets/CArtifactHolder.h"
|
|
|
|
#include "CWindowObject.h"
|
|
|
|
#include "../../lib/FunctionList.h"
|
2014-07-13 16:31:00 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2014-07-13 16:31:00 +03:00
|
|
|
class IMarket;
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2014-07-15 10:14:49 +03:00
|
|
|
class CSlider;
|
|
|
|
class CTextBox;
|
2022-12-02 18:52:05 +02:00
|
|
|
class CPicture;
|
2018-04-07 13:34:11 +02:00
|
|
|
class CGStatusBar;
|
2014-07-13 16:31:00 +03:00
|
|
|
|
|
|
|
class CTradeWindow : public CWindowObject, public CWindowWithArtifacts //base for markets and altar of sacrifice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum EType
|
|
|
|
{
|
|
|
|
RESOURCE, PLAYER, ARTIFACT_TYPE, CREATURE, CREATURE_PLACEHOLDER, ARTIFACT_PLACEHOLDER, ARTIFACT_INSTANCE
|
|
|
|
};
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
class CTradeableItem : public CIntObject, public std::enable_shared_from_this<CTradeableItem>
|
|
|
|
{
|
|
|
|
std::shared_ptr<CAnimImage> image;
|
2014-07-13 16:31:00 +03:00
|
|
|
std::string getFilename();
|
|
|
|
int getIndex();
|
|
|
|
public:
|
2018-04-07 13:34:11 +02:00
|
|
|
const CArtifactInstance * hlp; //holds ptr to artifact instance id type artifact
|
2014-07-13 16:31:00 +03:00
|
|
|
EType type;
|
|
|
|
int id;
|
|
|
|
const int serial;
|
|
|
|
const bool left;
|
|
|
|
std::string subtitle; //empty if default
|
|
|
|
|
|
|
|
void setType(EType newType);
|
|
|
|
void setID(int newID);
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
const CArtifactInstance * getArtInstance() const;
|
|
|
|
void setArtInstance(const CArtifactInstance * art);
|
2014-07-13 16:31:00 +03:00
|
|
|
|
|
|
|
CFunctionList<void()> callback;
|
|
|
|
bool downSelection;
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void showAllAt(const Point & dstPos, const std::string & customSub, SDL_Surface * to);
|
2014-07-13 16:31:00 +03:00
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
void clickRight(tribool down, bool previousState) override;
|
2018-04-07 13:34:11 +02:00
|
|
|
void hover(bool on) override;
|
2015-10-12 15:47:10 +02:00
|
|
|
void showAll(SDL_Surface * to) override;
|
|
|
|
void clickLeft(tribool down, bool previousState) override;
|
2014-07-13 16:31:00 +03:00
|
|
|
std::string getName(int number = -1) const;
|
|
|
|
CTradeableItem(Point pos, EType Type, int ID, bool Left, int Serial);
|
|
|
|
};
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
const IMarket * market;
|
|
|
|
const CGHeroInstance * hero;
|
2014-07-13 16:31:00 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CArtifactsOfHero> arts;
|
2014-07-13 16:31:00 +03:00
|
|
|
//all indexes: 1 = left, 0 = right
|
2018-04-07 13:34:11 +02:00
|
|
|
std::array<std::vector<std::shared_ptr<CTradeableItem>>, 2> items;
|
|
|
|
|
|
|
|
//highlighted items (nullptr if no highlight)
|
|
|
|
std::shared_ptr<CTradeableItem> hLeft;
|
|
|
|
std::shared_ptr<CTradeableItem> hRight;
|
2014-07-13 16:31:00 +03:00
|
|
|
EType itemsType[2];
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
EMarketMode::EMarketMode mode;
|
|
|
|
std::shared_ptr<CButton> ok;
|
|
|
|
std::shared_ptr<CButton> max;
|
|
|
|
std::shared_ptr<CButton> deal;
|
|
|
|
|
|
|
|
std::shared_ptr<CSlider> slider; //for choosing amount to be exchanged
|
2014-07-13 16:31:00 +03:00
|
|
|
bool readyToTrade;
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CTradeWindow(std::string bgName, const IMarket * Market, const CGHeroInstance * Hero, EMarketMode::EMarketMode Mode); //c
|
2014-07-13 16:31:00 +03:00
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
void showAll(SDL_Surface * to) override;
|
2014-07-13 16:31:00 +03:00
|
|
|
|
|
|
|
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;
|
2018-04-07 13:34:11 +02:00
|
|
|
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);
|
2014-07-13 16:31:00 +03:00
|
|
|
void setMode(EMarketMode::EMarketMode Mode); //mode setter
|
|
|
|
|
2016-11-04 18:54:09 +02:00
|
|
|
void artifactSelected(CHeroArtPlace *slot); //used when selling artifacts -> called when user clicked on artifact slot
|
2014-07-13 16:31:00 +03:00
|
|
|
|
|
|
|
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;
|
2018-04-07 13:34:11 +02:00
|
|
|
protected:
|
|
|
|
std::shared_ptr<CGStatusBar> statusBar;
|
|
|
|
std::vector<std::shared_ptr<CLabel>> labels;
|
2022-12-02 18:52:05 +02:00
|
|
|
std::vector<std::shared_ptr<CPicture>> images;
|
2018-04-07 13:34:11 +02:00
|
|
|
std::vector<std::shared_ptr<CButton>> buttons;
|
|
|
|
std::vector<std::shared_ptr<CTextBox>> texts;
|
2014-07-13 16:31:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CMarketplaceWindow : public CTradeWindow
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CLabel> titleLabel;
|
|
|
|
|
2014-07-13 16:31:00 +03:00
|
|
|
bool printButtonFor(EMarketMode::EMarketMode M) const;
|
|
|
|
|
|
|
|
std::string getBackgroundForMode(EMarketMode::EMarketMode mode);
|
|
|
|
public:
|
|
|
|
int r1, r2; //suggested amounts of traded resources
|
|
|
|
bool madeTransaction; //if player made at least one transaction
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CTextBox> traderText;
|
2014-07-13 16:31:00 +03:00
|
|
|
|
|
|
|
void setMax();
|
|
|
|
void sliderMoved(int to);
|
|
|
|
void makeDeal();
|
2015-10-12 15:47:10 +02:00
|
|
|
void selectionChanged(bool side) override; //true == left
|
2018-04-07 13:34:11 +02:00
|
|
|
CMarketplaceWindow(const IMarket * Market, const CGHeroInstance * Hero = nullptr, EMarketMode::EMarketMode Mode = EMarketMode::RESOURCE_RESOURCE);
|
2017-07-17 23:04:00 +02:00
|
|
|
~CMarketplaceWindow();
|
2014-07-13 16:31:00 +03:00
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
Point selectionOffset(bool Left) const override;
|
|
|
|
std::string selectionSubtitle(bool Left) const override;
|
2014-07-13 16:31:00 +03:00
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
void garrisonChanged() override; //removes creatures with count 0 from the list (apparently whole stack has been sold)
|
|
|
|
void artifactsChanged(bool left) override;
|
2016-11-26 14:14:43 +02:00
|
|
|
void resourceChanged();
|
2014-07-13 16:31:00 +03:00
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const override;
|
2014-07-13 16:31:00 +03:00
|
|
|
void updateTraderText();
|
|
|
|
};
|
|
|
|
|
|
|
|
class CAltarWindow : public CTradeWindow
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CAnimImage> artIcon;
|
2014-07-13 16:31:00 +03:00
|
|
|
public:
|
2018-04-07 13:34:11 +02:00
|
|
|
std::vector<int> sacrificedUnits; //[slot_nr] -> how many creatures from that slot will be sacrificed
|
|
|
|
std::vector<int> expPerUnit;
|
2014-07-13 16:31:00 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CButton> sacrificeAll;
|
|
|
|
std::shared_ptr<CButton> sacrificeBackpack;
|
|
|
|
std::shared_ptr<CLabel> expToLevel;
|
|
|
|
std::shared_ptr<CLabel> expOnAltar;
|
2014-07-13 16:31:00 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CAltarWindow(const IMarket * Market, const CGHeroInstance * Hero, EMarketMode::EMarketMode Mode);
|
|
|
|
~CAltarWindow();
|
2014-07-13 16:31:00 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void getExpValues();
|
2014-07-13 16:31:00 +03:00
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
void selectionChanged(bool side) override; //true == left
|
2017-08-01 17:17:46 +02:00
|
|
|
void selectOppositeItem(bool side);
|
2014-07-13 16:31:00 +03:00
|
|
|
void SacrificeAll();
|
|
|
|
void SacrificeBackpack();
|
|
|
|
|
|
|
|
void putOnAltar(int backpackIndex);
|
2018-04-07 13:34:11 +02:00
|
|
|
bool putOnAltar(std::shared_ptr<CTradeableItem> altarSlot, const CArtifactInstance * art);
|
2014-07-13 16:31:00 +03:00
|
|
|
void makeDeal();
|
2015-10-12 15:47:10 +02:00
|
|
|
void showAll(SDL_Surface * to) override;
|
2014-07-13 16:31:00 +03:00
|
|
|
|
|
|
|
void blockTrade();
|
|
|
|
void sliderMoved(int to);
|
2015-10-12 15:47:10 +02:00
|
|
|
void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const override;
|
2014-07-13 16:31:00 +03:00
|
|
|
void mimicCres();
|
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
Point selectionOffset(bool Left) const override;
|
|
|
|
std::string selectionSubtitle(bool Left) const override;
|
|
|
|
void garrisonChanged() override;
|
|
|
|
void artifactsChanged(bool left) override;
|
2014-07-13 16:31:00 +03:00
|
|
|
void calcTotalExp();
|
|
|
|
void setExpToLevel();
|
2018-04-07 13:34:11 +02:00
|
|
|
void updateRight(std::shared_ptr<CTradeableItem> toUpdate);
|
2014-07-13 16:31:00 +03:00
|
|
|
|
|
|
|
void artifactPicked();
|
|
|
|
int firstFreeSlot();
|
2018-04-07 13:34:11 +02:00
|
|
|
void moveFromSlotToAltar(ArtifactPosition slotID, std::shared_ptr<CTradeableItem>, const CArtifactInstance * art);
|
2014-07-13 16:31:00 +03:00
|
|
|
};
|