Improve colouring of restricted signal posts with original TTD graphics

This commit is contained in:
Jonathan G Rennison
2023-07-08 19:12:39 +01:00
parent 0d6940e4ca
commit 126b31a744
7 changed files with 38 additions and 25 deletions

Binary file not shown.

View File

@@ -177,7 +177,10 @@ static void LoadSpriteTables()
{ {
const GraphicsSet *used_set = BaseGraphics::GetUsedSet(); const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
LoadGrfFile(used_set->files[GFT_BASE].filename, 0, PAL_DOS != used_set->palette); SpriteFile &baseset_file = LoadGrfFile(used_set->files[GFT_BASE].filename, 0, PAL_DOS != used_set->palette);
if (StrStartsWith(used_set->name, "original_")) {
baseset_file.flags |= SFF_OPENTTDGRF;
}
/* Progsignal sprites. */ /* Progsignal sprites. */
SpriteFile &progsig_file = LoadGrfFile("progsignals.grf", SPR_PROGSIGNAL_BASE, false); SpriteFile &progsig_file = LoadGrfFile("progsignals.grf", SPR_PROGSIGNAL_BASE, false);

View File

@@ -11287,8 +11287,8 @@ void LoadNewGRFFile(GRFConfig *config, GrfLoadingStage stage, Subdirectory subdi
} else { } else {
SpriteFile &file = OpenCachedSpriteFile(filename, subdir, needs_palette_remap); SpriteFile &file = OpenCachedSpriteFile(filename, subdir, needs_palette_remap);
LoadNewGRFFileFromFile(config, stage, file); LoadNewGRFFileFromFile(config, stage, file);
file.flags |= SFF_USERGRF; if (!HasBit(config->flags, GCF_SYSTEM)) file.flags |= SFF_USERGRF;
if (config->ident.grfid == BSWAP32(0xFF4F4701)) file.flags |= SFF_OGFX; if (config->ident.grfid == BSWAP32(0xFFFFFFFE)) file.flags |= SFF_OPENTTDGRF;
} }
} }

View File

