From 7f0efbe00e3c100319a1633deb1d6bc9eeb8e86b Mon Sep 17 00:00:00 2001 From: Tyler Trahan Date: Wed, 2 Feb 2022 14:26:46 -0700 Subject: [PATCH] Feature: Remember the last-used signal between games (#9792) --- src/rail_gui.cpp | 9 ++++++--- src/settings_type.h | 2 ++ src/table/settings/gui_settings.ini | 8 ++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 267caee17e..7bde44483f 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -250,7 +250,7 @@ static void GenericPlaceSignals(TileIndex tile) } else { SignalVariant sigvar = _cur_year < _settings_client.gui.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC; Command::Post(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE, CcPlaySound_CONSTRUCTION_RAIL, - tile, track, SIGTYPE_PBS_ONEWAY, sigvar, false, false, _ctrl_pressed, cycle_start, SIGTYPE_LAST, 0, 0); + tile, track, _settings_client.gui.default_signal_type, sigvar, false, false, _ctrl_pressed, cycle_start, SIGTYPE_LAST, 0, 0); } } @@ -396,7 +396,7 @@ static void HandleAutoSignalPlacement() TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), track, _ctrl_pressed); } else { bool sig_gui = FindWindowById(WC_BUILD_SIGNAL, 0) != nullptr; - SignalType sigtype = sig_gui ? _cur_signal_type : SIGTYPE_PBS_ONEWAY; + SignalType sigtype = sig_gui ? _cur_signal_type : _settings_client.gui.default_signal_type; SignalVariant sigvar = sig_gui ? _cur_signal_variant : (_cur_year < _settings_client.gui.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC); Command::Post(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE, CcPlaySound_CONSTRUCTION_RAIL, TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), track, sigtype, sigvar, false, _ctrl_pressed, !_settings_client.gui.drag_signals_fixed_distance, _settings_client.gui.drag_signals_density); @@ -1793,6 +1793,9 @@ public: _cur_signal_type = (SignalType)((uint)((widget - WID_BS_SEMAPHORE_NORM) % (SIGTYPE_LAST + 1))); _cur_signal_variant = widget >= WID_BS_ELECTRIC_NORM ? SIG_ELECTRIC : SIG_SEMAPHORE; + /* Update default (last-used) signal type in config file. */ + _settings_client.gui.default_signal_type = _cur_signal_type; + /* If 'remove' button of rail build toolbar is active, disable it. */ if (_remove_button_clicked) { Window *w = FindWindowById(WC_BUILD_TOOLBAR, TRANSPORT_RAIL); @@ -2200,7 +2203,7 @@ void InitializeRailGUI() SetDefaultRailGui(); _convert_signal_button = false; - _cur_signal_type = SIGTYPE_PBS_ONEWAY; + _cur_signal_type = _settings_client.gui.default_signal_type; ResetSignalVariant(); } diff --git a/src/settings_type.h b/src/settings_type.h index 9da2655d6b..71f95142f9 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -21,6 +21,7 @@ #include "zoom_type.h" #include "openttd.h" #include "rail_gui.h" +#include "signal_type.h" /* Used to validate sizes of "max" value in settings. */ const size_t MAX_SLE_UINT8 = UINT8_MAX; @@ -146,6 +147,7 @@ struct GUISettings { bool pause_on_newgame; ///< whether to start new games paused or not SignalGUISettings signal_gui_mode; ///< select which signal types are shown in the signal GUI SignalCycleSettings cycle_signal_types; ///< Which signal types to cycle with the build signal tool. + SignalType default_signal_type; ///< The default signal type, which is set automatically by the last signal used. Not available in Settings. Year coloured_news_year; ///< when does newspaper become coloured? bool timetable_in_ticks; ///< whether to show the timetable in ticks rather than days bool quick_goto; ///< Allow quick access to 'goto button' in vehicle orders window diff --git a/src/table/settings/gui_settings.ini b/src/table/settings/gui_settings.ini index ad18f83188..27fe44dd0d 100644 --- a/src/table/settings/gui_settings.ini +++ b/src/table/settings/gui_settings.ini @@ -458,6 +458,14 @@ strval = STR_CONFIG_SETTING_SIGNAL_GUI_MODE_PATH post_cb = [](auto) { CloseWindowByClass(WC_BUILD_SIGNAL); } cat = SC_ADVANCED +[SDTC_VAR] +var = gui.default_signal_type +type = SLE_UINT8 +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC +def = 5 +min = 0 +max = 5 + [SDTC_VAR] var = gui.coloured_news_year type = SLE_INT32