Browse Source

Merge pull request #243 from vcmi/guiCleanup

Gui cleanup
Alexander Shishkin 9 years ago
parent
commit
0cf5a10bd1

+ 3 - 1
client/CMT.cpp

@@ -154,7 +154,7 @@ void init()
 		logGlobal->infoStream()<<"Screen handler: "<<pomtime.getDiff();
 		pomtime.getDiff();
 
-		graphics->loadHeroAnims();
+		graphics->load();
 		logGlobal->infoStream()<<"\tMain graphics: "<<pomtime.getDiff();
 		logGlobal->infoStream()<<"Initializing game graphics: "<<tmh.getDiff();
 
@@ -934,6 +934,8 @@ void dispose()
 	}
 	CMessage::dispose();
 
+	vstd::clear_pointer(graphics);
+
 	if(console)
 	{
 		delete console; // should be removed after everything else since used by logging

+ 10 - 8
client/Graphics.cpp

@@ -5,6 +5,7 @@
 #include "../lib/filesystem/CBinaryReader.h"
 #include "CDefHandler.h"
 #include "gui/SDL_Extensions.h"
+#include "gui/CAnimation.h"
 #include <SDL_ttf.h>
 #include "../lib/CThreadHelper.h"
 #include "CGameInfo.h"
@@ -144,8 +145,6 @@ Graphics::Graphics()
 	tasks += std::bind(&Graphics::initializeBattleGraphics,this);
 	tasks += std::bind(&Graphics::loadErmuToPicture,this);
 	tasks += std::bind(&Graphics::initializeImageLists,this);
-	tasks += GET_DEF_ESS(resources32,"RESOURCE.DEF");
-	tasks += GET_DEF_ESS(heroMoveArrows,"ADAG.DEF");
 
 	CThreadHelper th(&tasks,std::max((ui32)1,boost::thread::hardware_concurrency()));
 	th.run();
@@ -156,14 +155,17 @@ Graphics::Graphics()
 	initializeBattleGraphics();
 	loadErmuToPicture();
 	initializeImageLists();
-	resources32 = CDefHandler::giveDefEss("RESOURCE.DEF");
-	heroMoveArrows = CDefHandler::giveDefEss("ADAG.DEF");
 	#endif
 
-	for(auto & elem : heroMoveArrows->ourImages)
-	{
-		CSDL_Ext::alphaTransform(elem.bitmap);
-	}
+	//(!) do not load any CAnimation here
+}
+
+void Graphics::load()
+{
+	heroMoveArrows = std::make_shared<CAnimation>("ADAG");
+	heroMoveArrows->preload();
+
+	loadHeroAnims();
 }
 
 void Graphics::loadHeroAnims()

+ 18 - 15
client/Graphics.h

@@ -38,20 +38,30 @@ class Graphics
 {
 	void addImageListEntry(size_t index, std::string listName, std::string imageName);
 
+	void initializeBattleGraphics();
+	void loadPaletteAndColors();
+	void loadHeroFlags();
+	void loadHeroFlagsDetail(std::pair<std::vector<CDefEssential *> Graphics::*, std::vector<const char *> > &pr, bool mode);
+	void loadHeroAnims();
+	CDefEssential *  loadHeroAnim(const std::string &name, const std::vector<std::pair<int,int> > &rotations);
+	void loadErmuToPicture();
+
+	void loadFonts();
+	void initializeImageLists();
+
 public:
 	//Fonts
 	static const int FONTS_NUMBER = 9;
 	IFont * fonts[FONTS_NUMBER];
-	
+
 	//various graphics
 	SDL_Color * playerColors; //array [8]
 	SDL_Color * neutralColor;
 	SDL_Color * playerColorPalette; //palette to make interface colors good - array of size [256]
-	SDL_Color * neutralColorPalette; 
+	SDL_Color * neutralColorPalette;
 
 	std::vector<CDefEssential *> flags1, flags2, flags3, flags4; //flags blitted on heroes when ,
-	CDefEssential * resources32; //resources 32x32
-	CDefEssential * heroMoveArrows;
+	std::shared_ptr<CAnimation> heroMoveArrows;
 	std::map<std::string, CDefEssential *> heroAnims; // [hero class def name]  //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
 	std::vector<CDefEssential *> boatAnims; // [boat type: 0 - 3]  //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
 	CDefHandler * FoWfullHide; //for Fog of War
@@ -68,18 +78,11 @@ public:
 	std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type
 	std::map< int, std::vector < std::string > > battleACToDef; //maps AC format to vector of appropriate def names
 	//functions
-	Graphics();	
-	void initializeBattleGraphics();
-	void loadPaletteAndColors();
-	void loadHeroFlags();
-	void loadHeroFlagsDetail(std::pair<std::vector<CDefEssential *> Graphics::*, std::vector<const char *> > &pr, bool mode);
-	void loadHeroAnims();
-	CDefEssential *  loadHeroAnim(const std::string &name, const std::vector<std::pair<int,int> > &rotations);
-	void loadErmuToPicture();
-	void blueToPlayersAdv(SDL_Surface * sur, PlayerColor player); //replaces blue interface colour with a color of player
+	Graphics();
 
-	void loadFonts();
-	void initializeImageLists();
+	void load();
+
+	void blueToPlayersAdv(SDL_Surface * sur, PlayerColor player); //replaces blue interface colour with a color of player
 };
 
 extern Graphics * graphics;

