mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
* half-working minimap
* minor improvements
This commit is contained in:
@ -156,8 +156,124 @@ void CStatusBar::show()
|
||||
blitAtWR(bg,pos.x,pos.y);
|
||||
printAtMiddle(current,middlex,middley,GEOR13,zwykly);
|
||||
}
|
||||
CMinimap::CMinimap(bool draw)
|
||||
{
|
||||
statusbarTxt = CGI->preth->advWorldMap.first;
|
||||
pos.x=630;
|
||||
pos.y=26;
|
||||
pos.h=pos.w=144;
|
||||
radar = CGI->spriteh->giveDef("RADAR.DEF");
|
||||
std::ifstream is("minimap.txt",std::ifstream::in);
|
||||
for (int i=0;i<TERRAIN_TYPES;i++)
|
||||
{
|
||||
std::pair<int,SDL_Color> vinya;
|
||||
std::pair<int,SDL_Color> vinya2;
|
||||
int pom;
|
||||
is >> pom;
|
||||
vinya2.first=vinya.first=pom;
|
||||
is >> pom;
|
||||
vinya.second.r=pom;
|
||||
is >> pom;
|
||||
vinya.second.g=pom;
|
||||
is >> pom;
|
||||
vinya.second.b=pom;
|
||||
is >> pom;
|
||||
vinya2.second.r=pom;
|
||||
is >> pom;
|
||||
vinya2.second.g=pom;
|
||||
is >> pom;
|
||||
vinya2.second.b=pom;
|
||||
vinya.second.unused=vinya2.second.unused=255;
|
||||
colors.insert(vinya);
|
||||
colorsBlocked.insert(vinya2);
|
||||
}
|
||||
is.close();
|
||||
if (draw)
|
||||
redraw();
|
||||
}
|
||||
void CMinimap::draw()
|
||||
{
|
||||
blitAtWR(map[LOCPLINT->adventureInt->position.z],pos.x,pos.y);
|
||||
}
|
||||
void CMinimap::redraw(int level)// (level==-1) => redraw all levels
|
||||
{
|
||||
(CGameInfo::mainObj);
|
||||
for (int i=0; i<CGI->mh->sizes.z; i++)
|
||||
{
|
||||
SDL_Surface * pom ;
|
||||
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);
|
||||
else pom = map[i];
|
||||
for (int x=0;x<pos.w;x++)
|
||||
{
|
||||
for (int y=0;y<pos.h;y++)
|
||||
{
|
||||
int mx=(CGI->mh->sizes.x*x)/pos.w;
|
||||
int my=(CGI->mh->sizes.y*y)/pos.h;
|
||||
if (CGI->mh->ttiles[mx][my][i].blocked && (!CGI->mh->ttiles[mx][my][i].visitable))
|
||||
SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].b);
|
||||
else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].terType].r,colors[CGI->mh->ttiles[mx][my][i].terType].g,colors[CGI->mh->ttiles[mx][my][i].terType].b);
|
||||
}
|
||||
}
|
||||
map.push_back(pom);
|
||||
}
|
||||
}
|
||||
void CMinimap::updateRadar()
|
||||
{}
|
||||
void CMinimap::clickRight (tribool down)
|
||||
{}
|
||||
void CMinimap::clickLeft (tribool down)
|
||||
{
|
||||
ClickableL::clickLeft(down);
|
||||
if (!((bool)down))
|
||||
return;
|
||||
|
||||
float dx=((float)(LOCPLINT->current->motion.x-pos.x))/((float)pos.w),
|
||||
dy=((float)(LOCPLINT->current->motion.y-pos.y))/((float)pos.h);
|
||||
|
||||
int dxa = (CGI->mh->sizes.x*dx)-(LOCPLINT->adventureInt->terrain.tilesw/2);
|
||||
int dya = (CGI->mh->sizes.y*dy)-(LOCPLINT->adventureInt->terrain.tilesh/2);
|
||||
|
||||
if (dxa<0)
|
||||
dxa=-(Woff/2);
|
||||
else if((dxa+LOCPLINT->adventureInt->terrain.tilesw) > (CGI->mh->sizes.x))
|
||||
dxa=CGI->mh->sizes.x-LOCPLINT->adventureInt->terrain.tilesw+(Woff/2);
|
||||
|
||||
if (dya<0)
|
||||
dya = -(Hoff/2);
|
||||
else if((dya+LOCPLINT->adventureInt->terrain.tilesh) > (CGI->mh->sizes.y))
|
||||
dya = CGI->mh->sizes.y-LOCPLINT->adventureInt->terrain.tilesh+(Hoff/2);
|
||||
|
||||
LOCPLINT->adventureInt->position.x=dxa;
|
||||
LOCPLINT->adventureInt->position.y=dya;
|
||||
LOCPLINT->adventureInt->updateScreen=true;
|
||||
}
|
||||
void CMinimap::hover (bool on)
|
||||
{
|
||||
Hoverable::hover(on);
|
||||
if (on)
|
||||
LOCPLINT->adventureInt->statusbar.print(statusbarTxt);
|
||||
else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt)
|
||||
LOCPLINT->adventureInt->statusbar.clear();
|
||||
}
|
||||
void CMinimap::activate()
|
||||
{
|
||||
ClickableL::activate();
|
||||
ClickableR::activate();
|
||||
Hoverable::activate();
|
||||
}
|
||||
void CMinimap::deactivate()
|
||||
{
|
||||
ClickableL::deactivate();
|
||||
ClickableR::deactivate();
|
||||
Hoverable::deactivate();
|
||||
}
|
||||
CTerrainRect::CTerrainRect():currentPath(NULL)
|
||||
{
|
||||
tilesw=19;
|
||||
tilesh=18;
|
||||
pos.x=7;
|
||||
pos.y=6;
|
||||
pos.w=594;
|
||||
@ -190,10 +306,10 @@ void CTerrainRect::show()
|
||||
{
|
||||
SDL_Surface * teren = CGI->mh->terrainRect
|
||||
(LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
|
||||
19,18,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim);
|
||||
SDL_BlitSurface(teren,&genRect(547,594,0,0),ekran,&genRect(547,594,7,6));
|
||||
tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim);
|
||||
SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),ekran,&genRect(547,594,7,6));
|
||||
SDL_FreeSurface(teren);
|
||||
if (currentPath)
|
||||
if (currentPath) //drawing path
|
||||
{
|
||||
for (int i=0;i<currentPath->nodes.size()-1;i++)
|
||||
{
|
||||
@ -388,8 +504,8 @@ void CTerrainRect::show()
|
||||
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)
|
||||
}
|
||||
|
||||
CAdvMapInt::CAdvMapInt(int Player)
|
||||
@ -512,6 +628,9 @@ void CAdvMapInt::show()
|
||||
endTurn.show();
|
||||
endTurn.activate();
|
||||
|
||||
minimap.activate();
|
||||
minimap.draw();
|
||||
|
||||
statusbar.show();
|
||||
|
||||
SDL_Flip(ekran);
|
||||
|
@ -84,22 +84,32 @@ public:
|
||||
void show(); //shows statusbar (with current text)
|
||||
};
|
||||
class CMinimap
|
||||
: public ClickableL, public ClickableR, public Hoverable, public CIntObject
|
||||
: public ClickableL, public ClickableR, public Hoverable, public virtual CIntObject
|
||||
{
|
||||
public:
|
||||
SDL_Surface * radar; //radar.def
|
||||
SDL_Surface * terrainMap;
|
||||
SDL_Surface * undTerrainMap; //underground
|
||||
|
||||
CDefHandler * radar; //radar.def; TODO: radars for maps with custom dimensions
|
||||
std::map<int,SDL_Color> colors;
|
||||
std::map<int,SDL_Color> colorsBlocked;
|
||||
std::vector<SDL_Surface *> map; //one bitmap for each level
|
||||
//TODO flagged buildings
|
||||
std::string statusbarTxt;
|
||||
|
||||
bool underground;
|
||||
CMinimap(bool draw=true);
|
||||
void draw();
|
||||
void redraw(int level=-1);// (level==-1) => redraw all levels
|
||||
void updateRadar();
|
||||
|
||||
void clickRight (tribool down);
|
||||
void clickLeft (tribool down);
|
||||
void hover (bool on);
|
||||
void activate(); // makes button active
|
||||
void deactivate(); // makes button inactive (but don't deletes)
|
||||
};
|
||||
class CTerrainRect
|
||||
: public ClickableL, public ClickableR, public Hoverable, public virtual CIntObject, public KeyInterested
|
||||
{
|
||||
public:
|
||||
int tilesw, tilesh;
|
||||
CDefHandler * arrows;
|
||||
CTerrainRect();
|
||||
CPath * currentPath;
|
||||
@ -131,6 +141,7 @@ public:
|
||||
bool updateScreen ;
|
||||
unsigned char anim, animValHitCount; //animation frame
|
||||
|
||||
CMinimap minimap;
|
||||
|
||||
|
||||
SDL_Surface * bg;
|
||||
|
@ -28,6 +28,13 @@ void CButtonBase::show()
|
||||
|
||||
}
|
||||
}
|
||||
void ClickableL::clickLeft(tribool down)
|
||||
{
|
||||
if (down)
|
||||
pressedL=true;
|
||||
else
|
||||
pressedL=false;
|
||||
}
|
||||
void ClickableL::activate()
|
||||
{
|
||||
LOCPLINT->lclickable.push_back(this);
|
||||
@ -155,6 +162,7 @@ void CPlayerInterface::yourTurn()
|
||||
|
||||
void CPlayerInterface::handleEvent(SDL_Event *sEvent)
|
||||
{
|
||||
current = sEvent;
|
||||
if(sEvent->type==SDL_QUIT)
|
||||
exit(0);
|
||||
else if (sEvent->type==SDL_KEYDOWN)
|
||||
@ -292,5 +300,6 @@ void CPlayerInterface::handleEvent(SDL_Event *sEvent)
|
||||
lclickable[i]->clickLeft(boost::logic::indeterminate);
|
||||
}
|
||||
}
|
||||
current = NULL;
|
||||
|
||||
} //event end
|
@ -78,6 +78,7 @@ public:
|
||||
class CPlayerInterface : public CGameInterface
|
||||
{
|
||||
public:
|
||||
SDL_Event * current;
|
||||
CAdvMapInt * adventureInt;
|
||||
//TODO: town interace, battle interface, other interfaces
|
||||
|
||||
|
12
CMT.cpp
12
CMT.cpp
@ -216,12 +216,12 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
mh->init();
|
||||
THC std::cout<<"Initializing mapHandler: "<<tmh.getDif()<<std::endl;
|
||||
//SDL_Rect * sr = new SDL_Rect(); sr->h=64;sr->w=64;sr->x=0;sr->y=0;
|
||||
SDL_Surface * teren = mh->terrainRect(xx,yy,25,19);
|
||||
THC std::cout<<"Preparing terrain to display: "<<tmh.getDif()<<std::endl;
|
||||
SDL_BlitSurface(teren,NULL,ekran,NULL);
|
||||
SDL_FreeSurface(teren);
|
||||
SDL_UpdateRect(ekran, 0, 0, ekran->w, ekran->h);
|
||||
THC std::cout<<"Displaying terrain: "<<tmh.getDif()<<std::endl;
|
||||
//SDL_Surface * teren = mh->terrainRect(xx,yy,25,19);
|
||||
//THC std::cout<<"Preparing terrain to display: "<<tmh.getDif()<<std::endl;
|
||||
//SDL_BlitSurface(teren,NULL,ekran,NULL);
|
||||
//SDL_FreeSurface(teren);
|
||||
//SDL_UpdateRect(ekran, 0, 0, ekran->w, ekran->h);
|
||||
//THC std::cout<<"Displaying terrain: "<<tmh.getDif()<<std::endl;
|
||||
|
||||
|
||||
for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++) //initializing interfaces
|
||||
|
11
global.h
11
global.h
@ -21,8 +21,9 @@ enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHE
|
||||
HERO_DEMONIAC, HERO_HERETIC, HERO_DEATHKNIGHT, HERO_NECROMANCER, HERO_WARLOCK, HERO_OVERLORD,
|
||||
HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST};
|
||||
|
||||
#define CURPLINT (((CPlayerInterface*)(CGI->playerint[CGI->state->currentPlayer])))
|
||||
#define LOCPLINT (((CPlayerInterface*)(CGI->playerint[CGI->localPlayer])))
|
||||
#define CGI (CGameInfo::mainObj)
|
||||
#define CURPLINT (((CPlayerInterface*)((CGameInfo::mainObj)->playerint[(CGameInfo::mainObj)->state->currentPlayer])))
|
||||
#define LOCPLINT (((CPlayerInterface*)((CGameInfo::mainObj)->playerint[(CGameInfo::mainObj)->localPlayer])))
|
||||
//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)
|
||||
|
||||
@ -33,13 +34,11 @@ const int HEROES_PER_TYPE=8; //amount of heroes of each type
|
||||
const int SKILL_QUANTITY=28;
|
||||
const int ARTIFACTS_QUANTITY=171;
|
||||
const int HEROES_QUANTITY=156;
|
||||
const int TERRAIN_TYPES=10;
|
||||
|
||||
#define MARK_BLOCKED_POSITIONS false
|
||||
#define MARK_VISITABLE_POSITIONS false
|
||||
|
||||
#define CGI (CGameInfo::mainObj)
|
||||
|
||||
|
||||
|
||||
#define DEFBYPASS
|
||||
|
||||
#endif //GLOBAL_H
|
@ -83,7 +83,9 @@ void CMapHandler::init()
|
||||
//roadBitmaps = new SDL_Surface** [reader->map.width+2*Woff];
|
||||
//for (int ii=0;ii<reader->map.width+2*Woff;ii++)
|
||||
// roadBitmaps[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory
|
||||
|
||||
sizes.x = CGI->ac->map.width;
|
||||
sizes.y = CGI->ac->map.height;
|
||||
sizes.z = CGI->ac->map.twoLevel+1;
|
||||
ttiles.resize(CGI->ac->map.width,Woff);
|
||||
for (int i=0-Woff;i<ttiles.size()-Woff;i++)
|
||||
{
|
||||
@ -430,7 +432,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
|
||||
int bmask = 0x00ff0000;
|
||||
int amask = 0xff000000;
|
||||
#endif
|
||||
|
||||
std::cout<<"x to "<<x<<std::endl;
|
||||
SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
|
||||
rmask, gmask, bmask, amask);
|
||||
if (((dx+x)>((reader->map.width+Woff)) || (dy+y)>((reader->map.height+Hoff))) || ((x<-Woff)||(y<-Hoff) ) )
|
||||
|
11
mapHandler.h
11
mapHandler.h
@ -58,10 +58,9 @@ class CMapHandler
|
||||
{
|
||||
public:
|
||||
PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles;
|
||||
int3 sizes;
|
||||
CAmbarCendamo * reader;
|
||||
SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0);
|
||||
SDL_Surface * terrBitmap(int x, int y);
|
||||
SDL_Surface * undTerrBitmap(int x, int y);
|
||||
|
||||
CDefHandler * fullHide;
|
||||
CDefHandler * partialHide;
|
||||
|
||||
@ -69,6 +68,8 @@ public:
|
||||
std::vector< std::vector<char> > undVisibility; //true means that pointed place is visible
|
||||
std::vector<CDefHandler *> roadDefs;
|
||||
std::vector<CDefHandler *> staticRiverDefs;
|
||||
|
||||
|
||||
char & visAccess(int x, int y);
|
||||
char & undVisAccess(int x, int y);
|
||||
SDL_Surface mirrorImage(SDL_Surface *src); //what is this??
|
||||
@ -76,6 +77,10 @@ public:
|
||||
|
||||
int getCost(int3 & a, int3 & b, CHeroInstance * hero);
|
||||
void init();
|
||||
SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0);
|
||||
SDL_Surface * terrBitmap(int x, int y);
|
||||
SDL_Surface * undTerrBitmap(int x, int y);
|
||||
|
||||
};
|
||||
|
||||
#endif //MAPHANDLER_H
|
26
minimap.txt
Normal file
26
minimap.txt
Normal file
@ -0,0 +1,26 @@
|
||||
0 82 56 8 57 40 8
|
||||
1 222 207 140 165 158 107
|
||||
2 0 65 0 0 48 0
|
||||
3 181 199 198 140 158 156
|
||||
4 74 134 107 33 89 66
|
||||
5 132 113 49 99 81 33
|
||||
6 132 48 0 90 8 0
|
||||
7 74 73 74 41 40 41
|
||||
8 8 81 148 8 81 148
|
||||
9 0 0 0 0 0 0
|
||||
|
||||
//end of data
|
||||
Colors of terrain in minimap
|
||||
Terrain_ID Unblocked_R Unblocked_G Unblocked_B Blocked_R Blocked_G Blocked_B
|
||||
(all values are decimal)
|
||||
Terrain types:
|
||||
00 Dirt
|
||||
01 Sand
|
||||
02 Grass
|
||||
03 Snow
|
||||
04 Swamp
|
||||
05 Rough
|
||||
06 Subterranean
|
||||
07 Lava
|
||||
08 Water
|
||||
09 Rock
|
Reference in New Issue
Block a user