mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-13 11:40:38 +02:00
* further code reorganization
This commit is contained in:
parent
2ab691ef40
commit
4c0936a3dc
@ -10,6 +10,7 @@
|
|||||||
#include "client/CConfigHandler.h"
|
#include "client/CConfigHandler.h"
|
||||||
#include "client/Graphics.h"
|
#include "client/Graphics.h"
|
||||||
#include "CBattleInterface.h"
|
#include "CBattleInterface.h"
|
||||||
|
#include "CPlayerInterface.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AdevntureMapButton.cpp, part of VCMI engine
|
* AdevntureMapButton.cpp, part of VCMI engine
|
||||||
@ -59,7 +60,7 @@ AdventureMapButton::AdventureMapButton( const std::pair<std::string, std::string
|
|||||||
pom[0] = help.first;
|
pom[0] = help.first;
|
||||||
init(Callback, pom, help.second, playerColoredButton, defName, add, x, y, key);
|
init(Callback, pom, help.second, playerColoredButton, defName, add, x, y, key);
|
||||||
}
|
}
|
||||||
void AdventureMapButton::clickLeft (tribool down)
|
void AdventureMapButton::clickLeft (boost::logic::tribool down)
|
||||||
{
|
{
|
||||||
if(blocked)
|
if(blocked)
|
||||||
return;
|
return;
|
||||||
@ -86,7 +87,7 @@ void AdventureMapButton::clickLeft (tribool down)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdventureMapButton::clickRight (tribool down)
|
void AdventureMapButton::clickRight (boost::logic::tribool down)
|
||||||
{
|
{
|
||||||
if(helpBox.size()) //there is no point to show window with nothing inside...
|
if(helpBox.size()) //there is no point to show window with nothing inside...
|
||||||
LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
|
LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "client/FunctionList.h"
|
#include "client/FunctionList.h"
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include "client/GUIClasses.h"
|
#include "client/GUIBase.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AdventureMapButton.h, part of VCMI engine
|
* AdventureMapButton.h, part of VCMI engine
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "AdventureMapButton.h"
|
#include "AdventureMapButton.h"
|
||||||
|
#include "client/GUIClasses.h"
|
||||||
class CDefHandler;
|
class CDefHandler;
|
||||||
class CCallback;
|
class CCallback;
|
||||||
struct CPath;
|
struct CPath;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "lib/CondSh.h"
|
#include "lib/CondSh.h"
|
||||||
#include "lib/NetPacks.h"
|
#include "lib/NetPacks.h"
|
||||||
|
#include "CPlayerInterface.h"
|
||||||
#include <boost/assign/list_of.hpp>
|
#include <boost/assign/list_of.hpp>
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
const double M_PI = 3.14159265358979323846;
|
const double M_PI = 3.14159265358979323846;
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
#define __CBATTLEINTERFACE_H__
|
#define __CBATTLEINTERFACE_H__
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "CPlayerInterface.h"
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "client/GUIClasses.h"
|
#include "client/GUIBase.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CBattleInterface.h, part of VCMI engine
|
* CBattleInterface.h, part of VCMI engine
|
||||||
@ -27,6 +26,8 @@ class CHighlightableButtonsGroup;
|
|||||||
struct BattleResult;
|
struct BattleResult;
|
||||||
struct SpellCast;
|
struct SpellCast;
|
||||||
template <typename T> struct CondSh;
|
template <typename T> struct CondSh;
|
||||||
|
struct SetStackEffect;;
|
||||||
|
struct BattleAction;
|
||||||
|
|
||||||
class CBattleInterface;
|
class CBattleInterface;
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
#include "CCastleInterface.h"
|
||||||
#include "AdventureMapButton.h"
|
#include "AdventureMapButton.h"
|
||||||
#include "CAdvmapInterface.h"
|
#include "CAdvmapInterface.h"
|
||||||
#include "CCallback.h"
|
#include "CCallback.h"
|
||||||
#include "CCastleInterface.h"
|
|
||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
#include "CHeroWindow.h"
|
#include "CHeroWindow.h"
|
||||||
#include "CMessage.h"
|
#include "CMessage.h"
|
||||||
@ -1004,9 +1004,10 @@ CHallInterface::CBuildingBox::CBuildingBox(int id, int x, int y)
|
|||||||
|
|
||||||
CHallInterface::CHallInterface(CCastleInterface * owner)
|
CHallInterface::CHallInterface(CCastleInterface * owner)
|
||||||
{
|
{
|
||||||
|
resdatabar = new CMinorResDataBar;
|
||||||
pos = owner->pos;
|
pos = owner->pos;
|
||||||
resdatabar.pos.x += pos.x;
|
resdatabar->pos.x += pos.x;
|
||||||
resdatabar.pos.y += pos.y;
|
resdatabar->pos.y += pos.y;
|
||||||
bg = BitmapHandler::loadBitmap(CGI->buildh->hall[owner->town->subID].first);
|
bg = BitmapHandler::loadBitmap(CGI->buildh->hall[owner->town->subID].first);
|
||||||
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
|
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
|
||||||
exit = new AdventureMapButton
|
exit = new AdventureMapButton
|
||||||
@ -1073,6 +1074,7 @@ CHallInterface::~CHallInterface()
|
|||||||
for(size_t j=0;j<boxes[i].size();j++)
|
for(size_t j=0;j<boxes[i].size();j++)
|
||||||
delete boxes[i][j]; //TODO whats wrong with smartpointers?
|
delete boxes[i][j]; //TODO whats wrong with smartpointers?
|
||||||
delete exit;
|
delete exit;
|
||||||
|
delete resdatabar;
|
||||||
}
|
}
|
||||||
void CHallInterface::close()
|
void CHallInterface::close()
|
||||||
{
|
{
|
||||||
@ -1081,7 +1083,7 @@ void CHallInterface::close()
|
|||||||
void CHallInterface::show(SDL_Surface * to)
|
void CHallInterface::show(SDL_Surface * to)
|
||||||
{
|
{
|
||||||
blitAt(bg,pos,to);
|
blitAt(bg,pos,to);
|
||||||
resdatabar.show(to);
|
resdatabar->show(to);
|
||||||
exit->show(to);
|
exit->show(to);
|
||||||
for(int i=0; i<5; i++)
|
for(int i=0; i<5; i++)
|
||||||
{
|
{
|
||||||
@ -1303,6 +1305,7 @@ CFortScreen::~CFortScreen()
|
|||||||
delete recAreas[i];
|
delete recAreas[i];
|
||||||
SDL_FreeSurface(bg);
|
SDL_FreeSurface(bg);
|
||||||
delete exit;
|
delete exit;
|
||||||
|
delete resdatabar;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFortScreen::show( SDL_Surface * to)
|
void CFortScreen::show( SDL_Surface * to)
|
||||||
@ -1315,7 +1318,7 @@ void CFortScreen::show( SDL_Surface * to)
|
|||||||
}
|
}
|
||||||
anim++;
|
anim++;
|
||||||
exit->show(to);
|
exit->show(to);
|
||||||
resdatabar.show(to);
|
resdatabar->show(to);
|
||||||
LOCPLINT->statusbar->show(to);
|
LOCPLINT->statusbar->show(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1345,6 +1348,7 @@ void CFortScreen::close()
|
|||||||
|
|
||||||
CFortScreen::CFortScreen( CCastleInterface * owner )
|
CFortScreen::CFortScreen( CCastleInterface * owner )
|
||||||
{
|
{
|
||||||
|
resdatabar = new CMinorResDataBar;
|
||||||
pos = owner->pos;
|
pos = owner->pos;
|
||||||
bg = NULL;
|
bg = NULL;
|
||||||
exit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CFortScreen::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
|
exit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CFortScreen::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
|
||||||
@ -1353,7 +1357,7 @@ CFortScreen::CFortScreen( CCastleInterface * owner )
|
|||||||
genRect(126,386,10,288),genRect(126,386,404,288),
|
genRect(126,386,10,288),genRect(126,386,404,288),
|
||||||
genRect(126,386,206,421);
|
genRect(126,386,206,421);
|
||||||
draw(owner,true);
|
draw(owner,true);
|
||||||
resdatabar.pos += pos;
|
resdatabar->pos += pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFortScreen::draw( CCastleInterface * owner, bool first)
|
void CFortScreen::draw( CCastleInterface * owner, bool first)
|
||||||
@ -1459,9 +1463,10 @@ void CFortScreen::RecArea::clickRight( tribool down )
|
|||||||
}
|
}
|
||||||
CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
|
CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
|
||||||
{
|
{
|
||||||
|
resdatabar = new CMinorResDataBar;
|
||||||
pos = owner->pos;
|
pos = owner->pos;
|
||||||
resdatabar.pos.x += pos.x;
|
resdatabar->pos.x += pos.x;
|
||||||
resdatabar.pos.y += pos.y;
|
resdatabar->pos.y += pos.y;
|
||||||
bg = BitmapHandler::loadBitmap("TPMAGE.bmp");
|
bg = BitmapHandler::loadBitmap("TPMAGE.bmp");
|
||||||
exit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CMageGuildScreen::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
|
exit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CMageGuildScreen::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
|
||||||
exit->assignedKeys.insert(SDLK_ESCAPE);
|
exit->assignedKeys.insert(SDLK_ESCAPE);
|
||||||
@ -1505,6 +1510,7 @@ CMageGuildScreen::~CMageGuildScreen()
|
|||||||
{
|
{
|
||||||
delete exit;
|
delete exit;
|
||||||
SDL_FreeSurface(bg);
|
SDL_FreeSurface(bg);
|
||||||
|
delete resdatabar;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMageGuildScreen::close()
|
void CMageGuildScreen::close()
|
||||||
@ -1515,7 +1521,7 @@ void CMageGuildScreen::close()
|
|||||||
void CMageGuildScreen::show(SDL_Surface * to)
|
void CMageGuildScreen::show(SDL_Surface * to)
|
||||||
{
|
{
|
||||||
blitAt(bg,pos,to);
|
blitAt(bg,pos,to);
|
||||||
resdatabar.show(to);
|
resdatabar->show(to);
|
||||||
LOCPLINT->statusbar->show(to);
|
LOCPLINT->statusbar->show(to);
|
||||||
exit->show(to);
|
exit->show(to);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include "client/GUIClasses.h"
|
#include "client/GUIBase.h"
|
||||||
#include "hch/CMusicBase.h"
|
#include "hch/CMusicBase.h"
|
||||||
//#include "boost/tuple/tuple.hpp"
|
//#include "boost/tuple/tuple.hpp"
|
||||||
class CGTownInstance;
|
class CGTownInstance;
|
||||||
@ -15,6 +15,11 @@ struct Structure;
|
|||||||
class CSpell;
|
class CSpell;
|
||||||
class AdventureMapButton;
|
class AdventureMapButton;
|
||||||
class CResDataBar;
|
class CResDataBar;
|
||||||
|
class CStatusBar;
|
||||||
|
class CTownList;
|
||||||
|
class CRecruitmentWindow;
|
||||||
|
class CCreaturePic;
|
||||||
|
class CMinorResDataBar;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CCastleInterface.h, part of VCMI engine
|
* CCastleInterface.h, part of VCMI engine
|
||||||
@ -110,7 +115,7 @@ public:
|
|||||||
class CHallInterface : public IShowActivable
|
class CHallInterface : public IShowActivable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CMinorResDataBar resdatabar;
|
CMinorResDataBar * resdatabar;
|
||||||
SDL_Rect pos;
|
SDL_Rect pos;
|
||||||
|
|
||||||
class CBuildingBox : public Hoverable, public ClickableL, public ClickableR
|
class CBuildingBox : public Hoverable, public ClickableL, public ClickableR
|
||||||
@ -177,7 +182,7 @@ class CFortScreen : public IShowActivable, public CIntObject
|
|||||||
void deactivate();
|
void deactivate();
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
CMinorResDataBar resdatabar;
|
CMinorResDataBar * resdatabar;
|
||||||
AdventureMapButton *exit;
|
AdventureMapButton *exit;
|
||||||
SDL_Surface * bg;
|
SDL_Surface * bg;
|
||||||
std::vector<Rect> positions;
|
std::vector<Rect> positions;
|
||||||
@ -215,7 +220,7 @@ public:
|
|||||||
CDefEssential *scrolls, *scrolls2;
|
CDefEssential *scrolls, *scrolls2;
|
||||||
AdventureMapButton *exit;
|
AdventureMapButton *exit;
|
||||||
std::vector<Scroll> spells;
|
std::vector<Scroll> spells;
|
||||||
CMinorResDataBar resdatabar;
|
CMinorResDataBar * resdatabar;
|
||||||
|
|
||||||
|
|
||||||
CMageGuildScreen(CCastleInterface * owner); //c-tor
|
CMageGuildScreen(CCastleInterface * owner); //c-tor
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "../global.h"
|
#include "../global.h"
|
||||||
#include "../hch/CDefHandler.h"
|
#include "../hch/CDefHandler.h"
|
||||||
#include "GUIClasses.h"
|
#include "GUIBase.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CCreatureAnimation.h, part of VCMI engine
|
* CCreatureAnimation.h, part of VCMI engine
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
#include "../SDL_Extensions.h"
|
#include "../SDL_Extensions.h"
|
||||||
#include "../CMessage.h"
|
#include "../CMessage.h"
|
||||||
|
#include "../CPlayerInterface.h"
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "../global.h"
|
#include "../global.h"
|
||||||
#include "GUIClasses.h"
|
#include "GUIBase.h"
|
||||||
|
#include "boost/function.hpp"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CSpellWindow.h, part of VCMI engine
|
* CSpellWindow.h, part of VCMI engine
|
||||||
@ -19,6 +20,7 @@ struct SDL_Surface;
|
|||||||
class CDefHandler;
|
class CDefHandler;
|
||||||
struct SDL_Rect;
|
struct SDL_Rect;
|
||||||
class CGHeroInstance;
|
class CGHeroInstance;
|
||||||
|
class CStatusBar;
|
||||||
|
|
||||||
class SpellbookInteractiveArea : public ClickableL, public ClickableR, public Hoverable
|
class SpellbookInteractiveArea : public ClickableL, public ClickableR, public Hoverable
|
||||||
{
|
{
|
||||||
|
168
client/GUIBase.cpp
Normal file
168
client/GUIBase.cpp
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
#include "GUIBase.h"
|
||||||
|
#include "../SDL_extensions.h"
|
||||||
|
#include "../CPlayerInterface.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GUIBase.cpp, 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void KeyShortcut::keyPressed(const SDL_KeyboardEvent & key)
|
||||||
|
{
|
||||||
|
if(vstd::contains(assignedKeys,key.keysym.sym))
|
||||||
|
{
|
||||||
|
if(key.state == SDL_PRESSED)
|
||||||
|
clickLeft(true);
|
||||||
|
else
|
||||||
|
clickLeft(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CButtonBase::CButtonBase()
|
||||||
|
{
|
||||||
|
bitmapOffset = 0;
|
||||||
|
curimg=0;
|
||||||
|
type=-1;
|
||||||
|
abs=false;
|
||||||
|
active=false;
|
||||||
|
notFreeButton = false;
|
||||||
|
ourObj=NULL;
|
||||||
|
state=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CButtonBase::~CButtonBase()
|
||||||
|
{
|
||||||
|
if(notFreeButton)
|
||||||
|
return;
|
||||||
|
for(int i =0; i<imgs.size();i++)
|
||||||
|
for(int j=0;j<imgs[i].size();j++)
|
||||||
|
SDL_FreeSurface(imgs[i][j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CButtonBase::show(SDL_Surface * to)
|
||||||
|
{
|
||||||
|
int img = std::min(state+bitmapOffset,int(imgs[curimg].size()-1));
|
||||||
|
img = std::max(0, img);
|
||||||
|
|
||||||
|
if (abs)
|
||||||
|
{
|
||||||
|
blitAt(imgs[curimg][img],pos.x,pos.y,to);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
blitAt(imgs[curimg][img],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ClickableL::ClickableL()
|
||||||
|
{
|
||||||
|
pressedL=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClickableL::~ClickableL()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClickableL::clickLeft(boost::logic::tribool down)
|
||||||
|
{
|
||||||
|
if (down)
|
||||||
|
pressedL=true;
|
||||||
|
else
|
||||||
|
pressedL=false;
|
||||||
|
}
|
||||||
|
void ClickableL::activate()
|
||||||
|
{
|
||||||
|
LOCPLINT->lclickable.push_front(this);
|
||||||
|
}
|
||||||
|
void ClickableL::deactivate()
|
||||||
|
{
|
||||||
|
LOCPLINT->lclickable.erase
|
||||||
|
(std::find(LOCPLINT->lclickable.begin(),LOCPLINT->lclickable.end(),this));
|
||||||
|
}
|
||||||
|
|
||||||
|
ClickableR::ClickableR()
|
||||||
|
{
|
||||||
|
pressedR=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClickableR::~ClickableR()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void ClickableR::clickRight(boost::logic::tribool down)
|
||||||
|
{
|
||||||
|
if (down)
|
||||||
|
pressedR=true;
|
||||||
|
else
|
||||||
|
pressedR=false;
|
||||||
|
}
|
||||||
|
void ClickableR::activate()
|
||||||
|
{
|
||||||
|
LOCPLINT->rclickable.push_front(this);
|
||||||
|
}
|
||||||
|
void ClickableR::deactivate()
|
||||||
|
{
|
||||||
|
LOCPLINT->rclickable.erase(std::find(LOCPLINT->rclickable.begin(),LOCPLINT->rclickable.end(),this));
|
||||||
|
}
|
||||||
|
//ClickableR
|
||||||
|
|
||||||
|
Hoverable::~Hoverable()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void Hoverable::activate()
|
||||||
|
{
|
||||||
|
LOCPLINT->hoverable.push_front(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Hoverable::deactivate()
|
||||||
|
{
|
||||||
|
LOCPLINT->hoverable.erase(std::find(LOCPLINT->hoverable.begin(),LOCPLINT->hoverable.end(),this));
|
||||||
|
}
|
||||||
|
void Hoverable::hover(bool on)
|
||||||
|
{
|
||||||
|
hovered=on;
|
||||||
|
}
|
||||||
|
//Hoverable
|
||||||
|
|
||||||
|
KeyInterested::~KeyInterested()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void KeyInterested::activate()
|
||||||
|
{
|
||||||
|
LOCPLINT->keyinterested.push_front(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyInterested::deactivate()
|
||||||
|
{
|
||||||
|
LOCPLINT->
|
||||||
|
keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this));
|
||||||
|
}
|
||||||
|
//KeyInterested
|
||||||
|
|
||||||
|
void MotionInterested::activate()
|
||||||
|
{
|
||||||
|
LOCPLINT->motioninterested.push_front(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MotionInterested::deactivate()
|
||||||
|
{
|
||||||
|
LOCPLINT->
|
||||||
|
motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimeInterested::activate()
|
||||||
|
{
|
||||||
|
LOCPLINT->timeinterested.push_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimeInterested::deactivate()
|
||||||
|
{
|
||||||
|
LOCPLINT->
|
||||||
|
timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this));
|
||||||
|
}
|
||||||
|
|
368
client/GUIBase.h
Normal file
368
client/GUIBase.h
Normal file
@ -0,0 +1,368 @@
|
|||||||
|
#ifndef __GUIBASE_H__
|
||||||
|
#define __GUIBASE_H__
|
||||||
|
|
||||||
|
#include "../global.h"
|
||||||
|
#include "SDL.h"
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
#ifdef max
|
||||||
|
#undef max
|
||||||
|
#endif
|
||||||
|
#ifdef min
|
||||||
|
#undef min
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GUIBase.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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class CDefEssential;
|
||||||
|
class AdventureMapButton;
|
||||||
|
class CHighlightableButtonsGroup;
|
||||||
|
class CDefHandler;
|
||||||
|
struct HeroMoveDetails;
|
||||||
|
class CDefEssential;
|
||||||
|
class CGHeroInstance;
|
||||||
|
class CAdvMapInt;
|
||||||
|
class CCastleInterface;
|
||||||
|
class CBattleInterface;
|
||||||
|
class CStack;
|
||||||
|
class SComponent;
|
||||||
|
class CCreature;
|
||||||
|
struct SDL_Surface;
|
||||||
|
struct CPath;
|
||||||
|
class CCreatureAnimation;
|
||||||
|
class CSelectableComponent;
|
||||||
|
class CCreatureSet;
|
||||||
|
class CGObjectInstance;
|
||||||
|
class CSlider;
|
||||||
|
struct UpgradeInfo;
|
||||||
|
template <typename T> struct CondSh;
|
||||||
|
class CInGameConsole;
|
||||||
|
class CGarrisonInt;
|
||||||
|
class CInGameConsole;
|
||||||
|
class Component;
|
||||||
|
class CArmedInstance;
|
||||||
|
class CGTownInstance;
|
||||||
|
class StackState;
|
||||||
|
class CPlayerInterface;
|
||||||
|
|
||||||
|
struct Point
|
||||||
|
{
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
//constructors
|
||||||
|
Point(){};
|
||||||
|
Point(int X, int Y)
|
||||||
|
:x(X),y(Y)
|
||||||
|
{};
|
||||||
|
Point(const int3 &a)
|
||||||
|
:x(a.x),y(a.y)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Point operator+(const Point &b) const
|
||||||
|
{
|
||||||
|
return Point(x+b.x,y+b.y);
|
||||||
|
}
|
||||||
|
Point& operator+=(const Point &b)
|
||||||
|
{
|
||||||
|
x += b.x;
|
||||||
|
y += b.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
Point operator-(const Point &b) const
|
||||||
|
{
|
||||||
|
return Point(x+b.x,y+b.y);
|
||||||
|
}
|
||||||
|
Point& operator-=(const Point &b)
|
||||||
|
{
|
||||||
|
x -= b.x;
|
||||||
|
y -= b.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
bool operator<(const Point &b) const //product order
|
||||||
|
{
|
||||||
|
return x < b.x && y < b.y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Rect : public SDL_Rect
|
||||||
|
{
|
||||||
|
Rect()//default c-tor
|
||||||
|
{
|
||||||
|
x = y = w = h = -1;
|
||||||
|
}
|
||||||
|
Rect(int X, int Y, int W, int H) //c-tor
|
||||||
|
{
|
||||||
|
x = X;
|
||||||
|
y = Y;
|
||||||
|
w = W;
|
||||||
|
h = H;
|
||||||
|
}
|
||||||
|
Rect(const SDL_Rect & r) //c-tor
|
||||||
|
{
|
||||||
|
x = r.x;
|
||||||
|
y = r.y;
|
||||||
|
w = r.w;
|
||||||
|
h = r.h;
|
||||||
|
}
|
||||||
|
bool isIn(int qx, int qy) const //determines if given point lies inside rect
|
||||||
|
{
|
||||||
|
if (qx > x && qx<x+w && qy>y && qy<y+h)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool isIn(const Point &q) const //determines if given point lies inside rect
|
||||||
|
{
|
||||||
|
return isIn(q.x,q.y);
|
||||||
|
}
|
||||||
|
Point topLeft() const //top left corner of this rect
|
||||||
|
{
|
||||||
|
return Point(x,y);
|
||||||
|
}
|
||||||
|
Point topRight() const //top right corner of this rect
|
||||||
|
{
|
||||||
|
return Point(x+w,y);
|
||||||
|
}
|
||||||
|
Point bottomLeft() const //bottom left corner of this rect
|
||||||
|
{
|
||||||
|
return Point(x,y+h);
|
||||||
|
}
|
||||||
|
Point bottomRight() const //bottom right corner of this rect
|
||||||
|
{
|
||||||
|
return Point(x+w,y+h);
|
||||||
|
}
|
||||||
|
Rect operator+(const Rect &p) const //moves this rect by p's rect position
|
||||||
|
{
|
||||||
|
return Rect(x+p.x,y+p.y,w,h);
|
||||||
|
}
|
||||||
|
Rect operator+(const Point &p) const //moves this rect by p's point position
|
||||||
|
{
|
||||||
|
return Rect(x+p.x,y+p.y,w,h);
|
||||||
|
}
|
||||||
|
Rect& operator=(const Rect &p) //assignment operator
|
||||||
|
{
|
||||||
|
x = p.x;
|
||||||
|
y = p.y;
|
||||||
|
w = p.w;
|
||||||
|
h = p.h;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
Rect& operator+=(const Rect &p) //works as operator+
|
||||||
|
{
|
||||||
|
x += p.x;
|
||||||
|
y += p.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
Rect operator&(const Rect &p) const //rect intersection
|
||||||
|
{
|
||||||
|
bool intersect = true;
|
||||||
|
|
||||||
|
if(p.topLeft().y < y && p.bottomLeft().y < y) //rect p is above *this
|
||||||
|
{
|
||||||
|
intersect = false;
|
||||||
|
}
|
||||||
|
else if(p.topLeft().y > y+h && p.bottomLeft().y > y+h) //rect p is below *this
|
||||||
|
{
|
||||||
|
intersect = false;
|
||||||
|
}
|
||||||
|
else if(p.topLeft().x > x+w && p.topRight().x > x+w) //rect p is on the right hand side of this
|
||||||
|
{
|
||||||
|
intersect = false;
|
||||||
|
}
|
||||||
|
else if(p.topLeft().x < x && p.topRight().x < x) //rect p is on the left hand side of this
|
||||||
|
{
|
||||||
|
intersect = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(intersect)
|
||||||
|
{
|
||||||
|
Rect ret;
|
||||||
|
ret.x = std::max(this->x, p.x);
|
||||||
|
ret.y = std::max(this->y, p.y);
|
||||||
|
Point bR; //bottomRight point of returned rect
|
||||||
|
bR.x = std::min(this->w+this->x, p.w+p.x);
|
||||||
|
bR.y = std::min(this->h+this->y, p.h+p.y);
|
||||||
|
ret.w = bR.x - ret.x;
|
||||||
|
ret.h = bR.y - ret.y;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Rect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class IShowable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void show(SDL_Surface * to)=0;
|
||||||
|
virtual void showAll(SDL_Surface * to)
|
||||||
|
{
|
||||||
|
show(to);
|
||||||
|
}
|
||||||
|
virtual ~IShowable(){}; //d-tor
|
||||||
|
};
|
||||||
|
|
||||||
|
class IStatusBar
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IStatusBar(){}; //d-tor
|
||||||
|
virtual void print(const std::string & text)=0; //prints text and refreshes statusbar
|
||||||
|
virtual void clear()=0;//clears statusbar and refreshes
|
||||||
|
virtual void show(SDL_Surface * to)=0; //shows statusbar (with current text)
|
||||||
|
virtual std::string getCurrent()=0; //returns currently displayed text
|
||||||
|
};
|
||||||
|
|
||||||
|
class IActivable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void activate()=0;
|
||||||
|
virtual void deactivate()=0;
|
||||||
|
virtual ~IActivable(){}; //d-tor
|
||||||
|
};
|
||||||
|
class IShowActivable : public IShowable, public IActivable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum {WITH_GARRISON = 1};
|
||||||
|
int type; //bin flags using etype
|
||||||
|
IShowActivable();
|
||||||
|
virtual ~IShowActivable(){}; //d-tor
|
||||||
|
};
|
||||||
|
|
||||||
|
class CWindowWithGarrison : public IShowActivable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CGarrisonInt *garr;
|
||||||
|
CWindowWithGarrison();
|
||||||
|
};
|
||||||
|
|
||||||
|
class CMainInterface : public IShowActivable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IShowActivable *subInt;
|
||||||
|
};
|
||||||
|
class CIntObject //interface object
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Rect pos; //position of object on the screen
|
||||||
|
int ID; //object uniqe ID, rarely (if at all) used
|
||||||
|
|
||||||
|
//virtual bool isIn(int x, int y)
|
||||||
|
//{
|
||||||
|
// return pos.isIn(x,y);
|
||||||
|
//}
|
||||||
|
virtual ~CIntObject(){}; //d-tor
|
||||||
|
};
|
||||||
|
class CSimpleWindow : public IShowActivable, public virtual CIntObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SDL_Surface * bitmap; //background
|
||||||
|
CIntObject * owner; //who made this window
|
||||||
|
virtual void show(SDL_Surface * to);
|
||||||
|
CSimpleWindow():bitmap(NULL),owner(NULL){}; //c-tor
|
||||||
|
virtual ~CSimpleWindow(); //d-tor
|
||||||
|
void activate(){};
|
||||||
|
void deactivate(){};
|
||||||
|
};
|
||||||
|
class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int bitmapOffset; //TODO: comment me
|
||||||
|
int type; //advmapbutton=2 //TODO: comment me
|
||||||
|
bool abs;//TODO: comment me
|
||||||
|
bool active; //if true, this button is active and can be pressed
|
||||||
|
bool notFreeButton; //TODO: comment me
|
||||||
|
CIntObject * ourObj; // "owner"
|
||||||
|
int state; //TODO: comment me
|
||||||
|
std::vector< std::vector<SDL_Surface*> > imgs; //images for this button
|
||||||
|
int curimg; //curently displayed image from imgs
|
||||||
|
virtual void show(SDL_Surface * to);
|
||||||
|
virtual void activate()=0;
|
||||||
|
virtual void deactivate()=0;
|
||||||
|
CButtonBase(); //c-tor
|
||||||
|
virtual ~CButtonBase(); //d-tor
|
||||||
|
};
|
||||||
|
class ClickableL : public virtual CIntObject //for left-clicks
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool pressedL; //for determining if object is L-pressed
|
||||||
|
ClickableL(); //c-tor
|
||||||
|
virtual ~ClickableL();//{};//d-tor
|
||||||
|
virtual void clickLeft (boost::logic::tribool down)=0;
|
||||||
|
virtual void activate();
|
||||||
|
virtual void deactivate();
|
||||||
|
};
|
||||||
|
class ClickableR : public virtual CIntObject //for right-clicks
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool pressedR; //for determining if object is R-pressed
|
||||||
|
ClickableR(); //c-tor
|
||||||
|
virtual ~ClickableR();//{};//d-tor
|
||||||
|
virtual void clickRight (boost::logic::tribool down)=0;
|
||||||
|
virtual void activate()=0;
|
||||||
|
virtual void deactivate()=0;
|
||||||
|
};
|
||||||
|
class Hoverable : public virtual CIntObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Hoverable() : hovered(false){} //c-tor
|
||||||
|
virtual ~Hoverable();//{}; //d-tor
|
||||||
|
bool hovered; //for determining if object is hovered
|
||||||
|
virtual void hover (bool on)=0;
|
||||||
|
virtual void activate()=0;
|
||||||
|
virtual void deactivate()=0;
|
||||||
|
};
|
||||||
|
class KeyInterested : public virtual CIntObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool captureAllKeys; //if true, only this object should get info about pressed keys
|
||||||
|
KeyInterested(): captureAllKeys(false){}
|
||||||
|
virtual ~KeyInterested();//{};//d-tor
|
||||||
|
virtual void keyPressed(const SDL_KeyboardEvent & key)=0;
|
||||||
|
virtual void activate()=0;
|
||||||
|
virtual void deactivate()=0;
|
||||||
|
};
|
||||||
|
|
||||||
|
//class for binding keys to left mouse button clicks
|
||||||
|
//classes wanting use it should have it as one of their base classes
|
||||||
|
class KeyShortcut : public KeyInterested, public ClickableL
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::set<int> assignedKeys;
|
||||||
|
KeyShortcut(){}; //c-tor
|
||||||
|
KeyShortcut(int key){assignedKeys.insert(key);}; //c-tor
|
||||||
|
KeyShortcut(std::set<int> Keys):assignedKeys(Keys){}; //c-tor
|
||||||
|
virtual void keyPressed(const SDL_KeyboardEvent & key); //call-in
|
||||||
|
};
|
||||||
|
|
||||||
|
class MotionInterested: public virtual CIntObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool strongInterest; //if true - report all mouse movements, if not - only when hovered
|
||||||
|
MotionInterested(){strongInterest=false;};
|
||||||
|
virtual ~MotionInterested(){};//d-tor
|
||||||
|
virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0;
|
||||||
|
virtual void activate()=0;
|
||||||
|
virtual void deactivate()=0;
|
||||||
|
};
|
||||||
|
class TimeInterested: public virtual CIntObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~TimeInterested(){}; //d-tor
|
||||||
|
int toNextTick;
|
||||||
|
virtual void tick()=0;
|
||||||
|
virtual void activate();
|
||||||
|
virtual void deactivate();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //__GUIBASE_H__
|
@ -69,16 +69,6 @@ StackState* getStackState(const CGObjectInstance *obj, int pos, bool town)
|
|||||||
return pom;
|
return pom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyShortcut::keyPressed(const SDL_KeyboardEvent & key)
|
|
||||||
{
|
|
||||||
if(vstd::contains(assignedKeys,key.keysym.sym))
|
|
||||||
{
|
|
||||||
if(key.state == SDL_PRESSED)
|
|
||||||
clickLeft(true);
|
|
||||||
else
|
|
||||||
clickLeft(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CGarrisonSlot::hover (bool on)
|
void CGarrisonSlot::hover (bool on)
|
||||||
{
|
{
|
||||||
@ -949,143 +939,7 @@ void CSelWindow::madeChoice()
|
|||||||
LOCPLINT->cb->selectionMade(ret+1,ID);
|
LOCPLINT->cb->selectionMade(ret+1,ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
CButtonBase::CButtonBase()
|
|
||||||
{
|
|
||||||
bitmapOffset = 0;
|
|
||||||
curimg=0;
|
|
||||||
type=-1;
|
|
||||||
abs=false;
|
|
||||||
active=false;
|
|
||||||
notFreeButton = false;
|
|
||||||
ourObj=NULL;
|
|
||||||
state=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CButtonBase::~CButtonBase()
|
|
||||||
{
|
|
||||||
if(notFreeButton)
|
|
||||||
return;
|
|
||||||
for(int i =0; i<imgs.size();i++)
|
|
||||||
for(int j=0;j<imgs[i].size();j++)
|
|
||||||
SDL_FreeSurface(imgs[i][j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CButtonBase::show(SDL_Surface * to)
|
|
||||||
{
|
|
||||||
int img = std::min(state+bitmapOffset,int(imgs[curimg].size()-1));
|
|
||||||
img = std::max(0, img);
|
|
||||||
|
|
||||||
if (abs)
|
|
||||||
{
|
|
||||||
blitAt(imgs[curimg][img],pos.x,pos.y,to);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
blitAt(imgs[curimg][img],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ClickableL::ClickableL()
|
|
||||||
{
|
|
||||||
pressedL=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClickableL::~ClickableL()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClickableL::clickLeft(tribool down)
|
|
||||||
{
|
|
||||||
if (down)
|
|
||||||
pressedL=true;
|
|
||||||
else
|
|
||||||
pressedL=false;
|
|
||||||
}
|
|
||||||
void ClickableL::activate()
|
|
||||||
{
|
|
||||||
LOCPLINT->lclickable.push_front(this);
|
|
||||||
}
|
|
||||||
void ClickableL::deactivate()
|
|
||||||
{
|
|
||||||
LOCPLINT->lclickable.erase
|
|
||||||
(std::find(LOCPLINT->lclickable.begin(),LOCPLINT->lclickable.end(),this));
|
|
||||||
}
|
|
||||||
|
|
||||||
ClickableR::ClickableR()
|
|
||||||
{
|
|
||||||
pressedR=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClickableR::~ClickableR()
|
|
||||||
{}
|
|
||||||
|
|
||||||
void ClickableR::clickRight(tribool down)
|
|
||||||
{
|
|
||||||
if (down)
|
|
||||||
pressedR=true;
|
|
||||||
else
|
|
||||||
pressedR=false;
|
|
||||||
}
|
|
||||||
void ClickableR::activate()
|
|
||||||
{
|
|
||||||
LOCPLINT->rclickable.push_front(this);
|
|
||||||
}
|
|
||||||
void ClickableR::deactivate()
|
|
||||||
{
|
|
||||||
LOCPLINT->rclickable.erase(std::find(LOCPLINT->rclickable.begin(),LOCPLINT->rclickable.end(),this));
|
|
||||||
}
|
|
||||||
//ClickableR
|
|
||||||
|
|
||||||
Hoverable::~Hoverable()
|
|
||||||
{}
|
|
||||||
|
|
||||||
void Hoverable::activate()
|
|
||||||
{
|
|
||||||
LOCPLINT->hoverable.push_front(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Hoverable::deactivate()
|
|
||||||
{
|
|
||||||
LOCPLINT->hoverable.erase(std::find(LOCPLINT->hoverable.begin(),LOCPLINT->hoverable.end(),this));
|
|
||||||
}
|
|
||||||
void Hoverable::hover(bool on)
|
|
||||||
{
|
|
||||||
hovered=on;
|
|
||||||
}
|
|
||||||
//Hoverable
|
|
||||||
|
|
||||||
KeyInterested::~KeyInterested()
|
|
||||||
{}
|
|
||||||
|
|
||||||
void KeyInterested::activate()
|
|
||||||
{
|
|
||||||
LOCPLINT->keyinterested.push_front(this);
|
|
||||||
}
|
|
||||||
void KeyInterested::deactivate()
|
|
||||||
{
|
|
||||||
LOCPLINT->
|
|
||||||
keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this));
|
|
||||||
}
|
|
||||||
//KeyInterested
|
|
||||||
|
|
||||||
void MotionInterested::activate()
|
|
||||||
{
|
|
||||||
LOCPLINT->motioninterested.push_front(this);
|
|
||||||
}
|
|
||||||
void MotionInterested::deactivate()
|
|
||||||
{
|
|
||||||
LOCPLINT->
|
|
||||||
motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
|
|
||||||
}
|
|
||||||
void TimeInterested::activate()
|
|
||||||
{
|
|
||||||
LOCPLINT->timeinterested.push_back(this);
|
|
||||||
}
|
|
||||||
void TimeInterested::deactivate()
|
|
||||||
{
|
|
||||||
LOCPLINT->
|
|
||||||
timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this));
|
|
||||||
}
|
|
||||||
|
|
||||||
CStatusBar::CStatusBar(int x, int y, std::string name, int maxw)
|
CStatusBar::CStatusBar(int x, int y, std::string name, int maxw)
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
#define __GUICLASSES_H__
|
#define __GUICLASSES_H__
|
||||||
|
|
||||||
#include "../global.h"
|
#include "../global.h"
|
||||||
#include "SDL_framerate.h"
|
#include "../SDL_framerate.h"
|
||||||
|
#include "GUIBase.h"
|
||||||
#include "FunctionList.h"
|
#include "FunctionList.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <list>
|
#include <list>
|
||||||
@ -55,315 +56,6 @@ class CGTownInstance;
|
|||||||
class StackState;
|
class StackState;
|
||||||
class CPlayerInterface;
|
class CPlayerInterface;
|
||||||
|
|
||||||
struct Point
|
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
|
|
||||||
//constructors
|
|
||||||
Point(){};
|
|
||||||
Point(int X, int Y)
|
|
||||||
:x(X),y(Y)
|
|
||||||
{};
|
|
||||||
Point(const int3 &a)
|
|
||||||
:x(a.x),y(a.y)
|
|
||||||
{}
|
|
||||||
|
|
||||||
Point operator+(const Point &b) const
|
|
||||||
{
|
|
||||||
return Point(x+b.x,y+b.y);
|
|
||||||
}
|
|
||||||
Point& operator+=(const Point &b)
|
|
||||||
{
|
|
||||||
x += b.x;
|
|
||||||
y += b.y;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
Point operator-(const Point &b) const
|
|
||||||
{
|
|
||||||
return Point(x+b.x,y+b.y);
|
|
||||||
}
|
|
||||||
Point& operator-=(const Point &b)
|
|
||||||
{
|
|
||||||
x -= b.x;
|
|
||||||
y -= b.y;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
bool operator<(const Point &b) const //product order
|
|
||||||
{
|
|
||||||
return x < b.x && y < b.y;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Rect : public SDL_Rect
|
|
||||||
{
|
|
||||||
Rect()//default c-tor
|
|
||||||
{
|
|
||||||
x = y = w = h = -1;
|
|
||||||
}
|
|
||||||
Rect(int X, int Y, int W, int H) //c-tor
|
|
||||||
{
|
|
||||||
x = X;
|
|
||||||
y = Y;
|
|
||||||
w = W;
|
|
||||||
h = H;
|
|
||||||
}
|
|
||||||
Rect(const SDL_Rect & r) //c-tor
|
|
||||||
{
|
|
||||||
x = r.x;
|
|
||||||
y = r.y;
|
|
||||||
w = r.w;
|
|
||||||
h = r.h;
|
|
||||||
}
|
|
||||||
bool isIn(int qx, int qy) const //determines if given point lies inside rect
|
|
||||||
{
|
|
||||||
if (qx > x && qx<x+w && qy>y && qy<y+h)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool isIn(const Point &q) const //determines if given point lies inside rect
|
|
||||||
{
|
|
||||||
return isIn(q.x,q.y);
|
|
||||||
}
|
|
||||||
Point topLeft() const //top left corner of this rect
|
|
||||||
{
|
|
||||||
return Point(x,y);
|
|
||||||
}
|
|
||||||
Point topRight() const //top right corner of this rect
|
|
||||||
{
|
|
||||||
return Point(x+w,y);
|
|
||||||
}
|
|
||||||
Point bottomLeft() const //bottom left corner of this rect
|
|
||||||
{
|
|
||||||
return Point(x,y+h);
|
|
||||||
}
|
|
||||||
Point bottomRight() const //bottom right corner of this rect
|
|
||||||
{
|
|
||||||
return Point(x+w,y+h);
|
|
||||||
}
|
|
||||||
Rect operator+(const Rect &p) const //moves this rect by p's rect position
|
|
||||||
{
|
|
||||||
return Rect(x+p.x,y+p.y,w,h);
|
|
||||||
}
|
|
||||||
Rect operator+(const Point &p) const //moves this rect by p's point position
|
|
||||||
{
|
|
||||||
return Rect(x+p.x,y+p.y,w,h);
|
|
||||||
}
|
|
||||||
Rect& operator=(const Rect &p) //assignment operator
|
|
||||||
{
|
|
||||||
x = p.x;
|
|
||||||
y = p.y;
|
|
||||||
w = p.w;
|
|
||||||
h = p.h;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
Rect& operator+=(const Rect &p) //works as operator+
|
|
||||||
{
|
|
||||||
x += p.x;
|
|
||||||
y += p.y;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
Rect operator&(const Rect &p) const //rect intersection
|
|
||||||
{
|
|
||||||
bool intersect = true;
|
|
||||||
|
|
||||||
if(p.topLeft().y < y && p.bottomLeft().y < y) //rect p is above *this
|
|
||||||
{
|
|
||||||
intersect = false;
|
|
||||||
}
|
|
||||||
else if(p.topLeft().y > y+h && p.bottomLeft().y > y+h) //rect p is below *this
|
|
||||||
{
|
|
||||||
intersect = false;
|
|
||||||
}
|
|
||||||
else if(p.topLeft().x > x+w && p.topRight().x > x+w) //rect p is on the right hand side of this
|
|
||||||
{
|
|
||||||
intersect = false;
|
|
||||||
}
|
|
||||||
else if(p.topLeft().x < x && p.topRight().x < x) //rect p is on the left hand side of this
|
|
||||||
{
|
|
||||||
intersect = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(intersect)
|
|
||||||
{
|
|
||||||
Rect ret;
|
|
||||||
ret.x = std::max(this->x, p.x);
|
|
||||||
ret.y = std::max(this->y, p.y);
|
|
||||||
Point bR; //bottomRight point of returned rect
|
|
||||||
bR.x = std::min(this->w+this->x, p.w+p.x);
|
|
||||||
bR.y = std::min(this->h+this->y, p.h+p.y);
|
|
||||||
ret.w = bR.x - ret.x;
|
|
||||||
ret.h = bR.y - ret.y;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Rect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class IShowable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual void show(SDL_Surface * to)=0;
|
|
||||||
virtual void showAll(SDL_Surface * to)
|
|
||||||
{
|
|
||||||
show(to);
|
|
||||||
}
|
|
||||||
virtual ~IShowable(){}; //d-tor
|
|
||||||
};
|
|
||||||
|
|
||||||
class IStatusBar
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~IStatusBar(){}; //d-tor
|
|
||||||
virtual void print(const std::string & text)=0; //prints text and refreshes statusbar
|
|
||||||
virtual void clear()=0;//clears statusbar and refreshes
|
|
||||||
virtual void show(SDL_Surface * to)=0; //shows statusbar (with current text)
|
|
||||||
virtual std::string getCurrent()=0; //returns currently displayed text
|
|
||||||
};
|
|
||||||
|
|
||||||
class IActivable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual void activate()=0;
|
|
||||||
virtual void deactivate()=0;
|
|
||||||
virtual ~IActivable(){}; //d-tor
|
|
||||||
};
|
|
||||||
class IShowActivable : public IShowable, public IActivable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum {WITH_GARRISON = 1};
|
|
||||||
int type; //bin flags using etype
|
|
||||||
IShowActivable();
|
|
||||||
virtual ~IShowActivable(){}; //d-tor
|
|
||||||
};
|
|
||||||
|
|
||||||
class CWindowWithGarrison : public IShowActivable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CGarrisonInt *garr;
|
|
||||||
CWindowWithGarrison();
|
|
||||||
};
|
|
||||||
|
|
||||||
class CMainInterface : public IShowActivable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
IShowActivable *subInt;
|
|
||||||
};
|
|
||||||
class CIntObject //interface object
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Rect pos; //position of object on the screen
|
|
||||||
int ID; //object uniqe ID, rarely (if at all) used
|
|
||||||
|
|
||||||
//virtual bool isIn(int x, int y)
|
|
||||||
//{
|
|
||||||
// return pos.isIn(x,y);
|
|
||||||
//}
|
|
||||||
virtual ~CIntObject(){}; //d-tor
|
|
||||||
};
|
|
||||||
class CSimpleWindow : public IShowActivable, public virtual CIntObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SDL_Surface * bitmap; //background
|
|
||||||
CIntObject * owner; //who made this window
|
|
||||||
virtual void show(SDL_Surface * to);
|
|
||||||
CSimpleWindow():bitmap(NULL),owner(NULL){}; //c-tor
|
|
||||||
virtual ~CSimpleWindow(); //d-tor
|
|
||||||
void activate(){};
|
|
||||||
void deactivate(){};
|
|
||||||
};
|
|
||||||
class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int bitmapOffset; //TODO: comment me
|
|
||||||
int type; //advmapbutton=2 //TODO: comment me
|
|
||||||
bool abs;//TODO: comment me
|
|
||||||
bool active; //if true, this button is active and can be pressed
|
|
||||||
bool notFreeButton; //TODO: comment me
|
|
||||||
CIntObject * ourObj; // "owner"
|
|
||||||
int state; //TODO: comment me
|
|
||||||
std::vector< std::vector<SDL_Surface*> > imgs; //images for this button
|
|
||||||
int curimg; //curently displayed image from imgs
|
|
||||||
virtual void show(SDL_Surface * to);
|
|
||||||
virtual void activate()=0;
|
|
||||||
virtual void deactivate()=0;
|
|
||||||
CButtonBase(); //c-tor
|
|
||||||
virtual ~CButtonBase(); //d-tor
|
|
||||||
};
|
|
||||||
class ClickableL : public virtual CIntObject //for left-clicks
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool pressedL; //for determining if object is L-pressed
|
|
||||||
ClickableL(); //c-tor
|
|
||||||
virtual ~ClickableL();//{};//d-tor
|
|
||||||
virtual void clickLeft (boost::logic::tribool down)=0;
|
|
||||||
virtual void activate();
|
|
||||||
virtual void deactivate();
|
|
||||||
};
|
|
||||||
class ClickableR : public virtual CIntObject //for right-clicks
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool pressedR; //for determining if object is R-pressed
|
|
||||||
ClickableR(); //c-tor
|
|
||||||
virtual ~ClickableR();//{};//d-tor
|
|
||||||
virtual void clickRight (boost::logic::tribool down)=0;
|
|
||||||
virtual void activate()=0;
|
|
||||||
virtual void deactivate()=0;
|
|
||||||
};
|
|
||||||
class Hoverable : public virtual CIntObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Hoverable() : hovered(false){} //c-tor
|
|
||||||
virtual ~Hoverable();//{}; //d-tor
|
|
||||||
bool hovered; //for determining if object is hovered
|
|
||||||
virtual void hover (bool on)=0;
|
|
||||||
virtual void activate()=0;
|
|
||||||
virtual void deactivate()=0;
|
|
||||||
};
|
|
||||||
class KeyInterested : public virtual CIntObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool captureAllKeys; //if true, only this object should get info about pressed keys
|
|
||||||
KeyInterested(): captureAllKeys(false){}
|
|
||||||
virtual ~KeyInterested();//{};//d-tor
|
|
||||||
virtual void keyPressed(const SDL_KeyboardEvent & key)=0;
|
|
||||||
virtual void activate()=0;
|
|
||||||
virtual void deactivate()=0;
|
|
||||||
};
|
|
||||||
|
|
||||||
//class for binding keys to left mouse button clicks
|
|
||||||
//classes wanting use it should have it as one of their base classes
|
|
||||||
class KeyShortcut : public KeyInterested, public ClickableL
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::set<int> assignedKeys;
|
|
||||||
KeyShortcut(){}; //c-tor
|
|
||||||
KeyShortcut(int key){assignedKeys.insert(key);}; //c-tor
|
|
||||||
KeyShortcut(std::set<int> Keys):assignedKeys(Keys){}; //c-tor
|
|
||||||
virtual void keyPressed(const SDL_KeyboardEvent & key); //call-in
|
|
||||||
};
|
|
||||||
|
|
||||||
class MotionInterested: public virtual CIntObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool strongInterest; //if true - report all mouse movements, if not - only when hovered
|
|
||||||
MotionInterested(){strongInterest=false;};
|
|
||||||
virtual ~MotionInterested(){};//d-tor
|
|
||||||
virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0;
|
|
||||||
virtual void activate()=0;
|
|
||||||
virtual void deactivate()=0;
|
|
||||||
};
|
|
||||||
class TimeInterested: public virtual CIntObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~TimeInterested(){}; //d-tor
|
|
||||||
int toNextTick;
|
|
||||||
virtual void tick()=0;
|
|
||||||
virtual void activate();
|
|
||||||
virtual void deactivate();
|
|
||||||
};
|
|
||||||
|
|
||||||
class CInfoWindow : public CSimpleWindow //text + comp. + ok button
|
class CInfoWindow : public CSimpleWindow //text + comp. + ok button
|
||||||
{ //window able to delete its components when closed
|
{ //window able to delete its components when closed
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
#ifndef __CMUSICBASE_H__
|
#ifndef __CMUSICBASE_H__
|
||||||
#define __CMUSICBASE_H__
|
#define __CMUSICBASE_H__
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CMusicBase.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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
// Use some magic to keep the list of files and their code name in sync.
|
// Use some magic to keep the list of files and their code name in sync.
|
||||||
|
|
||||||
#define VCMI_MUSIC_LIST \
|
#define VCMI_MUSIC_LIST \
|
||||||
|
@ -273,7 +273,8 @@ void CMusicHandler::freeMusics()
|
|||||||
|
|
||||||
musicMutex.lock();
|
musicMutex.lock();
|
||||||
|
|
||||||
if (currentMusic) {
|
if (currentMusic)
|
||||||
|
{
|
||||||
Mix_HaltMusic();
|
Mix_HaltMusic();
|
||||||
Mix_FreeMusic(currentMusic);
|
Mix_FreeMusic(currentMusic);
|
||||||
}
|
}
|
||||||
@ -293,19 +294,23 @@ void CMusicHandler::playMusic(musicBase::musicID musicID, int loop)
|
|||||||
|
|
||||||
musicMutex.lock();
|
musicMutex.lock();
|
||||||
|
|
||||||
if (nextMusic) {
|
if (nextMusic)
|
||||||
|
{
|
||||||
// There's already a music queued, so remove it
|
// There's already a music queued, so remove it
|
||||||
Mix_FreeMusic(nextMusic);
|
Mix_FreeMusic(nextMusic);
|
||||||
nextMusic = NULL;
|
nextMusic = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentMusic) {
|
if (currentMusic)
|
||||||
|
{
|
||||||
// A music is already playing. Stop it and the callback will
|
// A music is already playing. Stop it and the callback will
|
||||||
// start the new one
|
// start the new one
|
||||||
nextMusic = Mix_LoadMUS(filename.c_str());
|
nextMusic = Mix_LoadMUS(filename.c_str());
|
||||||
nextMusicLoop = loop;
|
nextMusicLoop = loop;
|
||||||
Mix_FadeOutMusic(1000);
|
Mix_FadeOutMusic(1000);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
currentMusic = Mix_LoadMUS(filename.c_str());
|
currentMusic = Mix_LoadMUS(filename.c_str());
|
||||||
if (Mix_PlayMusic(currentMusic, loop) == -1)
|
if (Mix_PlayMusic(currentMusic, loop) == -1)
|
||||||
tlog1 << "Unable to play sound file " << musicID << "(" << Mix_GetError() << ")" << std::endl;
|
tlog1 << "Unable to play sound file " << musicID << "(" << Mix_GetError() << ")" << std::endl;
|
||||||
@ -325,7 +330,8 @@ void CMusicHandler::stopMusic(int fade_ms)
|
|||||||
{
|
{
|
||||||
musicMutex.lock();
|
musicMutex.lock();
|
||||||
|
|
||||||
if (currentMusic) {
|
if (currentMusic)
|
||||||
|
{
|
||||||
Mix_FadeOutMusic(fade_ms);
|
Mix_FadeOutMusic(fade_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,12 +359,14 @@ void CMusicHandler::musicFinishedCallback(void)
|
|||||||
{
|
{
|
||||||
musicMutex.lock();
|
musicMutex.lock();
|
||||||
|
|
||||||
if (currentMusic) {
|
if (currentMusic)
|
||||||
|
{
|
||||||
Mix_FreeMusic(currentMusic);
|
Mix_FreeMusic(currentMusic);
|
||||||
currentMusic = NULL;
|
currentMusic = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextMusic) {
|
if (nextMusic)
|
||||||
|
{
|
||||||
currentMusic = nextMusic;
|
currentMusic = nextMusic;
|
||||||
nextMusic = NULL;
|
nextMusic = NULL;
|
||||||
if (Mix_PlayMusic(currentMusic, nextMusicLoop) == -1)
|
if (Mix_PlayMusic(currentMusic, nextMusicLoop) == -1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user