From ff7e8fb2dde6c537da364b3602f4a2e56990c582 Mon Sep 17 00:00:00 2001 From: smatz Date: Thu, 3 Apr 2008 21:54:31 +0000 Subject: (svn r12550) -Change: the signal GUI is now persistent - has the same data when it is reopened --- src/date.cpp | 3 +++ src/misc_gui.cpp | 2 ++ src/openttd.cpp | 6 +++--- src/rail_gui.cpp | 44 +++++++++++++++++++++++++++++++++++--------- src/rail_gui.h | 1 + src/settings.cpp | 3 ++- 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/date.cpp b/src/date.cpp index f382fc416..fd9478513 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -15,6 +15,7 @@ #include "date_func.h" #include "vehicle_base.h" #include "debug.h" +#include "rail_gui.h" #ifdef DEBUG_DUMP_COMMANDS #include "saveload.h" #endif @@ -282,6 +283,8 @@ void IncreaseDate() ShipsYearlyLoop(); if (_network_server) NetworkServerYearlyLoop(); + if (_cur_year == _patches.semaphore_build_before) ResetSignalVariant(); + /* check if we reached end of the game */ if (_cur_year == _patches.ending_year) { ShowEndGameChart(); diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 04a7374d3..6b9a6bca0 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -41,6 +41,7 @@ #include "player_gui.h" #include "settings_type.h" #include "newgrf_cargo.h" +#include "rail_gui.h" #include "table/sprites.h" #include "table/strings.h" @@ -1833,6 +1834,7 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2) SetDate(ConvertYMDToDate(_cur_year + p2, ymd.month, ymd.day)); EnginesMonthlyLoop(); SetWindowDirty(FindWindowById(WC_STATUS_BAR, 0)); + ResetSignalVariant(); return _cur_year; } diff --git a/src/openttd.cpp b/src/openttd.cpp index a82636b6f..14a5f432d 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -93,7 +93,7 @@ void ResetMusic(); extern void SetDifficultyLevel(int mode, GameOptions *gm_opt); extern Player* DoStartupNewPlayer(bool is_ai); extern void ShowOSErrorBox(const char *buf); -extern void SetDefaultRailGui(); +extern void InitializeRailGUI(); /* TODO: usrerror() for errors which are not of an internal nature but * caused by the user, i.e. missing files or fatal configuration errors. @@ -702,7 +702,7 @@ static void MakeNewGameDone() DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE); SettingsDisableElrail(_patches.disable_elrails); - SetDefaultRailGui(); + InitializeRailGUI(); #ifdef ENABLE_NETWORK /* We are the server, we start a new player (not dedicated), @@ -1997,7 +1997,7 @@ bool AfterLoadGame() if (CheckSavegameVersion(38)) _patches.disable_elrails = false; /* do the same as when elrails were enabled/disabled manually just now */ SettingsDisableElrail(_patches.disable_elrails); - SetDefaultRailGui(); + InitializeRailGUI(); /* From version 53, the map array was changed for house tiles to allow * space for newhouses grf features. A new byte, m7, was also added. */ diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index ecb87bdc0..861a41f3c 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -45,9 +45,9 @@ static bool _remove_button_clicked; static DiagDirection _build_depot_direction; static byte _waypoint_count = 1; static byte _cur_waypoint_type; -static bool _convert_signal_button = false; ///< convert signal button in the signal GUI pressed -static SignalVariant _cur_signal_variant = SIG_ELECTRIC; ///< set the signal variant (for signal GUI) -static SignalType _cur_signal_type = SIGTYPE_NORMAL; ///< set the signal type (for signal GUI) +static bool _convert_signal_button; ///< convert signal button in the signal GUI pressed +static SignalVariant _cur_signal_variant; ///< set the signal variant (for signal GUI) +static SignalType _cur_signal_type; ///< set the signal type (for signal GUI) static struct { byte orientation; @@ -1385,14 +1385,9 @@ static const WindowDesc _signal_builder_desc = { /** * Open the signal selection window - * @pre reset all signal GUI relevant variables */ static void ShowSignalBuilder() { - _convert_signal_button = false; - _cur_signal_variant = _cur_year < _patches.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC; - _cur_signal_type = SIGTYPE_NORMAL; - AllocateWindowDesc(&_signal_builder_desc); } @@ -1601,7 +1596,7 @@ void ReinitGuiAfterToggleElrail(bool disable) MarkWholeScreenDirty(); } -void SetDefaultRailGui() +static void SetDefaultRailGui() { if (_local_player == PLAYER_SPECTATOR || !IsValidPlayer(_local_player)) return; @@ -1650,5 +1645,36 @@ void SetDefaultRailGui() } } +/** + * Updates the current signal variant used in the signal GUI + * to the one adequate to current year. + * @param 0 needed to be called when a patch setting changes + * @return success, needed for patch settings + */ +int32 ResetSignalVariant(int32 = 0) +{ + SignalVariant new_variant = (_cur_year < _patches.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC); + + if (new_variant != _cur_signal_variant) { + Window *w = FindWindowById(WC_BUILD_SIGNAL, 0); + if (w != NULL) { + SetWindowDirty(w); + w->RaiseWidget((_cur_signal_variant == SIG_ELECTRIC ? BSW_ELECTRIC_NORM : BSW_SEMAPHORE_NORM) + _cur_signal_type); + } + _cur_signal_variant = new_variant; + } + + return 0; +} +/** Resets the rail GUI - sets default railtype to build + * and resets the signal GUI + */ +void InitializeRailGUI() +{ + SetDefaultRailGui(); + _convert_signal_button = false; + _cur_signal_type = SIGTYPE_NORMAL; + ResetSignalVariant(); +} diff --git a/src/rail_gui.h b/src/rail_gui.h index 67d590211..baaed991e 100644 --- a/src/rail_gui.h +++ b/src/rail_gui.h @@ -9,5 +9,6 @@ void ShowBuildRailToolbar(RailType railtype, int button); void ReinitGuiAfterToggleElrail(bool disable); +int32 ResetSignalVariant(int32 = 0); #endif /* RAIL_GUI_H */ diff --git a/src/settings.cpp b/src/settings.cpp index 8d2694d51..1827f1b07 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -51,6 +51,7 @@ #include "transparency.h" #include "textbuf_gui.h" #include "string_func.h" +#include "rail_gui.h" #include "gui.h" #include "town.h" #include "video/video_driver.hpp" @@ -1404,7 +1405,7 @@ const SettingDesc _patch_settings[] = { SDT_BOOL(Patches, always_small_airport, 0,NN, false, STR_CONFIG_PATCHES_SMALL_AIRPORTS, NULL), SDT_BOOL(Patches, enable_signal_gui, S, 0, false, STR_CONFIG_PATCHES_ENABLE_SIGNAL_GUI, NULL), SDT_VAR(Patches, drag_signals_density,SLE_UINT8,S, 0, 4, 1, 20, 0, STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY,NULL), - SDT_VAR(Patches, semaphore_build_before,SLE_INT32, S, NC, 1975, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_SEMAPHORE_BUILD_BEFORE_DATE, NULL), + SDT_VAR(Patches, semaphore_build_before,SLE_INT32, S, NC, 1975, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_SEMAPHORE_BUILD_BEFORE_DATE, ResetSignalVariant), SDT_CONDVAR(Patches, town_layout, SLE_UINT8, 59, SL_MAX_VERSION, 0, MS, TL_ORIGINAL, TL_NO_ROADS, NUM_TLS - 1, 1, STR_CONFIG_PATCHES_TOWN_LAYOUT, CheckTownLayout), /***************************************************************************/ -- cgit v1.2.3-54-g00ecf