1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-18 17:40:48 +02:00
vcmi/client/GUIClasses.h

496 lines
14 KiB
C
Raw Normal View History

#pragma once
#include "../lib/GameConstants.h"
#include "../lib/ResourceSet.h"
#include "../lib/CConfigHandler.h"
#include "gui/CArtifactHolder.h"
#include "gui/CGarrisonInt.h"
#include "CAnimation.h"
/*
* GUIClasses.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
*
*/
struct ArtifactLocation;
class CStackBasicDescriptor;
class CBonusSystemNode;
class CArtifact;
class CDefEssential;
class CAdventureMapButton;
class CHighlightableButtonsGroup;
class CDefHandler;
struct HeroMoveDetails;
class CDefEssential;
class CGHeroInstance;
class CAdvMapInt;
class CCastleInterface;
class CBattleInterface;
class CStack;
class CComponent;
class CCreature;
struct SDL_Surface;
struct CPath;
class CCreatureAnim;
class CSelectableComponent;
class CCreatureSet;
class CGObjectInstance;
class CGDwelling;
class CSlider;
struct UpgradeInfo;
template <typename T> struct CondSh;
class CInGameConsole;
class CGarrisonInt;
class CInGameConsole;
struct Component;
class CArmedInstance;
class CGTownInstance;
class StackState;
class CPlayerInterface;
2009-06-18 18:05:00 +03:00
class CHeroWindow;
class CArtifact;
class CArtifactsOfHero;
2012-01-30 19:07:52 +03:00
class CCreatureArtifactSet;
2009-08-31 18:57:15 +03:00
class CResDataBar;
struct SPuzzleInfo;
class CGGarrison;
class CStackInstance;
2010-05-18 10:01:54 +03:00
class IMarket;
class CTextBox;
2010-12-29 23:04:22 +02:00
class CArtifactInstance;
class IBonusBearer;
class CArtPlace;
class CAnimImage;
struct InfoAboutArmy;
struct InfoAboutHero;
struct InfoAboutTown;
class CCreaturePic;
class MoraleLuckBox;
class CHeroArea;
class CMinorResDataBar;
class CComponentBox;
/// Recruitment window where you can recruit creatures
class CRecruitmentWindow : public CWindowObject
{
class CCreatureCard : public CIntObject
{
CRecruitmentWindow * parent;
CCreaturePic *pic; //creature's animation
bool selected;
void clickLeft(tribool down, bool previousState);
void clickRight(tribool down, bool previousState);
void showAll(SDL_Surface *to);
public:
const CCreature * creature;
si32 amount;
void select(bool on);
CCreatureCard(CRecruitmentWindow * window, const CCreature *crea, int totalAmount);
};
/// small class to display creature costs
class CCostBox : public CIntObject
{
std::map<int, std::pair<CLabel *, CAnimImage * > > resources;
public:
//res - resources to show
void set(TResources res);
//res - visible resources
CCostBox(Rect position, std::string title);
void createItems(TResources res);
};
std::function<void(CreatureID,int)> onRecruit; //void (int ID, int amount) <-- call to recruit creatures
int level;
const CArmedInstance *dst;
CCreatureCard * selected;
std::vector<CCreatureCard *> cards;
CSlider *slider; //for selecting amount
CAdventureMapButton *maxButton, *buyButton, *cancelButton;
//labels for visible values
CLabel * title;
CLabel * availableValue;
CLabel * toRecruitValue;
CCostBox * costPerTroopValue;
CCostBox * totalCostValue;
void select(CCreatureCard * card);
void buy();
void sliderMoved(int to);
void showAll(SDL_Surface *to);
public:
const CGDwelling * const dwelling;
CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const std::function<void(CreatureID,int)> & Recruit, int y_offset = 0); //creatures - pairs<creature_ID,amount> //c-tor
void availableCreaturesChanged();
};
/// Split window where creatures can be split up into two single unit stacks
class CSplitWindow : public CWindowObject
{
std::function<void(int, int)> callback;
int leftAmount;
int rightAmount;
int leftMin;
int rightMin;
CSlider *slider;
CCreaturePic *animLeft, *animRight; //creature's animation
CAdventureMapButton *ok, *cancel;
CTextInput *leftInput, *rightInput;
void setAmountText(std::string text, bool left);
void setAmount(int value, bool left);
void sliderMoved(int value);
void apply();
public:
/**
* creature - displayed creature
* callback(leftAmount, rightAmount) - function to call on close
* leftMin, rightMin - minimal amount of creatures in each stack
* leftAmount, rightAmount - amount of creatures in each stack
*/
CSplitWindow(const CCreature * creature, std::function<void(int, int)> callback,
int leftMin, int rightMin, int leftAmount, int rightAmount);
};
/// Raised up level windowe where you can select one out of two skills
class CLevelWindow : public CWindowObject
{
CComponentBox * box; //skills to select
std::function<void(ui32)> cb;
void selectionChanged(unsigned to);
public:
CLevelWindow(const CGHeroInstance *hero, PrimarySkill::PrimarySkill pskill, std::vector<SecondarySkill> &skills, std::function<void(ui32)> callback); //c-tor
~CLevelWindow(); //d-tor
};
/// Town portal, castle gate window
class CObjectListWindow : public CWindowObject
{
class CItem : public CIntObject
{
CObjectListWindow *parent;
CLabel *text;
CPicture *border;
public:
const size_t index;
CItem(CObjectListWindow *parent, size_t id, std::string text);
void select(bool on);
void clickLeft(tribool down, bool previousState);
};
std::function<void(int)> onSelect;//called when OK button is pressed, returns id of selected item.
CLabel * title;
CLabel * descr;
CListBox * list;
CIntObject * titleImage;//title image (castle gate\town portal picture)
CAdventureMapButton *ok, *exit;
std::vector< std::pair<int, std::string> > items;//all items present in list
void init(CIntObject * titlePic, std::string _title, std::string _descr);
public:
size_t selected;//index of currently selected item
/// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
/// Image can be nullptr
///item names will be taken from map objects
CObjectListWindow(const std::vector<int> &_items, CIntObject * titlePic, std::string _title, std::string _descr,
std::function<void(int)> Callback);
CObjectListWindow(const std::vector<std::string> &_items, CIntObject * titlePic, std::string _title, std::string _descr,
std::function<void(int)> Callback);
CIntObject *genItem(size_t index);
void elementSelected();//call callback and close this window
void changeSelection(size_t which);
void keyPressed (const SDL_KeyboardEvent & key);
};
class CSystemOptionsWindow : public CWindowObject
{
private:
CLabel *title;
CLabelGroup *leftGroup;
CLabelGroup *rightGroup;
CAdventureMapButton *load, *save, *restart, *mainMenu, *quitGame, *backToMap; //load and restart are not used yet
CHighlightableButtonsGroup * heroMoveSpeed;
CHighlightableButtonsGroup * mapScrollSpeed;
CHighlightableButtonsGroup * musicVolume, * effectsVolume;
//CHighlightableButton * showPath;
CHighlightableButton * showReminder;
CHighlightableButton * quickCombat;
CHighlightableButton * spellbookAnim;
CHighlightableButton * newCreatureWin;
CHighlightableButton * fullscreen;
CAdventureMapButton *gameResButton;
CLabel *gameResLabel;
SettingsListener onFullscreenChanged;
void setMusicVolume( int newVolume );
void setSoundVolume( int newVolume );
void setHeroMoveSpeed( int newSpeed );
void setMapScrollingSpeed( int newSpeed );
//functions bound to buttons
void bloadf(); //load game
void bsavef(); //save game
void bquitf(); //quit game
void breturnf(); //return to game
void brestartf(); //restart game
void bmainmenuf(); //return to main menu
//functions for checkboxes
void toggleReminder(bool on);
void toggleQuickCombat(bool on);
void toggleSpellbookAnim(bool on);
void toggleCreatureWin(bool on);
void toggleFullscreen(bool on);
void selectGameRes();
void setGameRes(int index);
void closeAndPushEvent(int eventType, int code = 0);
public:
CSystemOptionsWindow(); //c-tor
};
class CTavernWindow : public CWindowObject
{
public:
class HeroPortrait : public CIntObject
{
public:
std::string hoverName;
std::string description; // "XXX is a level Y ZZZ with N artifacts"
const CGHeroInstance *h;
2010-07-09 02:03:27 +03:00
void clickLeft(tribool down, bool previousState);
void clickRight(tribool down, bool previousState);
void hover (bool on);
HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
private:
int *_sel;
const int _id;
2010-07-09 02:03:27 +03:00
} *h1, *h2; //recruitable heroes
CGStatusBar *bar; //tavern's internal status bar
int selected;//0 (left) or 1 (right)
int oldSelected;//0 (left) or 1 (right)
CAdventureMapButton *thiefGuild, *cancel, *recruit;
2010-07-09 02:03:27 +03:00
const CGObjectInstance *tavernObj;
2010-07-09 02:03:27 +03:00
CTavernWindow(const CGObjectInstance *TavernObj); //c-tor
~CTavernWindow(); //d-tor
void recruitb();
2010-01-31 20:41:22 +02:00
void thievesguildb();
void show(SDL_Surface * to);
};
class CExchangeWindow : public CWindowObject, public CWindowWithGarrison, public CWindowWithArtifacts
{
CGStatusBar * ourBar; //internal statusbar
CAdventureMapButton * quit, * questlogButton[2];
std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
MoraleLuckBox *morale[2], *luck[2];
LRClickableAreaWText *specialty[2];
LRClickableAreaWText *experience[2];
LRClickableAreaWText *spellPoints[2];
CHeroArea *portrait[2];
public:
const CGHeroInstance* heroInst[2];
CArtifactsOfHero * artifs[2];
void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
void prepareBackground(); //prepares or redraws bg
CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID queryID); //c-tor
~CExchangeWindow(); //d-tor
};
/// Here you can buy ships
class CShipyardWindow : public CWindowObject
{
public:
CGStatusBar *bar;
CPicture *bgWater;
CLabel *title;
CLabel *costLabel;
CAnimImage *woodPic, *goldPic;
CLabel *woodCost, *goldCost;
CAnimImage *bgShip;
CAdventureMapButton *build, *quit;
CGStatusBar * statusBar;
CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const std::function<void()> &onBuy);
};
/// Puzzle screen which gets uncovered when you visit obilisks
class CPuzzleWindow : public CWindowObject
2009-08-31 18:57:15 +03:00
{
private:
int3 grailPos;
CAdventureMapButton * quitb;
2009-08-31 18:57:15 +03:00
std::vector<CPicture * > piecesToRemove;
ui8 currentAlpha;
2009-08-31 18:57:15 +03:00
public:
void showAll(SDL_Surface * to);
2009-08-31 18:57:15 +03:00
void show(SDL_Surface * to);
CPuzzleWindow(const int3 &grailPos, double discoveredRatio);
2009-08-31 18:57:15 +03:00
};
/// Creature transformer window
class CTransformerWindow : public CWindowObject, public CGarrisonHolder
2010-07-03 15:00:53 +03:00
{
public:
class CItem : public CIntObject
{
public:
int id;//position of creature in hero army
bool left;//position of the item
int size; //size of creature stack
CTransformerWindow * parent;
CAnimImage *icon;
2010-07-03 15:00:53 +03:00
void move();
void clickLeft(tribool down, bool previousState);
void update();
CItem(CTransformerWindow * parent, int size, int id);
2010-07-03 15:00:53 +03:00
};
const CArmedInstance *army;//object with army for transforming (hero or town)
const CGHeroInstance *hero;//only if we have hero in town
const CGTownInstance *town;//market, town garrison is used if hero == nullptr
2010-07-03 15:00:53 +03:00
std::vector<CItem*> items;
CAdventureMapButton *all, *convert, *cancel;
CGStatusBar *bar;
2010-07-03 15:00:53 +03:00
void makeDeal();
void addAll();
void updateGarrisons();
2010-07-03 15:00:53 +03:00
CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town); //c-tor
};
class CUniversityWindow : public CWindowObject
{
class CItem : public CAnimImage
{
public:
int ID;//id of selected skill
CUniversityWindow * parent;
void showAll(SDL_Surface * to);
void clickLeft(tribool down, bool previousState);
void clickRight(tribool down, bool previousState);
void hover(bool on);
int state();//0=can't learn, 1=learned, 2=can learn
CItem(CUniversityWindow * _parent, int _ID, int X, int Y);
};
public:
const CGHeroInstance *hero;
const IMarket * market;
CPicture * green, * yellow, * red;//colored bars near skills
std::vector<CItem*> items;
CAdventureMapButton *cancel;
CGStatusBar *bar;
CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market); //c-tor
};
/// Confirmation window for University
class CUnivConfirmWindow : public CWindowObject
{
public:
CUniversityWindow * parent;
CGStatusBar *bar;
CAdventureMapButton *confirm, *cancel;
CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available); //c-tor
void makeDeal(int skill);
};
/// Hill fort is the building where you can upgrade units
class CHillFortWindow : public CWindowObject, public CWindowWithGarrison
{
public:
int slotsCount;//=7;
CGStatusBar * bar;
CDefEssential *resources;
CHeroArea *heroPic;//clickable hero image
CAdventureMapButton *quit,//closes window
*upgradeAll,//upgrade all creatures
*upgrade[7];//upgrade single creature
const CGObjectInstance * fort;
const CGHeroInstance * hero;
std::vector<int> currState;//current state of slot - to avoid calls to getState or updating buttons
std::vector<TResources> costs;// costs [slot ID] [resource ID] = resource count for upgrade
TResources totalSumm; // totalSum[resource ID] = value
CHillFortWindow(const CGHeroInstance *visitor, const CGObjectInstance *object); //c-tor
void showAll (SDL_Surface *to);
2013-02-16 17:03:47 +03:00
std::string getDefForSlot(SlotID slot);//return def name for this slot
std::string getTextForSlot(SlotID slot);//return hover text for this slot
void makeDeal(SlotID slot);//-1 for upgrading all creatures
int getState(SlotID slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade
void updateGarrisons();//update buttons after garrison changes
};
class CThievesGuildWindow : public CWindowObject
2010-01-31 20:41:22 +02:00
{
2010-02-01 19:51:33 +02:00
const CGObjectInstance * owner;
2010-07-09 02:03:27 +03:00
CGStatusBar * statusBar;
CAdventureMapButton * exitb;
2010-02-04 20:40:40 +02:00
CMinorResDataBar * resdatabar;
2010-01-31 20:41:22 +02:00
public:
2010-02-01 19:51:33 +02:00
CThievesGuildWindow(const CGObjectInstance * _owner);
2010-01-31 20:41:22 +02:00
};