1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

use CAnimation fro world view icons

This commit is contained in:
AlexVinS
2016-10-18 06:32:58 +03:00
parent 365c64a345
commit 536f36ede8
4 changed files with 37 additions and 37 deletions

View File

@@ -528,7 +528,7 @@ CMapHandler::CMapNormalBlitter::CMapNormalBlitter(CMapHandler * parent)
defaultTileRect = Rect(0, 0, tileSize, tileSize);
}
SDL_Surface * CMapHandler::CMapWorldViewBlitter::objectToIcon(Obj id, si32 subId, PlayerColor owner) const
IImage * CMapHandler::CMapWorldViewBlitter::objectToIcon(Obj id, si32 subId, PlayerColor owner) const
{
int ownerIndex = 0;
if(owner < PlayerColor::PLAYER_LIMIT)
@@ -545,19 +545,19 @@ SDL_Surface * CMapHandler::CMapWorldViewBlitter::objectToIcon(Obj id, si32 subId
case Obj::MONOLITH_ONE_WAY_ENTRANCE:
case Obj::MONOLITH_ONE_WAY_EXIT:
case Obj::MONOLITH_TWO_WAY:
return info->iconsDef->ourImages[(int)EWorldViewIcon::TELEPORT].bitmap;
return info->icons->getImage((int)EWorldViewIcon::TELEPORT);
case Obj::SUBTERRANEAN_GATE:
return info->iconsDef->ourImages[(int)EWorldViewIcon::GATE].bitmap;
return info->icons->getImage((int)EWorldViewIcon::GATE);
case Obj::ARTIFACT:
return info->iconsDef->ourImages[(int)EWorldViewIcon::ARTIFACT].bitmap;
return info->icons->getImage((int)EWorldViewIcon::ARTIFACT);
case Obj::TOWN:
return info->iconsDef->ourImages[(int)EWorldViewIcon::TOWN + ownerIndex].bitmap;
return info->icons->getImage((int)EWorldViewIcon::TOWN + ownerIndex);
case Obj::HERO:
return info->iconsDef->ourImages[(int)EWorldViewIcon::HERO + ownerIndex].bitmap;
return info->icons->getImage((int)EWorldViewIcon::HERO + ownerIndex);
case Obj::MINE:
return info->iconsDef->ourImages[(int)EWorldViewIcon::MINE_WOOD + subId + ownerIndex].bitmap;
return info->icons->getImage((int)EWorldViewIcon::MINE_WOOD + subId + ownerIndex);
case Obj::RESOURCE:
return info->iconsDef->ourImages[(int)EWorldViewIcon::RES_WOOD + subId + ownerIndex].bitmap;
return info->icons->getImage((int)EWorldViewIcon::RES_WOOD + subId + ownerIndex);
}
return nullptr;
}
@@ -645,13 +645,13 @@ void CMapHandler::CMapWorldViewBlitter::drawTileOverlay(SDL_Surface * targetSurf
{
auto drawIcon = [this,targetSurf](Obj id, si32 subId, PlayerColor owner)
{
SDL_Surface * wvIcon = this->objectToIcon(id, subId, owner);
IImage * wvIcon = this->objectToIcon(id, subId, owner);
if (nullptr != wvIcon)
if(nullptr != wvIcon)
{
// centering icon on the object
Rect destRect(realPos.x + tileSize / 2 - wvIcon->w / 2, realPos.y + tileSize / 2 - wvIcon->h / 2, wvIcon->w, wvIcon->h);
CSDL_Ext::blitSurface(wvIcon, nullptr, targetSurf, &destRect);
Point dest(realPos.x + tileSize / 2 - wvIcon->width() / 2, realPos.y + tileSize / 2 - wvIcon->height() / 2);
wvIcon->draw(targetSurf, dest.x, dest.y);
}
};
@@ -690,13 +690,13 @@ void CMapHandler::CMapWorldViewBlitter::drawOverlayEx(SDL_Surface * targetSurf)
realPos.x = initPos.x + (iconInfo.pos.x - topTile.x) * tileSize;
realPos.y = initPos.x + (iconInfo.pos.y - topTile.y) * tileSize;
SDL_Surface * wvIcon = this->objectToIcon(iconInfo.id, iconInfo.subId, iconInfo.owner);
IImage * wvIcon = this->objectToIcon(iconInfo.id, iconInfo.subId, iconInfo.owner);
if (nullptr != wvIcon)
if(nullptr != wvIcon)
{
// centering icon on the object
Rect destRect(realPos.x + tileSize / 2 - wvIcon->w / 2, realPos.y + tileSize / 2 - wvIcon->h / 2, wvIcon->w, wvIcon->h);
CSDL_Ext::blitSurface(wvIcon, nullptr, targetSurf, &destRect);
Point dest(realPos.x + tileSize / 2 - wvIcon->width() / 2, realPos.y + tileSize / 2 - wvIcon->height() / 2);
wvIcon->draw(targetSurf, dest.x, dest.y);
}
}
}

