1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Implemented generation of player-colored version of DiBoxBck

This commit is contained in:
Ivan Savenko 2024-09-12 16:11:03 +00:00
parent 6f6b20b716
commit 915533ed2e
17 changed files with 98 additions and 46 deletions

View File

@ -309,9 +309,8 @@ std::shared_ptr<CIntObject> AdventureMapWidget::buildStatusBar(const JsonNode &
std::shared_ptr<CIntObject> AdventureMapWidget::buildTexturePlayerColored(const JsonNode & input)
{
logGlobal->debug("Building widget CFilledTexture");
auto image = ImagePath::fromJson(input["image"]);
Rect area = readTargetArea(input["area"]);
return std::make_shared<FilledTexturePlayerColored>(image, area);
return std::make_shared<FilledTexturePlayerColored>(area);
}
std::shared_ptr<CHeroList> AdventureMapWidget::getHeroList()

View File

@ -78,7 +78,7 @@ GlobalLobbyInviteWindow::GlobalLobbyInviteWindow()
pos.w = 236;
pos.h = 420;
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
filledBackground->setPlayerColor(PlayerColor(1));
labelTitle = std::make_shared<CLabel>(
pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.invite.header").toString()

View File

@ -40,7 +40,7 @@ GlobalLobbyLoginWindow::GlobalLobbyLoginWindow()
loginAs.appendTextID("vcmi.lobby.login.as");
loginAs.replaceRawString(CSH->getGlobalLobby().getAccountDisplayName());
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
labelTitle = std::make_shared<CLabel>( pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.login.title"));
labelUsernameTitle = std::make_shared<CLabel>( 10, 65, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->translate("vcmi.lobby.login.username"));
labelUsername = std::make_shared<CLabel>( 10, 65, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, loginAs.toString(), 265);

View File

@ -152,7 +152,7 @@ GlobalLobbyRoomWindow::GlobalLobbyRoomWindow(GlobalLobbyWindow * window, const s
subtitleText.replaceRawString(roomDescription.description);
subtitleText.replaceRawString(roomDescription.hostAccountDisplayName);
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
labelTitle = std::make_shared<CLabel>( pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.preview.title").toString());
labelSubtitle = std::make_shared<CLabel>( pos.w / 2, 40, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, subtitleText.toString(), 400);

View File

@ -34,7 +34,7 @@ GlobalLobbyServerSetup::GlobalLobbyServerSetup()
pos.w = 284;
pos.h = 340;
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
labelTitle = std::make_shared<CLabel>( pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.room.create"));
labelPlayerLimit = std::make_shared<CLabel>( pos.w / 2, 48, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.room.players.limit"));
labelRoomType = std::make_shared<CLabel>( pos.w / 2, 108, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.room.type"));

View File

@ -566,16 +566,19 @@ std::shared_ptr<CAnimImage> InterfaceObjectConfigurable::buildImage(const JsonNo
std::shared_ptr<CFilledTexture> InterfaceObjectConfigurable::buildTexture(const JsonNode & config) const
{
logGlobal->debug("Building widget CFilledTexture");
auto image = ImagePath::fromJson(config["image"]);
auto rect = readRect(config["rect"]);
auto playerColor = readPlayerColor(config["color"]);
if(playerColor.isValidPlayer())
{
auto result = std::make_shared<FilledTexturePlayerColored>(image, rect);
auto result = std::make_shared<FilledTexturePlayerColored>(rect);
result->setPlayerColor(playerColor);
return result;
}
return std::make_shared<CFilledTexture>(image, rect);
else
{
auto image = ImagePath::fromJson(config["image"]);
return std::make_shared<CFilledTexture>(image, rect);
}
}
std::shared_ptr<ComboBox> InterfaceObjectConfigurable::buildComboBox(const JsonNode & config)

View File

@ -399,7 +399,7 @@ PvPBox::PvPBox(const Rect & rect)
pos += rect.topLeft();
setRedrawParent(true);
backgroundTexture = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, rect.w, rect.h));
backgroundTexture = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, rect.w, rect.h));
backgroundTexture->setPlayerColor(PlayerColor(1));
backgroundBorder = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, rect.w, rect.h), ColorRGBA(0, 0, 0, 64), ColorRGBA(96, 96, 96, 255), 1);

View File

@ -521,7 +521,7 @@ void OptionsTab::SelectionWindow::recreate(int sliderPos)
int sliderWidth = ((amountLines > MAX_LINES) ? 16 : 0);
pos = Rect(pos.x, pos.y, x + sliderWidth, y);
backgroundTexture = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w - sliderWidth, pos.h));
backgroundTexture = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w - sliderWidth, pos.h));
backgroundTexture->setPlayerColor(PlayerColor(1));
updateShadow();
@ -803,7 +803,7 @@ OptionsTab::HandicapWindow::HandicapWindow()
pos = Rect(0, 0, 660, 100 + SEL->getStartInfo()->playerInfos.size() * 30);
backgroundTexture = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), pos);
backgroundTexture = std::make_shared<FilledTexturePlayerColored>(pos);
backgroundTexture->setPlayerColor(PlayerColor(1));
labels.push_back(std::make_shared<CLabel>(pos.w / 2 + 8, 15, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.handicap")));

View File

@ -47,7 +47,7 @@ CStatisticScreen::CStatisticScreen(const StatisticDataSet & stat)
{
OBJECT_CONSTRUCTION;
pos = center(Rect(0, 0, 800, 600));
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
filledBackground->setPlayerColor(PlayerColor(1));
contentArea = Rect(10, 40, 780, 510);
@ -225,7 +225,7 @@ StatisticSelector::StatisticSelector(const std::vector<std::string> & texts, con
{
OBJECT_CONSTRUCTION;
pos = center(Rect(0, 0, 128 + 16, std::min(static_cast<int>(texts.size()), LINES) * 40));
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
filledBackground->setPlayerColor(PlayerColor(1));
slider = std::make_shared<CSlider>(Point(pos.w - 16, 0), pos.h, [this](int to){ update(to); redraw(); }, LINES, texts.size(), 0, Orientation::VERTICAL, CSlider::BLUE);

View File

@ -14,6 +14,7 @@
#include "../render/IImage.h"
#include "../render/IImageLoader.h"
#include "../render/Canvas.h"
#include "../render/ColorFilter.h"
#include "../render/IRenderHandler.h"
#include "../lib/filesystem/Filesystem.h"
@ -22,11 +23,13 @@ void AssetGenerator::generateAll()
{
createBigSpellBook();
createAdventureOptionsCleanBackground();
for (int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
createPlayerColoredBackground(PlayerColor(i));
}
void AssetGenerator::createAdventureOptionsCleanBackground()
{
std::string filename = "data/AdventureOptionsBackgroundClear.bmp";
std::string filename = "data/AdventureOptionsBackgroundClear.png";
if(CResourceHandler::get()->existsResource(ResourcePath(filename))) // overridden by mod, no generation
return;
@ -56,7 +59,7 @@ void AssetGenerator::createAdventureOptionsCleanBackground()
void AssetGenerator::createBigSpellBook()
{
std::string filename = "data/SpellBookLarge.bmp";
std::string filename = "data/SpellBookLarge.png";
if(CResourceHandler::get()->existsResource(ResourcePath(filename))) // overridden by mod, no generation
return;
@ -116,3 +119,43 @@ void AssetGenerator::createBigSpellBook()
image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
}
void AssetGenerator::createPlayerColoredBackground(const PlayerColor & player)
{
std::string filename = "data/DialogBoxBackground_" + player.toString() + ".png";
if(CResourceHandler::get()->existsResource(ResourcePath(filename))) // overridden by mod, no generation
return;
if(!CResourceHandler::get("local")->createResource(filename))
return;
ResourcePath savePath(filename, EResType::IMAGE);
auto locator = ImageLocator(ImagePath::builtin("DiBoxBck"));
locator.scalingFactor = 1;
std::shared_ptr<IImage> texture = GH.renderHandler().loadImage(locator, EImageBlitMode::OPAQUE);
// Color transform to make color of brown DIBOX.PCX texture match color of specified player
static const std::array<ColorFilter, PlayerColor::PLAYER_LIMIT_I> filters = {
ColorFilter::genRangeShifter( 0.25, 0, 0, 1.25, 0.00, 0.00 ), // red
ColorFilter::genRangeShifter( 0, 0, 0, 0.45, 1.20, 4.50 ), // blue
ColorFilter::genRangeShifter( 0.40, 0.27, 0.23, 1.10, 1.20, 1.15 ), // tan
ColorFilter::genRangeShifter( -0.27, 0.10, -0.27, 0.70, 1.70, 0.70 ), // green
ColorFilter::genRangeShifter( 0.47, 0.17, -0.27, 1.60, 1.20, 0.70 ), // orange
ColorFilter::genRangeShifter( 0.12, -0.1, 0.25, 1.15, 1.20, 2.20 ), // purple
ColorFilter::genRangeShifter( -0.13, 0.23, 0.23, 0.90, 1.20, 2.20 ), // teal
ColorFilter::genRangeShifter( 0.44, 0.15, 0.25, 1.00, 1.00, 1.75 ) // pink
};
assert(player.isValidPlayer());
if (!player.isValidPlayer())
{
logGlobal->error("Unable to colorize to invalid player color %d!", static_cast<int>(player.getNum()));
return;
}
texture->adjustPalette(filters[player.getNum()], 0);
texture->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
}

View File

@ -9,10 +9,15 @@
*/
#pragma once
VCMI_LIB_NAMESPACE_BEGIN
class PlayerColor;
VCMI_LIB_NAMESPACE_END
class AssetGenerator
{
public:
static void generateAll();
static void createAdventureOptionsCleanBackground();
static void createBigSpellBook();
static void generateAll();
static void createAdventureOptionsCleanBackground();
static void createBigSpellBook();
static void createPlayerColoredBackground(const PlayerColor & player);
};

View File

@ -90,7 +90,7 @@ class ISharedImage
{
public:
virtual Point dimensions() const = 0;
virtual void exportBitmap(const boost::filesystem::path & path) const = 0;
virtual void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const = 0;
virtual bool isTransparent(const Point & coords) const = 0;
virtual void draw(SDL_Surface * where, SDL_Palette * palette, const Point & dest, const Rect * src, const ColorRGBA & colorMultiplier, uint8_t alpha, EImageBlitMode mode) const = 0;

View File

@ -51,7 +51,7 @@ void ImageScaled::scaleTo(const Point & size)
void ImageScaled::exportBitmap(const boost::filesystem::path &path) const
{
source->exportBitmap(path);
source->exportBitmap(path, nullptr);
}
bool ImageScaled::isTransparent(const Point &coords) const

View File

@ -22,6 +22,7 @@
#include <tbb/parallel_for.h>
#include <SDL_surface.h>
#include <SDL_image.h>
class SDLImageLoader;
@ -327,9 +328,13 @@ std::shared_ptr<ISharedImage> SDLImageShared::scaleTo(const Point & size, SDL_Pa
return ret;
}
void SDLImageShared::exportBitmap(const boost::filesystem::path& path) const
void SDLImageShared::exportBitmap(const boost::filesystem::path& path, SDL_Palette * palette) const
{
SDL_SaveBMP(surf, path.string().c_str());
if (palette && surf->format->palette)
SDL_SetSurfacePalette(surf, palette);
IMG_SavePNG(surf, path.string().c_str());
if (palette && surf->format->palette)
SDL_SetSurfacePalette(surf, originalPalette);
}
void SDLImageIndexed::playerColored(PlayerColor player)
@ -532,6 +537,11 @@ void SDLImageIndexed::draw(SDL_Surface * where, const Point & pos, const Rect *
image->draw(where, currentPalette, pos, src, Colors::WHITE_TRUE, alphaValue, blitMode);
}
void SDLImageIndexed::exportBitmap(const boost::filesystem::path & path) const
{
image->exportBitmap(path, currentPalette);
}
void SDLImageIndexed::scaleTo(const Point & size)
{
image = image->scaleTo(size, currentPalette);
@ -552,9 +562,9 @@ void SDLImageRGB::scaleInteger(int factor)
image = image->scaleInteger(factor, nullptr);
}
void SDLImageBase::exportBitmap(const boost::filesystem::path & path) const
void SDLImageRGB::exportBitmap(const boost::filesystem::path & path) const
{
image->exportBitmap(path);
image->exportBitmap(path, nullptr);
}
bool SDLImageBase::isTransparent(const Point & coords) const

View File

@ -51,7 +51,7 @@ public:
void draw(SDL_Surface * where, SDL_Palette * palette, const Point & dest, const Rect * src, const ColorRGBA & colorMultiplier, uint8_t alpha, EImageBlitMode mode) const override;
void exportBitmap(const boost::filesystem::path & path) const override;
void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const override;
Point dimensions() const override;
bool isTransparent(const Point & coords) const override;
std::shared_ptr<IImage> createImageReference(EImageBlitMode mode) override;
@ -74,7 +74,6 @@ protected:
public:
SDLImageBase(const std::shared_ptr<ISharedImage> & image, EImageBlitMode mode);
void exportBitmap(const boost::filesystem::path & path) const override;
bool isTransparent(const Point & coords) const override;
Point dimensions() const override;
void setAlpha(uint8_t value) override;
@ -103,6 +102,7 @@ public:
void adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask) override;
void scaleInteger(int factor) override;
void scaleTo(const Point & size) override;
void exportBitmap(const boost::filesystem::path & path) const override;
void setShadowEnabled(bool on) override;
void setBodyEnabled(bool on) override;
@ -121,6 +121,7 @@ public:
void adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask) override;
void scaleInteger(int factor) override;
void scaleTo(const Point & size) override;
void exportBitmap(const boost::filesystem::path & path) const override;
void setShadowEnabled(bool on) override;
void setBodyEnabled(bool on) override;

View File

@ -14,6 +14,7 @@
#include "../gui/CGuiHandler.h"
#include "../renderSDL/SDL_Extensions.h"
#include "../render/AssetGenerator.h"
#include "../render/IImage.h"
#include "../render/IRenderHandler.h"
#include "../render/CAnimation.h"
@ -172,28 +173,18 @@ void FilledTexturePlayerIndexed::setPlayerColor(PlayerColor player)
texture->playerColored(player);
}
FilledTexturePlayerColored::FilledTexturePlayerColored(Rect position)
:CFilledTexture(ImagePath::builtin("DiBoxBck"), position)
{
}
void FilledTexturePlayerColored::setPlayerColor(PlayerColor player)
{
// Color transform to make color of brown DIBOX.PCX texture match color of specified player
std::array<ColorFilter, PlayerColor::PLAYER_LIMIT_I> filters = {
ColorFilter::genRangeShifter( 0.25, 0, 0, 1.25, 0.00, 0.00 ), // red
ColorFilter::genRangeShifter( 0, 0, 0, 0.45, 1.20, 4.50 ), // blue
ColorFilter::genRangeShifter( 0.40, 0.27, 0.23, 1.10, 1.20, 1.15 ), // tan
ColorFilter::genRangeShifter( -0.27, 0.10, -0.27, 0.70, 1.70, 0.70 ), // green
ColorFilter::genRangeShifter( 0.47, 0.17, -0.27, 1.60, 1.20, 0.70 ), // orange
ColorFilter::genRangeShifter( 0.12, -0.1, 0.25, 1.15, 1.20, 2.20 ), // purple
ColorFilter::genRangeShifter( -0.13, 0.23, 0.23, 0.90, 1.20, 2.20 ), // teal
ColorFilter::genRangeShifter( 0.44, 0.15, 0.25, 1.00, 1.00, 1.75 ) // pink
};
AssetGenerator::createPlayerColoredBackground(player);
assert(player.isValidPlayer());
if (!player.isValidPlayer())
{
logGlobal->error("Unable to colorize to invalid player color %d!", static_cast<int>(player.getNum()));
return;
}
ImagePath imagePath = ImagePath::builtin("DialogBoxBackground_" + player.toString() + ".bmp");
texture->adjustPalette(filters[player.getNum()], 0);
texture = GH.renderHandler().loadImage(imagePath, EImageBlitMode::COLORKEY);
}
CAnimImage::CAnimImage(const AnimationPath & name, size_t Frame, size_t Group, int x, int y, ui8 Flags):

View File

@ -92,7 +92,7 @@ public:
class FilledTexturePlayerColored : public CFilledTexture
{
public:
using CFilledTexture::CFilledTexture;
FilledTexturePlayerColored(Rect position);
void setPlayerColor(PlayerColor player);
};