+ 34 - 8
client/gui/CAnimation.cpp

@@ -127,8 +127,8 @@ CDefFile::CDefFile(std::string Name):
 	static SDL_Color H3Palette[8] =
 	{
 		{   0,   0,   0,   0},// 100% - transparency
-		{   0,   0,   0,  64},//  75% - shadow border,
-		{   0,   0,   0, 128},// TODO: find exact value
+		{   0,   0,   0,  32},//  75% - shadow border,
+		{   0,   0,   0,  64},// TODO: find exact value
 		{   0,   0,   0, 128},// TODO: for transparency
 		{   0,   0,   0, 128},//  50% - shadow body
 		{   0,   0,   0,   0},// 100% - selection highlight
@@ -269,7 +269,7 @@ void CDefFile::loadFrame(size_t frame, size_t group, ImageLoader &loader) const
 
 					if (code==7)//Raw data
 					{
-						loader.Load(length, FDef[currentOffset]);
+						loader.Load(length, FDef + currentOffset);
 						currentOffset += length;
 					}
 					else//RLE
@@ -631,10 +631,11 @@ SDLImage::SDLImage(std::string filename, bool compressed):
 	}
 }
 
-void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 rotation) const
+void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 alpha) const
 {
 	if (!surf)
 		return;
+
 	Rect sourceRect(margins.x, margins.y, surf->w, surf->h);
 	//TODO: rotation and scaling
 	if (src)
@@ -644,7 +645,21 @@ void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 rotat
 	Rect destRect(posX, posY, surf->w, surf->h);
 	destRect += sourceRect.topLeft();
 	sourceRect -= margins;
-	CSDL_Ext::blitSurface(surf, &sourceRect, where, &destRect);
+
+	if(surf->format->BitsPerPixel == 8)
+	{
+		CSDL_Ext::blit8bppAlphaTo24bpp(surf, &sourceRect, where, &destRect);
+	}
+	else if(surf->format->Amask == 0)
+	{
+		SDL_BlitSurface(surf, &sourceRect, where, &destRect);
+	}
+	else
+	{
+		SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_BLEND);
+		SDL_BlitSurface(surf, &sourceRect, where, &destRect);
+		SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE);
+	}
 }
 
 void SDLImage::playerColored(PlayerColor player)
@@ -1056,7 +1071,8 @@ void CAnimation::printError(size_t frame, size_t group, std::string type) const
 
 CAnimation::CAnimation(std::string Name, bool Compressed):
 	name(Name),
