2011-12-14 00:23:17 +03:00
# pragma once
2012-05-13 18:04:21 +03:00
# include "CAnimation.h"
2013-11-30 13:08:38 +03:00
# include "../lib/FunctionList.h"
2011-07-05 09:14:07 +03:00
# include "../lib/ResourceSet.h"
2012-09-30 13:35:17 +03:00
# include "../lib/CConfigHandler.h"
2011-12-14 00:23:17 +03:00
# include "../lib/GameConstants.h"
2013-04-07 14:52:07 +03:00
# include "gui/CIntObject.h"
# include "gui/CIntObjectClasses.h"
2013-02-07 02:24:43 +03:00
# include "../lib/GameConstants.h"
2009-05-19 21:23:04 +03:00
# ifdef max
# undef max
# endif
# ifdef min
# undef min
# endif
/*
* 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
*
*/
2011-01-06 22:00:19 +02:00
struct ArtifactLocation ;
2010-12-06 01:10:02 +02:00
class CStackBasicDescriptor ;
2010-08-02 17:29:30 +03:00
class CBonusSystemNode ;
class CArtifact ;
2009-05-19 21:23:04 +03:00
class CDefEssential ;
2011-12-22 16:05:19 +03:00
class CAdventureMapButton ;
2009-05-19 21:23:04 +03:00
class CHighlightableButtonsGroup ;
class CDefHandler ;
struct HeroMoveDetails ;
class CDefEssential ;
class CGHeroInstance ;
class CAdvMapInt ;
class CCastleInterface ;
class CBattleInterface ;
class CStack ;
2011-12-22 16:05:19 +03:00
class CComponent ;
2009-05-19 21:23:04 +03:00
class CCreature ;
struct SDL_Surface ;
struct CPath ;
2010-11-15 17:15:00 +02:00
class CCreatureAnim ;
2009-05-19 21:23:04 +03:00
class CSelectableComponent ;
class CCreatureSet ;
class CGObjectInstance ;
2009-07-26 13:43:22 +03:00
class CGDwelling ;
2009-05-19 21:23:04 +03:00
class CSlider ;
struct UpgradeInfo ;
template < typename T > struct CondSh ;
class CInGameConsole ;
class CGarrisonInt ;
class CInGameConsole ;
2010-10-31 00:53:41 +03:00
struct Component ;
2009-05-19 21:23:04 +03:00
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 ;
2010-03-21 00:17:19 +02:00
class CGGarrison ;
2010-05-02 21:20:26 +03:00
class CStackInstance ;
2010-05-18 10:01:54 +03:00
class IMarket ;
2010-07-06 05:10:26 +03:00
class CTextBox ;
2010-12-29 23:04:22 +02:00
class CArtifactInstance ;
2011-02-27 21:58:14 +02:00
class IBonusBearer ;
2011-04-23 00:51:10 +03:00
class CArtPlace ;
2011-09-23 18:58:18 +03:00
class CAnimImage ;
2012-06-13 16:04:06 +03:00
struct InfoAboutArmy ;
struct InfoAboutHero ;
struct InfoAboutTown ;
2009-05-19 21:23:04 +03:00
2011-02-22 13:52:36 +02:00
/// text + comp. + ok button
2012-01-12 18:23:00 +03:00
class CInfoWindow : public CSimpleWindow
2009-05-19 21:23:04 +03:00
{ //window able to delete its components when closed
2010-07-15 06:04:57 +03:00
bool delComps ; //whether comps will be deleted
2009-05-19 21:23:04 +03:00
public :
2011-03-12 23:55:31 +02:00
typedef std : : vector < std : : pair < std : : string , CFunctionList < void ( ) > > > TButtonsInfo ;
2011-12-22 16:05:19 +03:00
typedef std : : vector < CComponent * > TCompsInfo ;
2013-05-27 13:53:28 +03:00
QueryID ID ; //for identification
2010-07-06 05:10:26 +03:00
CTextBox * text ;
2011-12-22 16:05:19 +03:00
std : : vector < CAdventureMapButton * > buttons ;
std : : vector < CComponent * > components ;
2010-07-15 06:04:57 +03:00
CSlider * slider ;
2010-07-06 05:10:26 +03:00
2010-07-15 06:04:57 +03:00
void setDelComps ( bool DelComps ) ;
2009-05-19 21:23:04 +03:00
virtual void close ( ) ;
2010-07-15 06:04:57 +03:00
2009-08-17 11:50:31 +03:00
void show ( SDL_Surface * to ) ;
void showAll ( SDL_Surface * to ) ;
2010-07-15 06:04:57 +03:00
void sliderMoved ( int to ) ;
2013-03-03 20:06:03 +03:00
CInfoWindow ( std : : string Text , PlayerColor player , const TCompsInfo & comps = TCompsInfo ( ) , const TButtonsInfo & Buttons = TButtonsInfo ( ) , bool delComps = true ) ; //c-tor
2009-05-19 21:23:04 +03:00
CInfoWindow ( ) ; //c-tor
~ CInfoWindow ( ) ; //d-tor
2009-11-13 21:04:36 +02:00
2013-10-21 00:53:27 +03:00
//use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
static void showInfoDialog ( const std : : string & text , const std : : vector < CComponent * > * components , bool DelComps = true , PlayerColor player = PlayerColor ( 1 ) ) ;
2014-08-04 21:33:59 +03:00
static void showOkDialog ( const std : : string & text , const std : : vector < CComponent * > * components , const std : : function < void ( ) > & onOk , bool delComps = true , PlayerColor player = PlayerColor ( 1 ) ) ;
2013-10-21 00:53:27 +03:00
static void showYesNoDialog ( const std : : string & text , const std : : vector < CComponent * > * components , const CFunctionList < void ( ) > & onYes , const CFunctionList < void ( ) > & onNo , bool DelComps = true , PlayerColor player = PlayerColor ( 1 ) ) ;
2013-06-26 14:18:27 +03:00
static CInfoWindow * create ( const std : : string & text , PlayerColor playerID = PlayerColor ( 1 ) , const std : : vector < CComponent * > * components = nullptr , bool DelComps = false ) ;
2012-12-11 15:12:46 +03:00
/// create text from title and description: {title}\n\n description
static std : : string genText ( std : : string title , std : : string description ) ;
2009-05-19 21:23:04 +03:00
} ;
2011-02-22 13:52:36 +02:00
/// component selection window
2012-01-12 18:23:00 +03:00
class CSelWindow : public CInfoWindow
2009-05-19 21:23:04 +03:00
{ //warning - this window deletes its components by closing!
public :
void selectionChange ( unsigned to ) ;
void madeChoice ( ) ; //looks for selected component and calls callback
2013-05-27 13:53:28 +03:00
CSelWindow ( const std : : string & text , PlayerColor player , int charperline , const std : : vector < CSelectableComponent * > & comps , const std : : vector < std : : pair < std : : string , CFunctionList < void ( ) > > > & Buttons , QueryID askID ) ; //c-tor
2009-05-19 21:23:04 +03:00
CSelWindow ( ) { } ; //c-tor
//notification - this class inherits important destructor from CInfoWindow
} ;
2011-02-22 13:52:36 +02:00
/// popup displayed on R-click
2012-01-12 18:23:00 +03:00
class CRClickPopup : public CIntObject
2009-05-19 21:23:04 +03:00
{
public :
virtual void close ( ) ;
2009-08-11 19:05:33 +03:00
void clickRight ( tribool down , bool previousState ) ;
2010-03-21 00:17:19 +02:00
CRClickPopup ( ) ;
virtual ~ CRClickPopup ( ) ; //d-tor
2012-06-13 16:04:06 +03:00
static CIntObject * createInfoWin ( Point position , const CGObjectInstance * specific ) ;
2011-03-12 23:55:31 +02:00
static void createAndPush ( const std : : string & txt , const CInfoWindow : : TCompsInfo & comps = CInfoWindow : : TCompsInfo ( ) ) ;
2012-12-11 15:12:46 +03:00
static void createAndPush ( const std : : string & txt , CComponent * component ) ;
2011-12-22 16:05:19 +03:00
static void createAndPush ( const CGObjectInstance * obj , const Point & p , EAlignment alignment = BOTTOMRIGHT ) ;
2009-05-19 21:23:04 +03:00
} ;
2011-02-22 13:52:36 +02:00
/// popup displayed on R-click
2012-01-12 18:23:00 +03:00
class CRClickPopupInt : public CRClickPopup
2009-05-19 21:23:04 +03:00
{
public :
2011-12-17 21:59:59 +03:00
IShowActivatable * inner ;
2009-05-19 21:23:04 +03:00
bool delInner ;
void show ( SDL_Surface * to ) ;
2011-01-28 04:11:58 +02:00
void showAll ( SDL_Surface * to ) ;
2011-12-17 21:59:59 +03:00
CRClickPopupInt ( IShowActivatable * our , bool deleteInt ) ; //c-tor
2009-05-19 21:23:04 +03:00
virtual ~ CRClickPopupInt ( ) ; //d-tor
} ;
class CInfoPopup : public CRClickPopup
{
public :
bool free ; //TODO: comment me
SDL_Surface * bitmap ; //popup background
void close ( ) ;
void show ( SDL_Surface * to ) ;
2009-05-22 02:50:45 +03:00
CInfoPopup ( SDL_Surface * Bitmap , int x , int y , bool Free = false ) ; //c-tor
2011-12-22 16:05:19 +03:00
CInfoPopup ( SDL_Surface * Bitmap , const Point & p , EAlignment alignment , bool Free = false ) ; //c-tor
2013-06-26 14:18:27 +03:00
CInfoPopup ( SDL_Surface * Bitmap = nullptr , bool Free = false ) ; //default c-tor
2010-03-21 00:17:19 +02:00
void init ( int x , int y ) ;
2009-10-22 06:12:01 +03:00
~ CInfoPopup ( ) ; //d-tor
2009-05-19 21:23:04 +03:00
} ;
2012-06-13 16:04:06 +03:00
/// popup on adventure map for town\hero objects
class CInfoBoxPopup : public CWindowObject
{
Point toScreen ( Point pos ) ;
public :
CInfoBoxPopup ( Point position , const CGTownInstance * town ) ;
CInfoBoxPopup ( Point position , const CGHeroInstance * hero ) ;
CInfoBoxPopup ( Point position , const CGGarrison * garr ) ;
} ;
2011-02-22 13:52:36 +02:00
/// common popup window component
2011-12-22 16:05:19 +03:00
class CComponent : public virtual CIntObject
2009-05-19 21:23:04 +03:00
{
2012-07-03 00:51:48 +03:00
public :
enum Etype
{
2012-07-21 23:16:54 +03:00
primskill , secskill , resource , creature , artifact , experience , spell , morale , luck , building , hero , flag , typeInvalid
2012-07-07 16:32:37 +03:00
} ;
//NOTE: not all types have exact these sizes or have less than 4 of them. In such cases closest one will be used
enum ESize
{
tiny , // ~22-24px
small , // ~30px
medium , // ~42px
2012-07-21 23:16:54 +03:00
large , // ~82px
sizeInvalid
2012-07-03 00:51:48 +03:00
} ;
private :
2012-05-13 18:04:21 +03:00
size_t getIndex ( ) ;
2012-07-07 16:32:37 +03:00
const std : : vector < std : : string > getFileName ( ) ;
2012-07-03 00:51:48 +03:00
void setSurface ( std : : string defName , int imgPos ) ;
std : : string getSubtitleInternal ( ) ;
2012-07-07 16:32:37 +03:00
void init ( Etype Type , int Subtype , int Val , ESize imageSize ) ;
2012-05-13 18:04:21 +03:00
2012-07-07 16:32:37 +03:00
public :
2012-05-13 18:04:21 +03:00
CAnimImage * image ; //our image
2012-07-03 00:51:48 +03:00
Etype compType ; //component type
2012-07-07 16:32:37 +03:00
ESize size ; //component size.
2012-07-03 00:51:48 +03:00
int subtype ; //type-dependant subtype. See getSomething methods for details
int val ; // value \ strength \ amount of component. See getSomething methods for details
bool perDay ; // add "per day" text to subtitle
2009-05-19 21:23:04 +03:00
2012-07-03 00:51:48 +03:00
std : : string getDescription ( ) ;
std : : string getSubtitle ( ) ;
2009-05-19 21:23:04 +03:00
2012-12-11 15:12:46 +03:00
CComponent ( Etype Type , int Subtype , int Val = 0 , ESize imageSize = large ) ; //c-tor
2011-12-22 16:05:19 +03:00
CComponent ( const Component & c ) ; //c-tor
2009-05-19 21:23:04 +03:00
2009-08-11 19:05:33 +03:00
void clickRight ( tribool down , bool previousState ) ; //call-in
2009-05-19 21:23:04 +03:00
} ;
2012-07-03 00:51:48 +03:00
/// component that can be selected or deselected
2011-12-22 16:05:19 +03:00
class CSelectableComponent : public CComponent , public CKeyShortcut
2009-05-19 21:23:04 +03:00
{
2012-07-03 00:51:48 +03:00
void init ( ) ;
2009-05-19 21:23:04 +03:00
public :
bool selected ; //if true, this component is selected
2013-06-26 14:18:27 +03:00
std : : function < void ( ) > onSelect ; //function called on selection change
2009-05-19 21:23:04 +03:00
2012-07-03 00:51:48 +03:00
void showAll ( SDL_Surface * to ) ;
void select ( bool on ) ;
2009-08-11 19:05:33 +03:00
void clickLeft ( tribool down , bool previousState ) ; //call-in
2013-07-02 15:08:30 +03:00
CSelectableComponent ( Etype Type , int Sub , int Val , ESize imageSize = large , std : : function < void ( ) > OnSelect = nullptr ) ; //c-tor
CSelectableComponent ( const Component & c , std : : function < void ( ) > OnSelect = nullptr ) ; //c-tor
2012-07-03 00:51:48 +03:00
} ;
/// box with multiple components (up to 8?)
/// will take ownership on components and delete them afterwards
class CComponentBox : public CIntObject
{
std : : vector < CComponent * > components ;
CSelectableComponent * selected ;
2013-06-26 14:18:27 +03:00
std : : function < void ( int newID ) > onSelect ;
2012-07-03 00:51:48 +03:00
void selectionChanged ( CSelectableComponent * newSelection ) ;
2012-07-07 16:32:37 +03:00
//get position of "or" text between these comps
//it will place "or" equidistant to both images
Point getOrTextPos ( CComponent * left , CComponent * right ) ;
//get distance between these copmonents
int getDistance ( CComponent * left , CComponent * right ) ;
2012-07-03 00:51:48 +03:00
void placeComponents ( bool selectable ) ;
public :
/// return index of selected item
int selectedIndex ( ) ;
/// constructor for quite common 1-components popups
/// if position width or height are 0 then it will be determined automatically
CComponentBox ( CComponent * components , Rect position ) ;
/// constructor for non-selectable components
CComponentBox ( std : : vector < CComponent * > components , Rect position ) ;
/// constructor for selectable components
/// will also create "or" labels between components
/// onSelect - optional function that will be called every time on selection change
2013-07-02 15:08:30 +03:00
CComponentBox ( std : : vector < CSelectableComponent * > components , Rect position , std : : function < void ( int newID ) > onSelect = nullptr ) ;
2009-05-19 21:23:04 +03:00
} ;
2011-11-27 16:14:20 +03:00
////////////////////////////////////////////////////////////////////////////////
2012-06-13 16:04:06 +03:00
/// base class for hero/town/garrison tooltips
class CArmyTooltip : public CIntObject
{
void init ( const InfoAboutArmy & army ) ;
public :
CArmyTooltip ( Point pos , const InfoAboutArmy & army ) ;
CArmyTooltip ( Point pos , const CArmedInstance * army ) ;
} ;
/// Class for hero tooltip. Does not have any background!
/// background for infoBox: ADSTATHR
/// background for tooltip: HEROQVBK
class CHeroTooltip : public CArmyTooltip
{
void init ( const InfoAboutHero & hero ) ;
public :
CHeroTooltip ( Point pos , const InfoAboutHero & hero ) ;
CHeroTooltip ( Point pos , const CGHeroInstance * hero ) ;
} ;
/// Class for town tooltip. Does not have any background!
/// background for infoBox: ADSTATCS
/// background for tooltip: TOWNQVBK
class CTownTooltip : public CArmyTooltip
{
void init ( const InfoAboutTown & town ) ;
public :
CTownTooltip ( Point pos , const InfoAboutTown & town ) ;
CTownTooltip ( Point pos , const CGTownInstance * town ) ;
} ;
///////////////////////////////////////////////////////////////////////////////
2011-11-27 16:14:20 +03:00
2009-05-19 21:23:04 +03:00
class CGarrisonInt ;
2011-02-22 13:52:36 +02:00
/// A single garrison slot which holds one creature of a specific amount
2009-08-11 19:05:33 +03:00
class CGarrisonSlot : public CIntObject
2009-05-19 21:23:04 +03:00
{
2013-02-16 17:03:47 +03:00
SlotID ID ; //for identification
2009-05-19 21:23:04 +03:00
CGarrisonInt * owner ;
2013-06-26 14:18:27 +03:00
const CStackInstance * myStack ; //nullptr if slot is empty
2010-05-02 21:20:26 +03:00
const CCreature * creature ;
2009-05-19 21:23:04 +03:00
int upg ; //0 - up garrison, 1 - down garrison
2012-08-06 10:34:37 +03:00
CAnimImage * creatureImage ;
2012-12-11 15:12:46 +03:00
CAnimImage * selectionImage ; // image for selection, not always visible
CLabel * stackCount ;
void setHighlight ( bool on ) ;
2012-08-06 10:34:37 +03:00
public :
2009-05-19 21:23:04 +03:00
virtual void hover ( bool on ) ; //call-in
2012-12-11 15:12:46 +03:00
const CArmedInstance * getObj ( ) const ;
bool our ( ) const ;
2009-08-11 19:05:33 +03:00
void clickRight ( tribool down , bool previousState ) ;
void clickLeft ( tribool down , bool previousState ) ;
2012-12-11 15:12:46 +03:00
void update ( ) ;
2013-06-26 14:18:27 +03:00
CGarrisonSlot ( CGarrisonInt * Owner , int x , int y , SlotID IID , int Upg = 0 , const CStackInstance * Creature = nullptr ) ;
2012-08-06 10:34:37 +03:00
friend class CGarrisonInt ;
2009-05-19 21:23:04 +03:00
} ;
2011-02-22 13:52:36 +02:00
/// Class which manages slots of upper and lower garrison, splitting of units
2009-05-19 21:23:04 +03:00
class CGarrisonInt : public CIntObject
{
2012-12-11 15:12:46 +03:00
CGarrisonSlot * highlighted ; //chosen slot. Should be changed only via selectSlot
bool inSplittingMode ;
2009-05-19 21:23:04 +03:00
public :
2012-12-11 15:12:46 +03:00
void selectSlot ( CGarrisonSlot * slot ) ; //null = deselect
const CGarrisonSlot * getSelection ( ) ;
void setSplittingMode ( bool on ) ;
bool getSplittingMode ( ) ;
2009-06-28 11:21:50 +03:00
int interx ; //space between slots
2011-12-22 16:05:19 +03:00
Point garOffset ; //offset between garrisons (not used if only one hero)
std : : vector < CAdventureMapButton * > splitButtons ; //may be empty if no buttons
2009-05-19 21:23:04 +03:00
2013-02-16 17:03:47 +03:00
SlotID p2 ; //TODO: comment me
int shiftPos ; //1st slot of the second row, set shiftPoint for effect
2012-12-11 15:12:46 +03:00
bool pb ,
2010-08-12 18:54:25 +03:00
smallIcons , //true - 32x32 imgs, false - 58x64
2010-08-17 18:16:08 +03:00
removableUnits , //player can remove units from up
2010-08-12 18:54:25 +03:00
twoRows , //slots will be placed in 2 rows
2011-02-05 15:39:10 +02:00
owned [ 2 ] ; //player owns up or down army [0] upper, [1] lower
2009-05-19 21:23:04 +03:00
2011-02-05 15:39:10 +02:00
// const CCreatureSet *set1; //top set of creatures
// const CCreatureSet *set2; //bottom set of creatures
2009-05-19 21:23:04 +03:00
2010-08-27 19:20:35 +03:00
std : : vector < CGarrisonSlot * > slotsUp , slotsDown ; //slots of upper and lower garrison
2011-02-05 15:39:10 +02:00
const CArmedInstance * armedObjs [ 2 ] ; //[0] is upper, [1] is down
//const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
2009-05-19 21:23:04 +03:00
2011-02-05 15:39:10 +02:00
void setArmy ( const CArmedInstance * army , bool bottomGarrison ) ;
2011-12-22 16:05:19 +03:00
void addSplitBtn ( CAdventureMapButton * button ) ;
2010-08-27 19:20:35 +03:00
void createSet ( std : : vector < CGarrisonSlot * > & ret , const CCreatureSet * set , int posX , int distance , int posY , int Upg ) ;
2012-01-12 18:23:00 +03:00
2009-05-19 21:23:04 +03:00
void createSlots ( ) ;
void recreateSlots ( ) ;
void splitClick ( ) ; //handles click on split button
2012-06-13 16:04:06 +03:00
void splitStacks ( int amountLeft , int amountRight ) ; //TODO: comment me
2011-04-23 13:27:44 +03:00
//x, y - position;
//inx - distance between slots;
//pomsur, SurOffset - UNUSED
//s1, s2 - top and bottom armies;
//removableUnits - you can take units from top;
//smallImgs - units images size 64x58 or 32x32;
2012-06-13 16:04:06 +03:00
//twoRows - display slots in 2 row (1st row = 4 slots, 2nd = 3 slots)
2013-06-26 14:18:27 +03:00
CGarrisonInt ( int x , int y , int inx , const Point & garsOffset , SDL_Surface * pomsur , const Point & SurOffset , const CArmedInstance * s1 , const CArmedInstance * s2 = nullptr , bool _removableUnits = true , bool smallImgs = false , bool _twoRows = false ) ; //c-tor
2009-05-19 21:23:04 +03:00
} ;
2011-02-22 13:52:36 +02:00
/// draws picture with creature on background, use Animated=true to get animation
2012-01-12 18:23:00 +03:00
class CCreaturePic : public CIntObject
2009-05-19 21:23:04 +03:00
{
2010-11-15 17:15:00 +02:00
private :
2012-06-15 20:08:19 +03:00
CPicture * bg ;
2010-11-15 17:15:00 +02:00
CCreatureAnim * anim ; //displayed animation
2012-01-12 18:23:00 +03:00
2010-11-15 17:15:00 +02:00
public :
CCreaturePic ( int x , int y , const CCreature * cre , bool Big = true , bool Animated = true ) ; //c-tor
2009-05-19 21:23:04 +03:00
} ;
2011-02-22 13:52:36 +02:00
/// Recruitment window where you can recruit creatures
2012-06-15 20:08:19 +03:00
class CRecruitmentWindow : public CWindowObject
2009-05-19 21:23:04 +03:00
{
2012-06-22 14:40:16 +03:00
class CCreatureCard : public CIntObject
2009-05-19 21:23:04 +03:00
{
2012-06-22 14:40:16 +03:00
CRecruitmentWindow * parent ;
2009-05-19 21:23:04 +03:00
CCreaturePic * pic ; //creature's animation
2012-06-22 14:40:16 +03:00
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 ) ;
2009-05-19 21:23:04 +03:00
} ;
2013-06-26 14:18:27 +03:00
std : : function < void ( CreatureID , int ) > onRecruit ; //void (int ID, int amount) <-- call to recruit creatures
2012-06-22 14:40:16 +03:00
2009-07-26 13:43:22 +03:00
int level ;
const CArmedInstance * dst ;
2012-06-22 14:40:16 +03:00
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 ( ) ;
2009-05-19 21:23:04 +03:00
void sliderMoved ( int to ) ;
2012-06-22 14:40:16 +03:00
void showAll ( SDL_Surface * to ) ;
public :
const CGDwelling * const dwelling ;
2013-06-26 14:18:27 +03:00
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
2012-06-22 14:40:16 +03:00
void availableCreaturesChanged ( ) ;
2009-05-19 21:23:04 +03:00
} ;
2013-02-07 20:34:50 +03:00
/// Split window where creatures can be split up into two single unit stacks
2012-06-13 16:04:06 +03:00
class CSplitWindow : public CWindowObject
2009-05-19 21:23:04 +03:00
{
2013-06-26 14:18:27 +03:00
std : : function < void ( int , int ) > callback ;
2012-06-13 16:04:06 +03:00
int leftAmount ;
int rightAmount ;
int leftMin ;
int rightMin ;
2009-05-19 21:23:04 +03:00
CSlider * slider ;
2010-11-15 17:15:00 +02:00
CCreaturePic * animLeft , * animRight ; //creature's animation
2011-12-22 16:05:19 +03:00
CAdventureMapButton * ok , * cancel ;
2009-05-19 21:23:04 +03:00
2012-06-13 16:04:06 +03:00
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
*/
2013-06-26 14:18:27 +03:00
CSplitWindow ( const CCreature * creature , std : : function < void ( int , int ) > callback ,
2012-06-13 16:04:06 +03:00
int leftMin , int rightMin , int leftAmount , int rightAmount ) ;
2009-05-19 21:23:04 +03:00
} ;
2011-02-22 13:52:36 +02:00
/// Raised up level windowe where you can select one out of two skills
2012-06-15 20:08:19 +03:00
class CLevelWindow : public CWindowObject
2009-05-19 21:23:04 +03:00
{
2012-07-07 16:32:37 +03:00
CComponentBox * box ; //skills to select
2013-06-26 14:18:27 +03:00
std : : function < void ( ui32 ) > cb ;
2009-05-19 21:23:04 +03:00
2012-07-07 16:32:37 +03:00
void selectionChanged ( unsigned to ) ;
public :
2013-06-26 14:18:27 +03:00
CLevelWindow ( const CGHeroInstance * hero , PrimarySkill : : PrimarySkill pskill , std : : vector < SecondarySkill > & skills , std : : function < void ( ui32 ) > callback ) ; //c-tor
2009-05-19 21:23:04 +03:00
~ CLevelWindow ( ) ; //d-tor
2012-07-07 16:32:37 +03:00
2009-05-19 21:23:04 +03:00
} ;
2011-02-22 13:52:36 +02:00
/// Resource bar like that at the bottom of the adventure map screen
2009-08-11 19:05:33 +03:00
class CMinorResDataBar : public CIntObject
2009-05-19 21:23:04 +03:00
{
public :
SDL_Surface * bg ; //background bitmap
void show ( SDL_Surface * to ) ;
2010-11-15 17:15:00 +02:00
void showAll ( SDL_Surface * to ) ;
2009-05-19 21:23:04 +03:00
CMinorResDataBar ( ) ; //c-tor
~ CMinorResDataBar ( ) ; //d-tor
} ;
2011-02-22 13:52:36 +02:00
/// Town portal, castle gate window
2012-06-15 20:08:19 +03:00
class CObjectListWindow : public CWindowObject
2010-06-26 13:01:26 +03:00
{
2012-01-12 18:23:00 +03:00
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 ) ;
} ;
2010-06-26 13:01:26 +03:00
2013-06-26 14:18:27 +03:00
std : : function < void ( int ) > onSelect ; //called when OK button is pressed, returns id of selected item.
2012-01-12 18:23:00 +03:00
CLabel * title ;
CLabel * descr ;
2010-06-26 13:01:26 +03:00
2014-03-10 19:00:58 +03:00
CListBox * list ;
CIntObject * titleImage ; //title image (castle gate\town portal picture)
2011-12-22 16:05:19 +03:00
CAdventureMapButton * ok , * exit ;
2010-06-26 13:01:26 +03:00
2012-01-12 18:23:00 +03:00
std : : vector < std : : pair < int , std : : string > > items ; //all items present in list
2010-06-26 13:01:26 +03:00
2014-03-10 19:00:58 +03:00
void init ( CIntObject * titlePic , std : : string _title , std : : string _descr ) ;
2012-01-12 18:23:00 +03:00
public :
size_t selected ; //index of currently selected item
2010-06-26 13:01:26 +03:00
/// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
2013-06-26 14:18:27 +03:00
/// Image can be nullptr
2012-01-12 18:23:00 +03:00
///item names will be taken from map objects
2014-03-10 19:00:58 +03:00
CObjectListWindow ( const std : : vector < int > & _items , CIntObject * titlePic , std : : string _title , std : : string _descr ,
2013-06-26 14:18:27 +03:00
std : : function < void ( int ) > Callback ) ;
2014-03-10 19:00:58 +03:00
CObjectListWindow ( const std : : vector < std : : string > & _items , CIntObject * titlePic , std : : string _title , std : : string _descr ,
2013-06-26 14:18:27 +03:00
std : : function < void ( int ) > Callback ) ;
2010-06-26 13:01:26 +03:00
2012-01-12 18:23:00 +03:00
CIntObject * genItem ( size_t index ) ;
void elementSelected ( ) ; //call callback and close this window
void changeSelection ( size_t which ) ;
void keyPressed ( const SDL_KeyboardEvent & key ) ;
2010-06-26 13:01:26 +03:00
} ;
2012-06-15 20:08:19 +03:00
class CArtifactHolder
2011-04-30 21:16:58 +03:00
{
public :
CArtifactHolder ( ) ;
virtual void artifactRemoved ( const ArtifactLocation & artLoc ) = 0 ;
virtual void artifactMoved ( const ArtifactLocation & artLoc , const ArtifactLocation & destLoc ) = 0 ;
virtual void artifactDisassembled ( const ArtifactLocation & artLoc ) = 0 ;
virtual void artifactAssembled ( const ArtifactLocation & artLoc ) = 0 ;
} ;
class CWindowWithArtifacts : public CArtifactHolder
2011-01-28 04:11:58 +02:00
{
public :
std : : vector < CArtifactsOfHero * > artSets ;
2011-04-30 21:16:58 +03:00
void artifactRemoved ( const ArtifactLocation & artLoc ) ;
void artifactMoved ( const ArtifactLocation & artLoc , const ArtifactLocation & destLoc ) ;
void artifactDisassembled ( const ArtifactLocation & artLoc ) ;
void artifactAssembled ( const ArtifactLocation & artLoc ) ;
2011-01-28 04:11:58 +02:00
} ;
2012-06-15 20:08:19 +03:00
class CTradeWindow : public CWindowObject , public CWindowWithArtifacts //base for markets and altar of sacrifice
2009-05-19 21:23:04 +03:00
{
public :
2010-05-08 01:10:32 +03:00
enum EType
{
2010-12-29 23:04:22 +02:00
RESOURCE , PLAYER , ARTIFACT_TYPE , CREATURE , CREATURE_PLACEHOLDER , ARTIFACT_PLACEHOLDER , ARTIFACT_INSTANCE
2010-05-08 01:10:32 +03:00
} ;
2009-08-11 19:05:33 +03:00
class CTradeableItem : public CIntObject
2009-05-19 21:23:04 +03:00
{
2012-12-20 16:57:29 +03:00
CAnimImage * image ;
std : : string getFilename ( ) ;
int getIndex ( ) ;
2009-05-19 21:23:04 +03:00
public :
2012-12-20 16:57:29 +03:00
const CArtifactInstance * hlp ; //holds ptr to artifact instance id type artifact
2010-05-26 12:47:53 +03:00
EType type ;
2012-01-12 18:23:00 +03:00
int id ;
2012-12-20 16:57:29 +03:00
const int serial ;
const bool left ;
2010-07-20 09:05:45 +03:00
std : : string subtitle ; //empty if default
2012-12-20 16:57:29 +03:00
void setType ( EType newType ) ;
void setID ( int newID ) ;
2010-12-29 23:04:22 +02:00
const CArtifactInstance * getArtInstance ( ) const ;
2011-04-23 00:51:10 +03:00
void setArtInstance ( const CArtifactInstance * art ) ;
2010-12-29 23:04:22 +02:00
2009-05-19 21:23:04 +03:00
CFunctionList < void ( ) > callback ;
2010-07-20 09:05:45 +03:00
bool downSelection ;
2009-05-19 21:23:04 +03:00
2011-12-22 16:05:19 +03:00
void showAllAt ( const Point & dstPos , const std : : string & customSub , SDL_Surface * to ) ;
2010-07-20 09:05:45 +03:00
void clickRight ( tribool down , bool previousState ) ;
void hover ( bool on ) ;
void showAll ( SDL_Surface * to ) ;
2009-08-11 19:05:33 +03:00
void clickLeft ( tribool down , bool previousState ) ;
2010-07-31 04:38:12 +03:00
std : : string getName ( int number = - 1 ) const ;
2012-12-23 13:23:41 +03:00
CTradeableItem ( Point pos , EType Type , int ID , bool Left , int Serial ) ;
2009-05-19 21:23:04 +03:00
} ;
2010-05-18 10:01:54 +03:00
const IMarket * market ;
2010-05-26 12:47:53 +03:00
const CGHeroInstance * hero ;
2010-07-20 09:05:45 +03:00
CArtifactsOfHero * arts ;
//all indexes: 1 = left, 0 = right
std : : vector < CTradeableItem * > items [ 2 ] ;
2013-06-26 14:18:27 +03:00
CTradeableItem * hLeft , * hRight ; //highlighted items (nullptr if no highlight)
2010-07-20 09:05:45 +03:00
EType itemsType [ 2 ] ;
2009-05-19 21:23:04 +03:00
2011-12-14 00:23:17 +03:00
EMarketMode : : EMarketMode mode ; //0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
2011-12-22 16:05:19 +03:00
CAdventureMapButton * ok , * max , * deal ;
2009-05-19 21:23:04 +03:00
CSlider * slider ; //for choosing amount to be exchanged
2010-05-26 12:47:53 +03:00
bool readyToTrade ;
2009-05-19 21:23:04 +03:00
2012-06-15 20:08:19 +03:00
CTradeWindow ( std : : string bgName , const IMarket * Market , const CGHeroInstance * Hero , EMarketMode : : EMarketMode Mode ) ; //c
2010-07-20 09:05:45 +03:00
2010-05-26 12:47:53 +03:00
void showAll ( SDL_Surface * to ) ;
2010-07-20 09:05:45 +03:00
void initSubs ( bool Left ) ;
void initTypes ( ) ;
void initItems ( bool Left ) ;
2013-06-26 14:18:27 +03:00
std : : vector < int > * getItemsIds ( bool Left ) ; //nullptr if default
2011-12-22 16:05:19 +03:00
void getPositionsFor ( std : : vector < Rect > & poss , bool Left , EType type ) const ;
2010-07-20 09:05:45 +03:00
void removeItems ( const std : : set < CTradeableItem * > & toRemove ) ;
void removeItem ( CTradeableItem * t ) ;
void getEmptySlots ( std : : set < CTradeableItem * > & toRemove ) ;
2011-12-14 00:23:17 +03:00
void setMode ( EMarketMode : : EMarketMode Mode ) ; //mode setter
2010-07-20 09:05:45 +03:00
2011-04-23 00:51:10 +03:00
void artifactSelected ( CArtPlace * slot ) ; //used when selling artifacts -> called when user clicked on artifact slot
2010-07-20 09:05:45 +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
2011-12-22 16:05:19 +03:00
virtual Point selectionOffset ( bool Left ) const = 0 ;
2010-07-20 09:05:45 +03:00
virtual std : : string selectionSubtitle ( bool Left ) const = 0 ;
2012-01-12 18:23:00 +03:00
virtual void garrisonChanged ( ) = 0 ;
2010-07-20 09:05:45 +03:00
virtual void artifactsChanged ( bool left ) = 0 ;
} ;
class CMarketplaceWindow : public CTradeWindow
{
2011-12-14 00:23:17 +03:00
bool printButtonFor ( EMarketMode : : EMarketMode M ) const ;
2012-06-15 20:08:19 +03:00
std : : string getBackgroundForMode ( EMarketMode : : EMarketMode mode ) ;
2010-07-20 09:05:45 +03:00
public :
int r1 , r2 ; //suggested amounts of traded resources
2010-07-31 04:38:12 +03:00
bool madeTransaction ; //if player made at least one transaction
CTextBox * traderText ;
2010-07-20 09:05:45 +03:00
2009-05-19 21:23:04 +03:00
void setMax ( ) ;
void sliderMoved ( int to ) ;
void makeDeal ( ) ;
void selectionChanged ( bool side ) ; //true == left
2013-06-26 14:18:27 +03:00
CMarketplaceWindow ( const IMarket * Market , const CGHeroInstance * Hero = nullptr , EMarketMode : : EMarketMode Mode = EMarketMode : : RESOURCE_RESOURCE ) ; //c-tor
2009-05-19 21:23:04 +03:00
~ CMarketplaceWindow ( ) ; //d-tor
2010-05-08 01:10:32 +03:00
2011-12-22 16:05:19 +03:00
Point selectionOffset ( bool Left ) const ;
2010-07-20 09:05:45 +03:00
std : : string selectionSubtitle ( bool Left ) const ;
2010-05-26 12:47:53 +03:00
void garrisonChanged ( ) ; //removes creatures with count 0 from the list (apparently whole stack has been sold)
2010-06-27 19:03:01 +03:00
void artifactsChanged ( bool left ) ;
2010-07-20 09:05:45 +03:00
void resourceChanged ( int type , int val ) ;
void getBaseForPositions ( EType type , int & dx , int & dy , int & x , int & y , int & h , int & w , bool Right , int & leftToRightOffset ) const ;
2010-07-31 04:38:12 +03:00
void updateTraderText ( ) ;
2010-07-20 09:05:45 +03:00
} ;
class CAltarWindow : public CTradeWindow
{
2012-12-23 13:23:41 +03:00
CAnimImage * artIcon ;
2010-07-20 09:05:45 +03:00
public :
2011-12-14 00:23:17 +03:00
CAltarWindow ( const IMarket * Market , const CGHeroInstance * Hero , EMarketMode : : EMarketMode Mode ) ; //c-tor
2010-07-20 09:05:45 +03:00
void getExpValues ( ) ;
~ CAltarWindow ( ) ; //d-tor
std : : vector < int > sacrificedUnits , //[slot_nr] -> how many creatures from that slot will be sacrificed
expPerUnit ;
2011-12-22 16:05:19 +03:00
CAdventureMapButton * sacrificeAll , * sacrificeBackpack ;
2010-07-20 09:05:45 +03:00
CLabel * expToLevel , * expOnAltar ;
void selectionChanged ( bool side ) ; //true == left
void SacrificeAll ( ) ;
void SacrificeBackpack ( ) ;
2010-07-23 15:02:15 +03:00
void putOnAltar ( int backpackIndex ) ;
2011-01-15 04:17:56 +02:00
bool putOnAltar ( CTradeableItem * altarSlot , const CArtifactInstance * art ) ;
2010-07-20 09:05:45 +03:00
void makeDeal ( ) ;
2010-07-23 15:02:15 +03:00
void showAll ( SDL_Surface * to ) ;
2010-07-20 09:05:45 +03:00
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 ;
void mimicCres ( ) ;
2011-12-22 16:05:19 +03:00
Point selectionOffset ( bool Left ) const ;
2010-07-20 09:05:45 +03:00
std : : string selectionSubtitle ( bool Left ) const ;
2012-01-12 18:23:00 +03:00
void garrisonChanged ( ) ;
2010-07-20 09:05:45 +03:00
void artifactsChanged ( bool left ) ;
void calcTotalExp ( ) ;
void setExpToLevel ( ) ;
void updateRight ( CTradeableItem * toUpdate ) ;
2010-07-23 15:02:15 +03:00
void artifactPicked ( ) ;
int firstFreeSlot ( ) ;
2013-02-12 22:49:40 +03:00
void moveFromSlotToAltar ( ArtifactPosition slotID , CTradeableItem * altarSlot , const CArtifactInstance * art ) ;
2009-05-19 21:23:04 +03:00
} ;
2012-06-15 20:08:19 +03:00
class CSystemOptionsWindow : public CWindowObject
2009-05-19 21:23:04 +03:00
{
private :
2012-01-12 18:23:00 +03:00
CLabel * title ;
CLabelGroup * leftGroup ;
CLabelGroup * rightGroup ;
2011-12-22 16:05:19 +03:00
CAdventureMapButton * load , * save , * restart , * mainMenu , * quitGame , * backToMap ; //load and restart are not used yet
2009-05-19 21:23:04 +03:00
CHighlightableButtonsGroup * heroMoveSpeed ;
CHighlightableButtonsGroup * mapScrollSpeed ;
CHighlightableButtonsGroup * musicVolume , * effectsVolume ;
2012-01-12 18:23:00 +03:00
//CHighlightableButton * showPath;
CHighlightableButton * showReminder ;
2013-06-23 10:54:33 +03:00
CHighlightableButton * quickCombat ;
2013-10-27 16:05:01 +03:00
CHighlightableButton * spellbookAnim ;
2012-01-12 18:23:00 +03:00
CHighlightableButton * newCreatureWin ;
CHighlightableButton * fullscreen ;
CAdventureMapButton * gameResButton ;
2012-09-29 18:10:56 +03:00
CLabel * gameResLabel ;
2012-01-12 18:23:00 +03:00
2012-09-30 13:35:17 +03:00
SettingsListener onFullscreenChanged ;
2012-01-12 18:23:00 +03:00
void setMusicVolume ( int newVolume ) ;
void setSoundVolume ( int newVolume ) ;
void setHeroMoveSpeed ( int newSpeed ) ;
void setMapScrollingSpeed ( int newSpeed ) ;
2009-05-19 21:23:04 +03:00
//functions bound to buttons
2012-04-09 05:53:50 +03:00
void bloadf ( ) ; //load game
2009-05-19 21:23:04 +03:00
void bsavef ( ) ; //save game
void bquitf ( ) ; //quit game
void breturnf ( ) ; //return to game
2012-04-09 05:53:50 +03:00
void brestartf ( ) ; //restart game
2009-11-01 03:15:16 +02:00
void bmainmenuf ( ) ; //return to main menu
2012-01-12 18:23:00 +03:00
//functions for checkboxes
void toggleReminder ( bool on ) ;
2013-06-23 10:54:33 +03:00
void toggleQuickCombat ( bool on ) ;
2013-10-27 16:05:01 +03:00
void toggleSpellbookAnim ( bool on ) ;
2012-01-12 18:23:00 +03:00
void toggleCreatureWin ( bool on ) ;
void toggleFullscreen ( bool on ) ;
2012-05-18 20:35:46 +03:00
void selectGameRes ( ) ;
void setGameRes ( int index ) ;
2012-09-11 17:25:19 +03:00
void closeAndPushEvent ( int eventType , int code = 0 ) ;
2009-05-19 21:23:04 +03:00
2012-01-12 18:23:00 +03:00
public :
2012-06-15 20:08:19 +03:00
CSystemOptionsWindow ( ) ; //c-tor
2009-05-19 21:23:04 +03:00
} ;
2012-06-15 20:08:19 +03:00
class CTavernWindow : public CWindowObject
2009-05-19 21:23:04 +03:00
{
public :
2009-08-11 19:05:33 +03:00
class HeroPortrait : public CIntObject
2009-05-19 21:23:04 +03:00
{
public :
std : : string hoverName ;
2014-02-27 00:20:36 +03:00
std : : string description ; // "XXX is a level Y ZZZ with N artifacts"
2009-05-19 21:23:04 +03:00
const CGHeroInstance * h ;
2010-07-09 02:03:27 +03:00
2009-08-11 19:05:33 +03:00
void clickLeft ( tribool down , bool previousState ) ;
void clickRight ( tribool down , bool previousState ) ;
2009-05-19 21:23:04 +03:00
void hover ( bool on ) ;
HeroPortrait ( int & sel , int id , int x , int y , const CGHeroInstance * H ) ;
2011-12-14 00:23:17 +03:00
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
2009-05-19 21:23:04 +03:00
int selected ; //0 (left) or 1 (right)
2009-05-30 19:17:44 +03:00
int oldSelected ; //0 (left) or 1 (right)
2009-05-19 21:23:04 +03:00
2011-12-22 16:05:19 +03:00
CAdventureMapButton * thiefGuild , * cancel , * recruit ;
2010-07-09 02:03:27 +03:00
const CGObjectInstance * tavernObj ;
2009-05-19 21:23:04 +03:00
2010-07-09 02:03:27 +03:00
CTavernWindow ( const CGObjectInstance * TavernObj ) ; //c-tor
2009-05-19 21:23:04 +03:00
~ CTavernWindow ( ) ; //d-tor
void recruitb ( ) ;
2010-01-31 20:41:22 +02:00
void thievesguildb ( ) ;
2009-05-19 21:23:04 +03:00
void show ( SDL_Surface * to ) ;
} ;
2009-08-11 19:05:33 +03:00
class CInGameConsole : public CIntObject
2009-05-19 21:23:04 +03:00
{
private :
2013-11-07 15:48:41 +03:00
std : : list < std : : pair < std : : string , int > > texts ; //list<text to show, time of add>
2009-06-09 06:53:29 +03:00
boost : : mutex texts_mx ; // protects texts
2009-05-19 21:23:04 +03:00
std : : vector < std : : string > previouslyEntered ; //previously entered texts, for up/down arrows to work
int prevEntDisp ; //displayed entry from previouslyEntered - if none it's -1
int defaultTimeout ; //timeout for new texts (in ms)
int maxDisplayedTexts ; //hiw many texts can be displayed simultaneously
public :
std : : string enteredText ;
void show ( SDL_Surface * to ) ;
void print ( const std : : string & txt ) ;
void keyPressed ( const SDL_KeyboardEvent & key ) ; //call-in
2014-07-02 18:16:05 +03:00
# ifndef VCMI_SDL1
void textInputed ( const SDL_TextInputEvent & event ) override ;
void textEdited ( const SDL_TextEditingEvent & event ) override ;
# endif // VCMI_SDL1
2009-05-19 21:23:04 +03:00
void startEnteringText ( ) ;
void endEnteringText ( bool printEnteredText ) ;
void refreshEnteredText ( ) ;
CInGameConsole ( ) ; //c-tor
} ;
2011-02-22 13:52:36 +02:00
/// Can interact on left and right mouse clicks
2010-07-13 08:25:40 +03:00
class LRClickableAreaWTextComp : public LRClickableAreaWText
2009-06-18 18:05:00 +03:00
{
public :
int baseType ;
2010-07-13 08:25:40 +03:00
int bonusValue , type ;
2009-08-11 19:05:33 +03:00
virtual void clickLeft ( tribool down , bool previousState ) ;
2011-03-12 23:55:31 +02:00
virtual void clickRight ( tribool down , bool previousState ) ;
2010-12-17 00:32:53 +02:00
2011-12-22 16:05:19 +03:00
LRClickableAreaWTextComp ( const Rect & Pos = Rect ( 0 , 0 , 0 , 0 ) , int BaseType = - 1 ) ;
CComponent * createComponent ( ) const ;
2009-06-18 18:05:00 +03:00
} ;
2010-02-07 17:06:14 +02:00
class MoraleLuckBox : public LRClickableAreaWTextComp
{
2012-05-13 18:04:21 +03:00
CAnimImage * image ;
2010-02-07 17:06:14 +02:00
public :
2010-07-13 08:25:40 +03:00
bool morale ; //true if morale, false if luck
2011-04-30 21:16:58 +03:00
bool small ;
2012-01-12 18:23:00 +03:00
2011-02-27 21:58:14 +02:00
void set ( const IBonusBearer * node ) ;
2010-07-13 08:25:40 +03:00
2011-12-22 16:05:19 +03:00
MoraleLuckBox ( bool Morale , const Rect & r , bool Small = false ) ;
2010-02-07 17:06:14 +02:00
} ;
2011-02-22 13:52:36 +02:00
/// Opens hero window by left-clicking on it
2010-07-22 03:32:45 +03:00
class CHeroArea : public CIntObject
2010-02-04 17:50:59 +02:00
{
const CGHeroInstance * hero ;
2012-12-10 17:28:27 +03:00
public :
2012-01-12 18:23:00 +03:00
2010-07-22 03:32:45 +03:00
CHeroArea ( int x , int y , const CGHeroInstance * _hero ) ;
2012-01-12 18:23:00 +03:00
2010-02-04 17:50:59 +02:00
void clickLeft ( tribool down , bool previousState ) ;
void clickRight ( tribool down , bool previousState ) ;
2010-07-22 03:32:45 +03:00
void hover ( bool on ) ;
2010-02-04 17:50:59 +02:00
} ;
2011-02-22 13:52:36 +02:00
/// Opens town screen by left-clicking on it
2010-02-04 17:50:59 +02:00
class LRClickableAreaOpenTown : public LRClickableAreaWTextComp
{
public :
const CGTownInstance * town ;
void clickLeft ( tribool down , bool previousState ) ;
void clickRight ( tribool down , bool previousState ) ;
2010-12-17 00:32:53 +02:00
LRClickableAreaOpenTown ( ) ;
2010-02-04 17:50:59 +02:00
} ;
2011-02-22 13:52:36 +02:00
/// Artifacts can be placed there. Gets shown at the hero window
2009-08-11 19:05:33 +03:00
class CArtPlace : public LRClickableAreaWTextComp
2009-06-18 18:05:00 +03:00
{
2012-12-14 18:32:53 +03:00
CAnimImage * image ;
CAnimImage * selection ;
2009-06-18 18:05:00 +03:00
2012-12-14 18:32:53 +03:00
void createImage ( ) ;
public :
// consider these members as const - change them only with appropriate methods e.g. lockSlot()
bool locked ;
2011-01-15 04:17:56 +02:00
bool picked ;
2009-11-28 21:55:40 +02:00
bool marked ;
2012-12-14 18:32:53 +03:00
2013-02-12 22:49:40 +03:00
ArtifactPosition slotID ; //Arts::EPOS enum + backpack starting from Arts::BACKPACK_START
2012-12-14 18:32:53 +03:00
void lockSlot ( bool on ) ;
void pickSlot ( bool on ) ;
void selectSlot ( bool on ) ;
2009-06-18 18:05:00 +03:00
CArtifactsOfHero * ourOwner ;
2012-12-14 18:32:53 +03:00
const CArtifactInstance * ourArt ; // should be changed only with setArtifact()
2010-12-29 23:04:22 +02:00
2013-06-26 14:18:27 +03:00
CArtPlace ( Point position , const CArtifactInstance * Art = nullptr ) ; //c-tor
2009-08-11 19:05:33 +03:00
void clickLeft ( tribool down , bool previousState ) ;
void clickRight ( tribool down , bool previousState ) ;
2009-11-28 21:55:40 +02:00
void select ( ) ;
void deselect ( ) ;
2010-07-23 15:02:15 +03:00
void showAll ( SDL_Surface * to ) ;
2010-12-29 23:04:22 +02:00
bool fitsHere ( const CArtifactInstance * art ) const ; //returns true if given artifact can be placed here
void setMeAsDest ( bool backpackAsVoid = true ) ;
2011-01-15 04:17:56 +02:00
void setArtifact ( const CArtifactInstance * art ) ;
2009-06-18 18:05:00 +03:00
} ;
2011-02-22 13:52:36 +02:00
/// Contains artifacts of hero. Distincts which artifacts are worn or backpacked
2009-08-11 19:05:33 +03:00
class CArtifactsOfHero : public CIntObject
2009-06-18 18:05:00 +03:00
{
2011-02-27 21:58:14 +02:00
const CGHeroInstance * curHero ;
2009-06-18 18:05:00 +03:00
std : : vector < CArtPlace * > artWorn ; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
std : : vector < CArtPlace * > backpack ; //hero's visible backpack (only 5 elements!)
2010-02-08 23:17:22 +02:00
int backpackPos ; //number of first art visible in backpack (in hero's vector)
2009-06-18 18:05:00 +03:00
public :
2009-07-26 18:37:27 +03:00
struct SCommonPart
{
2011-01-06 22:00:19 +02:00
struct Artpos
{
2013-02-12 22:49:40 +03:00
ArtifactPosition slotID ;
2012-01-30 19:07:52 +03:00
const CArtifactsOfHero * AOH ;
2011-01-06 22:00:19 +02:00
const CArtifactInstance * art ;
Artpos ( ) ;
void clear ( ) ;
void setTo ( const CArtPlace * place , bool dontTakeBackpack ) ;
2011-01-18 20:56:14 +02:00
bool valid ( ) ;
2011-01-06 22:00:19 +02:00
bool operator = = ( const ArtifactLocation & al ) const ;
} src , dst ;
2009-11-28 21:55:40 +02:00
std : : set < CArtifactsOfHero * > participants ; // Needed to mark slots.
2010-07-20 21:34:32 +03:00
void reset ( ) ;
2009-07-26 18:37:27 +03:00
} * commonInfo ; //when we have more than one CArtifactsOfHero in one window with exchange possibility, we use this (eg. in exchange window); to be provided externally
2010-02-08 23:17:22 +02:00
bool updateState ; // Whether the commonInfo should be updated on setHero or not.
2011-12-22 16:05:19 +03:00
CAdventureMapButton * leftArtRoll , * rightArtRoll ;
2010-07-23 15:02:15 +03:00
bool allowedAssembling ;
2011-09-24 04:15:36 +03:00
std : : multiset < const CArtifactInstance * > artifactsOnAltar ; //artifacts id that are technically present in backpack but in GUI are moved to the altar - they'll be omitted in backpack slots
2013-06-26 14:18:27 +03:00
std : : function < void ( CArtPlace * ) > highlightModeCallback ; //if set, clicking on art place doesn't pick artifact but highlights the slot and calls this function
2009-06-19 15:10:36 +03:00
2010-12-29 23:04:22 +02:00
void realizeCurrentTransaction ( ) ; //calls callback with parameters stored in commonInfo
2011-01-06 22:00:19 +02:00
void artifactMoved ( const ArtifactLocation & src , const ArtifactLocation & dst ) ;
2011-04-23 00:51:10 +03:00
void artifactRemoved ( const ArtifactLocation & al ) ;
2011-01-24 01:49:17 +02:00
void artifactAssembled ( const ArtifactLocation & al ) ;
void artifactDisassembled ( const ArtifactLocation & al ) ;
2011-01-06 22:00:19 +02:00
CArtPlace * getArtPlace ( int slot ) ;
2010-12-29 23:04:22 +02:00
2009-06-18 18:05:00 +03:00
void setHero ( const CGHeroInstance * hero ) ;
2011-02-27 21:58:14 +02:00
const CGHeroInstance * getHero ( ) const ;
2009-06-18 18:05:00 +03:00
void dispose ( ) ; //free resources not needed after closing windows and reset state
2009-11-28 21:55:40 +02:00
void scrollBackpack ( int dir ) ; //dir==-1 => to left; dir==1 => to right
2010-07-23 15:02:15 +03:00
void safeRedraw ( ) ;
2010-12-29 23:04:22 +02:00
void markPossibleSlots ( const CArtifactInstance * art ) ;
2011-04-23 00:51:10 +03:00
void unmarkSlots ( bool withRedraw = true ) ; //unmarks slots in all visible AOHs
void unmarkLocalSlots ( bool withRedraw = true ) ; //unmarks slots in that particular AOH
2013-02-12 22:49:40 +03:00
void setSlotData ( CArtPlace * artPlace , ArtifactPosition slotID ) ;
2011-02-27 21:58:14 +02:00
void updateWornSlots ( bool redrawParent = true ) ;
2011-04-23 00:51:10 +03:00
2013-02-12 22:49:40 +03:00
void updateSlot ( ArtifactPosition i ) ;
void eraseSlotData ( CArtPlace * artPlace , ArtifactPosition slotID ) ;
2009-06-18 18:05:00 +03:00
2011-12-22 16:05:19 +03:00
CArtifactsOfHero ( const Point & position , bool createCommonPart = false ) ;
2011-04-23 13:27:44 +03:00
//Alternative constructor, used if custom artifacts positioning required (Kingdom interface)
CArtifactsOfHero ( std : : vector < CArtPlace * > ArtWorn , std : : vector < CArtPlace * > Backpack ,
2011-12-22 16:05:19 +03:00
CAdventureMapButton * leftScroll , CAdventureMapButton * rightScroll , bool createCommonPart = false ) ;
2009-06-18 18:05:00 +03:00
~ CArtifactsOfHero ( ) ; //d-tor
2010-07-21 22:50:15 +03:00
void updateParentWindow ( ) ;
2009-06-18 18:05:00 +03:00
friend class CArtPlace ;
} ;
2012-06-13 16:04:06 +03:00
class CGarrisonHolder
2011-12-17 21:59:59 +03:00
{
public :
CGarrisonHolder ( ) ;
2012-06-17 01:40:28 +03:00
virtual void updateGarrisons ( ) = 0 ;
2011-12-17 21:59:59 +03:00
} ;
2012-06-02 18:16:54 +03:00
class CWindowWithGarrison : public virtual CGarrisonHolder
2011-12-17 21:59:59 +03:00
{
public :
CGarrisonInt * garr ;
virtual void updateGarrisons ( ) ;
} ;
2011-02-22 13:52:36 +02:00
/// Garrison window where you can take creatures out of the hero to place it on the garrison
2012-06-02 18:16:54 +03:00
class CGarrisonWindow : public CWindowObject , public CWindowWithGarrison
2009-05-19 21:23:04 +03:00
{
public :
2012-06-17 01:40:28 +03:00
CAdventureMapButton * quit ;
2009-05-19 21:23:04 +03:00
2009-09-09 20:49:03 +03:00
CGarrisonWindow ( const CArmedInstance * up , const CGHeroInstance * down , bool removableUnits ) ; //c-tor
2009-05-19 21:23:04 +03:00
} ;
2012-06-15 20:08:19 +03:00
class CExchangeWindow : public CWindowObject , public CWindowWithGarrison , public CWindowWithArtifacts
2009-06-16 14:18:14 +03:00
{
2011-04-30 21:16:58 +03:00
CGStatusBar * ourBar ; //internal statusbar
2009-06-19 15:10:36 +03:00
2011-12-22 16:05:19 +03:00
CAdventureMapButton * quit , * questlogButton [ 2 ] ;
2009-06-16 14:18:14 +03:00
2009-06-19 15:10:36 +03:00
std : : vector < LRClickableAreaWTextComp * > secSkillAreas [ 2 ] , primSkillAreas ;
2010-02-28 12:01:36 +02:00
MoraleLuckBox * morale [ 2 ] , * luck [ 2 ] ;
2010-02-01 01:30:47 +02:00
2013-01-17 21:15:00 +03:00
LRClickableAreaWText * specialty [ 2 ] ;
2010-02-01 01:30:47 +02:00
LRClickableAreaWText * experience [ 2 ] ;
LRClickableAreaWText * spellPoints [ 2 ] ;
2010-07-22 03:32:45 +03:00
CHeroArea * portrait [ 2 ] ;
2009-06-26 18:41:19 +03:00
2009-06-19 15:10:36 +03:00
public :
2009-06-16 14:18:14 +03:00
2011-12-14 00:23:17 +03:00
const CGHeroInstance * heroInst [ 2 ] ;
2009-06-28 16:49:39 +03:00
CArtifactsOfHero * artifs [ 2 ] ;
2009-06-19 15:10:36 +03:00
void questlog ( int whichHero ) ; //questlog button callback; whichHero: 0 - left, 1 - right
2009-06-28 16:49:39 +03:00
void prepareBackground ( ) ; //prepares or redraws bg
2013-05-27 13:53:28 +03:00
CExchangeWindow ( ObjectInstanceID hero1 , ObjectInstanceID hero2 , QueryID queryID ) ; //c-tor
2009-06-16 14:18:14 +03:00
~ CExchangeWindow ( ) ; //d-tor
} ;
2009-05-19 21:23:04 +03:00
2011-02-22 13:52:36 +02:00
/// Here you can buy ships
2012-06-15 20:08:19 +03:00
class CShipyardWindow : public CWindowObject
2009-07-26 06:33:13 +03:00
{
public :
2011-09-23 18:58:18 +03:00
CGStatusBar * bar ;
CPicture * bgWater ;
CLabel * title ;
CLabel * costLabel ;
CAnimImage * woodPic , * goldPic ;
CLabel * woodCost , * goldCost ;
CAnimImage * bgShip ;
2011-12-22 16:05:19 +03:00
CAdventureMapButton * build , * quit ;
2009-07-26 06:33:13 +03:00
2011-09-23 18:58:18 +03:00
CGStatusBar * statusBar ;
2009-07-26 06:33:13 +03:00
2013-06-26 14:18:27 +03:00
CShipyardWindow ( const std : : vector < si32 > & cost , int state , int boatType , const std : : function < void ( ) > & onBuy ) ;
2009-07-26 06:33:13 +03:00
} ;
2009-05-19 21:23:04 +03:00
2011-02-22 13:52:36 +02:00
/// Puzzle screen which gets uncovered when you visit obilisks
2012-06-15 20:08:19 +03:00
class CPuzzleWindow : public CWindowObject
2009-08-31 18:57:15 +03:00
{
private :
2012-06-15 20:08:19 +03:00
int3 grailPos ;
2011-12-22 16:05:19 +03:00
CAdventureMapButton * quitb ;
2009-08-31 18:57:15 +03:00
2012-06-15 20:08:19 +03:00
std : : vector < CPicture * > piecesToRemove ;
ui8 currentAlpha ;
2009-08-31 18:57:15 +03:00
public :
2012-06-15 20:08:19 +03:00
void showAll ( SDL_Surface * to ) ;
2009-08-31 18:57:15 +03:00
void show ( SDL_Surface * to ) ;
2011-12-14 00:23:17 +03:00
CPuzzleWindow ( const int3 & grailPos , double discoveredRatio ) ;
2009-08-31 18:57:15 +03:00
} ;
2011-02-22 13:52:36 +02:00
/// Creature transformer window
2012-06-17 01:40:28 +03:00
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 ;
2012-05-13 18:04:21 +03:00
CAnimImage * icon ;
2010-07-03 15:00:53 +03:00
void move ( ) ;
void clickLeft ( tribool down , bool previousState ) ;
2012-06-17 01:40:28 +03:00
void update ( ) ;
2012-09-26 16:13:39 +03:00
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
2013-06-26 14:18:27 +03:00
const CGTownInstance * town ; //market, town garrison is used if hero == nullptr
2010-07-03 15:00:53 +03:00
std : : vector < CItem * > items ;
2011-12-22 16:05:19 +03:00
CAdventureMapButton * all , * convert , * cancel ;
2010-07-07 05:29:07 +03:00
CGStatusBar * bar ;
2010-07-03 15:00:53 +03:00
void makeDeal ( ) ;
void addAll ( ) ;
2012-06-17 01:40:28 +03:00
void updateGarrisons ( ) ;
2010-07-03 15:00:53 +03:00
CTransformerWindow ( const CGHeroInstance * _hero , const CGTownInstance * _town ) ; //c-tor
} ;
2012-06-15 20:08:19 +03:00
class CUniversityWindow : public CWindowObject
2010-07-20 17:08:13 +03:00
{
2012-05-13 18:04:21 +03:00
class CItem : public CAnimImage
2010-07-20 17:08:13 +03:00
{
public :
int ID ; //id of selected skill
CUniversityWindow * parent ;
2010-11-15 17:15:00 +02:00
2010-07-20 17:08:13 +03:00
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 ;
2010-11-15 17:15:00 +02:00
2010-08-06 16:14:10 +03:00
CPicture * green , * yellow , * red ; //colored bars near skills
2010-07-20 17:08:13 +03:00
std : : vector < CItem * > items ;
2011-12-22 16:05:19 +03:00
CAdventureMapButton * cancel ;
2010-07-20 17:08:13 +03:00
CGStatusBar * bar ;
2010-11-15 17:15:00 +02:00
2010-07-20 17:08:13 +03:00
CUniversityWindow ( const CGHeroInstance * _hero , const IMarket * _market ) ; //c-tor
} ;
2011-02-22 13:52:36 +02:00
/// Confirmation window for University
2012-06-15 20:08:19 +03:00
class CUnivConfirmWindow : public CWindowObject
2010-07-20 17:08:13 +03:00
{
public :
CUniversityWindow * parent ;
CGStatusBar * bar ;
2011-12-22 16:05:19 +03:00
CAdventureMapButton * confirm , * cancel ;
2010-07-20 17:08:13 +03:00
CUnivConfirmWindow ( CUniversityWindow * PARENT , int SKILL , bool available ) ; //c-tor
void makeDeal ( int skill ) ;
} ;
2011-02-22 13:52:36 +02:00
/// Hill fort is the building where you can upgrade units
2012-06-15 20:08:19 +03:00
class CHillFortWindow : public CWindowObject , public CWindowWithGarrison
2010-07-22 03:32:45 +03:00
{
public :
int slotsCount ; //=7;
CGStatusBar * bar ;
CDefEssential * resources ;
CHeroArea * heroPic ; //clickable hero image
2011-12-22 16:05:19 +03:00
CAdventureMapButton * quit , //closes window
2010-07-22 03:32:45 +03:00
* 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
2011-07-05 09:14:07 +03:00
std : : vector < TResources > costs ; // costs [slot ID] [resource ID] = resource count for upgrade
TResources totalSumm ; // totalSum[resource ID] = value
2010-07-22 03:32:45 +03:00
CHillFortWindow ( const CGHeroInstance * visitor , const CGObjectInstance * object ) ; //c-tor
2010-11-15 17:15:00 +02:00
2010-07-22 03:32:45 +03:00
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
2010-07-22 03:32:45 +03:00
void updateGarrisons ( ) ; //update buttons after garrison changes
} ;
2012-06-15 20:08:19 +03:00
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 ;
2011-12-22 16:05:19 +03:00
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
} ;