From df34a2cc969bc9afe3ecde88d97223b52519ddb1 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sun, 3 Sep 2017 23:38:15 +0300 Subject: [PATCH 1/3] Dirty hackfix for https://bugs.vcmi.eu/view.php?id=2780 --- client/gui/CAnimation.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/client/gui/CAnimation.cpp b/client/gui/CAnimation.cpp index 37563b7ac..301978061 100644 --- a/client/gui/CAnimation.cpp +++ b/client/gui/CAnimation.cpp @@ -253,10 +253,26 @@ static CFileCache animationCache; * DefFile, class used for def loading * *************************************************************************/ +bool operator== (const SDL_Color & lhs, const SDL_Color & rhs) +{ + return (lhs.a == rhs.a) && (lhs.b == rhs.b) &&(lhs.g == rhs.g) &&(lhs.r == rhs.r); +} + CDefFile::CDefFile(std::string Name): data(nullptr), palette(nullptr) { + static SDL_Color H3_ORIG_PALETTE[8] = + { + { 0, 255, 255, SDL_ALPHA_OPAQUE}, + {255, 150, 255, SDL_ALPHA_OPAQUE}, + {255, 100, 255, SDL_ALPHA_OPAQUE}, + {255, 50, 255, SDL_ALPHA_OPAQUE}, + {255, 0, 255, SDL_ALPHA_OPAQUE}, + {255, 255, 0, SDL_ALPHA_OPAQUE}, + {180, 0, 255, SDL_ALPHA_OPAQUE}, + { 0, 255, 0, SDL_ALPHA_OPAQUE} + }; //First 8 colors in def palette used for transparency static SDL_Color H3Palette[8] = { @@ -292,7 +308,17 @@ CDefFile::CDefFile(std::string Name): if (type == 71 || type == 64)//Buttons/buildings don't have shadows\semi-transparency memset(palette.get(), 0, sizeof(SDL_Color)*2); else - memcpy(palette.get(), H3Palette, sizeof(SDL_Color)*8);//initialize shadow\selection colors + { + //TODO: more accurate conversion + memcpy(palette.get(), H3Palette, sizeof(SDL_Color)*2); + + for(int i = 2; i < 8; i++) + { + if(palette[i] == H3_ORIG_PALETTE[i]) + palette[i] = H3Palette[i]; + } + } + for (ui32 i=0; i Date: Mon, 4 Sep 2017 17:52:36 +0300 Subject: [PATCH 2/3] Fixed battle animation --- client/battle/CCreatureAnimation.cpp | 6 +-- client/gui/CAnimation.cpp | 76 ++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/client/battle/CCreatureAnimation.cpp b/client/battle/CCreatureAnimation.cpp index bbd94eb50..d5262aa8d 100644 --- a/client/battle/CCreatureAnimation.cpp +++ b/client/battle/CCreatureAnimation.cpp @@ -291,8 +291,8 @@ std::array CCreatureAnimation::genSpecialPalette() ret[0] = genShadow(0); ret[1] = genShadow(64); - ret[2] = genShadow(128); - ret[3] = genShadow(128); + ret[2] = genShadow(128);//unused + ret[3] = genShadow(128);//unused ret[4] = genShadow(128); ret[5] = genBorderColor(getBorderStrength(elapsedTime), border); ret[6] = addColors(genShadow(128), genBorderColor(getBorderStrength(elapsedTime), border)); @@ -412,7 +412,7 @@ inline void CCreatureAnimation::putPixelAt(SDL_Surface * dest, int X, int Y, siz template inline void CCreatureAnimation::putPixel(ui8 * dest, const SDL_Color & color, size_t index, const std::array & special) const { - if (index < 8) + if((index <= 1) || (index >=4 && index < 8)) { const SDL_Color & pal = special[index]; ColorPutter::PutColor(dest, pal.r, pal.g, pal.b, pal.a); diff --git a/client/gui/CAnimation.cpp b/client/gui/CAnimation.cpp index 301978061..6a7ab5cfb 100644 --- a/client/gui/CAnimation.cpp +++ b/client/gui/CAnimation.cpp @@ -247,6 +247,20 @@ public: } }; +enum class DefType : uint32_t +{ + SPELL = 0x40, + UNUSED_1 = 0x41, + CREATURE = 0x42, + MAP = 0x43, + MAP_HERO = 0x44, + TERRAIN = 0x45, + CURSOR = 0x46, + INTERFACE = 0x47, + UNUSED_2 = 0x48, + BATTLE_HERO = 0x49 +}; + static CFileCache animationCache; /************************************************************************* @@ -262,6 +276,8 @@ CDefFile::CDefFile(std::string Name): data(nullptr), palette(nullptr) { + + #if 0 static SDL_Color H3_ORIG_PALETTE[8] = { { 0, 255, 255, SDL_ALPHA_OPAQUE}, @@ -273,6 +289,8 @@ CDefFile::CDefFile(std::string Name): {180, 0, 255, SDL_ALPHA_OPAQUE}, { 0, 255, 0, SDL_ALPHA_OPAQUE} }; + #endif // 0 + //First 8 colors in def palette used for transparency static SDL_Color H3Palette[8] = { @@ -305,18 +323,54 @@ CDefFile::CDefFile(std::string Name): palette[i].b = data[it++]; palette[i].a = SDL_ALPHA_OPAQUE; } - if (type == 71 || type == 64)//Buttons/buildings don't have shadows\semi-transparency - memset(palette.get(), 0, sizeof(SDL_Color)*2); - else - { - //TODO: more accurate conversion - memcpy(palette.get(), H3Palette, sizeof(SDL_Color)*2); - for(int i = 2; i < 8; i++) - { - if(palette[i] == H3_ORIG_PALETTE[i]) - palette[i] = H3Palette[i]; - } + switch(static_cast(type)) + { + case DefType::SPELL: + palette[0] = H3Palette[0]; + break; + case DefType::CREATURE: + palette[0] = H3Palette[0]; + palette[1] = H3Palette[1]; + palette[4] = H3Palette[4]; + palette[5] = H3Palette[5]; + palette[6] = H3Palette[6]; + palette[7] = H3Palette[7]; + break; + case DefType::MAP: + palette[0] = H3Palette[0]; + palette[1] = H3Palette[1]; + palette[4] = H3Palette[4]; + //5 = owner flag, handled separately + break; + case DefType::MAP_HERO: + palette[0] = H3Palette[0]; + palette[1] = H3Palette[1]; + palette[4] = H3Palette[4]; + //5 = owner flag, handled separately + break; + case DefType::TERRAIN: + palette[0] = H3Palette[0]; + palette[1] = H3Palette[1]; + palette[2] = H3Palette[2]; + palette[3] = H3Palette[3]; + palette[4] = H3Palette[4]; + break; + case DefType::CURSOR: + palette[0] = H3Palette[0]; + break; + case DefType::INTERFACE: + palette[0] = H3Palette[0]; + palette[1] = H3Palette[1]; + palette[4] = H3Palette[4]; + break; + case DefType::BATTLE_HERO: + //TODO: + logAnim->error("Unimplemented def type %d in %s", type, Name); + break; + default: + logAnim->error("Unknown def type %d in %s", type, Name); + break; } From 2f7968b803753a42fb5ef1e8ad3426b51776ab1f Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Mon, 4 Sep 2017 18:41:22 +0300 Subject: [PATCH 3/3] Fixed wrong animation paths --- client/gui/CAnimation.cpp | 3 +++ lib/mapObjects/ObjectTemplate.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/client/gui/CAnimation.cpp b/client/gui/CAnimation.cpp index 6a7ab5cfb..20e921207 100644 --- a/client/gui/CAnimation.cpp +++ b/client/gui/CAnimation.cpp @@ -1468,6 +1468,9 @@ CAnimation::CAnimation(std::string Name, bool Compressed): CDefFile * file = getFile(); init(file); delete file; + + if(source.empty()) + logAnim->error("Animation %s failed to load", Name); } CAnimation::CAnimation(): diff --git a/lib/mapObjects/ObjectTemplate.cpp b/lib/mapObjects/ObjectTemplate.cpp index 114d338f9..7a554db67 100644 --- a/lib/mapObjects/ObjectTemplate.cpp +++ b/lib/mapObjects/ObjectTemplate.cpp @@ -101,6 +101,8 @@ void ObjectTemplate::afterLoadFixup() usedTiles[0][0] = VISITABLE; visitDir = 0xFF; } + boost::algorithm::replace_all(animationFile, "\\", "/"); + boost::algorithm::replace_all(editorAnimationFile, "\\", "/"); } void ObjectTemplate::readTxt(CLegacyConfigParser & parser)