-	compressed(Compressed)
+	compressed(Compressed),
+	preloaded(false)
 {
 	size_t dotPos = name.find_last_of('.');
 	if ( dotPos!=-1 )
@@ -1069,14 +1085,18 @@ CAnimation::CAnimation(std::string Name, bool Compressed):
 
 CAnimation::CAnimation():
 	name(""),
-	compressed(false)
+	compressed(false),
+	preloaded(false)
 {
 	init(nullptr);
 }
 
 CAnimation::~CAnimation()
 {
-	if (!images.empty())
+	if(preloaded)
+		unload();
+
+	if(!images.empty())
 	{
 		logGlobal->warnStream()<<"Warning: not all frames were unloaded from "<<name;
 		for (auto & elem : images)
@@ -1126,6 +1146,12 @@ void CAnimation::unload()
 
 }
 
+void CAnimation::preload()
+{
+	preloaded = true;
+	load();
+}
+
 void CAnimation::loadGroup(size_t group)
 {
 	CDefFile * file = getFile();

+ 4 - 0
client/gui/CAnimation.h

@@ -99,6 +99,7 @@ public:
 	~SDLImage();
 
 	void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=nullptr,  ui8 alpha=255) const override;
+
 	void playerColored(PlayerColor player) override;
 	int width() const override;
 	int height() const override;
@@ -169,6 +170,8 @@ private:
 	//if true all frames will be stored in compressed (RLE) state
 	const bool compressed;
 
+	bool preloaded;
+
 	//loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
 	bool loadFrame(CDefFile * file, size_t frame, size_t group);
 
@@ -204,6 +207,7 @@ public:
 	//all available frames
 	void load  ();
 	void unload();
+	void preload();
 
 	//all frames from group
 	void loadGroup  (size_t group);

+ 18 - 18
client/mapHandler.cpp

@@ -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);
 		}
 	}
 }
@@ -778,8 +778,8 @@ void CMapHandler::CMapPuzzleViewBlitter::drawObjects(SDL_Surface * targetSurf, c
 	// grail X mark
 	if(pos.x == info->grailPos.x && pos.y == info->grailPos.y)
 	{
-		Rect destRect(realTileRect);
-		CSDL_Ext::blit8bppAlphaTo24bpp(graphics->heroMoveArrows->ourImages[0].bitmap, nullptr, targetSurf, &destRect);
+		const IImage * mark = graphics->heroMoveArrows->getImage(0);
+		mark->draw(targetSurf,realTileRect.x,realTileRect.y);
 	}
 }
 

+ 17 - 15
client/mapHandler.h

@@ -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;
 

+ 15 - 21
client/widgets/AdventureMapClasses.cpp

@@ -17,6 +17,8 @@
 #include "../gui/CGuiHandler.h"
 #include "../gui/SDL_Pixels.h"
 
+#include "../widgets/Images.h"
+
 #include "../windows/InfoWindows.h"
 #include "../windows/CAdvmapInterface.h"
 #include "../windows/GUIClasses.h"
@@ -1256,11 +1258,11 @@ void CAdvMapPanel::addChildToPanel(CIntObject * obj, ui8 actions /* = 0 */)
 	addChild(obj, false);
 }
 
-CAdvMapWorldViewPanel::CAdvMapWorldViewPanel(SDL_Surface * bg, Point position, int spaceBottom, const PlayerColor &color)
-	: CAdvMapPanel(bg, position)	  
+CAdvMapWorldViewPanel::CAdvMapWorldViewPanel(std::shared_ptr<CAnimation> _icons, SDL_Surface * bg, Point position, int spaceBottom, const PlayerColor &color)
+	: CAdvMapPanel(bg, position), icons(_icons)
 {
 	fillerHeight = bg ? spaceBottom - pos.y - pos.h : 0;
-	
+
 	if (fillerHeight > 0)
 	{
 		tmpBackgroundFiller = CMessage::drawDialogBox(pos.w, fillerHeight, color);
@@ -1275,23 +1277,16 @@ CAdvMapWorldViewPanel::~CAdvMapWorldViewPanel()
 		SDL_FreeSurface(tmpBackgroundFiller);
 }
 
-void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor &color, const CDefHandler *def, int indexOffset)
+void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor &color, int indexOffset)
 {
-	for (auto &pic : currentIcons)
-	{
-		removeChild(pic);
-		delete pic;
-	}
-	currentIcons.clear();
+	assert(iconsData.size() == currentIcons.size());
 
-	for (auto &data : iconsData)
+	for(size_t idx = 0; idx < iconsData.size(); idx++)
 	{
-		auto pic = new CPicture(def->ourImages[data.first + indexOffset].bitmap, data.second.x, data.second.y, false);
-		pic->recActions |= SHOWALL;
-		currentIcons.push_back(pic);
-		addChildToPanel(pic);
+		const auto & data = iconsData.at(idx);
+		currentIcons[idx]->setFrame(data.first + indexOffset);
 	}
-	
+
 	if (fillerHeight > 0)
 	{
 		if (tmpBackgroundFiller)
@@ -1300,18 +1295,17 @@ void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor &color, const CDefHan
 	}
 }
 
