mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
* new files (CAdvmapInterface.h and CAdvmapInterface.cpp)
* more player interface (but it's still beginning) * int3 members public * more usage of int3 * adjusted animation speed * reversed changes from rev.165 in CPreGame - it wasn't bug, it just works so. That change was breaking a few things in CPreGame and was needless - Player ID == Player's Color. I thought it was obvious. * minor stuff
This commit is contained in:
parent
9b5686b40c
commit
0ea7a46309
71
CAdvmapInterface.cpp
Normal file
71
CAdvmapInterface.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
#include "stdafx.h"
|
||||
#include "CAdvmapInterface.h"
|
||||
|
||||
CAdvMapInt::CAdvMapInt(int Player)
|
||||
:player(Player)
|
||||
{
|
||||
bg = CGI->bitmaph->loadBitmap("ADVMAP.bmp");
|
||||
blueToPlayersAdv(bg,player);
|
||||
}
|
||||
CAdvMapInt::~CAdvMapInt()
|
||||
{
|
||||
SDL_FreeSurface(bg);
|
||||
}
|
||||
|
||||
void AdventureMapButton::clickLeft (tribool down)
|
||||
{
|
||||
if (down)
|
||||
state=1;
|
||||
else state=0;
|
||||
show();
|
||||
int i;
|
||||
}
|
||||
void AdventureMapButton::clickRight (tribool down)
|
||||
{
|
||||
//TODO: show/hide infobox
|
||||
}
|
||||
void AdventureMapButton::hover (bool on)
|
||||
{
|
||||
//TODO: print info in statusbar
|
||||
}
|
||||
void AdventureMapButton::activate()
|
||||
{
|
||||
ClickableL::activate();
|
||||
Hoverable::activate();
|
||||
KeyInterested::activate();
|
||||
}
|
||||
void AdventureMapButton::keyPressed (SDL_KeyboardEvent & key)
|
||||
{
|
||||
//TODO: check if it's shortcut
|
||||
}
|
||||
void AdventureMapButton::deactivate()
|
||||
{
|
||||
ClickableL::deactivate();
|
||||
Hoverable::deactivate();
|
||||
KeyInterested::deactivate();
|
||||
}
|
||||
AdventureMapButton::AdventureMapButton ()
|
||||
{
|
||||
type=2;
|
||||
abs=true;
|
||||
active=false;
|
||||
ourObj=NULL;
|
||||
state=0;
|
||||
}
|
||||
void CList::activate()
|
||||
{
|
||||
ClickableL::activate();
|
||||
ClickableR::activate();
|
||||
Hoverable::activate();
|
||||
KeyInterested::activate();
|
||||
};
|
||||
void CList::deactivate()
|
||||
{
|
||||
ClickableL::deactivate();
|
||||
ClickableR::deactivate();
|
||||
Hoverable::deactivate();
|
||||
KeyInterested::deactivate();
|
||||
};
|
||||
void CList::clickLeft(tribool down)
|
||||
{
|
||||
};
|
116
CAdvmapInterface.h
Normal file
116
CAdvmapInterface.h
Normal file
@ -0,0 +1,116 @@
|
||||
#ifndef CADVENTUREMAPINTERFACE_H
|
||||
#define CADVENTUREMAPINTERFACE_H
|
||||
|
||||
#include "SDL.h"
|
||||
#include "CDefHandler.h"
|
||||
#include "SDL_Extensions.h"
|
||||
#include "CGameInterface.h"
|
||||
#include "CGameInfo.h"
|
||||
#include "SDL_Extensions.h"
|
||||
#include <boost/logic/tribool.hpp>
|
||||
#define CGI (CGameInfo::mainObj)
|
||||
using namespace boost::logic;
|
||||
using namespace CSDL_Ext;
|
||||
class AdventureMapButton
|
||||
: public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public CButtonBase
|
||||
{
|
||||
public:
|
||||
std::string name; //for status bar
|
||||
std::string helpBox; //for right-click help
|
||||
char key; //key shortcut
|
||||
void (CAdvMapInt::*function)(); //function in CAdvMapInt called when this button is pressed, different for each button
|
||||
|
||||
void clickRight (tribool down);
|
||||
void clickLeft (tribool down);
|
||||
void hover (bool on);
|
||||
void keyPressed (SDL_KeyboardEvent & key);
|
||||
void activate(); // makes button active
|
||||
void deactivate(); // makes button inactive (but don't deletes)
|
||||
|
||||
AdventureMapButton(); //c-tor
|
||||
AdventureMapButton( std::string Name, std::string HelpBox, void(CAdvMapInt::*Function)() );//c-tor
|
||||
|
||||
};
|
||||
/*****************************/
|
||||
class CList
|
||||
: public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public CIntObject
|
||||
{
|
||||
SDL_Surface * bg;
|
||||
//arrow up, arrow down
|
||||
int posw, posh; //position width/height
|
||||
|
||||
void clickLeft(tribool down);
|
||||
void activate();
|
||||
void deactivate();
|
||||
virtual void select(int which)=0;
|
||||
};
|
||||
class CHeroList
|
||||
: public CList
|
||||
{
|
||||
void select(int which);
|
||||
void clickRight(tribool down);
|
||||
};
|
||||
class CTownList
|
||||
: public CList
|
||||
{
|
||||
void select(int which);
|
||||
void clickRight(tribool down);
|
||||
};
|
||||
class CResourceBar
|
||||
:public ClickableR, public CIntObject
|
||||
{
|
||||
SDL_Surface * bg;
|
||||
void clickRight(tribool down);
|
||||
void refresh();
|
||||
};
|
||||
class CDataBar
|
||||
:public ClickableR, public CIntObject
|
||||
{
|
||||
SDL_Surface * bg;
|
||||
void clickRight(tribool down);
|
||||
void refresh();
|
||||
};
|
||||
class CStatusBar
|
||||
{
|
||||
SDL_Surface * bg;
|
||||
std::string current;
|
||||
void print(std::string text);
|
||||
};
|
||||
class CMinimap
|
||||
: public ClickableL, public ClickableR, public Hoverable, public CIntObject
|
||||
{
|
||||
SDL_Surface * radar; //radar.def
|
||||
SDL_Surface * terrainMap;
|
||||
SDL_Surface * undTerrainMap; //underground
|
||||
|
||||
//TODO flagged buildings
|
||||
|
||||
bool underground;
|
||||
|
||||
int3 position; //top left corner of visible map part
|
||||
};
|
||||
/*****************************/
|
||||
class CAdvMapInt : public CGameInterface //adventure map interface
|
||||
{
|
||||
CAdvMapInt(int Player);
|
||||
~CAdvMapInt();
|
||||
|
||||
int player;
|
||||
SDL_Surface * bg;
|
||||
AdventureMapButton kingOverview,//- kingdom overview
|
||||
undeground,//- underground switch
|
||||
questlog,//- questlog
|
||||
sleepWake, //- sleep/wake hero
|
||||
moveHero, //- move hero
|
||||
spellbook,//- spellbook
|
||||
advOptions, //- adventure options
|
||||
sysOptions,//- system options
|
||||
nextHero, //- next hero
|
||||
endTurn;//- end turn
|
||||
//CHeroList herolist;
|
||||
|
||||
void show();
|
||||
|
||||
|
||||
};
|
||||
#endif //CADVENTUREMAPINTERFACE_H
|
@ -465,9 +465,9 @@ void CAmbarCendamo::deh3m()
|
||||
//std::cout << "object nr "<<ww<<"\ti= "<<i<<std::endl;
|
||||
CObjectInstance nobj; //we will read this object
|
||||
nobj.id = CGameInfo::mainObj->objh->objInstances.size();
|
||||
nobj.x = bufor[i++];
|
||||
nobj.y = bufor[i++];
|
||||
nobj.z = bufor[i++];
|
||||
nobj.pos.x = bufor[i++];
|
||||
nobj.pos.y = bufor[i++];
|
||||
nobj.pos.z = bufor[i++];
|
||||
nobj.defNumber = readNormalNr(i, 4); i+=4;
|
||||
|
||||
//if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size())
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "CLodHandler.h"
|
||||
#include "CTownHandler.h"
|
||||
#include "CGeneralTextHandler.h"
|
||||
#include "CGameInterface.h"
|
||||
#include "SDL.h"
|
||||
|
||||
#include <vector>
|
||||
@ -43,6 +44,7 @@ public:
|
||||
CLodHandler * spriteh;
|
||||
CLodHandler * bitmaph;
|
||||
CGeneralTextHandler * generaltexth;
|
||||
CPlayerInterface * playerint;
|
||||
std::vector<SDL_Color> playerColors;
|
||||
SDL_Color neutralColor;
|
||||
StartInfo scenarioOps;
|
||||
|
@ -1,8 +1,63 @@
|
||||
#include "stdafx.h"
|
||||
#include "CGameInterface.h"
|
||||
#include "CMessage.h"
|
||||
#include "SDL_Extensions.h"
|
||||
using namespace CSDL_Ext;
|
||||
|
||||
|
||||
|
||||
CButtonBase::CButtonBase()
|
||||
{
|
||||
type=-1;
|
||||
abs=false;
|
||||
active=false;
|
||||
ourObj=NULL;
|
||||
state=0;
|
||||
}
|
||||
void CButtonBase::show()
|
||||
{
|
||||
blitAt(imgs[state],pos.x,pos.y);
|
||||
updateRect(&pos);
|
||||
if (!abs)
|
||||
{
|
||||
blitAt(imgs[state],pos.x,pos.y);
|
||||
updateRect(&pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
blitAt(imgs[state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y);
|
||||
updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y));
|
||||
|
||||
}
|
||||
}
|
||||
void ClickableL::activate()
|
||||
{
|
||||
CGI->playerint->lclickable.push_back(this);
|
||||
}
|
||||
void ClickableL::deactivate()
|
||||
{
|
||||
CGI->playerint->lclickable.erase(std::find(CGI->playerint->lclickable.begin(),CGI->playerint->lclickable.end(),this));
|
||||
}
|
||||
void ClickableR::activate()
|
||||
{
|
||||
CGI->playerint->rclickable.push_back(this);
|
||||
}
|
||||
void ClickableR::deactivate()
|
||||
{
|
||||
CGI->playerint->rclickable.erase(std::find(CGI->playerint->rclickable.begin(),CGI->playerint->rclickable.end(),this));
|
||||
}
|
||||
void Hoverable::activate()
|
||||
{
|
||||
CGI->playerint->hoverable.push_back(this);
|
||||
}
|
||||
void Hoverable::deactivate()
|
||||
{
|
||||
CGI->playerint->hoverable.erase(std::find(CGI->playerint->hoverable.begin(),CGI->playerint->hoverable.end(),this));
|
||||
}
|
||||
void KeyInterested::activate()
|
||||
{
|
||||
CGI->playerint->keyinterested.push_back(this);
|
||||
}
|
||||
void KeyInterested::deactivate()
|
||||
{
|
||||
CGI->playerint->
|
||||
keyinterested.erase(std::find(CGI->playerint->keyinterested.begin(),CGI->playerint->keyinterested.end(),this));
|
||||
}
|
@ -4,16 +4,11 @@
|
||||
#include "SDL.h"
|
||||
#include "CDefHandler.h"
|
||||
#include "SDL_Extensions.h"
|
||||
class CGameInterface
|
||||
{
|
||||
};
|
||||
class CAdvMapInt : public CGameInterface //adventure map interface
|
||||
{
|
||||
SDL_Surface * bg;
|
||||
};
|
||||
class CAICallback : public CGameInterface // callback for AI
|
||||
{
|
||||
};
|
||||
#include <boost/logic/tribool.hpp>
|
||||
BOOST_TRIBOOL_THIRD_STATE(outOfRange)
|
||||
using namespace boost::logic;
|
||||
class CAdvMapInt;
|
||||
|
||||
class CIntObject //interface object
|
||||
{
|
||||
public:
|
||||
@ -23,45 +18,65 @@ public:
|
||||
class CButtonBase : public CIntObject
|
||||
{
|
||||
public:
|
||||
int type;
|
||||
int type; //advmapbutton=2
|
||||
bool abs;
|
||||
struct Offset
|
||||
{
|
||||
int x, y;
|
||||
} *offset;
|
||||
bool active;
|
||||
CIntObject * ourObj;
|
||||
int state;
|
||||
std::vector<SDL_Surface*> imgs;
|
||||
virtual void show() ;
|
||||
CButtonBase(){abs=true;ourObj=NULL;}
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
CButtonBase();
|
||||
};
|
||||
class ClickableL : public virtual CButtonBase //for left-clicks
|
||||
class ClickableL //for left-clicks
|
||||
{
|
||||
public:
|
||||
bool pressed;
|
||||
virtual void press (bool down)=0;
|
||||
virtual void clickLeft (tribool down)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class ClickableR : public virtual CButtonBase //for right-clicks
|
||||
class ClickableR //for right-clicks
|
||||
{
|
||||
public:
|
||||
bool pressed;
|
||||
virtual void click (bool down)=0;
|
||||
virtual void clickRight (tribool down)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class Hoverable : public virtual CButtonBase
|
||||
class Hoverable
|
||||
{
|
||||
public:
|
||||
bool hovered;
|
||||
virtual void hover (bool on)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class KeyInterested : public virtual CButtonBase
|
||||
class KeyInterested
|
||||
{
|
||||
public:
|
||||
virtual void keyPressed (SDL_KeyboardEvent & key)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class CGameInterface
|
||||
{
|
||||
};
|
||||
class CAICallback : public CGameInterface // callback for AI
|
||||
{
|
||||
};
|
||||
|
||||
class CPlayerInterface
|
||||
{
|
||||
static CGameInterface * gamein;
|
||||
public:
|
||||
static CAdvMapInt * adventureInt;
|
||||
|
||||
std::vector<ClickableL*> lclickable;
|
||||
std::vector<ClickableR*> rclickable;
|
||||
std::vector<Hoverable*> hoverable;
|
||||
std::vector<KeyInterested*> keyinterested;
|
||||
|
||||
void handleEvent(SDL_Event * sEvent);
|
||||
};
|
||||
|
||||
#endif //CGAMEINTERFACE_H
|
@ -44,17 +44,17 @@ class CHeroInstance
|
||||
{
|
||||
public:
|
||||
int owner;
|
||||
CHero type;
|
||||
int exp; //experience point
|
||||
int level; //current level of hero
|
||||
std::string name; //may be custom
|
||||
std::string biography; //may be custom
|
||||
int portrait; //may be custom
|
||||
CHero type;
|
||||
int3 pos; //position on adventure map
|
||||
CCreatureSet army; //army
|
||||
int mana; // remaining spell points
|
||||
int movement; //remaining movement points
|
||||
//TODO: artifacts, primary and secondary skills, known spells, commander, blessings, curses, morale/luck modifiers
|
||||
//TODO: artifacts, primary and secondary skills, known spells, commander, blessings, curses, morale/luck special modifiers
|
||||
};
|
||||
|
||||
class CHeroHandler
|
||||
|
1
CMT.cpp
1
CMT.cpp
@ -237,6 +237,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
CGameInfo * cgi = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.)
|
||||
CGameInfo::mainObj = cgi;
|
||||
cgi->mush = mush;
|
||||
|
||||
THC std::cout<<"Initializing screen, fonts and sound handling: "<<tmh.getDif()<<std::endl;
|
||||
cgi->spriteh = new CLodHandler;
|
||||
cgi->spriteh->init(std::string("newH3sprite.lod"));
|
||||
|
@ -27,8 +27,8 @@ public:
|
||||
static SDL_Surface * drawBox1(int w, int h, int playerColor=1);
|
||||
static std::vector<std::string> * breakText(std::string text, int line=30, bool userBreak=true); //line - chars per line
|
||||
CMessage();
|
||||
void init();
|
||||
void dispose();
|
||||
static void init();
|
||||
static void dispose();
|
||||
};
|
||||
//
|
||||
|
||||
|
@ -292,7 +292,7 @@ class CObjectInstance //instance of object
|
||||
public:
|
||||
int defNumber; //specifies number of def file with animation of this object
|
||||
int id; //number of object in CObjectHandler's vector
|
||||
int x, y, z; // position
|
||||
int3 pos; // position
|
||||
CSpecObjInfo * info; //pointer to something with additional information
|
||||
};
|
||||
|
||||
|
BIN
CPreGame.cpp
BIN
CPreGame.cpp
Binary file not shown.
@ -74,6 +74,8 @@ void CSDL_Ext::printAtMiddle(std::string text, int x, int y, TTF_Font * font, SD
|
||||
}
|
||||
void CSDL_Ext::printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality)
|
||||
{
|
||||
if (text.length()==0)
|
||||
return;
|
||||
SDL_Surface * temp;
|
||||
switch (quality)
|
||||
{
|
||||
|
@ -9,6 +9,7 @@ extern SDL_Color tytulowy, tlo, zwykly ;
|
||||
void blitAtWR(SDL_Surface * src, int x, int y, SDL_Surface * dst=ekran);
|
||||
void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=ekran);
|
||||
void updateRect (SDL_Rect * rect, SDL_Surface * scr = ekran);
|
||||
SDL_Rect genRect(int hh, int ww, int xx, int yy);
|
||||
namespace CSDL_Ext
|
||||
{
|
||||
void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC=0, Uint8 A = 255); //myC influences the start of reading pixels
|
||||
|
@ -9,7 +9,8 @@ struct StartInfo
|
||||
{
|
||||
struct PlayerSettings
|
||||
{
|
||||
int castle, hero, heroPortrait; //ID, if -1 then random, if -2 then none
|
||||
int castle, hero, //ID, if -1 then random, if -2 then none
|
||||
heroPortrait; //-1 if default, else ID
|
||||
std::string heroName;
|
||||
Ebonus bonus;
|
||||
Ecolor color; //from 0 -
|
||||
|
1
int3.h
1
int3.h
@ -3,6 +3,7 @@
|
||||
|
||||
class int3
|
||||
{
|
||||
public:
|
||||
int x,y,z;
|
||||
inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0
|
||||
inline int3(const int X, const int Y, const int Z):x(X),y(Y),z(Z){}; //c-tor
|
||||
|
@ -684,14 +684,14 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
|
||||
std::vector<ObjSorter> highPrObjsVis;
|
||||
for(int gg=0; gg<CGameInfo::mainObj->objh->objInstances.size(); ++gg)
|
||||
{
|
||||
if(CGameInfo::mainObj->objh->objInstances[gg].x >= x-Woff-4 && CGameInfo::mainObj->objh->objInstances[gg].x < dx+x-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg].y >= y-Hoff-4 && CGameInfo::mainObj->objh->objInstances[gg].y < dy+y-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg].z == level)
|
||||
if(CGameInfo::mainObj->objh->objInstances[gg].pos.x >= x-Woff-4 && CGameInfo::mainObj->objh->objInstances[gg].pos.x < dx+x-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg].pos.y >= y-Hoff-4 && CGameInfo::mainObj->objh->objInstances[gg].pos.y < dy+y-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg].pos.z == level)
|
||||
{
|
||||
if(!CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].isOnDefList)
|
||||
{
|
||||
ObjSorter os;
|
||||
os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap;
|
||||
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+Woff)*32;
|
||||
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+Hoff)*32;
|
||||
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].pos.x-x+Woff)*32;
|
||||
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].pos.y-y+Hoff)*32;
|
||||
highPrObjsVis.push_back(os);
|
||||
}
|
||||
else if(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].printPriority==0)
|
||||
@ -703,8 +703,8 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
|
||||
|
||||
os.bitmap = CGameInfo::mainObj->ac->map.defy[defyod].handler->ourImages[ourimagesod].bitmap;
|
||||
|
||||
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+Woff)*32;
|
||||
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+Hoff)*32;
|
||||
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].pos.x-x+Woff)*32;
|
||||
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].pos.y-y+Hoff)*32;
|
||||
if (CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].isVisitable())
|
||||
highPrObjsVis.push_back(os);
|
||||
else
|
||||
@ -714,8 +714,8 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
|
||||
{
|
||||
ObjSorter os;
|
||||
os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap;
|
||||
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+Woff)*32;
|
||||
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+Hoff)*32;
|
||||
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].pos.x-x+Woff)*32;
|
||||
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].pos.y-y+Hoff)*32;
|
||||
lowPrObjs.push_back(os);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user