Per-pixel transparency.
This commit is contained in:
parent
a02c091376
commit
41b2f9b911
|
@ -105,6 +105,7 @@ GameNewOutfitProtocol = 49
|
||||||
GamePVPMode = 50
|
GamePVPMode = 50
|
||||||
GameWritableDate = 51
|
GameWritableDate = 51
|
||||||
GameAdditionalVipInfo = 52
|
GameAdditionalVipInfo = 52
|
||||||
|
GameSpritesAlphaChannel = 56
|
||||||
|
|
||||||
TextColors = {
|
TextColors = {
|
||||||
red = '#f55e5e', --'#c83200'
|
red = '#f55e5e', --'#c83200'
|
||||||
|
|
|
@ -387,6 +387,7 @@ namespace Otc
|
||||||
GameBaseSkillU16 = 53,
|
GameBaseSkillU16 = 53,
|
||||||
GameCreatureIcons = 54,
|
GameCreatureIcons = 54,
|
||||||
GameHideNpcNames = 55,
|
GameHideNpcNames = 55,
|
||||||
|
GameSpritesAlphaChannel = 56,
|
||||||
|
|
||||||
LastGameFeature = 101
|
LastGameFeature = 101
|
||||||
};
|
};
|
||||||
|
|
|
@ -81,6 +81,7 @@ void SpriteManager::saveSpr(std::string fileName)
|
||||||
else
|
else
|
||||||
fin->addU16(m_spritesCount);
|
fin->addU16(m_spritesCount);
|
||||||
|
|
||||||
|
bool useAlpha = g_game.getFeature(Otc::GameSpritesAlphaChannel);
|
||||||
uint32 offset = fin->tell();
|
uint32 offset = fin->tell();
|
||||||
uint32 spriteAddress = offset + 4 * m_spritesCount;
|
uint32 spriteAddress = offset + 4 * m_spritesCount;
|
||||||
for(int i = 1; i <= m_spritesCount; i++)
|
for(int i = 1; i <= m_spritesCount; i++)
|
||||||
|
@ -98,6 +99,7 @@ void SpriteManager::saveSpr(std::string fileName)
|
||||||
fin->addU8(m_spritesFile->getU8());
|
fin->addU8(m_spritesFile->getU8());
|
||||||
fin->addU8(m_spritesFile->getU8());
|
fin->addU8(m_spritesFile->getU8());
|
||||||
fin->addU8(m_spritesFile->getU8());
|
fin->addU8(m_spritesFile->getU8());
|
||||||
|
if (useAlpha) fin->addU8(m_spritesFile->getU8());
|
||||||
|
|
||||||
uint16 dataSize = m_spritesFile->getU16();
|
uint16 dataSize = m_spritesFile->getU16();
|
||||||
fin->addU16(dataSize);
|
fin->addU16(dataSize);
|
||||||
|
@ -153,6 +155,8 @@ ImagePtr SpriteManager::getSpriteImage(int id)
|
||||||
uint8 *pixels = image->getPixelData();
|
uint8 *pixels = image->getPixelData();
|
||||||
int writePos = 0;
|
int writePos = 0;
|
||||||
int read = 0;
|
int read = 0;
|
||||||
|
bool useAlpha = g_game.getFeature(Otc::GameSpritesAlphaChannel);
|
||||||
|
uint8 channels = useAlpha ? 4 : 3;
|
||||||
|
|
||||||
// decompress pixels
|
// decompress pixels
|
||||||
while(read < pixelDataSize && writePos < SPRITE_DATA_SIZE) {
|
while(read < pixelDataSize && writePos < SPRITE_DATA_SIZE) {
|
||||||
|
@ -171,11 +175,11 @@ ImagePtr SpriteManager::getSpriteImage(int id)
|
||||||
pixels[writePos + 0] = m_spritesFile->getU8();
|
pixels[writePos + 0] = m_spritesFile->getU8();
|
||||||
pixels[writePos + 1] = m_spritesFile->getU8();
|
pixels[writePos + 1] = m_spritesFile->getU8();
|
||||||
pixels[writePos + 2] = m_spritesFile->getU8();
|
pixels[writePos + 2] = m_spritesFile->getU8();
|
||||||
pixels[writePos + 3] = 0xFF;
|
pixels[writePos + 3] = useAlpha ? m_spritesFile->getU8() : 0xFF;
|
||||||
writePos += 4;
|
writePos += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
read += 4 + (3 * coloredPixels);
|
read += 4 + (channels * coloredPixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill remaining pixels with alpha
|
// fill remaining pixels with alpha
|
||||||
|
|
|
@ -110,7 +110,7 @@ void Image::blit(const Point& dest, const ImagePtr& other)
|
||||||
int y = p / other->getWidth();
|
int y = p / other->getWidth();
|
||||||
int pos = ((dest.y + y) * m_size.width() + (dest.x + x)) * 4;
|
int pos = ((dest.y + y) * m_size.width() + (dest.x + x)) * 4;
|
||||||
|
|
||||||
if(otherPixels[p*4+3] == 0xFF) {
|
if (otherPixels[p*4+3] != 0) {
|
||||||
m_pixels[pos+0] = otherPixels[p*4+0];
|
m_pixels[pos+0] = otherPixels[p*4+0];
|
||||||
m_pixels[pos+1] = otherPixels[p*4+1];
|
m_pixels[pos+1] = otherPixels[p*4+1];
|
||||||
m_pixels[pos+2] = otherPixels[p*4+2];
|
m_pixels[pos+2] = otherPixels[p*4+2];
|
||||||
|
|
Loading…
Reference in New Issue