-void CAdvMapWorldViewPanel::addChildIcon(std::pair<int, Point> data, const CDefHandler *def, int indexOffset)
+void CAdvMapWorldViewPanel::addChildIcon(std::pair<int, Point> data, int indexOffset)
 {
+	OBJ_CONSTRUCTION_CAPTURING_ALL;
 	iconsData.push_back(data);
-	auto pic = new CPicture(def->ourImages[data.first + indexOffset].bitmap, data.second.x, data.second.y, false);
-	currentIcons.push_back(pic);
-	addChildToPanel(pic);
+	currentIcons.push_back(new CAnimImage(icons, data.first + indexOffset, 0, data.second.x, data.second.y));
 }
 
 void CAdvMapWorldViewPanel::showAll(SDL_Surface * to)
 {
 	if (tmpBackgroundFiller)
-	{		
+	{
 		blitAt(tmpBackgroundFiller, pos.x, pos.y + pos.h, to);
 	}
 

+ 7 - 4
client/widgets/AdventureMapClasses.h

@@ -4,6 +4,8 @@
 #include "../../lib/FunctionList.h"
 
 class CArmedInstance;
+class CAnimation;
+class CAnimImage;
 class CShowableAnim;
 class CGGarrison;
 class CGObjectInstance;
@@ -340,17 +342,18 @@ class CAdvMapWorldViewPanel : public CAdvMapPanel
 	/// data that allows reconstruction of panel info icons
 	std::vector<std::pair<int, Point>> iconsData;
 	/// ptrs to child-pictures constructed from iconsData
-	std::vector<CPicture *> currentIcons;
+	std::vector<CAnimImage *> currentIcons;
 	/// temporary surface drawn below world view panel on higher resolutions (won't be needed when world view panel is configured for extraResolutions mod)
 	SDL_Surface * tmpBackgroundFiller;
 	int fillerHeight;
+	std::shared_ptr<CAnimation> icons;
 public:
-	CAdvMapWorldViewPanel(SDL_Surface * bg, Point position, int spaceBottom, const PlayerColor &color);
+	CAdvMapWorldViewPanel(std::shared_ptr<CAnimation> _icons, SDL_Surface * bg, Point position, int spaceBottom, const PlayerColor &color);
 	virtual ~CAdvMapWorldViewPanel();
 
-	void addChildIcon(std::pair<int, Point> data, const CDefHandler *def, int indexOffset);
+	void addChildIcon(std::pair<int, Point> data, int indexOffset);
 	/// recreates all pictures from given def to recolor them according to current player color
-	void recolorIcons(const PlayerColor &color, const CDefHandler *def, int indexOffset);
+	void recolorIcons(const PlayerColor &color, int indexOffset);
 	void showAll(SDL_Surface * to) override;
 };
 

+ 37 - 47
client/windows/CAdvmapInterface.cpp

@@ -227,13 +227,14 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to)
 			pn+=25;
 		if (pn>=0)
 		{
-			CDefEssential * arrows = graphics->heroMoveArrows;
+			const IImage * arrow = graphics->heroMoveArrows->getImage(pn);
+
 			int x = 32*(curPos.x-adventureInt->position.x)+CGI->mh->offsetX + pos.x,
 				y = 32*(curPos.y-adventureInt->position.y)+CGI->mh->offsetY + pos.y;
 			if (x< -32 || y< -32 || 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);
+			int hvx = (x + arrow->width())  - (pos.x + pos.w),
+				hvy = (y + arrow->height()) - (pos.y + pos.h);
 
 			SDL_Rect prevClip;
 			SDL_GetClipRect(to, &prevClip);
@@ -243,52 +244,44 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to)
 			{
 				if (hvx<0 && hvy<0)
 				{
-					Rect dstRect = genRect(32, 32, x + moveX, y + moveY);
-					CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, nullptr, to, &dstRect);
+					arrow->draw(to, x + moveX, y + moveY);
 				}
 				else if(hvx<0)
 				{
-					Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0);
-					Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x + moveX, y + moveY);
-					CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
+					Rect srcRect = genRect(arrow->height() - hvy, arrow->width(), 0, 0);
+					arrow->draw(to, x + moveX, y + moveY, &srcRect);
 				}
 				else if (hvy<0)
 				{
-					Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0);
-					Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY);
-					CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
+					Rect srcRect = genRect(arrow->height(), arrow->width() - hvx, 0, 0);
+					arrow->draw(to, x + moveX, y + moveY, &srcRect);
 				}
 				else
 				{
-					Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0);
-					Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY);
-					CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
+					Rect srcRect = genRect(arrow->height() - hvy, arrow->width() - hvx, 0, 0);
+					arrow->draw(to, x + moveX, y + moveY, &srcRect);
 				}
 			}
 			else //standard version
 			{
 				if (hvx<0 && hvy<0)
 				{
-					Rect dstRect = genRect(32, 32, x, y);
-					CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, nullptr, to, &dstRect);
+					arrow->draw(to, x, y);
 				}
 				else if(hvx<0)
 				{
-					Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0);
-					Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x, y);
-					CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
+					Rect srcRect = genRect(arrow->height() - hvy, arrow->width(), 0, 0);
+					arrow->draw(to, x, y, &srcRect);
 				}
 				else if (hvy<0)
 				{
-					Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0);
-					Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x, y);
-					CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
+					Rect srcRect = genRect(arrow->height(), arrow->width() - hvx, 0, 0);
+					arrow->draw(to, x, y, &srcRect);
 				}
 				else
 				{
-					Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0);
-					Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x, y);
-					CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
+					Rect srcRect = genRect(arrow->height() - hvy, arrow->width() - hvx, 0, 0);
+					arrow->draw(to, x, y, &srcRect);
 				}
 			}
 			SDL_SetClipRect(to, &prevClip);
