mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Created separate classes for shared, unchangeable image and image
manipulators owned by UI elements
This commit is contained in:
@@ -135,71 +135,34 @@ Graphics::Graphics()
|
||||
//(!) do not load any CAnimation here
|
||||
}
|
||||
|
||||
void Graphics::blueToPlayersAdv(SDL_Surface * sur, PlayerColor player)
|
||||
void Graphics::setPlayerPalette(SDL_Palette * targetPalette, PlayerColor player)
|
||||
{
|
||||
if(sur->format->palette)
|
||||
SDL_Color palette[32];
|
||||
if(player.isValidPlayer())
|
||||
{
|
||||
SDL_Color palette[32];
|
||||
if(player.isValidPlayer())
|
||||
{
|
||||
for(int i=0; i<32; ++i)
|
||||
palette[i] = CSDL_Ext::toSDL(playerColorPalette[player][i]);
|
||||
}
|
||||
else if(player == PlayerColor::NEUTRAL)
|
||||
{
|
||||
for(int i=0; i<32; ++i)
|
||||
palette[i] = CSDL_Ext::toSDL(neutralColorPalette[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
logGlobal->error("Wrong player id in blueToPlayersAdv (%s)!", player.toString());
|
||||
return;
|
||||
}
|
||||
//FIXME: not all player colored images have player palette at last 32 indexes
|
||||
//NOTE: following code is much more correct but still not perfect (bugged with status bar)
|
||||
CSDL_Ext::setColors(sur, palette, 224, 32);
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
SDL_Color * bluePalette = playerColorPalette + 32;
|
||||
|
||||
SDL_Palette * oldPalette = sur->format->palette;
|
||||
|
||||
SDL_Palette * newPalette = SDL_AllocPalette(256);
|
||||
|
||||
for(size_t destIndex = 0; destIndex < 256; destIndex++)
|
||||
{
|
||||
SDL_Color old = oldPalette->colors[destIndex];
|
||||
|
||||
bool found = false;
|
||||
|
||||
for(size_t srcIndex = 0; srcIndex < 32; srcIndex++)
|
||||
{
|
||||
if(old.b == bluePalette[srcIndex].b && old.g == bluePalette[srcIndex].g && old.r == bluePalette[srcIndex].r)
|
||||
{
|
||||
found = true;
|
||||
newPalette->colors[destIndex] = palette[srcIndex];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
newPalette->colors[destIndex] = old;
|
||||
}
|
||||
|
||||
SDL_SetSurfacePalette(sur, newPalette);
|
||||
|
||||
SDL_FreePalette(newPalette);
|
||||
|
||||
#endif // 0
|
||||
for(int i=0; i<32; ++i)
|
||||
palette[i] = CSDL_Ext::toSDL(playerColorPalette[player][i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO: implement. H3 method works only for images with palettes.
|
||||
// Add some kind of player-colored overlay?
|
||||
// Or keep palette approach here and replace only colors of specific value(s)
|
||||
// Or just wait for OpenGL support?
|
||||
logGlobal->warn("Image must have palette to be player-colored!");
|
||||
for(int i=0; i<32; ++i)
|
||||
palette[i] = CSDL_Ext::toSDL(neutralColorPalette[i]);
|
||||
}
|
||||
|
||||
SDL_SetPaletteColors(targetPalette, palette, 224, 32);
|
||||
}
|
||||
|
||||
void Graphics::setPlayerFlagColor(SDL_Palette * targetPalette, PlayerColor player)
|
||||
{
|
||||
if(player.isValidPlayer())
|
||||
{
|
||||
SDL_Color color = CSDL_Ext::toSDL(playerColors[player.getNum()]);
|
||||
SDL_SetPaletteColors(targetPalette, &color, 5, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Color color = CSDL_Ext::toSDL(neutralColor);
|
||||
SDL_SetPaletteColors(targetPalette, &color, 5, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user