View File

@@ -26,6 +26,8 @@ struct TerrainTile;
struct SDL_Surface;
struct SDL_Rect;
class CDefEssential;
class CAnimation;
class IImage;
class CFadeAnimation;
class PlayerColor;
@@ -71,7 +73,7 @@ struct TerrainTileObject
const CGObjectInstance *obj;
SDL_Rect rect;
int fadeAnimKey;
TerrainTileObject(const CGObjectInstance *obj_, SDL_Rect rect_);
~TerrainTileObject();
};
@@ -90,7 +92,7 @@ struct MapDrawingInfo
int3 &topTile; // top-left tile in viewport [in tiles]
const std::vector< std::vector< std::vector<ui8> > > * visibilityMap;
SDL_Rect * drawBounds; // map rect drawing bounds on screen
CDefHandler * iconsDef; // holds overlay icons for world view mode
std::shared_ptr<CAnimation> icons; // holds overlay icons for world view mode
float scale; // map scale for world view mode (only if scaled == true)
bool otherheroAnim;
@@ -101,17 +103,17 @@ struct MapDrawingInfo
bool puzzleMode;
int3 grailPos; // location of grail for puzzle mode [in tiles]
const std::vector<ObjectPosInfo> * additionalIcons;
bool showAllTerrain; //for expert viewEarth
MapDrawingInfo(int3 &topTile_, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap_, SDL_Rect * drawBounds_, CDefHandler * iconsDef_ = nullptr)
MapDrawingInfo(int3 &topTile_, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap_, SDL_Rect * drawBounds_, std::shared_ptr<CAnimation> icons_ = nullptr)
: scaled(false),
topTile(topTile_),
visibilityMap(visibilityMap_),
drawBounds(drawBounds_),
iconsDef(iconsDef_),
icons(icons_),
scale(1.0f),
otherheroAnim(false),
anim(0u),
@@ -188,14 +190,14 @@ class CMapHandler
SDL_Surface * cacheWorldViewEntry(EMapCacheType type, intptr_t key, SDL_Surface * entry);
intptr_t genKey(intptr_t realPtr, ui8 mod);
};
/// helper struct to pass around resolved bitmaps of an object; surfaces can be nullptr if object doesn't have bitmap of that type
struct AnimBitmapHolder
{
SDL_Surface * objBitmap; // main object bitmap
SDL_Surface * flagBitmap; // flag bitmap for the object (probably only for heroes and boats with heroes)
bool isMoving; // indicates if the object is moving (again, heroes/boats only)
AnimBitmapHolder(SDL_Surface * objBitmap_ = nullptr, SDL_Surface * flagBitmap_ = nullptr, bool moving = false)
: objBitmap(objBitmap_),
flagBitmap(flagBitmap_),
@@ -205,7 +207,7 @@ class CMapHandler
class CMapBlitter
{
{
protected:
const int FRAMES_PER_MOVE_ANIM_GROUP = 8;
CMapHandler * parent; // ptr to enclosing map handler; generally for legacy reasons, probably could/should be refactored out of here
@@ -267,16 +269,16 @@ class CMapHandler
virtual bool canDrawObject(const CGObjectInstance * obj) const;
virtual bool canDrawCurrentTile() const;
// internal helper methods to choose correct bitmap(s) for object; called internally by findObjectBitmap
AnimBitmapHolder findHeroBitmap(const CGHeroInstance * hero, int anim) const;
AnimBitmapHolder findBoatBitmap(const CGBoat * hero, int anim) const;
AnimBitmapHolder findBoatBitmap(const CGBoat * hero, int anim) const;
SDL_Surface * findFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor * color, int indexOffset) const;
SDL_Surface * findHeroFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor * color, int indexOffset) const;
SDL_Surface * findBoatFlagBitmap(const CGBoat * obj, int anim, const PlayerColor * color, int indexOffset, ui8 dir) const;
SDL_Surface * findFlagBitmapInternal(const CDefEssential * def, int anim, int indexOffset, ui8 dir, bool moving) const;
int findAnimIndexByGroup(const CDefEssential * def, int groupNum) const;
public:
CMapBlitter(CMapHandler * p) : parent(p) {}
virtual ~CMapBlitter(){}
@@ -303,7 +305,7 @@ class CMapHandler
class CMapWorldViewBlitter : public CMapBlitter
{
private:
SDL_Surface * objectToIcon(Obj id, si32 subId, PlayerColor owner) const;
IImage * objectToIcon(Obj id, si32 subId, PlayerColor owner) const;
protected:
void drawElement(EMapCacheType cacheType, SDL_Surface * sourceSurf, SDL_Rect * sourceRect,
SDL_Surface * targetSurf, SDL_Rect * destRect, bool alphaBlit = false, ui8 rotationInfo = 0u) const override;
@@ -344,7 +346,7 @@ class CMapHandler
CMapBlitter * normalBlitter;
CMapBlitter * worldViewBlitter;
CMapBlitter * puzzleViewBlitter;
std::map<int, std::pair<int3, CFadeAnimation*>> fadeAnims;
int fadeAnimCounter;

View File

@@ -328,7 +328,7 @@ void CTerrainRect::showAll(SDL_Surface * to)
// world view map is static and doesn't need redraw every frame
if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
{
MapDrawingInfo info(adventureInt->position, &LOCPLINT->cb->getVisibilityMap(), &pos, adventureInt->worldViewIconsDef);
MapDrawingInfo info(adventureInt->position, &LOCPLINT->cb->getVisibilityMap(), &pos, adventureInt->worldViewIcons);
info.scaled = true;
info.scale = adventureInt->worldViewScale;
adventureInt->worldViewOptions.adjustDrawingInfo(info);
@@ -498,9 +498,10 @@ CAdvMapInt::CAdvMapInt():
logGlobal->warn("bgWorldView not defined in resolution config; fallback to VWorld.bmp");
bgWorldView = BitmapHandler::loadBitmap("VWorld.bmp");
}
worldViewIconsDef = CDefHandler::giveDef("VwSymbol.def");
worldViewIcons = std::make_shared<CAnimation>("VwSymbol");//todo: customize with ADVOPT
//preload all for faster map drawing
worldViewIcons->load();//TODO: make special method in CAnimation fro that
for (int g=0; g<ADVOPT.gemG.size(); ++g)
{
@@ -633,7 +634,7 @@ CAdvMapInt::~CAdvMapInt()
{
SDL_FreeSurface(bg);
delete worldViewIconsDef;
worldViewIcons->unload();
}
void CAdvMapInt::fshowOverview()

View File

@@ -8,7 +8,6 @@
#include "../../lib/spells/ViewSpellInt.h"
class CDefHandler;
class CCallback;
struct CGPath;
class CAdvMapInt;
@@ -176,8 +175,6 @@ public:
CAdvMapWorldViewPanel *panelWorldView; // panel that holds all buttons and other ui in world view
CAdvMapPanel *activeMapPanel; // currently active panel (either main or world view, depending on current mode)
CDefHandler * worldViewIconsDef; // images for world view overlay(DEPRECATED)
std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
const CSpell *spellBeingCasted; //nullptr if none