浏览代码

Fix fade-in animation - per-surface alpha was not set correctly

Ivan Savenko 1 年之前
父节点
当前提交
c40eea6e10
共有 4 个文件被更改,包括 6 次插入5 次删除
  1. 2 2
      client/renderSDL/SDLImage.cpp
  2. 2 2
      client/widgets/Images.cpp
  3. 1 0
      client/widgets/Images.h
  4. 1 1
      client/windows/CCastleInterface.cpp

+ 2 - 2
client/renderSDL/SDLImage.cpp

@@ -111,7 +111,7 @@ void SDLImageConst::draw(SDL_Surface * where, SDL_Palette * palette, const Point
 
 	SDL_SetSurfaceAlphaMod(surf, alpha);
 
-	if (mode != EImageBlitMode::OPAQUE && surf->format->Amask != 0)
+	if (alpha != SDL_ALPHA_OPAQUE || (mode != EImageBlitMode::OPAQUE && surf->format->Amask != 0))
 		SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_BLEND);
 	else
 		SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE);
@@ -119,7 +119,7 @@ void SDLImageConst::draw(SDL_Surface * where, SDL_Palette * palette, const Point
 	if (palette && surf->format->palette)
 		SDL_SetSurfacePalette(surf, palette);
 
-	if(surf->format->BitsPerPixel == 8 && alpha == SDL_ALPHA_OPAQUE && mode == EImageBlitMode::ALPHA)
+	if(surf->format->palette && alpha == SDL_ALPHA_OPAQUE && mode == EImageBlitMode::ALPHA)
 	{
 		CSDL_Ext::blit8bppAlphaTo24bpp(surf, sourceRect, where, destShift);
 	}

+ 2 - 2
client/widgets/Images.cpp

@@ -318,7 +318,7 @@ bool CAnimImage::isPlayerColored() const
 }
 
 CShowableAnim::CShowableAnim(int x, int y, const AnimationPath & name, ui8 Flags, ui32 frameTime, size_t Group, uint8_t alpha):
-	anim(GH.renderHandler().loadAnimation(name, EImageBlitMode::ALPHA)),
+	anim(GH.renderHandler().loadAnimation(name, (Flags & PALETTE_ALPHA) ? EImageBlitMode::ALPHA : EImageBlitMode::COLORKEY)),
 	group(Group),
 	frame(0),
 	first(0),
@@ -451,7 +451,7 @@ void CShowableAnim::setDuration(int durationMs)
 }
 
 CCreatureAnim::CCreatureAnim(int x, int y, const AnimationPath & name, ui8 flags, ECreatureAnimType type):
-	CShowableAnim(x, y, name, flags, 100, size_t(type)) // H3 uses 100 ms per frame, irregardless of battle speed settings
+	CShowableAnim(x, y, name, flags | PALETTE_ALPHA, 100, size_t(type)) // H3 uses 100 ms per frame, irregardless of battle speed settings
 {
 	xOffset = 0;
 	yOffset = 0;

+ 1 - 0
client/widgets/Images.h

@@ -146,6 +146,7 @@ public:
 		BASE=1,            //base frame will be blitted before current one
 		HORIZONTAL_FLIP=2, //TODO: will be displayed rotated
 		VERTICAL_FLIP=4,   //TODO: will be displayed rotated
+		PALETTE_ALPHA=8,   // use alpha channel for images with palette. Required for creatures in battle and map objects
 		PLAY_ONCE=32       //play animation only once and stop at last frame
 	};
 protected:

+ 1 - 1
client/windows/CCastleInterface.cpp

@@ -95,7 +95,7 @@ CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town
 	}
 
 	if(!str->borderName.empty())
-		border = GH.renderHandler().loadImage(str->borderName, EImageBlitMode::ALPHA);
+		border = GH.renderHandler().loadImage(str->borderName, EImageBlitMode::COLORKEY);
 
 	if(!str->areaName.empty())
 		area = GH.renderHandler().loadImage(str->areaName, EImageBlitMode::ALPHA);