2007-11-19 00:58:28 +02:00
# pragma once
# include "global.h"
# include "CGameInterface.h"
# include "SDL.h"
# include "SDL_framerate.h"
class CDefEssential ;
class CDefHandler ;
struct HeroMoveDetails ;
class CDefEssential ;
class CGHeroInstance ;
2007-11-24 00:33:55 +02:00
class CAdvMapInt ;
2008-01-09 19:21:31 +02:00
class CCastleInterface ;
2007-12-01 14:50:33 +02:00
class IShowable
{
public :
virtual void show ( SDL_Surface * to = NULL ) = 0 ;
} ;
2008-01-27 22:37:10 +02:00
class IStatusBar
{
public :
virtual ~ IStatusBar ( ) { } ; //d-tor
virtual void print ( std : : string text ) = 0 ; //prints text and refreshes statusbar
virtual void clear ( ) = 0 ; //clears statusbar and refreshes
virtual void show ( ) = 0 ; //shows statusbar (with current text)
virtual std : : string getCurrent ( ) = 0 ;
} ;
2007-12-01 14:50:33 +02:00
class IActivable
{
public :
virtual void activate ( ) = 0 ;
virtual void deactivate ( ) = 0 ;
} ;
2007-11-19 00:58:28 +02:00
class CIntObject //interface object
{
public :
SDL_Rect pos ;
int ID ;
} ;
2007-12-01 14:50:33 +02:00
class CSimpleWindow : public virtual CIntObject , public IShowable
2007-11-19 00:58:28 +02:00
{
public :
SDL_Surface * bitmap ;
CIntObject * owner ;
2007-12-01 14:50:33 +02:00
virtual void show ( SDL_Surface * to = NULL ) ;
2007-11-19 00:58:28 +02:00
CSimpleWindow ( ) : bitmap ( NULL ) , owner ( NULL ) { } ;
virtual ~ CSimpleWindow ( ) ;
} ;
2007-12-01 14:50:33 +02:00
class CButtonBase : public virtual CIntObject , public IShowable , public IActivable //basic buttton class
2007-11-19 00:58:28 +02:00
{
public :
2008-01-09 19:21:31 +02:00
int bitmapOffset ;
2007-11-19 00:58:28 +02:00
int type ; //advmapbutton=2
bool abs ;
bool active ;
2008-01-27 16:07:51 +02:00
bool notFreeButton ;
2007-11-24 00:33:55 +02:00
CIntObject * ourObj ; // "owner"
2007-11-19 00:58:28 +02:00
int state ;
std : : vector < std : : vector < SDL_Surface * > > imgs ;
int curimg ;
2007-12-01 14:50:33 +02:00
virtual void show ( SDL_Surface * to = NULL ) ;
2007-11-19 00:58:28 +02:00
virtual void activate ( ) = 0 ;
virtual void deactivate ( ) = 0 ;
CButtonBase ( ) ;
2008-01-21 20:22:51 +02:00
virtual ~ CButtonBase ( ) ;
2007-11-19 00:58:28 +02:00
} ;
class ClickableL : public virtual CIntObject //for left-clicks
{
public :
bool pressedL ;
ClickableL ( ) ;
virtual void clickLeft ( tribool down ) = 0 ;
virtual void activate ( ) = 0 ;
virtual void deactivate ( ) = 0 ;
} ;
class ClickableR : public virtual CIntObject //for right-clicks
{
public :
bool pressedR ;
ClickableR ( ) ;
virtual void clickRight ( tribool down ) = 0 ;
virtual void activate ( ) = 0 ;
virtual void deactivate ( ) = 0 ;
} ;
class Hoverable : public virtual CIntObject
{
public :
Hoverable ( ) { hovered = false ; }
bool hovered ;
virtual void hover ( bool on ) = 0 ;
virtual void activate ( ) = 0 ;
virtual void deactivate ( ) = 0 ;
} ;
class KeyInterested : public virtual CIntObject
{
public :
virtual void keyPressed ( SDL_KeyboardEvent & key ) = 0 ;
virtual void activate ( ) = 0 ;
virtual void deactivate ( ) = 0 ;
} ;
class MotionInterested : public virtual CIntObject
{
public :
virtual void mouseMoved ( SDL_MouseMotionEvent & sEvent ) = 0 ;
virtual void activate ( ) = 0 ;
virtual void deactivate ( ) = 0 ;
} ;
2007-12-19 02:06:51 +02:00
class TimeInterested : public virtual CIntObject
{
public :
int toNextTick ;
virtual void tick ( ) = 0 ;
virtual void activate ( ) ;
virtual void deactivate ( ) ;
} ;
2007-11-24 00:33:55 +02:00
template < typename T > class CSCButton : public CButtonBase , public ClickableL //prosty guzik, ktory tylko zmienia obrazek
{
public :
int3 posr ; //position in the bitmap
int state ;
T * delg ;
void ( T : : * func ) ( tribool ) ;
CSCButton ( CDefHandler * img , CIntObject * obj , void ( T : : * poin ) ( tribool ) , T * Delg = NULL ) ;
void clickLeft ( tribool down ) ;
void activate ( ) ;
void deactivate ( ) ;
2007-12-01 14:50:33 +02:00
void show ( SDL_Surface * to = NULL ) ;
2007-11-24 00:33:55 +02:00
} ;
class CInfoWindow : public CSimpleWindow //text + comp. + ok button
2007-12-28 01:43:36 +02:00
{ //okno usuwa swoje komponenty w chwili zamkniecia
2007-11-24 00:33:55 +02:00
public :
CSCButton < CInfoWindow > okb ;
std : : vector < SComponent * > components ;
2007-12-19 02:06:51 +02:00
virtual void okClicked ( tribool down ) ;
virtual void close ( ) ;
2007-11-24 00:33:55 +02:00
CInfoWindow ( ) ;
2007-12-27 02:11:46 +02:00
virtual ~ CInfoWindow ( ) ;
2007-11-24 00:33:55 +02:00
} ;
2007-12-19 02:06:51 +02:00
class CSelWindow : public CInfoWindow //component selection window
2007-12-28 01:43:36 +02:00
{ //uwaga - to okno nie usuwa swoich komponentow przy usuwaniu, moga sie one jeszcze przydac skryptowi - tak wiec skrypt korzystajacyz tego okna musi je usunac
2007-12-25 18:25:53 +02:00
public :
2007-12-28 01:43:36 +02:00
void selectionChange ( CSelectableComponent * to ) ;
2007-12-19 02:06:51 +02:00
void okClicked ( tribool down ) ;
void close ( ) ;
2007-12-27 02:11:46 +02:00
CSelWindow ( ) { } ;
2007-12-19 02:06:51 +02:00
} ;
2008-02-18 23:14:28 +02:00
class CRClickPopup : public IShowable , public ClickableR
{
2008-02-23 00:26:31 +02:00
public :
2008-02-18 23:14:28 +02:00
virtual void activate ( ) = 0 ;
virtual void deactivate ( ) = 0 ;
virtual void close ( ) = 0 ;
2008-02-23 00:26:31 +02:00
virtual ~ CRClickPopup ( ) { } ;
} ;
class CInfoPopup : public CRClickPopup
{
public :
bool free ;
SDL_Surface * bitmap ;
CInfoPopup ( SDL_Surface * Bitmap , int x , int y , bool Free = false ) ;
void clickRight ( tribool down ) ;
void activate ( ) ;
void deactivate ( ) ;
void close ( ) ;
void show ( SDL_Surface * to = NULL ) ;
~ CInfoPopup ( ) { } ;
2008-02-18 23:14:28 +02:00
} ;
2007-11-24 00:33:55 +02:00
class SComponent : public ClickableR
{
public :
enum Etype
{
2007-12-25 18:25:53 +02:00
primskill , secskill , resource , creature , artifact , experience
2007-11-24 00:33:55 +02:00
} type ;
int subtype ;
int val ;
std : : string description ; //r-click
std : : string subtitle ;
SComponent ( Etype Type , int Subtype , int Val ) ;
//SComponent(const & SComponent r);
void clickRight ( tribool down ) ;
2007-12-19 02:06:51 +02:00
virtual SDL_Surface * getImg ( ) ;
virtual void activate ( ) ;
virtual void deactivate ( ) ;
} ;
class CSelectableComponent : public SComponent , public ClickableL
{
public :
bool selected ;
2007-12-27 02:11:46 +02:00
bool customB ;
2007-12-19 02:06:51 +02:00
SDL_Surface * border , * myBitmap ;
2007-12-23 18:25:14 +02:00
CSelWindow * owner ;
2007-12-19 02:06:51 +02:00
void clickLeft ( tribool down ) ;
2007-12-25 18:25:53 +02:00
CSelectableComponent ( Etype Type , int Sub , int Val , CSelWindow * Owner = NULL , SDL_Surface * Border = NULL ) ;
2007-12-27 02:11:46 +02:00
~ CSelectableComponent ( ) ;
2007-11-24 00:33:55 +02:00
void activate ( ) ;
void deactivate ( ) ;
2007-12-19 02:06:51 +02:00
void select ( bool on ) ;
SDL_Surface * getImg ( ) ;
2007-11-24 00:33:55 +02:00
} ;
2008-01-26 21:36:31 +02:00
class CGarrisonInt ;
class CGarrisonSlot : public ClickableL , public ClickableR , public Hoverable
{
public :
CGarrisonInt * owner ;
const CCreature * creature ;
int count ;
2008-01-29 15:00:45 +02:00
int upg ; //0 - up garrison, 1 - down garrison
2008-01-26 21:36:31 +02:00
virtual void hover ( bool on ) ;
void clickRight ( tribool down ) ;
void clickLeft ( tribool down ) ;
void activate ( ) ;
void deactivate ( ) ;
void show ( ) ;
2008-01-28 16:01:09 +02:00
CGarrisonSlot ( CGarrisonInt * Owner , int x , int y , int IID , int Upg = 0 , const CCreature * Creature = NULL , int Count = 0 ) ;
2008-01-26 21:36:31 +02:00
} ;
class CGarrisonInt : public CIntObject
{
public :
int interx , intery ;
CGarrisonSlot * highlighted ;
SDL_Surface * sur ;
int offx , offy ;
2008-01-31 23:35:30 +02:00
bool ignoreEvent , update ;
2008-01-26 21:36:31 +02:00
const CCreatureSet * set1 ;
const CCreatureSet * set2 ;
std : : vector < CGarrisonSlot * > * sup , * sdown ;
2008-01-28 16:01:09 +02:00
const CGObjectInstance * oup , * odown ;
2008-01-26 21:36:31 +02:00
void activate ( ) ;
void deactivate ( ) ;
void show ( ) ;
void activeteSlots ( ) ;
void deactiveteSlots ( ) ;
void deleteSlots ( ) ;
void createSlots ( ) ;
void recreateSlots ( ) ;
2008-01-28 16:01:09 +02:00
CGarrisonInt ( int x , int y , int inx , int iny , SDL_Surface * pomsur , int OX , int OY , const CGObjectInstance * s1 , const CGObjectInstance * s2 = NULL ) ;
2008-01-26 21:36:31 +02:00
~ CGarrisonInt ( ) ;
} ;
2007-11-24 00:33:55 +02:00
2007-11-19 00:58:28 +02:00
class CPlayerInterface : public CGameInterface
{
public :
bool makingTurn ;
2008-01-09 19:21:31 +02:00
SDL_Event * current ;
2008-01-20 14:34:39 +02:00
IActivable * curint ;
2007-11-19 00:58:28 +02:00
CAdvMapInt * adventureInt ;
2008-01-09 19:21:31 +02:00
CCastleInterface * castleInt ;
2007-11-19 00:58:28 +02:00
FPSmanager * mainFPSmng ;
2008-01-27 22:37:10 +02:00
IStatusBar * statusbar ;
2007-11-19 00:58:28 +02:00
//TODO: town interace, battle interface, other interfaces
CCallback * cb ;
std : : vector < ClickableL * > lclickable ;
std : : vector < ClickableR * > rclickable ;
std : : vector < Hoverable * > hoverable ;
std : : vector < KeyInterested * > keyinterested ;
std : : vector < MotionInterested * > motioninterested ;
2007-12-19 02:06:51 +02:00
std : : vector < TimeInterested * > timeinterested ;
2007-12-01 14:50:33 +02:00
std : : vector < IShowable * > objsToBlit ;
2007-11-19 00:58:28 +02:00
2008-02-18 23:14:28 +02:00
SDL_Surface * hInfo , * tInfo ;
2007-11-19 00:58:28 +02:00
std : : vector < std : : pair < int , int > > slotsPos ;
CDefEssential * luck22 , * luck30 , * luck42 , * luck82 ,
2008-02-18 23:14:28 +02:00
* morale22 , * morale30 , * morale42 , * morale82 ,
* halls , * forts , * bigTownPic ;
2007-12-19 02:06:51 +02:00
std : : map < int , SDL_Surface * > heroWins ;
2008-02-18 23:14:28 +02:00
std : : map < int , SDL_Surface * > townWins ;
2007-11-19 00:58:28 +02:00
//overloaded funcs from Interface
void yourTurn ( ) ;
void heroMoved ( const HeroMoveDetails & details ) ;
2007-12-06 20:55:58 +02:00
void tileRevealed ( int3 pos ) ;
void tileHidden ( int3 pos ) ;
2007-12-19 02:06:51 +02:00
void heroKilled ( const CGHeroInstance * hero ) ;
void heroCreated ( const CGHeroInstance * hero ) ;
2007-11-19 00:58:28 +02:00
void heroPrimarySkillChanged ( const CGHeroInstance * hero , int which , int val ) ;
2007-11-25 15:16:45 +02:00
void receivedResource ( int type , int val ) ;
2007-12-27 02:11:46 +02:00
void showSelDialog ( std : : string text , std : : vector < CSelectableComponent * > & components , int askID ) ;
2008-01-28 16:01:09 +02:00
void heroVisitsTown ( const CGHeroInstance * hero , const CGTownInstance * town ) ;
void garrisonChanged ( const CGObjectInstance * obj ) ;
2007-12-22 16:40:27 +02:00
2008-02-25 01:06:27 +02:00
//battles
void battleStart ( CCreatureSet * army1 , CCreatureSet * army2 , int3 tile , CGHeroInstance * hero1 , CGHeroInstance * hero2 , tribool side ) ; //called by engine when battle starts; side=0 - left, side=1 - right
void battlefieldPrepared ( int battlefieldType , std : : vector < CObstacle * > obstacles ) ; //called when battlefield is prepared, prior the battle beginning
void battleNewRound ( int round ) ; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
void actionStarted ( Action action ) ; //occurs BEFORE every action taken by any stack or by the hero
void actionFinished ( Action action ) ; //occurs AFTER every action taken by any stack or by the hero
void activeStack ( int stackID ) ; //called when it's turn of that stack
void battleEnd ( CCreatureSet * army1 , CCreatureSet * army2 , CGHeroInstance * hero1 , CGHeroInstance * hero2 , std : : vector < int > capturedArtifacts , int expForWinner , bool winner ) ;
//-------------//
2007-12-22 16:40:27 +02:00
void showComp ( SComponent comp ) ;
2008-01-10 21:01:25 +02:00
void openTownWindow ( const CGTownInstance * town ) ; //shows townscreen
void openHeroWindow ( const CGHeroInstance * hero ) ; //shows hero window with given hero
2007-12-19 02:06:51 +02:00
SDL_Surface * infoWin ( const CGObjectInstance * specific ) ; //specific=0 => draws info about selected town/hero //TODO - gdy sie dorobi sensowna hierarchie klas ins. to wywalic tego brzydkiego void*
2007-11-19 00:58:28 +02:00
void handleEvent ( SDL_Event * sEvent ) ;
2007-12-22 16:40:27 +02:00
void handleKeyDown ( SDL_Event * sEvent ) ;
void handleKeyUp ( SDL_Event * sEvent ) ;
void handleMouseMotion ( SDL_Event * sEvent ) ;
2007-12-06 20:32:06 +02:00
void init ( ICallback * CB ) ;
2007-11-19 00:58:28 +02:00
int3 repairScreenPos ( int3 pos ) ;
2007-11-24 00:33:55 +02:00
void showInfoDialog ( std : : string text , std : : vector < SComponent * > & components ) ;
2007-12-01 14:50:33 +02:00
void removeObjToBlit ( IShowable * obj ) ;
2007-12-19 02:06:51 +02:00
SDL_Surface * drawHeroInfoWin ( const CGHeroInstance * curh ) ;
2007-12-22 16:40:27 +02:00
SDL_Surface * drawPrimarySkill ( const CGHeroInstance * curh , SDL_Surface * ret , int from = 0 , int to = PRIMARY_SKILLS ) ;
2007-12-19 02:06:51 +02:00
SDL_Surface * drawTownInfoWin ( const CGTownInstance * curh ) ;
2007-11-19 00:58:28 +02:00
CPlayerInterface ( int Player , int serial ) ;
2008-01-27 22:37:10 +02:00
} ;
class CStatusBar
: public CIntObject , public IStatusBar
{
public :
SDL_Surface * bg ; //background
int middlex , middley ; //middle of statusbar
std : : string current ; //text currently printed
CStatusBar ( int x , int y , std : : string name = " ADROLLVR.bmp " , int maxw = - 1 ) ; //c-tor
~ CStatusBar ( ) ; //d-tor
void print ( std : : string text ) ; //prints text and refreshes statusbar
void clear ( ) ; //clears statusbar and refreshes
void show ( ) ; //shows statusbar (with current text)
std : : string getCurrent ( ) ;
2008-01-31 23:35:30 +02:00
} ;
class CList
: public ClickableL , public ClickableR , public Hoverable , public KeyInterested , public virtual CIntObject , public MotionInterested
{
public :
SDL_Surface * bg ;
CDefHandler * arrup , * arrdo ;
SDL_Surface * empty , * selection ;
SDL_Rect arrupp , arrdop ; //positions of arrows
int posw , posh ; //position width/height
int selected , //id of selected position, <0 if none
from ;
const int SIZE ;
tribool pressed ; //true=up; false=down; indeterminate=none
CList ( int Size = 5 ) ;
void clickLeft ( tribool down ) ;
void activate ( ) ;
void deactivate ( ) ;
virtual void mouseMoved ( SDL_MouseMotionEvent & sEvent ) = 0 ;
virtual void genList ( ) = 0 ;
virtual void select ( int which ) = 0 ;
virtual void draw ( ) = 0 ;
} ;
class CHeroList
: public CList
{
public :
CDefHandler * mobile , * mana ;
std : : vector < std : : pair < const CGHeroInstance * , CPath * > > items ;
int posmobx , posporx , posmanx , posmoby , pospory , posmany ;
CHeroList ( int Size = 5 ) ;
void genList ( ) ;
void select ( int which ) ;
void mouseMoved ( SDL_MouseMotionEvent & sEvent ) ;
void clickLeft ( tribool down ) ;
void clickRight ( tribool down ) ;
void hover ( bool on ) ;
void keyPressed ( SDL_KeyboardEvent & key ) ;
void updateHList ( ) ;
void updateMove ( const CGHeroInstance * which ) ; //draws move points bar
void redrawAllOne ( int which ) ;
void draw ( ) ;
void init ( ) ;
} ;
template < typename T >
class CTownList
: public CList
{
public :
T * owner ;
void ( T : : * fun ) ( ) ;
std : : vector < const CGTownInstance * > items ;
int posporx , pospory ;
CTownList ( int Size , SDL_Rect * Pos , int arupx , int arupy , int ardox , int ardoy ) ;
~ CTownList ( ) ;
void genList ( ) ;
void select ( int which ) ;
void mouseMoved ( SDL_MouseMotionEvent & sEvent ) ;
void clickLeft ( tribool down ) ;
void clickRight ( tribool down ) ;
void hover ( bool on ) ;
void keyPressed ( SDL_KeyboardEvent & key ) ;
void draw ( ) ;
2007-11-19 00:58:28 +02:00
} ;