1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Fix battle rendering

This commit is contained in:
Ivan Savenko 2023-02-21 15:44:18 +02:00
parent 11e4d84749
commit 7df5c612f7
7 changed files with 44 additions and 32 deletions

View File

@ -24,6 +24,7 @@
#include "../CPlayerInterface.h"
#include "../render/Canvas.h"
#include "../render/IImage.h"
#include "../renderSDL/SDL_Extensions.h"
#include "../gui/CGuiHandler.h"
#include "../gui/CursorHandler.h"
#include "../adventureMap/CInGameConsole.h"
@ -43,7 +44,7 @@ BattleFieldController::BattleFieldController(BattleInterface & owner):
strongInterest = true;
//preparing cells and hexes
cellBorder = IImage::createFromFile("CCELLGRD.BMP");
cellBorder = IImage::createFromFile("CCELLGRD.BMP", EImageBlitMode::COLORKEY);
cellShade = IImage::createFromFile("CCELLSHD.BMP");
if(!owner.siegeController)
@ -53,29 +54,17 @@ BattleFieldController::BattleFieldController(BattleInterface & owner):
if(bfieldType == BattleField::NONE)
logGlobal->error("Invalid battlefield returned for current battle");
else
background = IImage::createFromFile(bfieldType.getInfo()->graphics);
background = IImage::createFromFile(bfieldType.getInfo()->graphics, EImageBlitMode::OPAQUE);
}
else
{
std::string backgroundName = owner.siegeController->getBattleBackgroundName();
background = IImage::createFromFile(backgroundName);
background = IImage::createFromFile(backgroundName, EImageBlitMode::OPAQUE);
}
pos.w = background->width();
pos.h = background->height();
//preparing graphic with cell borders
cellBorders = std::make_unique<Canvas>(Point(background->width(), background->height()));
for (int i=0; i<GameConstants::BFIELD_SIZE; ++i)
{
if ( i % GameConstants::BFIELD_WIDTH == 0)
continue;
if ( i % GameConstants::BFIELD_WIDTH == GameConstants::BFIELD_WIDTH - 1)
continue;
cellBorders->draw(cellBorder, hexPositionLocal(i).topLeft());
}
backgroundWithHexes = std::make_unique<Canvas>(Point(background->width(), background->height()));
auto accessibility = owner.curInt->cb->getAccesibility();
@ -166,7 +155,17 @@ void BattleFieldController::showBackgroundImage(Canvas & canvas)
owner.siegeController->showAbsoluteObstacles(canvas);
if (settings["battle"]["cellBorders"].Bool())
canvas.draw(*cellBorders, Point(0, 0));
{
for (int i=0; i<GameConstants::BFIELD_SIZE; ++i)
{
if ( i % GameConstants::BFIELD_WIDTH == 0)
continue;
if ( i % GameConstants::BFIELD_WIDTH == GameConstants::BFIELD_WIDTH - 1)
continue;
canvas.draw(cellBorder, hexPositionLocal(i).topLeft());
}
}
}
void BattleFieldController::showBackgroundImageWithHexes(Canvas & canvas)
@ -203,7 +202,17 @@ void BattleFieldController::redrawBackgroundWithHexes()
}
if(settings["battle"]["cellBorders"].Bool())
backgroundWithHexes->draw(*cellBorders, Point(0, 0));
{
for (int i=0; i<GameConstants::BFIELD_SIZE; ++i)
{
if ( i % GameConstants::BFIELD_WIDTH == 0)
continue;
if ( i % GameConstants::BFIELD_WIDTH == GameConstants::BFIELD_WIDTH - 1)
continue;
backgroundWithHexes->draw(cellBorder, hexPositionLocal(i).topLeft());
}
}
}
void BattleFieldController::showHighlightedHex(Canvas & canvas, BattleHex hex, bool darkBorder)
@ -586,6 +595,7 @@ void BattleFieldController::show(SDL_Surface * to)
owner.obstacleController->update();
Canvas canvas(to);
CSDL_Ext::CClipRectGuard guard(to, pos);
renderBattlefield(canvas);
}

View File

@ -37,9 +37,6 @@ class BattleFieldController : public CIntObject
/// Canvas that contains background, hex grid (if enabled), absolute obstacles and movement range of active stack
std::unique_ptr<Canvas> backgroundWithHexes;
/// Canvas that contains cell borders of all tiles in the battlefield
std::unique_ptr<Canvas> cellBorders;
/// hex from which the stack would perform attack with current cursor
BattleHex attackingHex;

View File

@ -77,10 +77,10 @@ BattleStacksController::BattleStacksController(BattleInterface & owner):
animIDhelper(0)
{
//preparing graphics for displaying amounts of creatures
amountNormal = IImage::createFromFile("CMNUMWIN.BMP");
amountPositive = IImage::createFromFile("CMNUMWIN.BMP");
amountNegative = IImage::createFromFile("CMNUMWIN.BMP");
amountEffNeutral = IImage::createFromFile("CMNUMWIN.BMP");
amountNormal = IImage::createFromFile("CMNUMWIN.BMP", EImageBlitMode::COLORKEY);
amountPositive = IImage::createFromFile("CMNUMWIN.BMP", EImageBlitMode::COLORKEY);
amountNegative = IImage::createFromFile("CMNUMWIN.BMP", EImageBlitMode::COLORKEY);
amountEffNeutral = IImage::createFromFile("CMNUMWIN.BMP", EImageBlitMode::COLORKEY);
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 );

View File

@ -486,9 +486,9 @@ void MapRendererObjects::renderTile(const IMapRendererContext & context, Canvas
}
MapRendererDebug::MapRendererDebug()
: imageGrid(IImage::createFromFile("debug/grid"))
, imageBlockable(IImage::createFromFile("debug/blocked"))
, imageVisitable(IImage::createFromFile("debug/visitable"))
: imageGrid(IImage::createFromFile("debug/grid", EImageBlitMode::ALPHA))
, imageBlockable(IImage::createFromFile("debug/blocked", EImageBlitMode::ALPHA))
, imageVisitable(IImage::createFromFile("debug/visitable", EImageBlitMode::ALPHA))
{
}

View File

@ -26,7 +26,12 @@ class SDLImageLoader;
std::shared_ptr<IImage> IImage::createFromFile( const std::string & path )
{
return std::shared_ptr<IImage>(new SDLImage(path, EImageBlitMode::ALPHA));
return createFromFile(path, EImageBlitMode::ALPHA);
}
std::shared_ptr<IImage> IImage::createFromFile( const std::string & path, EImageBlitMode mode )
{
return std::shared_ptr<IImage>(new SDLImage(path, mode));
}
std::shared_ptr<IImage> IImage::createFromSurface( SDL_Surface * source )

View File

@ -84,10 +84,10 @@ CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town
}
if(!str->borderName.empty())
border = IImage::createFromFile(str->borderName);
border = IImage::createFromFile(str->borderName, EImageBlitMode::ALPHA);
if(!str->areaName.empty())
area = IImage::createFromFile(str->areaName);
area = IImage::createFromFile(str->areaName, EImageBlitMode::ALPHA);
}
const CBuilding * CBuildingRect::getBuilding()

View File

@ -87,7 +87,7 @@ void CMessage::init()
}
}
background = IImage::createFromFile("DIBOXBCK.BMP");
background = IImage::createFromFile("DIBOXBCK.BMP", EImageBlitMode::OPAQUE);
}
void CMessage::dispose()