@@ -3157,6 +3157,28 @@ static void GetSignalXY(TileIndex tile, uint pos, bool opposite, uint &x, uint &
y = TileY(tile) * TILE_SIZE + SignalPositions[side][pos].y; y = TileY(tile) * TILE_SIZE + SignalPositions[side][pos].y;
} }
void DrawRestrictedSignal(SignalType type, SpriteID sprite, int x, int y, int z, int dz, int bb_offset_z)
{
SpriteFile *file = GetOriginFile(sprite);
if (file != nullptr && (file->flags & SFF_OPENTTDGRF)) {
static const SubSprite lower_part = { -50, -8, 50, 50 };
static const SubSprite upper_part = { -50, -50, 50, -9 };
static const SubSprite lower_part_plain = { -50, -5, 50, 50 };
static const SubSprite upper_part_plain = { -50, -50, 50, -6 };
AddSortableSpriteToDraw(sprite, SPR_TRACERESTRICT_BASE + 2, x, y, 1, 1, dz, z, false, 0, 0, bb_offset_z, (type == SIGTYPE_NORMAL) ? &lower_part_plain : &lower_part);
AddSortableSpriteToDraw(sprite, PAL_NONE, x, y, 1, 1, dz, z, false, 0, 0, bb_offset_z, (type == SIGTYPE_NORMAL) ? &upper_part_plain : &upper_part);
} else if (type == SIGTYPE_PBS || type == SIGTYPE_PBS_ONEWAY) {
static const SubSprite lower_part = { -50, -10, 50, 50 };
static const SubSprite upper_part = { -50, -50, 50, -11 };
AddSortableSpriteToDraw(sprite, SPR_TRACERESTRICT_BASE, x, y, 1, 1, dz, z, false, 0, 0, bb_offset_z, &lower_part);
AddSortableSpriteToDraw(sprite, PAL_NONE, x, y, 1, 1, dz, z, false, 0, 0, bb_offset_z, &upper_part);
} else {
AddSortableSpriteToDraw(sprite, SPR_TRACERESTRICT_BASE + (type == SIGTYPE_NO_ENTRY ? 0 : 1), x, y, 1, 1, dz, z, false, 0, 0, bb_offset_z);
}
}
void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track track, SignalState condition, SignalOffsets image, uint pos, SignalType type, void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track track, SignalState condition, SignalOffsets image, uint pos, SignalType type,
SignalVariant variant, const TraceRestrictProgram *prog, CustomSignalSpriteContext context) SignalVariant variant, const TraceRestrictProgram *prog, CustomSignalSpriteContext context)
{ {
@@ -3242,7 +3264,7 @@ void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track track, Sign
sprite += type * 16 + variant * 64 + image * 2 + condition + (IsSignalSpritePBS(type) ? 64 : 0); sprite += type * 16 + variant * 64 + image * 2 + condition + (IsSignalSpritePBS(type) ? 64 : 0);
SpriteFile *file = GetOriginFile(sprite); SpriteFile *file = GetOriginFile(sprite);
is_custom_sprite = file != nullptr && (file->flags & SFF_USERGRF) && !(file->flags & SFF_OGFX); is_custom_sprite = (file != nullptr) && (file->flags & SFF_USERGRF);
} }
if ((_settings_client.gui.show_all_signal_default || (is_custom_sprite && show_restricted && _settings_client.gui.show_restricted_signal_default && !result.restricted_valid && variant == SIG_ELECTRIC)) && style == 0) { if ((_settings_client.gui.show_all_signal_default || (is_custom_sprite && show_restricted && _settings_client.gui.show_restricted_signal_default && !result.restricted_valid && variant == SIG_ELECTRIC)) && style == 0) {
@@ -3268,15 +3290,7 @@ void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track track, Sign
} }
if (!is_custom_sprite && show_restricted && variant == SIG_ELECTRIC) { if (!is_custom_sprite && show_restricted && variant == SIG_ELECTRIC) {
if (type == SIGTYPE_PBS || type == SIGTYPE_PBS_ONEWAY) { DrawRestrictedSignal(type, sprite, x, y, z, BB_HEIGHT_UNDER_BRIDGE, 0);
static const SubSprite lower_part = { -50, -10, 50, 50 };
static const SubSprite upper_part = { -50, -50, 50, -11 };
AddSortableSpriteToDraw(sprite, SPR_TRACERESTRICT_BASE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, z, false, 0, 0, 0, &lower_part);
AddSortableSpriteToDraw(sprite, PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, z, false, 0, 0, 0, &upper_part);
} else {
AddSortableSpriteToDraw(sprite, SPR_TRACERESTRICT_BASE + (type == SIGTYPE_NO_ENTRY ? 0 : 1), x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, z);
}
} else { } else {
AddSortableSpriteToDraw(sprite, pal, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, z); AddSortableSpriteToDraw(sprite, pal, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, z);
} }

View File

@@ -15,8 +15,8 @@
enum SpriteFileFlags : uint8 { enum SpriteFileFlags : uint8 {
SFF_NONE = 0, SFF_NONE = 0,
SFF_USERGRF = 1 << 0, SFF_USERGRF = 1 << 0,
SFF_OGFX = 1 << 1, SFF_PROGSIG = 1 << 1,
SFF_PROGSIG = 1 << 2, SFF_OPENTTDGRF = 1 << 2,
}; };
DECLARE_ENUM_AS_BIT_SET(SpriteFileFlags) DECLARE_ENUM_AS_BIT_SET(SpriteFileFlags)

View File

@@ -340,7 +340,7 @@ static const SpriteID ROUTE_STEP_SPRITE_COUNT = 4;
/* Tracerestrict sprites */ /* Tracerestrict sprites */
static const SpriteID SPR_TRACERESTRICT_BASE = SPR_ROUTE_STEP_BASE + ROUTE_STEP_SPRITE_COUNT; static const SpriteID SPR_TRACERESTRICT_BASE = SPR_ROUTE_STEP_BASE + ROUTE_STEP_SPRITE_COUNT;
static const uint16 TRACERESTRICT_SPRITE_COUNT = 2; static const uint16 TRACERESTRICT_SPRITE_COUNT = 3;
/* Misc GUI sprites */ /* Misc GUI sprites */
static const SpriteID SPR_MISC_GUI_BASE = SPR_TRACERESTRICT_BASE + TRACERESTRICT_SPRITE_COUNT; static const SpriteID SPR_MISC_GUI_BASE = SPR_TRACERESTRICT_BASE + TRACERESTRICT_SPRITE_COUNT;