@@ -321,9 +314,6 @@ void CTerrainRect::show(SDL_Surface * to)
 			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)
@@ -331,7 +321,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);
@@ -501,11 +491,14 @@ 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)
 	{
-		gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[g]));
+		gems.push_back(new CAnimImage(ADVOPT.gemG[g], 0, 0, ADVOPT.gemX[g], ADVOPT.gemY[g]));
 	}
 
 	auto makeButton = [&] (int textID, std::function<void()> callback, config::ButtonInfo info, int key) -> CButton *
@@ -531,7 +524,7 @@ CAdvMapInt::CAdvMapInt():
 
 	panelMain = new CAdvMapPanel(nullptr, Point(0, 0));
 	// TODO correct drawing position
-	panelWorldView = new CAdvMapWorldViewPanel(bgWorldView, Point(heroList.pos.x - 2, 195), panelSpaceBottom, LOCPLINT->playerID);
+	panelWorldView = new CAdvMapWorldViewPanel(worldViewIcons, bgWorldView, Point(heroList.pos.x - 2, 195), panelSpaceBottom, LOCPLINT->playerID);
 
 	panelMain->addChildColorableButton(kingOverview);
 	panelMain->addChildColorableButton(underground);
@@ -600,16 +593,17 @@ CAdvMapInt::CAdvMapInt():
 
 	int iconColorMultiplier = player.getNum() * 19;
 	int wvLeft = heroList.pos.x - 2; // TODO correct drawing position
