Add support for translatable sprites

Language folders can now have a graphics folder, with these files:
- sprites.png and flipsprites.png: spritesheets which contain
  translated versions of the word enemies and checkpoints
- spritesmask.xml: an XML file containing all the sprites that should
  be copied from the translated sprites and flipsprites images to
  the original sprites/flipsprites.

This means that the translated spritesheets don't have to contain ALL
sprites - they only have to contain the translated ones. When loading
them, the game assembles a combined spritesheet with translated sprites
replacing English ones as needed, and this sheet is used to visually
substitute the normal sprites at rendering time.

It's important to note that even if 32x32 enemies have pixel-perfect
hitboxes, this is only a visual change. This has been discussed several
times on Discord - basically we don't want to give people unfair
advantages or disadvantages because of their language setting, or
change existing gameplay and speedruns tactics, which may depend on the
exact pixel arrangements of the enemies. Therefore, the hitboxes are
still based on the English sprites. This should be basically
unnoticeable for casual players, especially with some thought from
translators and artists, but there will be an option in the speedrunner
menu to display the original sprites all the time.

I removed the `VVV_freefunc(SDL_FreeSurface, *tilesheet)` in
make_array() in Graphics.cpp, which frees grphx.im_sprites_surf and
grphx.im_flipsprites_surf. Since GraphicsResources::destroy() already
frees these, it looks like the only purpose the one in make_array()
serves is to do it earlier. But now we need them again later (when
switching languages) so let's just not free them early.
This commit is contained in:
Dav999
2023-09-27 03:53:36 +02:00
committed by Misa Elizabeth Kai
parent 8ef000554d
commit 9045e26d3e
6 changed files with 209 additions and 2 deletions

View File

@@ -503,23 +503,82 @@ int Graphics::clear(void)
return clear(0, 0, 0, 255);
}
bool Graphics::substitute(SDL_Texture** texture)
{
/* Either keep the given texture the same and return false,
* or substitute it for a translation and return true. */
if (loc::english_sprites)
{
return false;
}
SDL_Texture* subst = NULL;
if (*texture == grphx.im_sprites)
{
subst = grphx.im_sprites_translated;
}
else if (*texture == grphx.im_flipsprites)
{
subst = grphx.im_flipsprites_translated;
}
if (subst == NULL)
{
return false;
}
// Apply the same colors as on the original
Uint8 r, g, b, a;
SDL_GetTextureColorMod(*texture, &r, &g, &b);
SDL_GetTextureAlphaMod(*texture, &a);
set_texture_color_mod(subst, r, g, b);
set_texture_alpha_mod(subst, a);
*texture = subst;
return true;
}
void Graphics::post_substitute(SDL_Texture* subst)
{
set_texture_color_mod(subst, 255, 255, 255);
set_texture_alpha_mod(subst, 255);
}
int Graphics::copy_texture(SDL_Texture* texture, const SDL_Rect* src, const SDL_Rect* dest)
{
bool is_substituted = substitute(&texture);
const int result = SDL_RenderCopy(gameScreen.m_renderer, texture, src, dest);
if (result != 0)
{
WHINE_ONCE_ARGS(("Could not copy texture: %s", SDL_GetError()));
}
if (is_substituted)
{
post_substitute(texture);
}
return result;
}
int Graphics::copy_texture(SDL_Texture* texture, const SDL_Rect* src, const SDL_Rect* dest, const double angle, const SDL_Point* center, const SDL_RendererFlip flip)
{
bool is_substituted = substitute(&texture);
const int result = SDL_RenderCopyEx(gameScreen.m_renderer, texture, src, dest, angle, center, flip);
if (result != 0)
{
WHINE_ONCE_ARGS(("Could not copy texture: %s", SDL_GetError()));
}
if (is_substituted)
{
post_substitute(texture);
}
return result;
}
@@ -3423,8 +3482,6 @@ static void make_array(
vector.push_back(temp);
}
}
VVV_freefunc(SDL_FreeSurface, *tilesheet);
}
bool Graphics::reloadresources(void)