View File

@@ -51,6 +51,7 @@
#include "tracerestrict.h" #include "tracerestrict.h"
#include "newgrf_roadstop.h" #include "newgrf_roadstop.h"
#include "newgrf_newsignals.h" #include "newgrf_newsignals.h"
#include "spritecache.h"
#include "table/strings.h" #include "table/strings.h"
#include "table/bridge_land.h" #include "table/bridge_land.h"
@@ -1781,6 +1782,8 @@ static void DrawTunnelBridgeRampSingleSignal(const TileInfo *ti, bool is_green,
sprite = { SPR_SIGNALS_BASE + ((type - 1) * 16 + variant * 64 + (position << 1) + is_green) + (IsSignalSpritePBS(type) ? 64 : 0), PAL_NONE }; sprite = { SPR_SIGNALS_BASE + ((type - 1) * 16 + variant * 64 + (position << 1) + is_green) + (IsSignalSpritePBS(type) ? 64 : 0), PAL_NONE };
if (_settings_client.gui.show_all_signal_default) sprite.sprite += SPR_DUP_SIGNALS_BASE - SPR_SIGNALS_BASE; if (_settings_client.gui.show_all_signal_default) sprite.sprite += SPR_DUP_SIGNALS_BASE - SPR_SIGNALS_BASE;
} }
SpriteFile *file = GetOriginFile(sprite.sprite);
is_custom_sprite = (file != nullptr) && (file->flags & SFF_USERGRF);
} }
if (is_custom_sprite && show_restricted && _settings_client.gui.show_restricted_signal_default && !result.restricted_valid && variant == SIG_ELECTRIC && style == 0) { if (is_custom_sprite && show_restricted && _settings_client.gui.show_restricted_signal_default && !result.restricted_valid && variant == SIG_ELECTRIC && style == 0) {
@@ -1791,15 +1794,8 @@ static void DrawTunnelBridgeRampSingleSignal(const TileInfo *ti, bool is_green,
} }
if (!is_custom_sprite && show_restricted && variant == SIG_ELECTRIC) { if (!is_custom_sprite && show_restricted && variant == SIG_ELECTRIC) {
if (type == SIGTYPE_PBS || type == SIGTYPE_PBS_ONEWAY) { extern void DrawRestrictedSignal(SignalType type, SpriteID sprite, int x, int y, int z, int dz, int bb_offset_z);
static const SubSprite lower_part = { -50, -10, 50, 50 }; DrawRestrictedSignal(type, sprite.sprite, x, y, z, TILE_HEIGHT, BB_Z_SEPARATOR);
static const SubSprite upper_part = { -50, -50, 50, -11 };
AddSortableSpriteToDraw(sprite.sprite, SPR_TRACERESTRICT_BASE, x, y, 1, 1, TILE_HEIGHT, z, false, 0, 0, BB_Z_SEPARATOR, &lower_part);
AddSortableSpriteToDraw(sprite.sprite, PAL_NONE, x, y, 1, 1, TILE_HEIGHT, z, false, 0, 0, BB_Z_SEPARATOR, &upper_part);
} else {
AddSortableSpriteToDraw(sprite.sprite, SPR_TRACERESTRICT_BASE + (type == SIGTYPE_NO_ENTRY ? 0 : 1), x, y, 1, 1, TILE_HEIGHT, z, false, 0, 0, BB_Z_SEPARATOR);
}
} else { } else {
AddSortableSpriteToDraw(sprite.sprite, sprite.pal, x, y, 1, 1, TILE_HEIGHT, z, false, 0, 0, BB_Z_SEPARATOR); AddSortableSpriteToDraw(sprite.sprite, sprite.pal, x, y, 1, 1, TILE_HEIGHT, z, false, 0, 0, BB_Z_SEPARATOR);
} }