mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
World view impl -- initial;
This commit is contained in:
parent
9f05f53e65
commit
4b248c2762
@ -2171,6 +2171,11 @@ void CPlayerInterface::showPuzzleMap()
|
||||
GH.pushInt(new CPuzzleWindow(grailPos, ratio));
|
||||
}
|
||||
|
||||
void CPlayerInterface::viewWorldMap()
|
||||
{
|
||||
adventureInt->changeMode(EAdvMapMode::WORLD_VIEW);
|
||||
}
|
||||
|
||||
void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, int spellID)
|
||||
{
|
||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||
|
@ -170,6 +170,7 @@ public:
|
||||
void showBlockingDialog(const std::string &text, const std::vector<Component> &components, QueryID askID, int soundID, bool selection, bool cancel) override; //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
|
||||
void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, QueryID queryID) override;
|
||||
void showPuzzleMap() override;
|
||||
void viewWorldMap() override;
|
||||
void showMarketWindow(const IMarket *market, const CGHeroInstance *visitor) override;
|
||||
void showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor) override;
|
||||
void showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor) override;
|
||||
|
@ -145,6 +145,11 @@ void CIntObject::printAtLoc( const std::string & text, int x, int y, EFonts font
|
||||
graphics->fonts[font]->renderTextLeft(dst, text, kolor, Point(pos.x + x, pos.y + y));
|
||||
}
|
||||
|
||||
void CIntObject::printAtRightLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::WHITE*/, SDL_Surface * dst/*=screen*/ )
|
||||
{
|
||||
graphics->fonts[font]->renderTextRight(dst, text, kolor, Point(pos.x + x, pos.y + y));
|
||||
}
|
||||
|
||||
void CIntObject::printAtMiddleLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::WHITE*/, SDL_Surface * dst/*=screen*/ )
|
||||
{
|
||||
printAtMiddleLoc(text, Point(x,y), font, kolor, dst);
|
||||
|
@ -201,6 +201,7 @@ public:
|
||||
//functions for printing text. Use CLabel where possible instead
|
||||
void printAtLoc(const std::string & text, int x, int y, EFonts font, SDL_Color color, SDL_Surface * dst);
|
||||
void printToLoc(const std::string & text, int x, int y, EFonts font, SDL_Color color, SDL_Surface * dst);
|
||||
void printAtRightLoc(const std::string & text, int x, int y, EFonts font, SDL_Color color, SDL_Surface * dst);
|
||||
void printAtMiddleLoc(const std::string & text, int x, int y, EFonts font, SDL_Color color, SDL_Surface * dst);
|
||||
void printAtMiddleLoc(const std::string & text, const Point &p, EFonts font, SDL_Color color, SDL_Surface * dst);
|
||||
void printAtMiddleWBLoc(const std::string & text, int x, int y, EFonts font, int charsPerLine, SDL_Color color, SDL_Surface * dst);
|
||||
|
@ -413,6 +413,439 @@ void CMapHandler::init()
|
||||
|
||||
}
|
||||
|
||||
void CMapHandler::drawWorldViewOverlay(int targetTilesX, int targetTilesY, int srx_init, int sry_init, CDefHandler * iconsDef, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap, float scale, int targetTileSize, int3 top_tile, SDL_Surface * extSurf)
|
||||
{
|
||||
int srx = srx_init;
|
||||
|
||||
int bxStart = top_tile.x;
|
||||
int byStart = top_tile.y;
|
||||
for (int bx = bxStart; bx < top_tile.x + targetTilesX; bx++, srx+=targetTileSize)
|
||||
{
|
||||
if (bx < 0 || bx >= sizes.x)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int sry = sry_init;
|
||||
|
||||
for (int by = byStart; by < top_tile.y + targetTilesY; by++, sry+=targetTileSize)
|
||||
{
|
||||
if (by < 0 || by >= sizes.y)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int3 pos(bx, by, top_tile.z);
|
||||
const TerrainTile2 & tile = ttiles[pos.x][pos.y][pos.z];
|
||||
|
||||
auto &objects = tile.objects;
|
||||
for(auto & object : objects)
|
||||
{
|
||||
const CGObjectInstance *obj = object.first;
|
||||
|
||||
if (obj->pos.z != top_tile.z)
|
||||
continue;
|
||||
if (!(*visibilityMap)[pos.x][pos.y][top_tile.z])
|
||||
continue;
|
||||
if (!obj->visitableAt(pos.x, pos.y))
|
||||
continue;
|
||||
|
||||
auto &ownerRaw = obj->tempOwner;
|
||||
int ownerIndex = 0;
|
||||
if (ownerRaw < PlayerColor::PLAYER_LIMIT)
|
||||
{
|
||||
ownerIndex = ownerRaw.getNum() * 19;
|
||||
}
|
||||
else if (ownerRaw == PlayerColor::NEUTRAL)
|
||||
{
|
||||
ownerIndex = PlayerColor::PLAYER_LIMIT.getNum() * 19;
|
||||
}
|
||||
|
||||
SDL_Surface * wvIcon = nullptr;
|
||||
switch (obj->ID)
|
||||
{
|
||||
default:
|
||||
continue;
|
||||
case Obj::MONOLITH_ONE_WAY_ENTRANCE:
|
||||
case Obj::MONOLITH_ONE_WAY_EXIT:
|
||||
case Obj::MONOLITH_TWO_WAY:
|
||||
wvIcon = iconsDef->ourImages[(int)EWorldViewIcon::TELEPORT].bitmap;
|
||||
break;
|
||||
case Obj::SUBTERRANEAN_GATE:
|
||||
wvIcon = iconsDef->ourImages[(int)EWorldViewIcon::GATE].bitmap;
|
||||
break;
|
||||
case Obj::ARTIFACT:
|
||||
wvIcon = iconsDef->ourImages[(int)EWorldViewIcon::ARTIFACT].bitmap;
|
||||
break;
|
||||
case Obj::TOWN:
|
||||
wvIcon = iconsDef->ourImages[(int)EWorldViewIcon::TOWN + ownerIndex].bitmap;
|
||||
break;
|
||||
case Obj::HERO:
|
||||
wvIcon = iconsDef->ourImages[(int)EWorldViewIcon::HERO + ownerIndex].bitmap;
|
||||
break;
|
||||
case Obj::MINE:
|
||||
wvIcon = iconsDef->ourImages[(int)EWorldViewIcon::MINE_WOOD + obj->subID + ownerIndex].bitmap;
|
||||
break;
|
||||
case Obj::RESOURCE:
|
||||
wvIcon = iconsDef->ourImages[(int)EWorldViewIcon::RES_WOOD + obj->subID + ownerIndex].bitmap;
|
||||
break;
|
||||
}
|
||||
|
||||
if (wvIcon)
|
||||
{
|
||||
Rect tempDst;
|
||||
tempDst.x = srx + targetTileSize / 2 - wvIcon->w / 2;
|
||||
tempDst.y = sry + targetTileSize / 2 - wvIcon->h / 2;
|
||||
tempDst.w = wvIcon->w;
|
||||
tempDst.h = wvIcon->h;
|
||||
CSDL_Ext::blitSurface(wvIcon, nullptr, extSurf, &tempDst);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMapHandler::calculateWorldViewCameraPos(int targetTilesX, int targetTilesY, int3 &top_tile)
|
||||
{
|
||||
bool outsideLeft = top_tile.x < 0;
|
||||
bool outsideTop = top_tile.y < 0;
|
||||
bool outsideRight = std::max(0, top_tile.x) + targetTilesX > sizes.x;
|
||||
bool outsideBottom = std::max(0, top_tile.y) + targetTilesY > sizes.y;
|
||||
|
||||
if (targetTilesX > sizes.x)
|
||||
top_tile.x = sizes.x / 2 - targetTilesX / 2; // center viewport if the whole map can fit into the screen at once
|
||||
else if (outsideLeft)
|
||||
{
|
||||
if (outsideRight)
|
||||
{
|
||||
top_tile.x = sizes.x / 2 - targetTilesX / 2;
|
||||
}
|
||||
else
|
||||
top_tile.x = 0;
|
||||
}
|
||||
else if (outsideRight)
|
||||
top_tile.x = sizes.x - targetTilesX;
|
||||
|
||||
if (targetTilesY > sizes.y)
|
||||
top_tile.y = sizes.y / 2 - targetTilesY / 2;
|
||||
else if (outsideTop)
|
||||
{
|
||||
if (outsideBottom)
|
||||
{
|
||||
top_tile.y = sizes.y / 2 - targetTilesY / 2;
|
||||
}
|
||||
else
|
||||
top_tile.y = 0;
|
||||
}
|
||||
else if (outsideBottom)
|
||||
top_tile.y = sizes.y - targetTilesY;
|
||||
}
|
||||
|
||||
// updates map terrain when adventure map is in world view mode;
|
||||
// this method was copied from terrainRect(), so some parts are the same -- that probably should be refactored slightly
|
||||
void CMapHandler::terrainRectScaled(int3 topTile, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap, SDL_Surface * extSurf, const SDL_Rect * extRect, float scale, CDefHandler * iconsDef)
|
||||
{
|
||||
cache.updateWorldViewScale(scale);
|
||||
|
||||
int targetTileSize = (int) floorf(32.0f * scale);
|
||||
int targetTilesX = (int) ceilf(tilesW / scale) + 1;
|
||||
int targetTilesY = (int) ceilf(tilesH / scale) + 1;
|
||||
|
||||
SDL_Rect rtile = { 0, 0, targetTileSize, targetTileSize };
|
||||
|
||||
// Absolute coords of the first pixel in the top left corner
|
||||
int srx_init = offsetX + extRect->x;
|
||||
int sry_init = offsetY + extRect->y;
|
||||
int srx, sry; // absolute screen coordinates in pixels
|
||||
|
||||
calculateWorldViewCameraPos(targetTilesX, targetTilesY, topTile);
|
||||
|
||||
SDL_FillRect(extSurf, extRect, SDL_MapRGB(extSurf->format, 0, 0, 0));
|
||||
|
||||
// makes the clip area smaller if the map is smaller than the screen frame
|
||||
Rect clipRect(std::max(extRect->x, -topTile.x * targetTileSize),
|
||||
std::max(extRect->y, -topTile.y * targetTileSize),
|
||||
std::min(extRect->w, sizes.x * targetTileSize),
|
||||
std::min(extRect->h, sizes.y * targetTileSize));
|
||||
SDL_Rect prevClip;
|
||||
SDL_GetClipRect(extSurf, &prevClip);
|
||||
SDL_SetClipRect(extSurf, &clipRect); //preventing blitting outside of that rect
|
||||
|
||||
const BlitterWithRotationVal blitterWithRotation = CSDL_Ext::getBlitterWithRotation(extSurf);
|
||||
const BlitterWithRotationVal blitterWithRotationAndAlpha = CSDL_Ext::getBlitterWithRotationAndAlpha(extSurf);
|
||||
|
||||
// printing terrain
|
||||
srx = srx_init;
|
||||
|
||||
for (int bx = topTile.x; bx < topTile.x + targetTilesX; bx++, srx+=targetTileSize)
|
||||
{
|
||||
// Skip column if not in map
|
||||
if (bx < 0 || bx >= sizes.x)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sry = sry_init;
|
||||
|
||||
for (int by = topTile.y; by < topTile.y + targetTilesY; by++, sry+=targetTileSize)
|
||||
{
|
||||
int3 pos(bx, by, topTile.z); //blitted tile position
|
||||
|
||||
// Skip tile if not in map
|
||||
if (by < 0 || by >= sizes.y)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const NeighborTilesInfo info(pos,sizes,*visibilityMap);
|
||||
|
||||
if(info.areAllHidden())
|
||||
continue;
|
||||
|
||||
const TerrainTile2 & tile = ttiles[pos.x][pos.y][pos.z];
|
||||
const TerrainTile &tinfo = map->getTile(int3(pos.x, pos.y, pos.z));
|
||||
|
||||
SDL_Rect sr;
|
||||
sr.x=srx;
|
||||
sr.y=sry;
|
||||
sr.h=sr.w=targetTileSize;
|
||||
|
||||
//blit terrain with river/road
|
||||
if(tile.terbitmap)
|
||||
{ //if custom terrain graphic - use it
|
||||
auto scaledSurf = cache.requestWorldViewCacheOrCreate(EMapCacheType::TERRAIN_CUSTOM, (int)tile.terbitmap, tile.terbitmap, scale);
|
||||
// Rect tempSrc = Rect(0, 0, scaledSurf->w, scaledSurf->h);
|
||||
Rect tempDst = Rect(sr.x, sr.y, scaledSurf->w, scaledSurf->h);
|
||||
CSDL_Ext::blitSurface(scaledSurf, nullptr, extSurf, &tempDst);
|
||||
}
|
||||
else //use default terrain graphic
|
||||
{
|
||||
auto baseSurf = terrainGraphics[tinfo.terType][tinfo.terView];
|
||||
auto scaledSurf = cache.requestWorldViewCacheOrCreate(EMapCacheType::TERRAIN, (int)baseSurf, baseSurf, scale);
|
||||
Rect tempSrc = Rect(0, 0, scaledSurf->w, scaledSurf->h);
|
||||
Rect tempDst = Rect(sr.x, sr.y, scaledSurf->w, scaledSurf->h);
|
||||
blitterWithRotation(scaledSurf, tempSrc, extSurf, tempDst, tinfo.extTileFlags%4);
|
||||
}
|
||||
|
||||
if(tinfo.riverType) //print river if present
|
||||
{
|
||||
auto baseSurf = staticRiverDefs[tinfo.riverType-1]->ourImages[tinfo.riverDir].bitmap;
|
||||
auto scaledSurf = cache.requestWorldViewCacheOrCreate(EMapCacheType::RIVERS, (int)baseSurf, baseSurf, scale);
|
||||
blitterWithRotationAndAlpha(scaledSurf, rtile, extSurf, sr, (tinfo.extTileFlags>>2)%4);
|
||||
}
|
||||
|
||||
//Roads are shifted by 16 pixels to bottom. We have to draw both parts separately
|
||||
if (pos.y > 0 && map->getTile(int3(pos.x, pos.y-1, pos.z)).roadType != ERoadType::NO_ROAD)
|
||||
{ //part from top tile
|
||||
const TerrainTile &topTile = map->getTile(int3(pos.x, pos.y-1, pos.z));
|
||||
Rect source(0, targetTileSize / 2, targetTileSize, targetTileSize / 2);
|
||||
Rect dest(sr.x, sr.y, sr.w, sr.h/2);
|
||||
auto baseSurf = roadDefs[topTile.roadType - 1]->ourImages[topTile.roadDir].bitmap;
|
||||
auto scaledSurf = cache.requestWorldViewCacheOrCreate(EMapCacheType::ROADS, (int)baseSurf, baseSurf, scale);
|
||||
blitterWithRotationAndAlpha(scaledSurf, source, extSurf, dest, (topTile.extTileFlags>>4)%4);
|
||||
}
|
||||
|
||||
if(tinfo.roadType != ERoadType::NO_ROAD) //print road from this tile
|
||||
{
|
||||
Rect source(0, 0, targetTileSize, targetTileSize);
|
||||
Rect dest(sr.x, sr.y + targetTileSize / 2, sr.w, sr.h / 2);
|
||||
auto baseSurf = roadDefs[tinfo.roadType-1]->ourImages[tinfo.roadDir].bitmap;
|
||||
auto scaledSurf = cache.requestWorldViewCacheOrCreate(EMapCacheType::ROADS, (int)baseSurf, baseSurf, scale);
|
||||
blitterWithRotationAndAlpha(scaledSurf, source, extSurf, dest, (tinfo.extTileFlags>>4)%4);
|
||||
}
|
||||
|
||||
//blit objects
|
||||
const std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > &objects = tile.objects;
|
||||
for(auto & object : objects)
|
||||
{
|
||||
const CGObjectInstance *obj = object.first;
|
||||
if (!graphics->getDef(obj))
|
||||
processDef(obj->appearance);
|
||||
if (!graphics->getDef(obj) && !obj->appearance.animationFile.empty())
|
||||
{
|
||||
logGlobal->errorStream() << "Failed to load image " << obj->appearance.animationFile;
|
||||
}
|
||||
|
||||
PlayerColor color = obj->tempOwner;
|
||||
|
||||
//checking if object has non-empty graphic on this tile
|
||||
if(obj->ID != Obj::HERO && !obj->coveringAt(bx, by))
|
||||
continue;
|
||||
|
||||
SDL_Rect sr2(sr);
|
||||
|
||||
SDL_Rect pp = object.second;
|
||||
pp.h = sr.h;
|
||||
pp.w = sr.w;
|
||||
|
||||
const CGHeroInstance * themp = (obj->ID != Obj::HERO
|
||||
? nullptr
|
||||
: static_cast<const CGHeroInstance*>(obj));
|
||||
|
||||
//print hero / boat and flag
|
||||
if((themp && themp->moveDir && themp->type) || (obj->ID == Obj::BOAT)) //it's hero or boat
|
||||
{
|
||||
const int IMGVAL = 8; //frames per group of movement animation
|
||||
ui8 dir;
|
||||
std::vector<Cimage> * iv = nullptr;
|
||||
std::vector<CDefEssential *> Graphics::*flg = nullptr;
|
||||
SDL_Surface * tb = nullptr; //surface to blitted
|
||||
|
||||
if(themp) //hero
|
||||
{
|
||||
if(themp->tempOwner >= PlayerColor::PLAYER_LIMIT) //Neutral hero?
|
||||
{
|
||||
logGlobal->errorStream() << "A neutral hero (" << themp->name << ") at " << themp->pos << ". Should not happen!";
|
||||
continue;
|
||||
}
|
||||
|
||||
dir = themp->moveDir;
|
||||
|
||||
//pick graphics of hero (or boat if hero is sailing)
|
||||
if (themp->boat)
|
||||
iv = &graphics->boatAnims[themp->boat->subID]->ourImages;
|
||||
else
|
||||
iv = &graphics->heroAnims[themp->appearance.animationFile]->ourImages;
|
||||
|
||||
//pick appropriate flag set
|
||||
if(themp->boat)
|
||||
{
|
||||
switch (themp->boat->subID)
|
||||
{
|
||||
case 0: flg = &Graphics::flags1; break;
|
||||
case 1: flg = &Graphics::flags2; break;
|
||||
case 2: flg = &Graphics::flags3; break;
|
||||
default: logGlobal->errorStream() << "Not supported boat subtype: " << themp->boat->subID;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
flg = &Graphics::flags4;
|
||||
}
|
||||
}
|
||||
else //boat
|
||||
{
|
||||
const CGBoat *boat = static_cast<const CGBoat*>(obj);
|
||||
dir = boat->direction;
|
||||
iv = &graphics->boatAnims[boat->subID]->ourImages;
|
||||
}
|
||||
|
||||
if(themp && !themp->isStanding) //hero is moving
|
||||
{
|
||||
size_t gg;
|
||||
for(gg=0; gg<iv->size(); ++gg)
|
||||
{
|
||||
if((*iv)[gg].groupNumber==getHeroFrameNum(dir, true))
|
||||
{
|
||||
tb = (*iv)[gg].bitmap;
|
||||
break;
|
||||
}
|
||||
}
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,extSurf,&sr2);
|
||||
|
||||
//printing flag
|
||||
pp.y+=IMGVAL*2-32;
|
||||
sr2.y-=16;
|
||||
CSDL_Ext::blitSurface((graphics->*flg)[color.getNum()]->ourImages[gg+35].bitmap, &pp, extSurf, &sr2);
|
||||
}
|
||||
else //hero / boat stands still
|
||||
{
|
||||
size_t gg;
|
||||
for(gg=0; gg < iv->size(); ++gg)
|
||||
{
|
||||
if((*iv)[gg].groupNumber==getHeroFrameNum(dir, false))
|
||||
{
|
||||
tb = (*iv)[gg].bitmap;
|
||||
break;
|
||||
}
|
||||
}
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,extSurf,&sr2);
|
||||
|
||||
//printing flag
|
||||
if(flg
|
||||
&& obj->pos.x == pos.x
|
||||
&& obj->pos.y == pos.y)
|
||||
{
|
||||
SDL_Rect bufr = sr2;
|
||||
bufr.x-=2*32;
|
||||
bufr.y-=1*32;
|
||||
bufr.h = 64;
|
||||
bufr.w = 96;
|
||||
if(bufr.x-extRect->x>-64)
|
||||
CSDL_Ext::blitSurface((graphics->*flg)[color.getNum()]->ourImages[getHeroFrameNum(dir, false) * 8].bitmap, nullptr, extSurf, &bufr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else //blit normal object
|
||||
{
|
||||
const std::vector<Cimage> &ourImages = graphics->getDef(obj)->ourImages;
|
||||
SDL_Surface *bitmap = ourImages[0].bitmap;
|
||||
|
||||
//setting appropriate flag color
|
||||
if(color < PlayerColor::PLAYER_LIMIT || color==PlayerColor::NEUTRAL)
|
||||
CSDL_Ext::setPlayerColor(bitmap, color);
|
||||
|
||||
auto scaledSurf = cache.requestWorldViewCacheOrCreate(EMapCacheType::OBJECTS, obj->id.getNum(), bitmap, scale);
|
||||
Rect tempSrc = Rect(pp.x * scale, pp.y * scale, pp.w, pp.h);
|
||||
Rect tempDst = Rect(sr2.x, sr2.y, pp.w, pp.h);
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(scaledSurf,&tempSrc,extSurf,&tempDst);
|
||||
}
|
||||
}
|
||||
//objects blitted
|
||||
}
|
||||
}
|
||||
// terrain printed
|
||||
|
||||
// blitting world view overlay
|
||||
drawWorldViewOverlay(targetTilesX, targetTilesY, srx_init, sry_init, iconsDef, visibilityMap, scale, targetTileSize, topTile, extSurf);
|
||||
// world view overlay blitted
|
||||
|
||||
|
||||
// printing borders
|
||||
srx = srx_init;
|
||||
|
||||
for (int bx = topTile.x; bx < topTile.x + targetTilesX; bx++, srx+=targetTileSize)
|
||||
{
|
||||
sry = sry_init;
|
||||
|
||||
for (int by = topTile.y; by < topTile.y + targetTilesY; by++, sry+=targetTileSize)
|
||||
{
|
||||
int3 pos(bx, by, topTile.z); //blitted tile position
|
||||
|
||||
SDL_Rect sr;
|
||||
sr.x=srx;
|
||||
sr.y=sry;
|
||||
sr.h=sr.w=targetTileSize;
|
||||
|
||||
if (pos.x < 0 || pos.x >= sizes.x ||
|
||||
pos.y < 0 || pos.y >= sizes.y)
|
||||
{
|
||||
// no borders in world view
|
||||
}
|
||||
else
|
||||
{
|
||||
//blitting Fog of War
|
||||
if (pos.x >= 0 &&
|
||||
pos.y >= 0 &&
|
||||
pos.x < sizes.x &&
|
||||
pos.y < sizes.y &&
|
||||
!(*visibilityMap)[pos.x][pos.y][topTile.z])
|
||||
{
|
||||
std::pair<SDL_Surface *, bool> hide = getVisBitmap(pos, *visibilityMap);
|
||||
auto scaledSurf = cache.requestWorldViewCacheOrCreate(EMapCacheType::FOW, (int)hide.first, hide.first, scale);
|
||||
if(hide.second)
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(scaledSurf, &rtile, extSurf, &sr);
|
||||
else
|
||||
CSDL_Ext::blitSurface(scaledSurf, &rtile, extSurf, &sr);
|
||||
}
|
||||
//FoW blitted
|
||||
}
|
||||
}
|
||||
}
|
||||
// borders printed
|
||||
|
||||
SDL_SetClipRect(extSurf, &prevClip); //restoring clip_rect
|
||||
}
|
||||
// Update map window screen
|
||||
// top_tile top left tile to draw. Not necessarily visible.
|
||||
// extRect, extRect = map window on screen
|
||||
@ -1112,6 +1545,76 @@ ui8 CMapHandler::getPhaseShift(const CGObjectInstance *object) const
|
||||
return i->second;
|
||||
}
|
||||
|
||||
void CMapHandler::discardWorldViewCache()
|
||||
{
|
||||
cache.discardWorldViewCache();
|
||||
}
|
||||
|
||||
void CMapHandler::CMapCache::discardWorldViewCache()
|
||||
{
|
||||
for (auto &cacheDataPair : data)
|
||||
{
|
||||
for (auto &cacheEntryPair : cacheDataPair.second)
|
||||
{
|
||||
if (cacheEntryPair.second)
|
||||
{
|
||||
SDL_FreeSurface(cacheEntryPair.second);
|
||||
}
|
||||
}
|
||||
data[cacheDataPair.first].clear();
|
||||
}
|
||||
logGlobal->debugStream() << "Discarded world view cache";
|
||||
}
|
||||
|
||||
void CMapHandler::CMapCache::updateWorldViewScale(float scale)
|
||||
{
|
||||
if (fabs(scale - worldViewCachedScale) > 0.001f)
|
||||
discardWorldViewCache();
|
||||
worldViewCachedScale = scale;
|
||||
}
|
||||
|
||||
void CMapHandler::CMapCache::removeFromWorldViewCache(CMapHandler::EMapCacheType type, int key)
|
||||
{
|
||||
auto iter = data[type].find(key);
|
||||
if (iter != data[type].end())
|
||||
{
|
||||
SDL_FreeSurface((*iter).second);
|
||||
data[type].erase(iter);
|
||||
// logGlobal->errorStream() << "Removed world view cache entry: type=" << (int)type << ", key=" << key;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Surface * CMapHandler::CMapCache::requestWorldViewCache(CMapHandler::EMapCacheType type, int key)
|
||||
{
|
||||
auto iter = data[type].find(key);
|
||||
if (iter == data[type].end())
|
||||
return nullptr;
|
||||
// logGlobal->errorStream() << "Returning requested world view cache entry: type=" << (int)type << ", key=" << key << ", ptr=" << (*iter).second;
|
||||
return (*iter).second;
|
||||
}
|
||||
|
||||
SDL_Surface * CMapHandler::CMapCache::requestWorldViewCacheOrCreate(CMapHandler::EMapCacheType type, int key, SDL_Surface * fullSurface, float scale)
|
||||
{
|
||||
auto cached = requestWorldViewCache(type, key);
|
||||
if (cached)
|
||||
return cached;
|
||||
|
||||
auto scaled = CSDL_Ext::scaleSurfaceFast(fullSurface, fullSurface->w * scale, fullSurface->h * scale);
|
||||
return cacheWorldViewEntry(type, key, scaled);
|
||||
}
|
||||
|
||||
SDL_Surface *CMapHandler::CMapCache::cacheWorldViewEntry(CMapHandler::EMapCacheType type, int key, SDL_Surface * entry)
|
||||
{
|
||||
if (!entry)
|
||||
return nullptr;
|
||||
if (requestWorldViewCache(type, key)) // valid cache already present, no need to do it again
|
||||
return requestWorldViewCache(type, key);
|
||||
|
||||
// logGlobal->errorStream() << "Added world view cache entry: type=" << (int)type << ", key=" << key << ", ptr=" << entry;
|
||||
data[type][key] = entry;
|
||||
return entry;
|
||||
}
|
||||
|
||||
TerrainTile2::TerrainTile2()
|
||||
:terbitmap(nullptr)
|
||||
{}
|
||||
|
@ -25,6 +25,30 @@ struct SDL_Surface;
|
||||
//struct SDL_Rect;
|
||||
class CDefEssential;
|
||||
|
||||
enum class EWorldViewIcon
|
||||
{
|
||||
TOWN = 0,
|
||||
HERO,
|
||||
ARTIFACT,
|
||||
TELEPORT,
|
||||
GATE,
|
||||
MINE_WOOD,
|
||||
MINE_MERCURY,
|
||||
MINE_STONE,
|
||||
MINE_SULFUR,
|
||||
MINE_CRYSTAL,
|
||||
MINE_GEM,
|
||||
MINE_GOLD,
|
||||
RES_WOOD,
|
||||
RES_MERCURY,
|
||||
RES_STONE,
|
||||
RES_SULFUR,
|
||||
RES_CRYSTAL,
|
||||
RES_GEM,
|
||||
RES_GOLD,
|
||||
|
||||
};
|
||||
|
||||
struct TerrainTile2
|
||||
{
|
||||
SDL_Surface * terbitmap; //bitmap of terrain
|
||||
@ -72,6 +96,33 @@ private:
|
||||
|
||||
class CMapHandler
|
||||
{
|
||||
enum class EMapCacheType
|
||||
{
|
||||
TERRAIN, TERRAIN_CUSTOM, OBJECTS, ROADS, RIVERS, FOW
|
||||
};
|
||||
|
||||
/// temporarily caches rescaled sdl surfaces for map world view redrawing
|
||||
class CMapCache
|
||||
{
|
||||
std::map<EMapCacheType, std::map<int, SDL_Surface *>> data;
|
||||
float worldViewCachedScale;
|
||||
public:
|
||||
/// destroys all cached data (frees surfaces)
|
||||
void discardWorldViewCache();
|
||||
/// updates scale and determines if currently cached data is still valid
|
||||
void updateWorldViewScale(float scale);
|
||||
void removeFromWorldViewCache(EMapCacheType type, int key);
|
||||
/// asks for cached data; @returns nullptr if data is not in cache
|
||||
SDL_Surface * requestWorldViewCache(EMapCacheType type, int key);
|
||||
/// asks for cached data; @returns cached data if found, new scaled surface otherwise
|
||||
SDL_Surface * requestWorldViewCacheOrCreate(EMapCacheType type, int key, SDL_Surface * fullSurface, float scale);
|
||||
SDL_Surface * cacheWorldViewEntry(EMapCacheType type, int key, SDL_Surface * entry);
|
||||
};
|
||||
|
||||
CMapCache cache;
|
||||
|
||||
void drawWorldViewOverlay(int targetTilesX, int targetTilesY, int srx_init, int sry_init, CDefHandler * iconsDef, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap, float scale, int targetTileSize, int3 top_tile, SDL_Surface * extSurf);
|
||||
void calculateWorldViewCameraPos(int targetTilesX, int targetTilesY, int3 &top_tile);
|
||||
public:
|
||||
PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles; //informations about map tiles
|
||||
int3 sizes; //map size (x = width, y = height, z = number of levels)
|
||||
@ -121,11 +172,13 @@ public:
|
||||
void prepareFOWDefs();
|
||||
|
||||
void terrainRect(int3 top_tile, ui8 anim, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap, bool otherHeroAnim, ui8 heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, int moveX, int moveY, bool puzzleMode, int3 grailPosRel) const;
|
||||
void terrainRectScaled(int3 top_tile, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap, SDL_Surface * extSurf, const SDL_Rect * extRect, float scale, CDefHandler * iconsDef);
|
||||
void updateWater();
|
||||
ui8 getHeroFrameNum(ui8 dir, bool isMoving) const; //terrainRect helper function
|
||||
void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
|
||||
static ui8 getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b]
|
||||
|
||||
static bool compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b);
|
||||
void discardWorldViewCache();
|
||||
|
||||
static bool compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b);
|
||||
};
|
||||
|
@ -595,6 +595,7 @@ void CMinimap::showAll(SDL_Surface * to)
|
||||
if (minimap)
|
||||
{
|
||||
int3 mapSizes = LOCPLINT->cb->getMapSize();
|
||||
int3 tileCountOnScreen = adventureInt->terrain.tileCountOnScreen();
|
||||
|
||||
//draw radar
|
||||
SDL_Rect oldClip;
|
||||
@ -602,8 +603,8 @@ void CMinimap::showAll(SDL_Surface * to)
|
||||
{
|
||||
si16(adventureInt->position.x * pos.w / mapSizes.x + pos.x),
|
||||
si16(adventureInt->position.y * pos.h / mapSizes.y + pos.y),
|
||||
ui16(adventureInt->terrain.tilesw * pos.w / mapSizes.x),
|
||||
ui16(adventureInt->terrain.tilesh * pos.h / mapSizes.y)
|
||||
ui16(tileCountOnScreen.x * pos.w / mapSizes.x),
|
||||
ui16(tileCountOnScreen.y * pos.h / mapSizes.y)
|
||||
};
|
||||
|
||||
SDL_GetClipRect(to, &oldClip);
|
||||
|
@ -81,6 +81,8 @@ void CTerrainRect::deactivate()
|
||||
|
||||
void CTerrainRect::clickLeft(tribool down, bool previousState)
|
||||
{
|
||||
if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
|
||||
return;
|
||||
if ((down==false) || indeterminate(down))
|
||||
return;
|
||||
|
||||
@ -93,6 +95,8 @@ void CTerrainRect::clickLeft(tribool down, bool previousState)
|
||||
|
||||
void CTerrainRect::clickRight(tribool down, bool previousState)
|
||||
{
|
||||
if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
|
||||
return;
|
||||
int3 mp = whichTileIsIt();
|
||||
|
||||
if (CGI->mh->map->isInTheMap(mp) && down)
|
||||
@ -259,6 +263,8 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to)
|
||||
}
|
||||
|
||||
void CTerrainRect::show(SDL_Surface * to)
|
||||
{
|
||||
if (adventureInt->mode == EAdvMapMode::NORMAL)
|
||||
{
|
||||
if (ADVOPT.smoothMove)
|
||||
CGI->mh->terrainRect
|
||||
@ -271,13 +277,23 @@ void CTerrainRect::show(SDL_Surface * to)
|
||||
&LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim,
|
||||
to, &pos, 0, 0, false, int3());
|
||||
|
||||
//SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
|
||||
//SDL_FreeSurface(teren);
|
||||
if (currentPath/* && adventureInt->position.z==currentPath->startPos().z*/) //drawing path
|
||||
{
|
||||
showPath(&pos, to);
|
||||
}
|
||||
}
|
||||
//SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
|
||||
//SDL_FreeSurface(teren);
|
||||
|
||||
}
|
||||
|
||||
void CTerrainRect::showAll(SDL_Surface * to)
|
||||
{
|
||||
// world view map is static and doesn't need redraw every frame
|
||||
if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
|
||||
CGI->mh->terrainRectScaled (adventureInt->position, &LOCPLINT->cb->getVisibilityMap(),
|
||||
to, &pos, adventureInt->worldViewScale, adventureInt->worldViewIconsDef);
|
||||
}
|
||||
|
||||
int3 CTerrainRect::whichTileIsIt(const int & x, const int & y)
|
||||
{
|
||||
@ -293,6 +309,20 @@ int3 CTerrainRect::whichTileIsIt()
|
||||
return whichTileIsIt(GH.current->motion.x,GH.current->motion.y);
|
||||
}
|
||||
|
||||
int3 CTerrainRect::tileCountOnScreen()
|
||||
{
|
||||
switch (adventureInt->mode)
|
||||
{
|
||||
default:
|
||||
logGlobal->errorStream() << "Unhandled map mode " << (int)adventureInt->mode;
|
||||
return int3();
|
||||
case EAdvMapMode::NORMAL:
|
||||
return int3(tilesw, tilesh, 1);
|
||||
case EAdvMapMode::WORLD_VIEW:
|
||||
return int3(tilesw / adventureInt->worldViewScale, tilesh / adventureInt->worldViewScale, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void CResDataBar::clickRight(tribool down, bool previousState)
|
||||
{
|
||||
}
|
||||
@ -367,6 +397,7 @@ void CResDataBar::showAll(SDL_Surface * to)
|
||||
}
|
||||
|
||||
CAdvMapInt::CAdvMapInt():
|
||||
mode(EAdvMapMode::NORMAL),
|
||||
minimap(Rect(ADVOPT.minimapX, ADVOPT.minimapY, ADVOPT.minimapW, ADVOPT.minimapH)),
|
||||
statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG),
|
||||
heroList(ADVOPT.hlistSize, Point(ADVOPT.hlistX, ADVOPT.hlistY), ADVOPT.hlistAU, ADVOPT.hlistAD),
|
||||
@ -384,6 +415,7 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
|
||||
townList.onSelect = std::bind(&CAdvMapInt::selectionChanged,this);
|
||||
adventureInt=this;
|
||||
bg = BitmapHandler::loadBitmap(ADVOPT.mainGraphic);
|
||||
bgWorldView = BitmapHandler::loadBitmap(ADVOPT.worldViewGraphic);
|
||||
scrollingDir = 0;
|
||||
updateScreen = false;
|
||||
anim=0;
|
||||
@ -391,6 +423,13 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
|
||||
heroAnim=0;
|
||||
heroAnimValHitCount=0; // hero animation frame
|
||||
|
||||
if (!bgWorldView)
|
||||
{
|
||||
logGlobal->warn("bgWorldView not defined in resolution config; fallback to VWorld.bmp");
|
||||
bgWorldView = BitmapHandler::loadBitmap("VWorld.bmp");
|
||||
}
|
||||
worldViewIconsDef = CDefHandler::giveDef("VwSymbol.def");
|
||||
|
||||
for (int g=0; g<ADVOPT.gemG.size(); ++g)
|
||||
{
|
||||
gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[g]));
|
||||
@ -416,23 +455,133 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
|
||||
nextHero = makeButton(301, std::bind(&CAdvMapInt::fnextHero,this), ADVOPT.nextHero, SDLK_h);
|
||||
endTurn = makeButton(302, std::bind(&CAdvMapInt::fendTurn,this), ADVOPT.endTurn, SDLK_e);
|
||||
|
||||
// TODO move configs to resolutions.json, similarly to previous buttons
|
||||
config::ButtonInfo worldViewBackConfig = config::ButtonInfo();
|
||||
worldViewBackConfig.defName = "IOK6432.DEF";
|
||||
worldViewBackConfig.x = screen->w - 73;
|
||||
worldViewBackConfig.y = 343 + 195;
|
||||
worldViewBackConfig.playerColoured = false;
|
||||
worldViewUIObjects.push_back(makeButton(288, std::bind(&CAdvMapInt::fworldViewBack,this), worldViewBackConfig, SDLK_ESCAPE));
|
||||
|
||||
config::ButtonInfo worldViewScale1xConfig = config::ButtonInfo();
|
||||
worldViewScale1xConfig.defName = "VWMAG1.DEF";
|
||||
worldViewScale1xConfig.x = screen->w - 191;
|
||||
worldViewScale1xConfig.y = 23 + 195;
|
||||
worldViewScale1xConfig.playerColoured = false;
|
||||
worldViewUIObjects.push_back(makeButton(291, std::bind(&CAdvMapInt::fworldViewScale1x,this), worldViewScale1xConfig, SDLK_y));
|
||||
|
||||
config::ButtonInfo worldViewScale2xConfig = config::ButtonInfo();
|
||||
worldViewScale2xConfig.defName = "VWMAG2.DEF";
|
||||
worldViewScale2xConfig.x = screen->w - 191 + 63;
|
||||
worldViewScale2xConfig.y = 23 + 195;
|
||||
worldViewScale2xConfig.playerColoured = false;
|
||||
worldViewUIObjects.push_back(makeButton(291, std::bind(&CAdvMapInt::fworldViewScale2x,this), worldViewScale2xConfig, SDLK_y));
|
||||
|
||||
config::ButtonInfo worldViewScale4xConfig = config::ButtonInfo();
|
||||
worldViewScale4xConfig.defName = "VWMAG4.DEF";
|
||||
worldViewScale4xConfig.x = screen->w - 191 + 126;
|
||||
worldViewScale4xConfig.y = 23 + 195;
|
||||
worldViewScale4xConfig.playerColoured = false;
|
||||
worldViewUIObjects.push_back(makeButton(291, std::bind(&CAdvMapInt::fworldViewScale4x,this), worldViewScale4xConfig, SDLK_y));
|
||||
|
||||
config::ButtonInfo worldViewUndergroundConfig = config::ButtonInfo();
|
||||
worldViewUndergroundConfig.defName = "IAM010.DEF";
|
||||
worldViewUndergroundConfig.additionalDefs.push_back("IAM003.DEF");
|
||||
worldViewUndergroundConfig.x = screen->w - 115;
|
||||
worldViewUndergroundConfig.y = 343 + 195;
|
||||
worldViewUndergroundConfig.playerColoured = true;
|
||||
worldViewUnderground = makeButton(294, std::bind(&CAdvMapInt::fworldViewSwitchLevel,this), worldViewUndergroundConfig, SDLK_u);
|
||||
worldViewUIObjects.push_back(worldViewUnderground);
|
||||
|
||||
setPlayer(LOCPLINT->playerID);
|
||||
|
||||
|
||||
int iconColorMultiplier = player.getNum() * 19;
|
||||
int wvLeft = heroList.pos.x - 2; // TODO correct drawing position?
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
worldViewUIObjects.push_back(new CPicture(worldViewIconsDef->ourImages[i].bitmap, wvLeft + 5, 253 + i * 20));
|
||||
worldViewUIObjects.push_back(new CLabel(wvLeft + 45, 263 + i * 20, EFonts::FONT_SMALL, EAlignment::TOPLEFT,
|
||||
Colors::WHITE, CGI->generaltexth->allTexts[612 + i]));
|
||||
}
|
||||
for (int i = 0; i < 7; ++i)
|
||||
{
|
||||
worldViewUIObjects.push_back(new CPicture(worldViewIconsDef->ourImages[i + 5 + iconColorMultiplier].bitmap, wvLeft + 5, 377 + i * 20));
|
||||
worldViewUIObjects.push_back(new CPicture(worldViewIconsDef->ourImages[i + 12 + iconColorMultiplier].bitmap, wvLeft + 160, 377 + i * 20));
|
||||
worldViewUIObjects.push_back(new CLabel(wvLeft + 45, 387 + i * 20, EFonts::FONT_SMALL, EAlignment::TOPLEFT,
|
||||
Colors::WHITE, CGI->generaltexth->allTexts[619 + i]));
|
||||
}
|
||||
worldViewUIObjects.push_back(new CLabel(wvLeft + 5, 367, EFonts::FONT_SMALL, EAlignment::TOPLEFT,
|
||||
Colors::WHITE, CGI->generaltexth->allTexts[617]));
|
||||
worldViewUIObjects.push_back(new CLabel(wvLeft + 185, 387, EFonts::FONT_SMALL, EAlignment::BOTTOMRIGHT,
|
||||
Colors::WHITE, CGI->generaltexth->allTexts[618]));
|
||||
|
||||
|
||||
underground->block(!CGI->mh->map->twoLevel);
|
||||
worldViewUnderground->block(!CGI->mh->map->twoLevel);
|
||||
addUsedEvents(MOVE);
|
||||
}
|
||||
|
||||
CAdvMapInt::~CAdvMapInt()
|
||||
{
|
||||
SDL_FreeSurface(bg);
|
||||
SDL_FreeSurface(bgWorldView);
|
||||
|
||||
for(int i=0; i<gems.size(); i++)
|
||||
delete gems[i];
|
||||
|
||||
delete worldViewIconsDef;
|
||||
}
|
||||
|
||||
void CAdvMapInt::fshowOverview()
|
||||
{
|
||||
GH.pushInt(new CKingdomInterface);
|
||||
}
|
||||
|
||||
void CAdvMapInt::fworldViewBack()
|
||||
{
|
||||
changeMode(EAdvMapMode::NORMAL);
|
||||
CGI->mh->discardWorldViewCache();
|
||||
}
|
||||
|
||||
void CAdvMapInt::fworldViewScale1x()
|
||||
{
|
||||
// TODO set corresponding scale button to "selected" mode
|
||||
changeMode(EAdvMapMode::WORLD_VIEW, 0.25f); // TODO find out correct scale values from OH3
|
||||
}
|
||||
|
||||
void CAdvMapInt::fworldViewScale2x()
|
||||
{
|
||||
changeMode(EAdvMapMode::WORLD_VIEW, 0.4f);
|
||||
}
|
||||
|
||||
void CAdvMapInt::fworldViewScale4x()
|
||||
{
|
||||
changeMode(EAdvMapMode::WORLD_VIEW, 0.6f);
|
||||
}
|
||||
|
||||
void CAdvMapInt::fworldViewSwitchLevel()
|
||||
{
|
||||
if(!CGI->mh->map->twoLevel)
|
||||
return;
|
||||
if (position.z)
|
||||
{
|
||||
position.z--;
|
||||
worldViewUnderground->setIndex(0,false);
|
||||
worldViewUnderground->showAll(screenBuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
worldViewUnderground->setIndex(1,false);
|
||||
position.z++;
|
||||
worldViewUnderground->showAll(screenBuf);
|
||||
}
|
||||
updateScreen = true;
|
||||
minimap.setLevel(position.z);
|
||||
|
||||
terrain.redraw();
|
||||
}
|
||||
|
||||
void CAdvMapInt::fswitchLevel()
|
||||
{
|
||||
if(!CGI->mh->map->twoLevel)
|
||||
@ -598,6 +747,8 @@ void CAdvMapInt::activate()
|
||||
screenBuf = screen;
|
||||
GH.statusbar = &statusbar;
|
||||
if(!duringAITurn)
|
||||
{
|
||||
if (mode == EAdvMapMode::NORMAL)
|
||||
{
|
||||
kingOverview->activate();
|
||||
underground->activate();
|
||||
@ -609,17 +760,23 @@ void CAdvMapInt::activate()
|
||||
advOptions->activate();
|
||||
nextHero->activate();
|
||||
endTurn->activate();
|
||||
|
||||
minimap.activate();
|
||||
heroList.activate();
|
||||
townList.activate();
|
||||
terrain.activate();
|
||||
infoBar.activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto &uiElem : worldViewUIObjects)
|
||||
uiElem->activate();
|
||||
}
|
||||
minimap.activate();
|
||||
terrain.activate();
|
||||
LOCPLINT->cingconsole->activate();
|
||||
|
||||
GH.fakeMouseMove(); //to restore the cursor
|
||||
}
|
||||
}
|
||||
|
||||
void CAdvMapInt::deactivate()
|
||||
{
|
||||
CIntObject::deactivate();
|
||||
@ -629,6 +786,8 @@ void CAdvMapInt::deactivate()
|
||||
scrollingDir = 0;
|
||||
|
||||
CCS->curh->changeGraphic(ECursor::ADVENTURE,0);
|
||||
if (mode == EAdvMapMode::NORMAL)
|
||||
{
|
||||
kingOverview->deactivate();
|
||||
underground->deactivate();
|
||||
questlog->deactivate();
|
||||
@ -639,15 +798,22 @@ void CAdvMapInt::deactivate()
|
||||
sysOptions->deactivate();
|
||||
nextHero->deactivate();
|
||||
endTurn->deactivate();
|
||||
minimap.deactivate();
|
||||
heroList.deactivate();
|
||||
townList.deactivate();
|
||||
terrain.deactivate();
|
||||
infoBar.deactivate();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto &uiElem : worldViewUIObjects)
|
||||
uiElem->deactivate();
|
||||
}
|
||||
minimap.deactivate();
|
||||
terrain.deactivate();
|
||||
if(LOCPLINT)
|
||||
LOCPLINT->cingconsole->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
void CAdvMapInt::showAll(SDL_Surface * to)
|
||||
{
|
||||
blitAt(bg,0,0,to);
|
||||
@ -655,6 +821,9 @@ void CAdvMapInt::showAll(SDL_Surface * to)
|
||||
if(state != INGAME)
|
||||
return;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case EAdvMapMode::NORMAL:
|
||||
kingOverview->showAll(to);
|
||||
underground->showAll(to);
|
||||
questlog->showAll(to);
|
||||
@ -666,17 +835,29 @@ void CAdvMapInt::showAll(SDL_Surface * to)
|
||||
nextHero->showAll(to);
|
||||
endTurn->showAll(to);
|
||||
|
||||
minimap.showAll(to);
|
||||
heroList.showAll(to);
|
||||
townList.showAll(to);
|
||||
infoBar.showAll(to);
|
||||
break;
|
||||
case EAdvMapMode::WORLD_VIEW:
|
||||
blitAt(bgWorldView, heroList.pos.x - 2, 195, to); // TODO correct drawing position
|
||||
|
||||
for (auto &uiElem : worldViewUIObjects)
|
||||
uiElem->showAll(to);
|
||||
|
||||
terrain.showAll(to);
|
||||
break;
|
||||
}
|
||||
|
||||
updateScreen = true;
|
||||
minimap.showAll(to);
|
||||
show(to);
|
||||
|
||||
|
||||
resdatabar.draw(to);
|
||||
|
||||
statusbar.show(to);
|
||||
|
||||
infoBar.showAll(to);
|
||||
LOCPLINT->cingconsole->showAll(to);
|
||||
}
|
||||
|
||||
@ -737,6 +918,8 @@ void CAdvMapInt::show(SDL_Surface * to)
|
||||
{
|
||||
updateScreen = true;
|
||||
minimap.redraw();
|
||||
if (mode == EAdvMapMode::WORLD_VIEW)
|
||||
terrain.redraw();
|
||||
}
|
||||
}
|
||||
if(updateScreen)
|
||||
@ -781,6 +964,9 @@ void CAdvMapInt::centerOn(int3 on)
|
||||
if (switchedLevels)
|
||||
minimap.setLevel(position.z);
|
||||
minimap.redraw();
|
||||
|
||||
if (mode == EAdvMapMode::WORLD_VIEW)
|
||||
terrain.redraw();
|
||||
}
|
||||
|
||||
void CAdvMapInt::centerOn(const CGObjectInstance *obj)
|
||||
@ -1040,7 +1226,8 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView /*= true*/)
|
||||
void CAdvMapInt::mouseMoved( const SDL_MouseMotionEvent & sEvent )
|
||||
{
|
||||
// adventure map scrolling with mouse
|
||||
if(!isCtrlKeyDown() && isActive())
|
||||
// currently blocked in world view mode (as it is in OH3), but should work correctly if mode check is removed
|
||||
if(!isCtrlKeyDown() && isActive() && mode == EAdvMapMode::NORMAL)
|
||||
{
|
||||
if(sEvent.x<15)
|
||||
{
|
||||
@ -1143,6 +1330,8 @@ const CGObjectInstance* CAdvMapInt::getActiveObject(const int3 &mapPos)
|
||||
|
||||
void CAdvMapInt::tileLClicked(const int3 &mapPos)
|
||||
{
|
||||
if(mode != EAdvMapMode::NORMAL)
|
||||
return;
|
||||
if(!LOCPLINT->cb->isVisible(mapPos) || !LOCPLINT->makingTurn)
|
||||
return;
|
||||
|
||||
@ -1227,6 +1416,8 @@ void CAdvMapInt::tileLClicked(const int3 &mapPos)
|
||||
|
||||
void CAdvMapInt::tileHovered(const int3 &mapPos)
|
||||
{
|
||||
if(mode != EAdvMapMode::NORMAL)
|
||||
return;
|
||||
if(!LOCPLINT->cb->isVisible(mapPos))
|
||||
{
|
||||
CCS->curh->changeGraphic(ECursor::ADVENTURE, 0);
|
||||
@ -1421,6 +1612,8 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
|
||||
|
||||
void CAdvMapInt::tileRClicked(const int3 &mapPos)
|
||||
{
|
||||
if(mode != EAdvMapMode::NORMAL)
|
||||
return;
|
||||
if(spellBeingCasted)
|
||||
{
|
||||
leaveCastingMode();
|
||||
@ -1519,19 +1712,77 @@ void CAdvMapInt::adjustActiveness(bool aiTurnStart)
|
||||
activate();
|
||||
}
|
||||
|
||||
void CAdvMapInt::changeMode(EAdvMapMode newMode, float newScale /* = 0.65f */)
|
||||
{
|
||||
if (mode != newMode)
|
||||
{
|
||||
mode = newMode;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case EAdvMapMode::NORMAL:
|
||||
kingOverview->activate();
|
||||
underground->activate();
|
||||
questlog->activate();
|
||||
sleepWake->activate();
|
||||
moveHero->activate();
|
||||
spellbook->activate();
|
||||
sysOptions->activate();
|
||||
advOptions->activate();
|
||||
nextHero->activate();
|
||||
endTurn->activate();
|
||||
townList.activate();
|
||||
heroList.activate();
|
||||
infoBar.activate();
|
||||
|
||||
for (auto &uiElem : worldViewUIObjects)
|
||||
uiElem->deactivate();
|
||||
break;
|
||||
case EAdvMapMode::WORLD_VIEW:
|
||||
kingOverview->deactivate();
|
||||
underground->deactivate();
|
||||
questlog->deactivate();
|
||||
sleepWake->deactivate();
|
||||
moveHero->deactivate();
|
||||
spellbook->deactivate();
|
||||
sysOptions->deactivate();
|
||||
advOptions->deactivate();
|
||||
nextHero->deactivate();
|
||||
endTurn->deactivate();
|
||||
townList.deactivate();
|
||||
heroList.deactivate();
|
||||
infoBar.showSelection(); // to prevent new day animation interfering world view mode
|
||||
infoBar.deactivate();
|
||||
|
||||
for (auto &uiElem : worldViewUIObjects)
|
||||
uiElem->activate();
|
||||
break;
|
||||
}
|
||||
worldViewScale = newScale;
|
||||
redraw();
|
||||
}
|
||||
else if (worldViewScale != newScale) // still in world view mode, but the scale changed
|
||||
{
|
||||
worldViewScale = newScale;
|
||||
terrain.redraw();
|
||||
minimap.redraw(); // to recalculate radar rect on minimap
|
||||
}
|
||||
}
|
||||
|
||||
CAdventureOptions::CAdventureOptions():
|
||||
CWindowObject(PLAYER_COLORED, "ADVOPTS")
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
|
||||
viewWorld = new CButton(Point(24, 23), "ADVVIEW.DEF", CButton::tooltip(), [&]{ close(); }, SDLK_x);
|
||||
viewWorld->addCallback(std::bind(&CPlayerInterface::viewWorldMap, LOCPLINT));
|
||||
|
||||
exit = new CButton(Point(204, 313), "IOK6432.DEF", CButton::tooltip(), std::bind(&CAdventureOptions::close, this), SDLK_RETURN);
|
||||
exit->assignedKeys.insert(SDLK_ESCAPE);
|
||||
|
||||
scenInfo = new CButton(Point(24, 198), "ADVINFO.DEF", CButton::tooltip(), [&]{ close(); }, SDLK_i);
|
||||
scenInfo->addCallback(CAdventureOptions::showScenarioInfo);
|
||||
|
||||
//viewWorld = new CButton("","",std::bind(&CGuiHandler::popIntTotally, &GH, this), 204, 313, "IOK6432.DEF",SDLK_RETURN);
|
||||
|
||||
puzzle = new CButton(Point(24, 81), "ADVPUZ.DEF", CButton::tooltip(), [&]{ close(); }, SDLK_p);
|
||||
puzzle->addCallback(std::bind(&CPlayerInterface::showPuzzleMap, LOCPLINT));
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <client/CDefHandler.h>
|
||||
#include "../widgets/AdventureMapClasses.h"
|
||||
#include "CWindowObject.h"
|
||||
|
||||
@ -28,6 +29,12 @@ class IShipyard;
|
||||
*
|
||||
*/
|
||||
|
||||
enum class EAdvMapMode
|
||||
{
|
||||
NORMAL,
|
||||
WORLD_VIEW
|
||||
};
|
||||
|
||||
/// Adventure options dialogue where you can view the world, dig, play the replay of the last turn,...
|
||||
class CAdventureOptions : public CWindowObject
|
||||
{
|
||||
@ -55,9 +62,12 @@ public:
|
||||
void hover(bool on);
|
||||
void mouseMoved (const SDL_MouseMotionEvent & sEvent);
|
||||
void show(SDL_Surface * to);
|
||||
void showAll(SDL_Surface * to);
|
||||
void showPath(const SDL_Rect * extRect, SDL_Surface * to);
|
||||
int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
|
||||
int3 whichTileIsIt(); //uses current cursor pos
|
||||
/// @returns number of visible tiles on screen respecting current map scaling
|
||||
int3 tileCountOnScreen();
|
||||
};
|
||||
|
||||
/// Resources bar which shows information about how many gold, crystals,... you have
|
||||
@ -105,7 +115,11 @@ public:
|
||||
ui8 anim, animValHitCount; //animation frame
|
||||
ui8 heroAnim, heroAnimValHitCount; //animation frame
|
||||
|
||||
EAdvMapMode mode;
|
||||
float worldViewScale;
|
||||
|
||||
SDL_Surface * bg;
|
||||
SDL_Surface * bgWorldView;
|
||||
std::vector<CDefHandler *> gems;
|
||||
CMinimap minimap;
|
||||
CGStatusBar statusbar;
|
||||
@ -121,18 +135,28 @@ public:
|
||||
CButton * nextHero;
|
||||
CButton * endTurn;
|
||||
|
||||
CButton * worldViewUnderground;
|
||||
std::vector<CIntObject *> worldViewUIObjects; // all ui objects visible in the right panel in world view mode
|
||||
|
||||
CTerrainRect terrain; //visible terrain
|
||||
CResDataBar resdatabar;
|
||||
CHeroList heroList;
|
||||
CTownList townList;
|
||||
CInfoBar infoBar;
|
||||
|
||||
CDefHandler * worldViewIconsDef; // images for world view overlay
|
||||
|
||||
const CSpell *spellBeingCasted; //nullptr if none
|
||||
|
||||
const CArmedInstance *selection; //currently selected town/hero
|
||||
|
||||
//functions bound to buttons
|
||||
void fshowOverview();
|
||||
void fworldViewBack();
|
||||
void fworldViewScale1x();
|
||||
void fworldViewScale2x();
|
||||
void fworldViewScale4x();
|
||||
void fworldViewSwitchLevel();
|
||||
void fswitchLevel();
|
||||
void fshowQuestlog();
|
||||
void fsleepWake();
|
||||
@ -182,6 +206,9 @@ public:
|
||||
void updateSleepWake(const CGHeroInstance *h);
|
||||
void updateMoveHero(const CGHeroInstance *h, tribool hasPath = boost::logic::indeterminate);
|
||||
void updateNextHero(const CGHeroInstance *h);
|
||||
|
||||
/// changes current adventure map mode; used to switch between default view and world view; scale is ignored if EAdvMapMode == NORMAL
|
||||
void changeMode(EAdvMapMode newMode, float newScale = 0.4f);
|
||||
};
|
||||
|
||||
extern CAdvMapInt *adventureInt;
|
||||
|
@ -11,6 +11,7 @@
|
||||
"gem2": { "x": 6, "y": 6, "graphic": "agemUL.def" },
|
||||
"gem3": { "x": 556, "y": 6, "graphic": "agemUR.def" },
|
||||
"background": "AdvMap.bmp",
|
||||
"backgroundWorldView": "VWorld.bmp",
|
||||
"HeroList": { "size": 5, "x": 609, "y": 196, "movePoints": "IMOBIL.DEF", "manaPoints": "IMANA.DEF", "arrowUp": "IAM012.DEF", "arrowDown": "IAM013.DEF" },
|
||||
"TownList": { "size": 5, "x": 747, "y": 196, "arrowUp": "IAM014.DEF", "arrowDown": "IAM015.DEF" },
|
||||
"Minimap": { "width": 144, "height": 144, "x": 630, "y": 26 },
|
||||
|
@ -238,6 +238,7 @@ void config::CConfigHandler::init()
|
||||
setGem(current->ac, 3, g["gem3"]);
|
||||
|
||||
current->ac.mainGraphic = g["background"].String();
|
||||
current->ac.worldViewGraphic = g["backgroundWorldView"].String();
|
||||
|
||||
current->ac.hlistX = g["HeroList"]["x"].Float();
|
||||
current->ac.hlistY = g["HeroList"]["y"].Float();
|
||||
|
@ -135,6 +135,7 @@ namespace config
|
||||
bool puzzleSepia;
|
||||
//general properties
|
||||
std::string mainGraphic;
|
||||
std::string worldViewGraphic;
|
||||
//buttons
|
||||
ButtonInfo kingOverview, underground, questlog, sleepWake, moveHero, spellbook, advOptions,
|
||||
sysOptions, nextHero, endTurn;
|
||||
|
@ -109,6 +109,7 @@ public:
|
||||
virtual void showShipyardDialog(const IShipyard *obj){} //obj may be town or shipyard; state: 0 - can buid, 1 - lack of resources, 2 - dest tile is blocked, 3 - no water
|
||||
|
||||
virtual void showPuzzleMap(){};
|
||||
virtual void viewWorldMap(){};
|
||||
virtual void showMarketWindow(const IMarket *market, const CGHeroInstance *visitor){};
|
||||
virtual void showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor){};
|
||||
virtual void showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor){};
|
||||
|
Loading…
Reference in New Issue
Block a user