From 8edf5e0a343745b27ef90a4261be1a64e99c46ae Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 8 Dec 2015 21:40:04 +0000 Subject: [PATCH 1/2] Special case OpenGFX as a "base" set to allow recolouring signals. --- src/gfxinit.cpp | 11 +++++++++++ src/rail_cmd.cpp | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 650d607f03..4ffec72007 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -42,6 +42,7 @@ static const SpriteID * const _landscape_spriteindexes[] = { /** file index of first user-added GRF file */ int _first_user_grf_file_index; +int _opengfx_grf_file_index; /** * Load an old fashioned GRF file. @@ -228,6 +229,16 @@ static void LoadSpriteTables() LoadNewGRF(SPR_NEWGRFS_BASE, i); _first_user_grf_file_index = i + 1; + _opengfx_grf_file_index = -1; + uint index = i; + for (GRFConfig *c = master; c != NULL; c = c->next, index++) { + if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND || HasBit(c->flags, GCF_INIT_ONLY)) continue; + if (c->ident.grfid == BSWAP32(0xFF4F4701)) { + /* Detect OpenGFX GRF ID */ + _opengfx_grf_file_index = index; + break; + } + } /* Free and remove the top element. */ delete master; diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index b363da0858..46a07e641a 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1871,8 +1871,11 @@ static void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track trac sprite = (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) ? SPR_ORIGINAL_SIGNALS_BASE : SPR_SIGNALS_BASE - 16; sprite += type * 16 + variant * 64 + image * 2 + condition + (type > SIGTYPE_LAST_NOPBS ? 64 : 0); } + + uint origin_slot = GetOriginFileSlot(sprite); extern uint _first_user_grf_file_index; - if (!is_custom_sprite) is_custom_sprite = (GetOriginFileSlot(sprite) >= _first_user_grf_file_index); + extern uint _opengfx_grf_file_index; + if (!is_custom_sprite) is_custom_sprite = origin_slot != _opengfx_grf_file_index && (origin_slot >= _first_user_grf_file_index); if (!is_custom_sprite && variant == SIG_ELECTRIC && IsRestrictedSignal(tile) && GetExistingTraceRestrictProgram(tile, track) != NULL) { if (type == SIGTYPE_PBS || type == SIGTYPE_PBS_ONEWAY) { From a93714a720342891cdb439d79441b1d38a877794 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 9 Dec 2015 01:01:37 +0000 Subject: [PATCH 2/2] Add setting to show restricted electric signals using the default sprites. This is to improve visual distinctiveness of restricted signals when using signal GRFs. This defaults to off. --- src/gfxinit.cpp | 5 +++++ src/lang/english.txt | 2 ++ src/newgrf.cpp | 10 +++++++++- src/rail_cmd.cpp | 11 ++++++++++- src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings.ini | 8 ++++++++ src/table/sprites.h | 8 +++++++- 8 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 4ffec72007..afeeee7306 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -177,6 +177,11 @@ static void LoadSpriteTables() /* Tracerestrict sprites. */ LoadGrfFile("tracerestrict.grf", SPR_TRACERESTRICT_BASE, i++); + /* Fill duplicate original signal graphics sprite block */ + for (uint i = 0; i < DUP_ORIGINAL_SIGNALS_SPRITE_COUNT; i++) { + DupSprite(SPR_ORIGINAL_SIGNALS_BASE + i, SPR_DUP_ORIGINAL_SIGNALS_BASE + i); + } + /* * The second basic file always starts at the given location and does * contain a different amount of sprites depending on the "type"; DOS diff --git a/src/lang/english.txt b/src/lang/english.txt index 13b2daa5af..49c1ae4296 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1287,6 +1287,8 @@ STR_CONFIG_SETTING_POPULATION_IN_LABEL :Show town popul STR_CONFIG_SETTING_POPULATION_IN_LABEL_HELPTEXT :Display the population of towns in their label on the map STR_CONFIG_SETTING_GRAPH_LINE_THICKNESS :Thickness of lines in graphs: {STRING2} STR_CONFIG_SETTING_GRAPH_LINE_THICKNESS_HELPTEXT :Width of the line in the graphs. A thin line is more precisely readable, a thicker line is easier to see and colours are easier to distinguish +STR_CONFIG_SETTING_SHOW_RESTRICTED_SIG_DEF :Show restricted electric signals using default graphics: {STRING2} +STR_CONFIG_SETTING_SHOW_RESTRICTED_SIG_DEF_HELPTEXT :Show electric signals with routing restriction programs using the default signal graphics with a blue signal post, instead of using any NewGRF signal graphics. This is to make it easier to visually distinguish restricted signals. STR_CONFIG_SETTING_LANDSCAPE :Landscape: {STRING2} STR_CONFIG_SETTING_LANDSCAPE_HELPTEXT :Landscapes define basic gameplay scenarios with different cargos and town growth requirements. NewGRF and Game Scripts allow finer control though diff --git a/src/newgrf.cpp b/src/newgrf.cpp index c9a78deb90..3b9b03690d 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -5671,11 +5671,19 @@ static void GraphicsNew(ByteReader *buf) /* Load sprites starting from , then skip sprites. */ grfmsg(2, "GraphicsNew: Replacing sprites %d to %d of %s (type 0x%02X) at SpriteID 0x%04X", offset, offset + num - 1, action5_type->name, type, replace); - for (; num > 0; num--) { + for (uint16 n = num; n > 0; n--) { _cur.nfo_line++; LoadNextSprite(replace == 0 ? _cur.spriteid++ : replace++, _cur.file_index, _cur.nfo_line, _cur.grf_container_ver); } + if (type == 0x04 && (_cur.grffile->is_ottdfile || _cur.grfconfig->ident.grfid == BSWAP32(0xFF4F4701))) { + /* Signal graphics action 5: Fill duplicate signal sprite block if this is a baseset GRF or OpenGFX */ + const SpriteID end = offset + num; + for (SpriteID i = offset; i < end; i++) { + DupSprite(SPR_SIGNALS_BASE + i, SPR_DUP_SIGNALS_BASE + i); + } + } + if (type == 0x0D) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_5; _cur.skip_sprites = skip_num; diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 46a07e641a..fc2263d989 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1862,6 +1862,8 @@ static void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track trac SignalType type = GetSignalType(tile, track); SignalVariant variant = GetSignalVariant(tile, track); + bool show_restricted = (variant == SIG_ELECTRIC) && IsRestrictedSignal(tile) && (GetExistingTraceRestrictProgram(tile, track) != NULL); + SpriteID sprite = GetCustomSignalSprite(rti, tile, type, variant, condition); bool is_custom_sprite = (sprite != 0); if (sprite != 0) { @@ -1877,7 +1879,14 @@ static void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track trac extern uint _opengfx_grf_file_index; if (!is_custom_sprite) is_custom_sprite = origin_slot != _opengfx_grf_file_index && (origin_slot >= _first_user_grf_file_index); - if (!is_custom_sprite && variant == SIG_ELECTRIC && IsRestrictedSignal(tile) && GetExistingTraceRestrictProgram(tile, track) != NULL) { + if (is_custom_sprite && show_restricted && _settings_client.gui.show_restricted_signal_default) { + /* Use duplicate sprite block, instead of GRF-specified signals */ + sprite = (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) ? SPR_DUP_ORIGINAL_SIGNALS_BASE : SPR_DUP_SIGNALS_BASE - 16; + sprite += type * 16 + variant * 64 + image * 2 + condition + (type > SIGTYPE_LAST_NOPBS ? 64 : 0); + is_custom_sprite = false; + } + + if (!is_custom_sprite && show_restricted) { 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 }; diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 0652d1bd81..0aa2222747 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1478,6 +1478,7 @@ static SettingsContainer &GetSettingsTree() graphics->Add(new SettingEntry("gui.zoom_max")); graphics->Add(new SettingEntry("gui.smallmap_land_colour")); graphics->Add(new SettingEntry("gui.graph_line_thickness")); + graphics->Add(new SettingEntry("gui.show_restricted_signal_default")); } SettingsPage *sound = main->Add(new SettingsPage(STR_CONFIG_SETTING_SOUND)); diff --git a/src/settings_type.h b/src/settings_type.h index 41366a7719..5f6f323c08 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -135,6 +135,7 @@ struct GUISettings { uint32 last_newgrf_count; ///< the numbers of NewGRFs we found during the last scan byte missing_strings_threshold; ///< the number of missing strings before showing the warning uint8 graph_line_thickness; ///< the thickness of the lines in the various graph guis + bool show_restricted_signal_default; ///< Show restricted electric signals using the default sprite uint8 osk_activation; ///< Mouse gesture to trigger the OSK. uint16 console_backlog_timeout; ///< the minimum amount of time items should be in the console backlog before they will be removed in ~3 seconds granularity. diff --git a/src/table/settings.ini b/src/table/settings.ini index f314f21e92..6fdcf48ba8 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -3133,6 +3133,14 @@ strhelp = STR_CONFIG_SETTING_GRAPH_LINE_THICKNESS_HELPTEXT strval = STR_JUST_COMMA proc = RedrawScreen +[SDTC_BOOL] +var = gui.show_restricted_signal_default +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = false +str = STR_CONFIG_SETTING_SHOW_RESTRICTED_SIG_DEF +strhelp = STR_CONFIG_SETTING_SHOW_RESTRICTED_SIG_DEF_HELPTEXT +proc = RedrawScreen + ; For the dedicated build we'll enable dates in logs by default. [SDTC_BOOL] ifdef = DEDICATED diff --git a/src/table/sprites.h b/src/table/sprites.h index 3bd7fdffeb..801e4ca071 100644 --- a/src/table/sprites.h +++ b/src/table/sprites.h @@ -300,8 +300,14 @@ static const uint16 PALETTE_SPRITE_COUNT = 1; static const SpriteID SPR_TRACERESTRICT_BASE = SPR_PALETTE_BASE + PALETTE_SPRITE_COUNT; static const uint16 TRACERESTRICT_SPRITE_COUNT = 2; +/* Duplicated signal sprites */ +static const SpriteID SPR_DUP_ORIGINAL_SIGNALS_BASE = SPR_TRACERESTRICT_BASE + TRACERESTRICT_SPRITE_COUNT; +static const uint16 DUP_ORIGINAL_SIGNALS_SPRITE_COUNT = 16; +static const SpriteID SPR_DUP_SIGNALS_BASE = SPR_DUP_ORIGINAL_SIGNALS_BASE + DUP_ORIGINAL_SIGNALS_SPRITE_COUNT; +static const uint16 DUP_SIGNALS_SPRITE_COUNT = PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT; + /* From where can we start putting NewGRFs? */ -static const SpriteID SPR_NEWGRFS_BASE = SPR_TRACERESTRICT_BASE + TRACERESTRICT_SPRITE_COUNT; +static const SpriteID SPR_NEWGRFS_BASE = SPR_DUP_SIGNALS_BASE + DUP_SIGNALS_SPRITE_COUNT; /* Manager face sprites */ static const SpriteID SPR_GRADIENT = 874; // background gradient behind manager face