+	//int wvTop = 195;
 	for (int i = 0; i < 5; ++i)
 	{
-		panelWorldView->addChildIcon(std::pair<int, Point>(i, Point(wvLeft + 5, 253 + i * 20)), worldViewIconsDef, iconColorMultiplier);
+		panelWorldView->addChildIcon(std::pair<int, Point>(i, Point(5, 58 + i * 20)), iconColorMultiplier);
 		panelWorldView->addChildToPanel(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)
 	{
-		panelWorldView->addChildIcon(std::pair<int, Point>(i +  5, Point(wvLeft +   5, 377 + i * 20)), worldViewIconsDef, iconColorMultiplier);
-		panelWorldView->addChildIcon(std::pair<int, Point>(i + 12, Point(wvLeft + 160, 377 + i * 20)), worldViewIconsDef, iconColorMultiplier);
+		panelWorldView->addChildIcon(std::pair<int, Point>(i +  5, Point(5, 182 + i * 20)), iconColorMultiplier);
+		panelWorldView->addChildIcon(std::pair<int, Point>(i + 12, Point(160, 182 + i * 20)), iconColorMultiplier);
 		panelWorldView->addChildToPanel(new CLabel(wvLeft + 45, 387 + i * 20, EFonts::FONT_SMALL, EAlignment::TOPLEFT,
 												Colors::WHITE, CGI->generaltexth->allTexts[619 + i]));
 	}
@@ -633,10 +627,7 @@ CAdvMapInt::~CAdvMapInt()
 {
 	SDL_FreeSurface(bg);
 
-	for(int i=0; i<gems.size(); i++)
-		delete gems[i];
-
-	delete worldViewIconsDef;
+	worldViewIcons->unload();
 }
 
 void CAdvMapInt::fshowOverview()
@@ -983,6 +974,8 @@ void CAdvMapInt::show(SDL_Surface * to)
 			scrollingState = false;
 		}
 	}
+	for(int i = 0; i < 4; i++)
+		gems[i]->setFrame(LOCPLINT->playerID.getNum());
 	if(updateScreen)
 	{
 		int3 betterPos = LOCPLINT->repairScreenPos(position);
@@ -993,16 +986,16 @@ void CAdvMapInt::show(SDL_Surface * to)
 		}
 
 		terrain.show(to);
-		for(int i=0;i<4;i++)
-			blitAt(gems[i]->ourImages[LOCPLINT->playerID.getNum()].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i],to);
+		for(int i = 0; i < 4; i++)
+			gems[i]->showAll(to);
 		updateScreen=false;
 		LOCPLINT->cingconsole->show(to);
 	}
 	else if (terrain.needsAnimUpdate())
 	{
 		terrain.showAnim(to);
-		for(int i=0;i<4;i++)
-			blitAt(gems[i]->ourImages[LOCPLINT->playerID.getNum()].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i],to);
+		for(int i = 0; i < 4; i++)
+			gems[i]->showAll(to);
 	}
 
 	infoBar.show(to);
@@ -1378,11 +1371,8 @@ void CAdvMapInt::setPlayer(PlayerColor Player)
 
 	panelMain->setPlayerColor(player);
 	panelWorldView->setPlayerColor(player);
-	panelWorldView->recolorIcons(player, worldViewIconsDef, player.getNum() * 19);
+	panelWorldView->recolorIcons(player, player.getNum() * 19);
 	graphics->blueToPlayersAdv(resdatabar.bg,player);
-
-	//heroList.updateHList();
-	//townList.genList();
 }
 
 void CAdvMapInt::startTurn()

+ 10 - 11
client/windows/CAdvmapInterface.h

@@ -8,7 +8,6 @@
 
 #include "../../lib/spells/ViewSpellInt.h"
 
-class CDefHandler;
 class CCallback;
 struct CGPath;
 class CAdvMapInt;
@@ -131,25 +130,25 @@ public:
 
 	EAdvMapMode mode;
 	float worldViewScale;
-	
+
 	struct WorldViewOptions
 	{
 		bool showAllTerrain; //for expert viewEarth
-		
+
 		std::vector<ObjectPosInfo> iconPositions;
-		
+
 		WorldViewOptions();
-		
+
 		void clear();
-		
-		void adjustDrawingInfo(MapDrawingInfo & info);		
+
+		void adjustDrawingInfo(MapDrawingInfo & info);
 	};
-	
-	WorldViewOptions worldViewOptions; 	
+
+	WorldViewOptions worldViewOptions;
 
 	SDL_Surface * bg;
 	SDL_Surface * bgWorldView;
-	std::vector<CDefHandler *> gems;
+	std::vector<CAnimImage *> gems;
 	CMinimap minimap;
 	CGStatusBar statusbar;
 
@@ -176,7 +175,7 @@ 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
+	std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
 
 	const CSpell *spellBeingCasted; //nullptr if none