1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/CPlayerInterface.h

238 lines
6.5 KiB
C
Raw Normal View History

#pragma once
#include "global.h"
#include "CGameInterface.h"
#include "SDL.h"
#include "SDL_framerate.h"
class CDefEssential;
class CHeroInstance;
class CDefHandler;
struct HeroMoveDetails;
class CDefEssential;
class CGHeroInstance;
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;
};
class IActivable
{
public:
virtual void activate()=0;
virtual void deactivate()=0;
};
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
{
public:
SDL_Surface * bitmap;
CIntObject * owner;
2007-12-01 14:50:33 +02:00
virtual void show(SDL_Surface * to = NULL);
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
{
public:
2008-01-09 19:21:31 +02:00
int bitmapOffset;
int type; //advmapbutton=2
bool abs;
bool active;
CIntObject * ourObj; // "owner"
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);
virtual void activate()=0;
virtual void deactivate()=0;
CButtonBase();
virtual ~CButtonBase(){};
};
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;
};
class TimeInterested: public virtual CIntObject
{
public:
int toNextTick;
virtual void tick()=0;
virtual void activate();
virtual void deactivate();
};
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);
};
class CInfoWindow : public CSimpleWindow //text + comp. + ok button
2007-12-28 01:43:36 +02:00
{ //okno usuwa swoje komponenty w chwili zamkniecia
public:
CSCButton<CInfoWindow> okb;
std::vector<SComponent*> components;
virtual void okClicked(tribool down);
virtual void close();
CInfoWindow();
virtual ~CInfoWindow();
};
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);
void okClicked(tribool down);
void close();
CSelWindow(){};
};
class SComponent : public ClickableR
{
public:
enum Etype
{
2007-12-25 18:25:53 +02:00
primskill, secskill, resource, creature, artifact, experience
} 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);
virtual SDL_Surface * getImg();
virtual void activate();
virtual void deactivate();
};
class CSelectableComponent : public SComponent, public ClickableL
{
public:
bool selected;
bool customB;
SDL_Surface * border, *myBitmap;
CSelWindow * owner;
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);
~CSelectableComponent();
void activate();
void deactivate();
void select(bool on);
SDL_Surface * getImg();
};
class CPlayerInterface : public CGameInterface
{
public:
bool makingTurn;
2008-01-09 19:21:31 +02:00
SDL_Event * current;
CAdvMapInt * adventureInt;
2008-01-09 19:21:31 +02:00
CCastleInterface * castleInt;
FPSmanager * mainFPSmng;
//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;
std::vector<TimeInterested*> timeinterested;
2007-12-01 14:50:33 +02:00
std::vector<IShowable*> objsToBlit;
SDL_Surface * hInfo;
std::vector<std::pair<int, int> > slotsPos;
CDefEssential *luck22, *luck30, *luck42, *luck82,
*morale22, *morale30, *morale42, *morale82;
std::map<int,SDL_Surface*> heroWins;
//std::map<int,SDL_Surface*> townWins;
//overloaded funcs from Interface
void yourTurn();
void heroMoved(const HeroMoveDetails & details);
void tileRevealed(int3 pos);
void tileHidden(int3 pos);
void heroKilled(const CGHeroInstance* hero);
void heroCreated(const CGHeroInstance* hero);
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
2007-11-25 15:16:45 +02:00
void receivedResource(int type, int val);
void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID);
void showComp(SComponent comp);
2008-01-09 19:21:31 +02:00
void openTownWindow(const CGTownInstance * town);
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*
void handleEvent(SDL_Event * sEvent);
void handleKeyDown(SDL_Event *sEvent);
void handleKeyUp(SDL_Event *sEvent);
void handleMouseMotion(SDL_Event *sEvent);
void init(ICallback * CB);
int3 repairScreenPos(int3 pos);
void showInfoDialog(std::string text, std::vector<SComponent*> & components);
2007-12-01 14:50:33 +02:00
void removeObjToBlit(IShowable* obj);
SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh);
SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS);
SDL_Surface * drawTownInfoWin(const CGTownInstance * curh);
CPlayerInterface(int Player, int serial);
};