1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00

* code reorganization

* minor stuff for resource <-> infoBar interaction
This commit is contained in:
Michał W. Urbańczyk
2007-12-22 14:40:27 +00:00
parent 84261a5de8
commit e427974875
7 changed files with 400 additions and 379 deletions

View File

@ -663,30 +663,6 @@ void CMinimap::draw()
} }
} }
} }
//draw FoW
//for (int i=0; i<mw; i++)
//{
// for (int j=0; j<mh; j++)
// {
// int3 pp((((float)i/mw)*CGI->mh->sizes.x), (((float)j/mh)*CGI->mh->sizes.y), LOCPLINT->adventureInt->position.z);
// /*pp.x = (((float)i/mw)*CGI->mh->sizes.x);
// pp.y = (((float)j/mh)*CGI->mh->sizes.y);
// pp.z = LOCPLINT->adventureInt->position.z;*/
// if ( !LOCPLINT->cb->isVisible(pp) )
// {
// for (int ii=0; ii<wo; ii++)
// {
// for (int jj=0; jj<ho; jj++)
// {
// if ((i+ii<pos.w-1) && (j+jj<pos.h-1))
// SDL_PutPixelWithoutRefresh(temps,i+ii,j+jj,0,0,0);
// }
// }
// }
// }
//}
//update(temps);
blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps); blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps);
//draw radar //draw radar
@ -864,14 +840,6 @@ void CTerrainRect::clickLeft(tribool down)
//bufpos.x-=1; //bufpos.x-=1;
if (mres) if (mres)
currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1); currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1);
//if (LOCPLINT->objsToBlit.size()==0)
//{
// CSimpleWindow * temp = CMessage::genWindow(" Tutaj dlugi dlugo test Tutaj dlugi dlugi dlugo test Tutaj dlugi dlugi dlugo test Tutaj dlugi dlugi dlugo test {Tutaj tytul} Tutaj dlugi dlugi dlugo test",0);
// temp->pos.x=temp->pos.y=0;temp->ID=3;
// LOCPLINT->objsToBlit.push_back(temp);
//}
//SDL_Delay(5000);
} }
void CTerrainRect::clickRight(tribool down) void CTerrainRect::clickRight(tribool down)
{ {
@ -900,6 +868,206 @@ void CTerrainRect::hover(bool on)
if (!on) if (!on)
LOCPLINT->adventureInt->statusbar.clear(); LOCPLINT->adventureInt->statusbar.clear();
} }
void CTerrainRect::showPath()
{
for (int i=0;i<currentPath->nodes.size()-1;i++)
{
int pn=-1;//number of picture
if (i==0) //last tile
{
int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
if (x<0 || y<0 || x>pos.w || y>pos.h)
continue;
pn=0;
}
else
{
std::vector<CPathNode> & cv = currentPath->nodes;
if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
{
if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 3;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 12;
}
else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 21;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 22;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 2;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
{
if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 4;
}
else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 13;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 22;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
{
if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 5;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 14;
}
else if(cv[i-1].coord.x+1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 23;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 24;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 4;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
{
if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 6;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 15;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 24;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
{
if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 7;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 16;
}
else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 17;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 6;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 18;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
{
if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 8;
}
else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 9;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 18;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
{
if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 1;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 10;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 19;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 8;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 20;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
{
if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 2;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 11;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 20;
}
}
}
if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->movement)
pn+=25;
if (pn>=0)
{
int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
if (x<0 || y<0 || x>pos.w || y>pos.h)
continue;
int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
if (hvx<0 && hvy<0)
blitAt(arrows->ourImages[pn].bitmap,x,y);
else if(hvx<0)
SDL_BlitSurface
(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
else if (hvy<0)
{
SDL_BlitSurface
(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
ekran,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
}
else
SDL_BlitSurface
(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
}
} //for (int i=0;i<currentPath->nodes.size()-1;i++)
}
void CTerrainRect::show() void CTerrainRect::show()
{ {
SDL_Surface * teren = CGI->mh->terrainRect SDL_Surface * teren = CGI->mh->terrainRect
@ -909,204 +1077,8 @@ void CTerrainRect::show()
SDL_FreeSurface(teren); SDL_FreeSurface(teren);
if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
{ {
for (int i=0;i<currentPath->nodes.size()-1;i++) showPath();
{ }
int pn=-1;//number of picture
if (i==0) //last tile
{
int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
if (x<0 || y<0 || x>pos.w || y>pos.h)
continue;
pn=0;
}
else
{
std::vector<CPathNode> & cv = currentPath->nodes;
if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
{
if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 3;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 12;
}
else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 21;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 22;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 2;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
{
if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 4;
}
else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 13;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 22;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
{
if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 5;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 14;
}
else if(cv[i-1].coord.x+1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 23;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 24;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 4;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
{
if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 6;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 15;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 24;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
{
if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 7;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 16;
}
else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 17;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 6;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 18;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
{
if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 8;
}
else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 9;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 18;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
{
if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 1;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 10;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 19;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 8;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 20;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
{
if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 2;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 11;
}
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 20;
}
}
}
if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->movement)
pn+=25;
if (pn>=0)
{
int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
if (x<0 || y<0 || x>pos.w || y>pos.h)
continue;
int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
if (hvx<0 && hvy<0)
blitAt(arrows->ourImages[pn].bitmap,x,y);
else if(hvx<0)
SDL_BlitSurface
(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
else if (hvy<0)
{
SDL_BlitSurface
(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
ekran,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
}
else
SDL_BlitSurface
(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
}
} //for (int i=0;i<currentPath->nodes.size()-1;i++)
} // if (currentPath)
} }
int3 CTerrainRect::whichTileIsIt(int x, int y) int3 CTerrainRect::whichTileIsIt(int x, int y)

View File

@ -166,6 +166,7 @@ public:
void mouseMoved (SDL_MouseMotionEvent & sEvent); void mouseMoved (SDL_MouseMotionEvent & sEvent);
void keyPressed (SDL_KeyboardEvent & key); void keyPressed (SDL_KeyboardEvent & key);
void show(); void show();
void showPath();
int3 whichTileIsIt(int x, int y); //x,y are cursor position int3 whichTileIsIt(int x, int y); //x,y are cursor position
int3 whichTileIsIt(); //uses current cursor pos int3 whichTileIsIt(); //uses current cursor pos
}; };
@ -190,6 +191,7 @@ class CInfoBar
{ {
public: public:
CDefHandler *day, *week1, *week2, *week3, *week4; CDefHandler *day, *week1, *week2, *week3, *week4;
SComponent * current;
int mode; int mode;
int pom; int pom;

View File

@ -454,6 +454,13 @@ void CScriptCallback::giveResource(int player, int which, int val)
gs->players[player].resources[which]+=val; gs->players[player].resources[which]+=val;
CGI->playerint[gs->players[player].serial]->receivedResource(which,val); CGI->playerint[gs->players[player].serial]->receivedResource(which,val);
} }
void CScriptCallback::showCompInfo(int player, SComponent * comp)
{
CPlayerInterface * i = dynamic_cast<CPlayerInterface*>(CGI->playerint[gs->players[player].serial]);
if(i)
i->showComp(*comp);
}
void CLuaCallback::registerFuncs(lua_State * L) void CLuaCallback::registerFuncs(lua_State * L)
{ {
lua_newtable(L); lua_newtable(L);

View File

@ -94,6 +94,7 @@ public:
static void changePrimSkill(int ID, int which, int val); static void changePrimSkill(int ID, int which, int val);
void showInfoDialog(int player, std::string text, std::vector<SComponent*> * components); void showInfoDialog(int player, std::string text, std::vector<SComponent*> * components);
void giveResource(int player, int which, int val); void giveResource(int player, int which, int val);
void showCompInfo(int player, SComponent * comp);
//friends //friends
friend void initGameState(CGameInfo * cgi); friend void initGameState(CGameInfo * cgi);

View File

@ -16,6 +16,8 @@
#include "hch/CGeneralTextHandler.h" #include "hch/CGeneralTextHandler.h"
#include <sstream> #include <sstream>
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp>
#pragma warning (disable : 4311) #pragma warning (disable : 4311)
bool getGlobalFunc(lua_State * L, std::string fname) bool getGlobalFunc(lua_State * L, std::string fname)
{ {
@ -470,7 +472,11 @@ void CPickable::onHeroVisit(CGObjectInstance *os, int heroID)
val = 3 + (rand()%3); val = 3 + (rand()%3);
break; break;
} }
SComponent ccc(SComponent::resource,os->subID,val);
ccc.description = CGI->objh->advobtxt[113];
boost::algorithm::replace_first(ccc.description,"%s",CGI->objh->restypes[os->subID]);
cb->giveResource(cb->getHeroOwner(heroID),os->subID,val); cb->giveResource(cb->getHeroOwner(heroID),os->subID,val);
cb->showCompInfo(cb->getHeroOwner(heroID),&ccc);
break; break;
} }
} }

View File

@ -1134,6 +1134,17 @@ void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero))); heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
} }
SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
{
char * buf = new char[10];
for (int i=from;i<to;i++)
{
itoa(curh->primSkills[i],buf,10);
printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
}
delete buf;
return ret;
}
SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh) SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
{ {
char * buf = new char[10]; char * buf = new char[10];
@ -1141,11 +1152,7 @@ SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
blueToPlayersAdv(ret,playerID,1); blueToPlayersAdv(ret,playerID,1);
printAt(curh->name,75,15,GEOR13,zwykly,ret); printAt(curh->name,75,15,GEOR13,zwykly,ret);
for (int i=0;i<PRIMARY_SKILLS;i++) drawPrimarySkill(curh, ret);
{
itoa(curh->primSkills[i],buf,10);
printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
}
for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
{ {
blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
@ -1183,23 +1190,165 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe
} }
else else
{ {
if (adventureInt->selection.type == HEROI_TYPE) switch (adventureInt->selection.type)
{ {
const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected; case HEROI_TYPE:
return drawHeroInfoWin(curh); {
} const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
else if (adventureInt->selection.type == TOWNI_TYPE) return drawHeroInfoWin(curh);
{ }
char * buf = new char[10]; case TOWNI_TYPE:
SDL_Surface * ret = copySurface(hInfo); {
return ret; return drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected);
} }
else default:
return NULL; return NULL;
}
} }
return NULL; return NULL;
} }
void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
{
for (int i=0; i<hoverable.size();i++)
{
if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
{
if (!hoverable[i]->hovered)
hoverable[i]->hover(true);
}
else if (hoverable[i]->hovered)
{
hoverable[i]->hover(false);
}
}
for(int i=0; i<motioninterested.size();i++)
{
if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
{
motioninterested[i]->mouseMoved(sEvent->motion);
}
}
if(sEvent->motion.x<15)
{
LOCPLINT->adventureInt->scrollingLeft = true;
}
else
{
LOCPLINT->adventureInt->scrollingLeft = false;
}
if(sEvent->motion.x>ekran->w-15)
{
LOCPLINT->adventureInt->scrollingRight = true;
}
else
{
LOCPLINT->adventureInt->scrollingRight = false;
}
if(sEvent->motion.y<15)
{
LOCPLINT->adventureInt->scrollingUp = true;
}
else
{
LOCPLINT->adventureInt->scrollingUp = false;
}
if(sEvent->motion.y>ekran->h-15)
{
LOCPLINT->adventureInt->scrollingDown = true;
}
else
{
LOCPLINT->adventureInt->scrollingDown = false;
}
}
void CPlayerInterface::handleKeyUp(SDL_Event *sEvent)
{
switch (sEvent->key.keysym.sym)
{
case SDLK_LEFT:
{
LOCPLINT->adventureInt->scrollingLeft = false;
break;
}
case (SDLK_RIGHT):
{
LOCPLINT->adventureInt->scrollingRight = false;
break;
}
case (SDLK_UP):
{
LOCPLINT->adventureInt->scrollingUp = false;
break;
}
case (SDLK_DOWN):
{
LOCPLINT->adventureInt->scrollingDown = false;
break;
}
case (SDLK_u):
{
adventureInt->underground.clickLeft(false);
break;
}
case (SDLK_m):
{
adventureInt->moveHero.clickLeft(false);
break;
}
case (SDLK_e):
{
adventureInt->endTurn.clickLeft(false);
break;
}
}
}
void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
{
switch (sEvent->key.keysym.sym)
{
case SDLK_LEFT:
{
LOCPLINT->adventureInt->scrollingLeft = true;
break;
}
case (SDLK_RIGHT):
{
LOCPLINT->adventureInt->scrollingRight = true;
break;
}
case (SDLK_UP):
{
LOCPLINT->adventureInt->scrollingUp = true;
break;
}
case (SDLK_DOWN):
{
LOCPLINT->adventureInt->scrollingDown = true;
break;
}
case (SDLK_q):
{
exit(0);
break;
}
case (SDLK_u):
{
adventureInt->underground.clickLeft(true);
break;
}
case (SDLK_m):
{
adventureInt->moveHero.clickLeft(true);
break;
}
case (SDLK_e):
{
adventureInt->endTurn.clickLeft(true);
break;
}
}
}
void CPlayerInterface::handleEvent(SDL_Event *sEvent) void CPlayerInterface::handleEvent(SDL_Event *sEvent)
{ {
current = sEvent; current = sEvent;
@ -1213,144 +1362,15 @@ void CPlayerInterface::handleEvent(SDL_Event *sEvent)
exit(0); exit(0);
else if (sEvent->type==SDL_KEYDOWN) else if (sEvent->type==SDL_KEYDOWN)
{ {
switch (sEvent->key.keysym.sym) handleKeyDown(sEvent);
{
case SDLK_LEFT:
{
LOCPLINT->adventureInt->scrollingLeft = true;
break;
}
case (SDLK_RIGHT):
{
LOCPLINT->adventureInt->scrollingRight = true;
break;
}
case (SDLK_UP):
{
LOCPLINT->adventureInt->scrollingUp = true;
break;
}
case (SDLK_DOWN):
{
LOCPLINT->adventureInt->scrollingDown = true;
break;
}
case (SDLK_q):
{
exit(0);
break;
}
case (SDLK_u):
{
adventureInt->underground.clickLeft(true);
break;
}
case (SDLK_m):
{
adventureInt->moveHero.clickLeft(true);
break;
}
case (SDLK_e):
{
adventureInt->endTurn.clickLeft(true);
break;
}
}
} //keydown end } //keydown end
else if(sEvent->type==SDL_KEYUP) else if(sEvent->type==SDL_KEYUP)
{ {
switch (sEvent->key.keysym.sym) handleKeyUp(sEvent);
{
case SDLK_LEFT:
{
LOCPLINT->adventureInt->scrollingLeft = false;
break;
}
case (SDLK_RIGHT):
{
LOCPLINT->adventureInt->scrollingRight = false;
break;
}
case (SDLK_UP):
{
LOCPLINT->adventureInt->scrollingUp = false;
break;
}
case (SDLK_DOWN):
{
LOCPLINT->adventureInt->scrollingDown = false;
break;
}
case (SDLK_u):
{
adventureInt->underground.clickLeft(false);
break;
}
case (SDLK_m):
{
adventureInt->moveHero.clickLeft(false);
break;
}
case (SDLK_e):
{
adventureInt->endTurn.clickLeft(false);
break;
}
}
}//keyup end }//keyup end
else if(sEvent->type==SDL_MOUSEMOTION) else if(sEvent->type==SDL_MOUSEMOTION)
{ {
for (int i=0; i<hoverable.size();i++) handleMouseMotion(sEvent);
{
if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
{
if (!hoverable[i]->hovered)
hoverable[i]->hover(true);
}
else if (hoverable[i]->hovered)
{
hoverable[i]->hover(false);
}
}
for(int i=0; i<motioninterested.size();i++)
{
if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
{
motioninterested[i]->mouseMoved(sEvent->motion);
}
}
if(sEvent->motion.x<15)
{
LOCPLINT->adventureInt->scrollingLeft = true;
}
else
{
LOCPLINT->adventureInt->scrollingLeft = false;
}
if(sEvent->motion.x>ekran->w-15)
{
LOCPLINT->adventureInt->scrollingRight = true;
}
else
{
LOCPLINT->adventureInt->scrollingRight = false;
}
if(sEvent->motion.y<15)
{
LOCPLINT->adventureInt->scrollingUp = true;
}
else
{
LOCPLINT->adventureInt->scrollingUp = false;
}
if(sEvent->motion.y>ekran->h-15)
{
LOCPLINT->adventureInt->scrollingDown = true;
}
else
{
LOCPLINT->adventureInt->scrollingDown = false;
}
} //mousemotion end } //mousemotion end
else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT)) else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
@ -1427,6 +1447,12 @@ void CPlayerInterface::receivedResource(int type, int val)
{ {
adventureInt->resdatabar.draw(); adventureInt->resdatabar.draw();
} }
void CPlayerInterface::showComp(SComponent comp)
{
}
void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components) void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
{ {
adventureInt->hide(); //dezaktywacja starego interfejsu adventureInt->hide(); //dezaktywacja starego interfejsu

View File

@ -206,13 +206,20 @@ public:
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val); void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
void receivedResource(int type, int val); void receivedResource(int type, int val);
void showComp(SComponent comp);
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* 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 handleEvent(SDL_Event * sEvent);
void handleKeyDown(SDL_Event *sEvent);
void handleKeyUp(SDL_Event *sEvent);
void handleMouseMotion(SDL_Event *sEvent);
void init(ICallback * CB); void init(ICallback * CB);
int3 repairScreenPos(int3 pos); int3 repairScreenPos(int3 pos);
void showInfoDialog(std::string text, std::vector<SComponent*> & components); void showInfoDialog(std::string text, std::vector<SComponent*> & components);
void removeObjToBlit(IShowable* obj); void removeObjToBlit(IShowable* obj);
SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh); 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); SDL_Surface * drawTownInfoWin(const CGTownInstance * curh);
CPlayerInterface(int Player, int serial); CPlayerInterface(int Player, int serial);