1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* a lot of improvements

* started making an infobar
This commit is contained in:
Michał W. Urbańczyk 2007-09-30 16:16:00 +00:00
parent cfc94847a1
commit 8421c901a4
17 changed files with 137 additions and 32 deletions

View File

@ -163,7 +163,7 @@ CHeroList::CHeroList()
void CHeroList::init()
{
bg = SDL_CreateRGBSurface(ekran->flags,68,193,ekran->format->BitsPerPixel,ekran->format->Rmask,ekran->format->Gmask,ekran->format->Bmask,ekran->format->Amask);
bg = CSDL_Ext::newSurface(68,193,ekran);
SDL_BlitSurface(LOCPLINT->adventureInt->bg,&genRect(193,68,607,196),bg,&genRect(193,68,0,0));
}
void CHeroList::genList()
@ -171,7 +171,7 @@ void CHeroList::genList()
int howMany = LOCPLINT->cb->howManyHeroes(LOCPLINT->playerID);
for (int i=0;i<howMany;i++)
{
items.push_back(LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,i,0));
items.push_back(std::pair<const CHeroInstance *,CPath *>(LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,i,0),NULL));
}
}
void CHeroList::select(int which)
@ -180,9 +180,10 @@ void CHeroList::select(int which)
if (which>=items.size())
which=items.size();
draw();
LOCPLINT->adventureInt->centerOn(items[which]->pos);
LOCPLINT->adventureInt->selection.type = &HEROI_TYPE;
LOCPLINT->adventureInt->selection.selected = items[which];
LOCPLINT->adventureInt->centerOn(items[which].first->pos);
LOCPLINT->adventureInt->selection.type = HEROI_TYPE;
LOCPLINT->adventureInt->selection.selected = items[which].first;
LOCPLINT->adventureInt->terrain.currentPath = items[which].second;
}
void CHeroList::clickLeft(tribool down)
{
@ -272,7 +273,7 @@ void CHeroList::mouseMoved (SDL_MouseMotionEvent & sEvent)
return;
}
std::vector<std::string> temp;
temp+=(items[from+ny]->name),(items[from+ny]->type->heroClass->name);
temp+=(items[from+ny].first->name),(items[from+ny].first->type->heroClass->name);
LOCPLINT->adventureInt->statusbar.print( processStr(CGI->generaltexth->allTexts[15],temp) );
//select(ny+from);
}
@ -473,7 +474,7 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels
if ((level>=0) && (i!=level))
continue;
if (map.size()<i+1)
pom = SDL_CreateRGBSurface(ekran->flags,pos.w,pos.h,ekran->format->BitsPerPixel,ekran->format->Rmask,ekran->format->Gmask,ekran->format->Bmask,ekran->format->Amask);
pom = CSDL_Ext::newSurface(pos.w,pos.h,ekran);
else pom = map[i];
for (int x=0;x<pos.w;x++)
{
@ -578,23 +579,36 @@ void CTerrainRect::clickLeft(tribool down)
{
if ((down==false) || indeterminate(down))
return;
if (LOCPLINT->adventureInt->selection.type != HEROI_TYPE)
{
if (currentPath)
{
delete currentPath;
currentPath = NULL;
}
return;
}
int3 mp;
mp.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
mp.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
mp.z = LOCPLINT->adventureInt->position.z;
if ((mp.x<0) || (mp.y<0))
return;
if (currentPath)
{
if ( (currentPath->endPos()) == mp)
{ //move
LOCPLINT->cb->moveHero(0,currentPath->endPos());//todo - move selected hero
return;
}
else
{
delete currentPath;
currentPath=NULL;
}
}
const CHeroInstance * currentHero = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected];
currentPath = CGI->pathf->getPath(currentHero->pos,mp,currentHero);
const CHeroInstance * currentHero = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first;
currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(currentHero->pos,mp,currentHero);
}
void CTerrainRect::clickRight(tribool down)
{
@ -860,7 +874,19 @@ void CResDataBar::draw()
updateRect(&pos,ekran);
delete buf;
}
CInfoBar::CInfoBar()
{
pos.x=604;
pos.y=389;
pos.w=194;
pos.h=186;
}
void CInfoBar::draw(void * specific)
{
SDL_Surface * todr = LOCPLINT->infoWin(specific);
blitAt(todr,pos.x,pos.y);
SDL_FreeSurface(todr);
}
CAdvMapInt::CAdvMapInt(int Player)
:player(Player),
statusbar(7,556),
@ -1033,6 +1059,6 @@ void CAdvMapInt::centerOn(int3 on)
}
CAdvMapInt::CurrentSelection::CurrentSelection()
{
type=NULL;
type=-1;
selected=NULL;
}

