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
|
|
|
|
|
|
|
class IMarket;
|
2014-07-15 10:14:49 +03:00
|
|
|
class CSlider;
|
|
|
|
class CTextBox;
|
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
|
|
|
|
};
|
|
|
|
class CTradeableItem : public CIntObject
|
|
|
|
{
|
|
|
|
CAnimImage * image;
|
|
|
|
|
|
|
|
std::string getFilename();
|
|
|
|
int getIndex();
|
|
|
|
public:
|
|
|
|
const CArtifactInstance *hlp; //holds ptr to artifact instance id type artifact
|
|
|
|
EType type;
|
|
|
|
int id;
|
|
|
|
const int serial;
|
|
|
|
const bool left;
|
|
|
|
std::string subtitle; //empty if default
|
|
|
|
|
|
|
|
void setType(EType newType);
|
|
|
|
void setID(int newID);
|
|
|
|
|
|
|
|
const CArtifactInstance *getArtInstance() const;
|
|
|
|
void setArtInstance(const CArtifactInstance *art);
|
|
|
|
|
|
|
|
CFunctionList<void()> callback;
|
|
|
|
bool downSelection;
|
|
|
|
|
|
|
|
void showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to);
|
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
void clickRight(tribool down, bool previousState) override;
|
|
|
|
void hover (bool on) override;
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
const IMarket *market;
|
|
|
|
const CGHeroInstance *hero;
|
|
|
|
|
|
|
|
CArtifactsOfHero *arts;
|
|
|
|
//all indexes: 1 = left, 0 = right
|
|
|
|
std::vector<CTradeableItem*> items[2];
|
|
|
|
CTradeableItem *hLeft, *hRight; //highlighted items (nullptr if no highlight)
|
|
|
|
EType itemsType[2];
|
|
|
|
|
|
|
|
EMarketMode::EMarketMode mode;//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
|
2014-08-03 14:16:19 +03:00
|
|
|
CButton *ok, *max, *deal;
|
2014-07-13 16:31:00 +03:00
|
|
|
CSlider *slider; //for choosing amount to be exchanged
|
|
|
|
bool readyToTrade;
|
|
|
|
|
|
|
|
CTradeWindow(std::string bgName, const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode); //c
|
|
|
|
|
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;
|
|
|
|
void removeItems(const std::set<CTradeableItem *> &toRemove);
|
|
|
|
void removeItem(CTradeableItem * t);
|
|
|
|
void getEmptySlots(std::set<CTradeableItem *> &toRemove);
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CMarketplaceWindow : public CTradeWindow
|
|
|
|
{
|
|
|
|
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
|
|
|
|
CTextBox *traderText;
|
|
|
|
|
|
|
|
void setMax();
|
|
|
|
void sliderMoved(int to);
|
|
|
|
void makeDeal();
|
2015-10-12 15:47:10 +02:00
|
|
|
void selectionChanged(bool side) override; //true == left
|
2017-07-17 23:04:00 +02:00
|
|
|
CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = nullptr, EMarketMode::EMarketMode Mode = EMarketMode::RESOURCE_RESOURCE);
|
|
|
|
~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
|
|
|
|
{
|
|
|
|
CAnimImage * artIcon;
|
|
|
|
public:
|
2017-07-17 23:04:00 +02:00
|
|
|
CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode);
|
2014-07-13 16:31:00 +03:00
|
|
|
|
|
|
|
void getExpValues();
|
2017-07-17 23:04:00 +02:00
|
|
|
~CAltarWindow();
|
2014-07-13 16:31:00 +03:00
|
|
|
|
|
|
|
std::vector<int> sacrificedUnits, //[slot_nr] -> how many creatures from that slot will be sacrificed
|
|
|
|
expPerUnit;
|
|
|
|
|
2014-08-03 14:16:19 +03:00
|
|
|
CButton *sacrificeAll, *sacrificeBackpack;
|
2014-07-13 16:31:00 +03:00
|
|
|
CLabel *expToLevel, *expOnAltar;
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
bool putOnAltar(CTradeableItem* altarSlot, const CArtifactInstance *art);
|
|
|
|
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();
|
|
|
|
void updateRight(CTradeableItem *toUpdate);
|
|
|
|
|
|
|
|
void artifactPicked();
|
|
|
|
int firstFreeSlot();
|
|
|
|
void moveFromSlotToAltar(ArtifactPosition slotID, CTradeableItem* altarSlot, const CArtifactInstance *art);
|
|
|
|
};
|