Pārlūkot izejas kodu

Updated resolved some issues.

toneyisnow 5 gadi atpakaļ
vecāks
revīzija
0f4a9e5106

+ 3 - 7
client/battle/CCreatureAnimation.cpp

@@ -142,17 +142,13 @@ void CCreatureAnimation::setType(CCreatureAnim::EAnimType type)
 	play();
 }
 
-void CCreatureAnimation::shiftColor(ColorShifter * shifter)
+void CCreatureAnimation::shiftColor(const ColorShifter* shifter)
 {
-	if (forward)
-	{
+	if(forward)
 		forward->shiftColor(shifter);
-	}
 
-	if (reverse)
-	{
+	if(reverse)
 		reverse->shiftColor(shifter);
-	}
 }
 
 CCreatureAnimation::CCreatureAnimation(const std::string & name_, TSpeedController controller)

+ 1 - 1
client/battle/CCreatureAnimation.h

@@ -105,7 +105,7 @@ public:
 	void setBorderColor(SDL_Color palette);
 
 	// tint color effect
-	void shiftColor(ColorShifter* shifter);
+	void shiftColor(const ColorShifter* shifter);
 
 	float getCurrentFrame() const; // Gets the current frame ID relative to frame group.
 

+ 13 - 9
client/gui/CAnimation.cpp

@@ -104,7 +104,7 @@ public:
 	void verticalFlip() override;
 
 	void shiftPalette(int from, int howMany) override;
-	void adjustPalette(ColorShifter * shifter) override;
+	void adjustPalette(const ColorShifter * shifter) override;
 	void resetPalette() override;
 
 	void setBorderPallete(const BorderPallete & borderPallete) override;
@@ -112,7 +112,7 @@ public:
 	friend class SDLImageLoader;
 
 private:
-	SDL_Palette * originalPalette;
+	std::unique_ptr<SDL_Palette> originalPalette;
 };
 
 class SDLImageLoader
@@ -758,8 +758,12 @@ void SDLImage::verticalFlip()
 // Keep the original palette, in order to do color switching operation
 void SDLImage::savePalette()
 {
-	originalPalette = new SDL_Palette();
-	memcpy(originalPalette, surf->format->palette, sizeof(SDL_Palette));
+	// For some images that don't have palette, skip this
+	if(surf->format->palette == NULL)
+		return;
+
+	originalPalette.reset(new SDL_Palette());
+	memcpy(originalPalette.get(), surf->format->palette, sizeof(SDL_Palette));
 }
 
 void SDLImage::shiftPalette(int from, int howMany)
@@ -779,7 +783,7 @@ void SDLImage::shiftPalette(int from, int howMany)
 	}
 }
 
-void SDLImage::adjustPalette(ColorShifter * shifter)
+void SDLImage::adjustPalette(const ColorShifter * shifter)
 {
 	SDL_Palette* palette = surf->format->palette;
 	for (int i = 0; i < 255; i++)
@@ -791,7 +795,7 @@ void SDLImage::adjustPalette(ColorShifter * shifter)
 void SDLImage::resetPalette()
 {
 	SDL_Palette * pal = new SDL_Palette();
-	memcpy(pal, originalPalette, sizeof(SDL_Palette));
+	memcpy(pal, originalPalette.get(), sizeof(SDL_Palette));
 
 	// Always keept the original palette not changed, copy a new palette to assign to surface
 	SDL_SetPaletteColors(surf->format->palette, originalPalette->colors, 0, 255);
@@ -1058,11 +1062,11 @@ void CAnimation::duplicateImage(const size_t sourceGroup, const size_t sourceFra
 		load(index, targetGroup);
 }
 
-void CAnimation::shiftColor(ColorShifter * shifter)
+void CAnimation::shiftColor(const ColorShifter * shifter)
 {
-	for (auto groupIter = images.begin(); groupIter != images.end(); groupIter++)
+	for(auto groupIter = images.begin(); groupIter != images.end(); groupIter++)
 	{
-		for (auto frameIter = groupIter->second.begin(); frameIter != groupIter->second.end(); frameIter++)
+		for(auto frameIter = groupIter->second.begin(); frameIter != groupIter->second.end(); frameIter++)
 		{
 			std::shared_ptr<IImage> image = frameIter->second;
 			image->adjustPalette(shifter);

+ 2 - 2
client/gui/CAnimation.h

@@ -45,7 +45,7 @@ public:
 
 	//only indexed bitmaps, 16 colors maximum
 	virtual void shiftPalette(int from, int howMany) = 0;
-	virtual void adjustPalette(ColorShifter * shifter) = 0;
+	virtual void adjustPalette(const ColorShifter * shifter) = 0;
 	virtual void resetPalette() = 0;
 
 	//only indexed bitmaps, colors 5,6,7 must be special
@@ -102,7 +102,7 @@ public:
 	void duplicateImage(const size_t sourceGroup, const size_t sourceFrame, const size_t targetGroup);
 
 	// adjust the color of the animation, used in battle spell effects, e.g. Cloned objects
-	void shiftColor(ColorShifter* shifter);
+	void shiftColor(const ColorShifter * shifter);
 
 	//add custom surface to the selected position.
 	void setCustom(std::string filename, size_t frame, size_t group=0);

+ 13 - 10
client/gui/SDL_Extensions.h

@@ -155,18 +155,19 @@ typedef void (*BlitterWithRotationVal)(SDL_Surface *src,SDL_Rect srcRect, SDL_Su
 class ColorShifter
 {
 public:
-	virtual SDL_Color shiftColor(SDL_Color clr) = 0;
+	virtual SDL_Color shiftColor(SDL_Color clr) const = 0;
 };
 
 class ColorShifterLightBlue : public ColorShifter
 {
 public:
-	static ColorShifterLightBlue* create()
+	static ColorShifterLightBlue * create()
 	{
-		return new ColorShifterLightBlue();
+		std::unique_ptr<ColorShifterLightBlue> shifter(new ColorShifterLightBlue());
+		return shifter.get();
 	}
 
-	SDL_Color shiftColor(SDL_Color clr) override
+	SDL_Color shiftColor(SDL_Color clr) const override
 	{
 		clr.b = clr.b + (255 - clr.b) / 2;
 		return clr;
@@ -176,12 +177,13 @@ public:
 class ColorShifterDeepBlue : public ColorShifter
 {
 public:
-	static ColorShifterDeepBlue* create()
+	static ColorShifterDeepBlue * create()
 	{
-		return new ColorShifterDeepBlue();
+		std::unique_ptr<ColorShifterDeepBlue> shifter(new ColorShifterDeepBlue());
+		return shifter.get();
 	}
 
-	SDL_Color shiftColor(SDL_Color clr) override
+	SDL_Color shiftColor(SDL_Color clr) const override
 	{
 		clr.b = 255;
 		return clr;
@@ -191,12 +193,13 @@ public:
 class ColorShifterDeepRed : public ColorShifter
 {
 public:
-	static ColorShifterDeepRed* create()
+	static ColorShifterDeepRed * create()
 	{
-		return new ColorShifterDeepRed();
+		std::unique_ptr<ColorShifterDeepRed> shifter(new ColorShifterDeepRed());
+		return shifter.get();
 	}
 
-	SDL_Color shiftColor(SDL_Color clr) override
+	SDL_Color shiftColor(SDL_Color clr) const override
 	{
 		clr.r = 255;
 		return clr;