View File

@ -59,7 +59,7 @@ class CHeroList
{
public:
CDefHandler *mobile, *mana;
std::vector<const CHeroInstance*> items;
std::vector<std::pair<const CHeroInstance*, CPath *> > items;
int posmobx, posporx, posmanx, posmoby, pospory, posmany;
CHeroList();
@ -177,6 +177,12 @@ public:
void draw();
};
class CInfoBar
:public virtual CIntObject
{
CInfoBar();
void draw(void * specific=NULL); // if specific==0 function draws info about selected hero/town
};
/*****************************/
class CAdvMapInt //adventure map interface
{
@ -240,7 +246,7 @@ public:
struct CurrentSelection
{
const type_info* type;
int type; //0 - hero, 1 - town
const void* selected;
CurrentSelection(); //ctor
} selection;

View File

@ -9,7 +9,7 @@
#include "CGameState.h"
#include "CGameInterface.h"
bool CCallback::moveHero(int ID, int3 destPoint)
bool CCallback::moveHero(int ID, int3 destPoint, int idtype)
{
if(ID<0 || ID>CGI->heroh->heroInstances.size())
return false;

View File

@ -6,20 +6,21 @@ class CTownInstance;
struct HeroMoveDetails
{
int3 src, dst; //source and destination points
int heroID; //which hero
int heroID; //position in vector
int owner;
};
class CCallback
{
private:
int player;
void newTurn();
CCallback(CGameState * GS, int Player):gs(GS),player(Player){};
protected:
CGameState * gs;
public:
CCallback(CGameState * GS):gs(GS){};
bool moveHero(int ID, int3 destPoint);
bool moveHero(int ID, int3 destPoint, int idtype=0);//idtype: 0-position in vector; 1-ID of hero
int howManyTowns();
const CTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
@ -28,6 +29,8 @@ public:
const CHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
int getResourceAmount(int type);
int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
friend int _tmain(int argc, _TCHAR* argv[]);
};
#endif //CCALLBACK_H

View File

@ -11,8 +11,9 @@
#include "mapHandler.h"
#include <sstream>
int internalFunc(void * nothingUsed)
int internalFunc(void * callback)
{
CCallback * cb = (CCallback*)callback;
char * usersMessage = new char[500];
std::string readed;
while(true)
@ -44,7 +45,7 @@ int internalFunc(void * nothingUsed)
break;
case 'M': //move hero
readed>>heronum>>dest;
CGI->state->cb->moveHero(heronum, dest);
cb->moveHero(heronum, dest);
break;
}
//SDL_Delay(100);
@ -54,5 +55,5 @@ int internalFunc(void * nothingUsed)
void CConsoleHandler::runConsole()
{
SDL_Thread * myth = SDL_CreateThread(&internalFunc, NULL);
SDL_Thread * myth = SDL_CreateThread(&internalFunc, cb);
}

View File

@ -1,9 +1,13 @@
#ifndef CCONSOLEHANDLER_H
#define CCONSOLEHANDLER_H
class CCallback;
class CConsoleHandler
{
CCallback * cb;
public:
void runConsole();
friend int _tmain(int argc, _TCHAR* argv[]);
};
#endif //CCONSOLEHANDLER_H

View File

@ -9,6 +9,8 @@
#include "CCursorHandler.h"
#include "CCallback.h"
#include "SDL_Extensions.h"
#include "hch/CLodHandler.h"
#include <sstream>
using namespace CSDL_Ext;
class OCM_HLP_CGIN
{
@ -109,6 +111,7 @@ CPlayerInterface::CPlayerInterface(int Player, int serial)
serialID=serial;
CGI->localPlayer = playerID;
human=true;
hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp");
}
void CPlayerInterface::init(CCallback * CB)
{
@ -744,6 +747,41 @@ void CPlayerInterface::heroCreated(const CHeroInstance * hero)
{
}
SDL_Surface * CPlayerInterface::infoWin(void * specific) //specific=0 => draws info about selected town/hero //TODO - gdy sie dorobi sensowna hierarchie klas ins. to wywalic tego brzydkiego void*
{
if (specific)
;//TODO: dorobic, ale w ogole to moze lepiej najpierw zastapic tego voida czym innym
else
{
if (adventureInt->selection.type == HEROI_TYPE)
{
char * buf = new char[10];
SDL_Surface * ret = copySurface(hInfo);
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
blueToPlayersAdv(ret,playerID);
const CHeroInstance * curh = (const CHeroInstance *)adventureInt->selection.selected;
printAt(curh->name,15,75,GEOR13,zwykly,ret);
for (int i=0;i<PRIMARY_SKILLS;i++)
{
itoa(curh->primSkills[i],buf,10);
printAtMiddle(buf,87+27*i,69,GEOR13,zwykly,ret);
}
itoa(curh->mana,buf,10);
printAtMiddle(buf,169,109,GEORM,zwykly,ret);
delete buf;
return ret;
}
else if (adventureInt->selection.type == TOWNI_TYPE)
{
//TODO: do it
return NULL;
}
else
return NULL;
}
return NULL;
}
void CPlayerInterface::handleEvent(SDL_Event *sEvent)
{
current = sEvent;

View File

@ -112,11 +112,15 @@ public:
std::vector<KeyInterested*> keyinterested;
std::vector<MotionInterested*> motioninterested;
SDL_Surface * hInfo;
//overloaded funcs from Interface
void yourTurn();
void heroMoved(const HeroMoveDetails & details);
void heroKilled(const CHeroInstance * hero);
void heroCreated(const CHeroInstance * hero);
SDL_Surface * infoWin(void * 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 init(CCallback * CB);

View File

@ -26,7 +26,7 @@ public:
friend CCallback;
friend int _tmain(int argc, _TCHAR* argv[]);
friend void initGameState(CGameInfo * cgi);
CCallback * cb; //for communication between PlayerInterface/AI and GameState
//CCallback * cb; //for communication between PlayerInterface/AI and GameState
};
#endif //CGAMESTATE_H

View File

@ -254,7 +254,6 @@ 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->consoleh = new CConsoleHandler;
cgi->consoleh->runConsole();
cgi->mush = mush;
cgi->curh = new CCursorHandler;
@ -334,8 +333,9 @@ int _tmain(int argc, _TCHAR* argv[])
cgi->dobjinfo->load();
cgi->state = new CGameState();
cgi->state->players = std::map<int, PlayerState>();
cgi->state->cb = new CCallback(cgi->state);
cgi->pathf = new CPathfinder();
cgi->consoleh->cb = new CCallback(cgi->state,-1);
cgi->consoleh->runConsole();
THC std::cout<<"Handlers initailization: "<<tmh.getDif()<<std::endl;
std::string mapname;
@ -386,9 +386,9 @@ int _tmain(int argc, _TCHAR* argv[])
// cgi->playerint.push_back(new CGlobalAI());
//else
{
cgi->state->currentPlayer=i;
cgi->state->currentPlayer=cgi->scenarioOps.playerInfos[i].color;
cgi->playerint.push_back(new CPlayerInterface(cgi->scenarioOps.playerInfos[i].color,i));
((CPlayerInterface*)(cgi->playerint[i]))->init(cgi->state->cb);
((CPlayerInterface*)(cgi->playerint[i]))->init(new CCallback(cgi->state,cgi->scenarioOps.playerInfos[i].color));
}
}

View File

@ -4,11 +4,11 @@
#include "CGameInfo.h"
#include "hch\CAmbarCendamo.h"
#include "mapHandler.h"
int3 CPath::startPos()
int3 CPath::endPos()
{
return int3(nodes[0].coord.x,nodes[0].coord.y,nodes[0].coord.z);
}
int3 CPath::endPos()
int3 CPath::startPos()
{
return int3(nodes[nodes.size()-1].coord.x,nodes[nodes.size()-1].coord.y,nodes[nodes.size()-1].coord.z);
}

Binary file not shown.

View File

@ -8,6 +8,17 @@
#include "CMessage.h"
#include <boost/algorithm/string.hpp>
SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given
{
return SDL_CreateRGBSurface(mod->flags,w,h,mod->format->BitsPerPixel,mod->format->Rmask,mod->format->Gmask,mod->format->Bmask,mod->format->Amask);
}
SDL_Surface * CSDL_Ext::copySurface(SDL_Surface * mod) //returns copy of given surface
{
SDL_Surface * ret = newSurface(mod->w,mod->h,mod);
SDL_BlitSurface(mod,NULL,ret,NULL);
return ret;
}
bool isItIn(const SDL_Rect * rect, int x, int y)
{
if ((x>rect->x && x<rect->x+rect->w) && (y>rect->y && y<rect->y+rect->h))

View File

@ -6,6 +6,7 @@
extern SDL_Surface * ekran;
extern SDL_Color tytulowy, tlo, zwykly ;
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
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);
@ -34,6 +35,8 @@ namespace CSDL_Ext
void blueToPlayersNice(SDL_Surface * sur, int player); //uses interface gems to substitute colours
void setPlayerColor(SDL_Surface * sur, int player); //sets correct color of flags; -1 for neutral
std::string processStr(std::string str, std::vector<std::string> & tor); //replaces %s in string
SDL_Surface * newSurface(int w, int h, SDL_Surface * mod=ekran); //creates new surface, with flags/format same as in surface given
SDL_Surface * copySurface(SDL_Surface * mod); //returns copy of given surface
};
#endif // SDL_EXTENSIONS_H

View File

@ -27,8 +27,8 @@ enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHE
//CURPLINT gives pointer to the interface of human player which is currently making turn,
//LOCPLINT gives pointer to the interface which is currently showed (on this machine)
#define HEROI_TYPE (typeid(CHeroInstance*))
#define TOWNI_TYPE (typeid(CTownInstance*))
#define HEROI_TYPE (0)
#define TOWNI_TYPE (1)
const int F_NUMBER = 9; //factions (town types) quantity

View File

@ -6,10 +6,13 @@
#include "CCreatureHandler.h"
#include "SDL.h"
#include "../int3.h"
#include "CAmbarCendamo.h"
#include "CGameInterface.h"
class CHeroClass;
class CObjectInstance;
class CDefHandler;
class CGameInfo;
class CHero
{
@ -73,9 +76,9 @@ public:
class CHeroHandler
{
public:
std::vector<CHeroInstance *> heroInstances;
std::vector<CHero*> heroes; //by³o nodrze
std::vector<CHeroClass *> heroClasses;
std::vector<CHeroInstance *> heroInstances;
unsigned int level(unsigned int experience);
void loadHeroes();
void loadSpecialAbilities();
@ -85,6 +88,12 @@ public:
void initHeroClasses();
~CHeroHandler();
void initTerrainCosts();
friend void CAmbarCendamo::deh3m();
friend void initGameState(CGameInfo * cgi);
friend class CConsoleHandler;
//friend void CPlayerInterface::heroMoved(const HeroMoveDetails & details); //TODO: wywalic, wstretne!!!
};

View File

@ -293,7 +293,7 @@ class CObjectInstance //instance of object
public:
int defNumber; //specifies number of def file with animation of this object
int defObjInfoNumber; //number of this object's def's additional informations in CDefObjInfo's vector
int id; //number of object in CObjectHandler's vector
int id; //number of object in CObjectHandler's vector //TODO: absolutnie wywalic i zastapic czyms sensownym
int3 pos; // position
CSpecObjInfo * info; //pointer to something with additional information
bool isHero; //true if this is a hero