From 5af7be6d1763acbbe7f53d0aa80ba6c66d48a57b Mon Sep 17 00:00:00 2001 From: RoqueDeicide Date: Sat, 1 Jul 2023 22:59:00 +0400 Subject: [PATCH] [Feature] Added station viewport tooltips. --- src/lang/extra/english.txt | 12 +++++++++ src/settings_gui.cpp | 2 ++ src/settings_type.h | 2 ++ src/station_gui.cpp | 48 +++++++++++++++++++++++++++++++++ src/strings.cpp | 5 ++++ src/table/settings/settings.ini | 18 +++++++++++++ src/viewport_gui.cpp | 12 +++++++++ 7 files changed, 99 insertions(+) diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index 9347a48470..0c5c70f6fd 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -1402,6 +1402,10 @@ STR_DEPOT_VIEW_WAITING_TOOLTIP :{}{COMMA} {P is STR_DEPOT_VIEW_CONSISTS_TOOLTIP :{}{COMMA} {P is are} {P "a " ""}consist{P "" s} STR_DEPOT_VIEW_INFO_TOOLTIP :{BLACK}{RAW_STRING} +STR_STATION_VIEW_NAME_TOOLTIP :{STATION}{NBSP} +STR_STATION_VIEW_CARGO_LINE_TOOLTIP :{STRING} ({COMMA}%): {CARGO_SHORT} +STR_STATION_VIEW_INFO_TOOLTIP :{BLACK}{RAW_STRING} + STR_VEHICLE_LIST_AGE :{STRING2}, Age: {COMMA} year{P "" s} ({COMMA}) STR_VEHICLE_LIST_AGE_RED :{STRING2}, Age: {RED}{COMMA} {BLACK}year{P "" s} ({COMMA}) STR_VEHICLE_LIST_CARGO_LIST :{STRING2}, Cargoes: {CARGO_LIST} @@ -2159,6 +2163,14 @@ STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_OFF :Off STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_SIMPLE :Simple STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_DETAILED :Detailed +STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME :Show names in station viewport tooltips: {STRING2} +STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_HELPTEXT :Show the name of the station in a viewport tooltip when hovering over it. +STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_CARGO :Show cargo details in station viewport tooltips: {STRING2} +STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_CARGO_HELPTEXT :Show the list of amounts and ratings of cargo that had ever been delivered to the station by industries, towns or by vehicles via unload/transfer order that doesn't result in the final delivery. +STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_OFF :Off +STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_ON_IF_HIDDEN :On, if station names are hidden +STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_ALWAYS_ON :Always on + STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE :Station rating tooltips: {STRING2} STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_HELPTEXT :Set whether station rating tooltips are shown and the level of information detail. STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_OFF :Off diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 743999f9a2..cef626c047 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1941,6 +1941,8 @@ static SettingsContainer &GetSettingsTree() tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_stockpiled_as_required", []() -> bool { return !_settings_client.gui.industry_tooltip_show || _settings_client.gui.industry_tooltip_show_stockpiled || !_settings_client.gui.industry_tooltip_show_required; })); tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_produced", []() -> bool { return !_settings_client.gui.industry_tooltip_show; })); tooltips->Add(new SettingEntry("gui.depot_tooltip_mode")); + tooltips->Add(new SettingEntry("gui.station_viewport_tooltip_name")); + tooltips->Add(new SettingEntry("gui.station_viewport_tooltip_cargo")); tooltips->Add(new SettingEntry("gui.station_rating_tooltip_mode")); } diff --git a/src/settings_type.h b/src/settings_type.h index 3fbdaa90c0..57fd893b24 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -141,6 +141,8 @@ struct GUISettings : public TimeSettings { bool industry_tooltip_show_stockpiled_as_required; ///< whether to display cargoes stockpiled by the industry as ones required by the industry, when hovering over one of its tiles and normal display of stockpiled cargoes in viewport tooltips is turned off. bool industry_tooltip_show_produced; ///< whether to display cargoes produced by the industry, when hovering over one of its tiles. uint8 depot_tooltip_mode; ///< Display mode for depot viewport tooltips. (0 = never, 1 = just a total number of vehicles, 2 = total number of vehicles in the depot along with a breakdown of numbers) + uint8 station_viewport_tooltip_name; ///< Show the name of the station in a viewport tooltip. (0 = never, 1 = only if station names are hidden, 2 = always) + bool station_viewport_tooltip_cargo; ///< Show a list of cargo details at the station in a viewport tooltip. uint8 station_rating_tooltip_mode; ///< Station rating tooltip mode bool link_terraform_toolbar; ///< display terraform toolbar when displaying rail, road, water and airport toolbars uint8 smallmap_land_colour; ///< colour used for land and heightmap at the smallmap diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 16058c2338..44b0e415c8 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -3096,3 +3096,51 @@ bool ShouldShowBaseStationViewportLabel(const BaseStation *bst) !HasBit(_extra_display_opt, XDO_SHOW_HIDDEN_SIGNS)) return false; return true; } + +enum StationTooltipNameMode : uint8 { + STNM_OFF, + STNM_ON_IF_HIDDEN, + STNM_ALWAYS_ON +}; + +char *StationGetSpecialStringExternal(char *buff, int x, const char *last); + +bool GetStationViewportTooltipString(const TileIndex tile, char *buffer_position, const char *buffer_tail) +{ + const StationID station_id = GetStationIndex(tile); + const Station *station = Station::Get(station_id); + + bool next = false; + + if (_settings_client.gui.station_viewport_tooltip_name == STNM_ALWAYS_ON || + _settings_client.gui.station_viewport_tooltip_name == STNM_ON_IF_HIDDEN && !HasBit(_display_opt, DO_SHOW_STATION_NAMES)) { + SetDParam(0, station_id); + buffer_position = GetString(buffer_position, STR_STATION_VIEW_NAME_TOOLTIP, buffer_tail); + buffer_position = StationGetSpecialStringExternal(buffer_position, station->facilities, buffer_tail); + + next = true; + } + + if (_settings_client.gui.station_viewport_tooltip_cargo) { + constexpr size_t goods_entry_count = lengthof(station->goods); + + for (size_t i = 0; i < goods_entry_count; ++i) { + const GoodsEntry *goods_entry = station->goods + i; + if (!HasBit(goods_entry->status, GoodsEntry::GES_RATING)) continue; + + if (next) { + buffer_position = GetString(buffer_position, STR_NEW_LINE, buffer_tail); + } + + SetDParam(0, CargoSpec::Get(i)->name); + SetDParam(1, ToPercent8(goods_entry->rating)); + SetDParam(2, i); + SetDParam(3, goods_entry->cargo.TotalCount()); + buffer_position = GetString(buffer_position, STR_STATION_VIEW_CARGO_LINE_TOOLTIP, buffer_tail); + + next = true; + } + } + + return next; +} diff --git a/src/strings.cpp b/src/strings.cpp index 32950e7802..4cf483a778 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -2046,6 +2046,11 @@ static char *StationGetSpecialString(char *buff, int x, const char *last) return buff; } +char *StationGetSpecialStringExternal(char *buff, int x, const char *last) +{ + return StationGetSpecialString(buff, x, last); +} + static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last) { return GenerateTownNameString(buff, last, ind, seed); diff --git a/src/table/settings/settings.ini b/src/table/settings/settings.ini index a29115a709..4192b64bc8 100644 --- a/src/table/settings/settings.ini +++ b/src/table/settings/settings.ini @@ -4619,6 +4619,24 @@ str = STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE strhelp = STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_HELPTEXT strval = STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_OFF +[SDTC_VAR] +var = gui.station_viewport_tooltip_name +type = SLE_UINT8 +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN +def = 1 +min = 0 +max = 2 +str = STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME +strhelp = STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_HELPTEXT +strval = STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_OFF + +[SDTC_BOOL] +var = gui.station_viewport_tooltip_cargo +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC +def = true +str = STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_CARGO +strhelp = STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_CARGO_HELPTEXT + [SDTC_VAR] var = gui.station_rating_tooltip_mode type = SLE_UINT8 diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp index 169e725306..61cb6f6f16 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -257,6 +257,16 @@ void ShowDepotTooltip(Window *w, const TileIndex tile, char *buffer_position, co GuiShowTooltips(w, STR_DEPOT_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); } +bool GetStationViewportTooltipString(TileIndex tile, char *buffer_position, const char *buffer_tail); + +void ShowStationViewportTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail) +{ + if (!GetStationViewportTooltipString(tile, buffer_position, buffer_tail)) return; + + SetDParamStr(0, buffer_position); + GuiShowTooltips(w, STR_STATION_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); +} + void ShowTooltipForTile(Window *w, const TileIndex tile) { static char buffer[1024]; @@ -291,6 +301,8 @@ void ShowTooltipForTile(Window *w, const TileIndex tile) case MP_STATION: { if (IsHangar(tile)) { ShowDepotTooltip(w, tile, buffer_start, buffer_tail); + } else { + ShowStationViewportTooltip(w, tile, buffer_start, buffer_tail); } break; }