1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/client/render/AssetGenerator.cpp

329 lines
13 KiB
C++
Raw Normal View History

2024-08-19 23:18:14 +02:00
/*
* AssetGenerator.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "AssetGenerator.h"
#include "../gui/CGuiHandler.h"
#include "../render/IImage.h"
#include "../render/IImageLoader.h"
#include "../render/Canvas.h"
#include "../render/ColorFilter.h"
2024-08-19 23:18:14 +02:00
#include "../render/IRenderHandler.h"
#include "../lib/filesystem/Filesystem.h"
2024-09-30 19:46:53 +02:00
#include "../lib/GameSettings.h"
#include "../lib/IGameSettings.h"
#include "../lib/json/JsonNode.h"
#include "../lib/VCMI_Lib.h"
2024-08-19 23:18:14 +02:00
2024-08-29 00:37:39 +02:00
void AssetGenerator::generateAll()
2024-08-19 23:18:14 +02:00
{
2024-08-20 21:22:40 +02:00
createBigSpellBook();
createAdventureOptionsCleanBackground();
for (int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
createPlayerColoredBackground(PlayerColor(i));
2024-09-17 23:03:30 +02:00
createCombatUnitNumberWindow();
2024-11-11 23:25:54 +02:00
createCampaignBackground();
createChroniclesCampaignImages();
2024-08-19 23:18:14 +02:00
}
2024-08-20 21:22:40 +02:00
void AssetGenerator::createAdventureOptionsCleanBackground()
2024-08-20 01:46:07 +02:00
{
std::string filename = "data/AdventureOptionsBackgroundClear.png";
2024-08-20 21:22:40 +02:00
2024-08-21 23:01:32 +02:00
if(CResourceHandler::get()->existsResource(ResourcePath(filename))) // overridden by mod, no generation
return;
2024-08-20 01:46:07 +02:00
if(!CResourceHandler::get("local")->createResource(filename))
return;
2024-08-20 21:22:40 +02:00
ResourcePath savePath(filename, EResType::IMAGE);
2024-08-20 01:46:07 +02:00
2024-09-12 16:26:05 +02:00
auto locator = ImageLocator(ImagePath::builtin("ADVOPTBK"));
locator.scalingFactor = 1;
2024-08-20 01:46:07 +02:00
2024-09-12 16:26:05 +02:00
std::shared_ptr<IImage> img = GH.renderHandler().loadImage(locator, EImageBlitMode::OPAQUE);
2024-08-20 01:46:07 +02:00
2024-08-20 21:22:40 +02:00
Canvas canvas = Canvas(Point(575, 585), CanvasScalingPolicy::IGNORE);
2024-08-20 01:46:07 +02:00
canvas.draw(img, Point(0, 0), Rect(0, 0, 575, 585));
canvas.draw(img, Point(54, 121), Rect(54, 123, 335, 1));
canvas.draw(img, Point(158, 84), Rect(156, 84, 2, 37));
canvas.draw(img, Point(234, 84), Rect(232, 84, 2, 37));
canvas.draw(img, Point(310, 84), Rect(308, 84, 2, 37));
2024-08-20 03:13:21 +02:00
canvas.draw(img, Point(53, 567), Rect(53, 520, 339, 3));
canvas.draw(img, Point(53, 520), Rect(53, 264, 339, 47));
2024-08-20 01:46:07 +02:00
std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
}
2024-08-20 01:58:02 +02:00
2024-08-20 21:22:40 +02:00
void AssetGenerator::createBigSpellBook()
2024-08-19 23:18:14 +02:00
{
std::string filename = "data/SpellBookLarge.png";
2024-08-20 21:22:40 +02:00
2024-08-21 23:01:32 +02:00
if(CResourceHandler::get()->existsResource(ResourcePath(filename))) // overridden by mod, no generation
return;
2024-08-19 23:18:14 +02:00
if(!CResourceHandler::get("local")->createResource(filename))
return;
2024-08-20 21:22:40 +02:00
ResourcePath savePath(filename, EResType::IMAGE);
2024-08-19 23:18:14 +02:00
2024-09-12 16:26:05 +02:00
auto locator = ImageLocator(ImagePath::builtin("SpelBack"));
locator.scalingFactor = 1;
2024-08-19 23:18:14 +02:00
2024-09-12 16:26:05 +02:00
std::shared_ptr<IImage> img = GH.renderHandler().loadImage(locator, EImageBlitMode::OPAQUE);
2024-08-20 21:22:40 +02:00
Canvas canvas = Canvas(Point(800, 600), CanvasScalingPolicy::IGNORE);
2024-08-19 23:18:14 +02:00
// edges
canvas.draw(img, Point(0, 0), Rect(15, 38, 90, 45));
canvas.draw(img, Point(0, 460), Rect(15, 400, 90, 141));
canvas.draw(img, Point(705, 0), Rect(509, 38, 95, 45));
canvas.draw(img, Point(705, 460), Rect(509, 400, 95, 141));
// left / right
2024-08-20 21:22:40 +02:00
Canvas tmp1 = Canvas(Point(90, 355 - 45), CanvasScalingPolicy::IGNORE);
2024-08-19 23:18:14 +02:00
tmp1.draw(img, Point(0, 0), Rect(15, 38 + 45, 90, 355 - 45));
canvas.drawScaled(tmp1, Point(0, 45), Point(90, 415));
2024-08-20 21:22:40 +02:00
Canvas tmp2 = Canvas(Point(95, 355 - 45), CanvasScalingPolicy::IGNORE);
2024-08-19 23:18:14 +02:00
tmp2.draw(img, Point(0, 0), Rect(509, 38 + 45, 95, 355 - 45));
canvas.drawScaled(tmp2, Point(705, 45), Point(95, 415));
// top / bottom
2024-08-20 21:22:40 +02:00
Canvas tmp3 = Canvas(Point(409, 45), CanvasScalingPolicy::IGNORE);
2024-08-19 23:18:14 +02:00
tmp3.draw(img, Point(0, 0), Rect(100, 38, 409, 45));
canvas.drawScaled(tmp3, Point(90, 0), Point(615, 45));
2024-08-20 21:22:40 +02:00
Canvas tmp4 = Canvas(Point(409, 141), CanvasScalingPolicy::IGNORE);
2024-08-19 23:18:14 +02:00
tmp4.draw(img, Point(0, 0), Rect(100, 400, 409, 141));
canvas.drawScaled(tmp4, Point(90, 460), Point(615, 141));
// middle
2024-08-20 21:22:40 +02:00
Canvas tmp5 = Canvas(Point(409, 141), CanvasScalingPolicy::IGNORE);
2024-08-19 23:18:14 +02:00
tmp5.draw(img, Point(0, 0), Rect(100, 38 + 45, 509 - 15, 400 - 38));
canvas.drawScaled(tmp5, Point(90, 45), Point(615, 415));
// carpet
2024-08-20 21:22:40 +02:00
Canvas tmp6 = Canvas(Point(590, 59), CanvasScalingPolicy::IGNORE);
2024-08-19 23:18:14 +02:00
tmp6.draw(img, Point(0, 0), Rect(15, 484, 590, 59));
canvas.drawScaled(tmp6, Point(0, 545), Point(800, 59));
// remove bookmarks
for (int i = 0; i < 56; i++)
canvas.draw(Canvas(canvas, Rect(i < 30 ? 268 : 327, 464, 1, 46)), Point(269 + i, 464));
for (int i = 0; i < 56; i++)
canvas.draw(Canvas(canvas, Rect(469, 464, 1, 42)), Point(470 + i, 464));
for (int i = 0; i < 57; i++)
canvas.draw(Canvas(canvas, Rect(i < 30 ? 564 : 630, 464, 1, 44)), Point(565 + i, 464));
for (int i = 0; i < 56; i++)
canvas.draw(Canvas(canvas, Rect(656, 464, 1, 47)), Point(657 + i, 464));
// draw bookmarks
canvas.draw(img, Point(278, 464), Rect(220, 405, 37, 47));
canvas.draw(img, Point(481, 465), Rect(354, 406, 37, 41));
canvas.draw(img, Point(575, 465), Rect(417, 406, 37, 45));
canvas.draw(img, Point(667, 465), Rect(478, 406, 37, 47));
2024-08-19 23:33:23 +02:00
std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
2024-08-19 23:18:14 +02:00
2024-08-19 23:33:23 +02:00
image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
2024-08-19 23:18:14 +02:00
}
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);
2024-09-30 19:46:53 +02:00
// transform to make color of brown DIBOX.PCX texture match color of specified player
2024-10-01 16:09:22 +02:00
auto filterSettings = VLC->settingsHandler->getFullConfig()["interface"]["playerColoredBackground"];
static const std::array<ColorFilter, PlayerColor::PLAYER_LIMIT_I> filters = {
2024-09-30 19:46:53 +02:00
ColorFilter::genRangeShifter( filterSettings["red" ].convertTo<std::vector<float>>() ),
ColorFilter::genRangeShifter( filterSettings["blue" ].convertTo<std::vector<float>>() ),
ColorFilter::genRangeShifter( filterSettings["tan" ].convertTo<std::vector<float>>() ),
ColorFilter::genRangeShifter( filterSettings["green" ].convertTo<std::vector<float>>() ),
ColorFilter::genRangeShifter( filterSettings["orange"].convertTo<std::vector<float>>() ),
ColorFilter::genRangeShifter( filterSettings["purple"].convertTo<std::vector<float>>() ),
ColorFilter::genRangeShifter( filterSettings["teal" ].convertTo<std::vector<float>>() ),
ColorFilter::genRangeShifter( filterSettings["pink" ].convertTo<std::vector<float>>() )
};
assert(player.isValidPlayer());
if (!player.isValidPlayer())
{
logGlobal->error("Unable to colorize to invalid player color %d!", player.getNum());
return;
}
texture->adjustPalette(filters[player.getNum()], 0);
texture->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
}
void AssetGenerator::createCombatUnitNumberWindow()
{
std::string filenameToSave = "data/combatUnitNumberWindow";
ResourcePath savePathDefault(filenameToSave + "Default.png", EResType::IMAGE);
ResourcePath savePathNeutral(filenameToSave + "Neutral.png", EResType::IMAGE);
ResourcePath savePathPositive(filenameToSave + "Positive.png", EResType::IMAGE);
ResourcePath savePathNegative(filenameToSave + "Negative.png", EResType::IMAGE);
if(CResourceHandler::get()->existsResource(savePathDefault)) // overridden by mod, no generation
return;
if(!CResourceHandler::get("local")->createResource(savePathDefault.getOriginalName() + ".png") ||
!CResourceHandler::get("local")->createResource(savePathNeutral.getOriginalName() + ".png") ||
!CResourceHandler::get("local")->createResource(savePathPositive.getOriginalName() + ".png") ||
!CResourceHandler::get("local")->createResource(savePathNegative.getOriginalName() + ".png"))
return;
auto locator = ImageLocator(ImagePath::builtin("CMNUMWIN"));
locator.scalingFactor = 1;
std::shared_ptr<IImage> texture = GH.renderHandler().loadImage(locator, EImageBlitMode::OPAQUE);
static const auto shifterNormal = ColorFilter::genRangeShifter( 0.f, 0.f, 0.f, 0.6f, 0.2f, 1.0f );
static const auto shifterPositive = ColorFilter::genRangeShifter( 0.f, 0.f, 0.f, 0.2f, 1.0f, 0.2f );
static const auto shifterNegative = ColorFilter::genRangeShifter( 0.f, 0.f, 0.f, 1.0f, 0.2f, 0.2f );
static const auto shifterNeutral = ColorFilter::genRangeShifter( 0.f, 0.f, 0.f, 1.0f, 1.0f, 0.2f );
// do not change border color
static const int32_t ignoredMask = 1 << 26;
texture->adjustPalette(shifterNormal, ignoredMask);
texture->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePathDefault));
texture->adjustPalette(shifterPositive, ignoredMask);
texture->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePathPositive));
texture->adjustPalette(shifterNegative, ignoredMask);
texture->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePathNegative));
texture->adjustPalette(shifterNeutral, ignoredMask);
texture->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePathNeutral));
}
2024-11-11 23:25:54 +02:00
void AssetGenerator::createCampaignBackground()
{
std::string filename = "data/CampaignBackground8.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("CAMPBACK"));
locator.scalingFactor = 1;
std::shared_ptr<IImage> img = GH.renderHandler().loadImage(locator, EImageBlitMode::OPAQUE);
Canvas canvas = Canvas(Point(800, 600), CanvasScalingPolicy::IGNORE);
canvas.draw(img, Point(0, 0), Rect(0, 0, 800, 600));
// left image
canvas.draw(img, Point(220, 73), Rect(290, 73, 141, 115));
canvas.draw(img, Point(37, 70), Rect(87, 70, 207, 120));
// right image
canvas.draw(img, Point(513, 67), Rect(463, 67, 71, 126));
canvas.draw(img, Point(586, 71), Rect(536, 71, 207, 117));
// middle image
canvas.draw(img, Point(306, 68), Rect(86, 68, 209, 122));
// disabled fields
canvas.draw(img, Point(40, 72), Rect(313, 74, 197, 114));
canvas.draw(img, Point(310, 72), Rect(313, 74, 197, 114));
canvas.draw(img, Point(590, 72), Rect(313, 74, 197, 114));
canvas.draw(img, Point(43, 245), Rect(313, 74, 197, 114));
canvas.draw(img, Point(313, 244), Rect(313, 74, 197, 114));
canvas.draw(img, Point(586, 246), Rect(313, 74, 197, 114));
canvas.draw(img, Point(34, 417), Rect(313, 74, 197, 114));
canvas.draw(img, Point(404, 414), Rect(313, 74, 197, 114));
// skull
auto locatorSkull = ImageLocator(ImagePath::builtin("CAMPNOSC"));
locatorSkull.scalingFactor = 1;
std::shared_ptr<IImage> imgSkull = GH.renderHandler().loadImage(locatorSkull, EImageBlitMode::OPAQUE);
canvas.draw(imgSkull, Point(562, 509), Rect(178, 108, 43, 19));
std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
}
void AssetGenerator::createChroniclesCampaignImages()
{
for(int i = 1; i < 9; i++)
{
std::string filename = "data/CampaignHc" + std::to_string(i) + "Image.png";
if(CResourceHandler::get()->existsResource(ResourcePath(filename))) // overridden by mod, no generation
continue;
auto imgPathBg = ImagePath::builtin("data/chronicles_" + std::to_string(i) + "/GamSelBk");
if(!CResourceHandler::get()->existsResource(imgPathBg)) // Chronicle episode not installed
continue;
if(!CResourceHandler::get("local")->createResource(filename))
continue;
ResourcePath savePath(filename, EResType::IMAGE);
auto locator = ImageLocator(imgPathBg);
locator.scalingFactor = 1;
std::shared_ptr<IImage> img = GH.renderHandler().loadImage(locator, EImageBlitMode::OPAQUE);
Canvas canvas = Canvas(Point(200, 116), CanvasScalingPolicy::IGNORE);
switch (i)
{
case 1:
canvas.draw(img, Point(0, 0), Rect(149, 144, 200, 116));
break;
case 2:
canvas.draw(img, Point(0, 0), Rect(156, 150, 200, 116));
break;
case 3:
canvas.draw(img, Point(0, 0), Rect(171, 153, 200, 116));
break;
case 4:
canvas.draw(img, Point(0, 0), Rect(35, 358, 200, 116));
break;
case 5:
canvas.draw(img, Point(0, 0), Rect(216, 248, 200, 116));
break;
case 6:
canvas.draw(img, Point(0, 0), Rect(58, 234, 200, 116));
break;
case 7:
canvas.draw(img, Point(0, 0), Rect(184, 219, 200, 116));
break;
case 8:
canvas.draw(img, Point(0, 0), Rect(268, 210, 200, 116));
//skull
auto locatorSkull = ImageLocator(ImagePath::builtin("CampSP1"));
locatorSkull.scalingFactor = 1;
std::shared_ptr<IImage> imgSkull = GH.renderHandler().loadImage(locatorSkull, EImageBlitMode::OPAQUE);
canvas.draw(imgSkull, Point(162, 94), Rect(162, 94, 41, 22));
canvas.draw(img, Point(162, 94), Rect(424, 304, 14, 4));
canvas.draw(img, Point(162, 98), Rect(424, 308, 10, 4));
canvas.draw(img, Point(158, 102), Rect(424, 312, 10, 4));
canvas.draw(img, Point(154, 106), Rect(424, 316, 10, 4));
break;
}
std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
}
}