From d6041744ca2e17fbf387208648fd484c5c7b0cca Mon Sep 17 00:00:00 2001 From: RoqueDeicide Date: Wed, 28 Jun 2023 14:38:52 +0400 Subject: [PATCH 01/11] [Change] Moved tooltip-related settings to a dedicated category. --- src/lang/extra/english.txt | 14 ++++++++------ src/settings_gui.cpp | 10 +++++++--- src/settings_type.h | 2 +- src/table/settings/settings.ini | 22 +++++++++++----------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index 9957b38c1e..f50b551b0f 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -292,12 +292,6 @@ STR_CONFIG_SETTING_VEHICLE_NAMES_LONG :Long STR_CONFIG_SETTING_SHADED_TREES_ON_SLOPES :Shade trees on slopes: {STRING2} STR_CONFIG_SETTING_SHADED_TREES_ON_SLOPES_HELPTEXT :Change brightness of trees drawn on slopes. Improves the look of tree cover in mountainous areas. -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 -STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_SIMPLE :Simple -STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_DETAILED :Detailed - STR_CONFIG_SETTING_DEMOLISH_CONFIRM_MODE :Ask before demolishing structures: {STRING2} STR_CONFIG_SETTING_DEMOLISH_CONFIRM_MODE_HELPTEXT :Ask for confirmation before irreversibly demolishing structures. STR_CONFIG_SETTING_DEMOLISH_CONFIRM_MODE_OFF :Off @@ -2122,5 +2116,13 @@ STR_TOWN_DIRECTORY_INFO :{BLACK}{STRING1 STR_GAME_OPTIONS_GUI_SCALE_MAIN_TOOLBAR :{BLACK}Bigger main toolbar STR_GAME_OPTIONS_GUI_SCALE_MAIN_TOOLBAR_TOOLTIP :{BLACK}Check this box to increase the scale of the main toolbar +STR_CONFIG_SETTING_INTERFACE_TOOLTIPS :{ORANGE}Tooltips + STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP :Show viewport tooltips for tiles without a right-click: {STRING2} STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP_HELPTEXT :Show viewport tooltips for tile types such as industries without requiring a right-click, when the show tooltips setting is set to right-click. + +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 +STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_SIMPLE :Simple +STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_DETAILED :Detailed diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 7dd1f17c17..b9fed63c4e 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1923,14 +1923,19 @@ static SettingsContainer &GetSettingsTree() SettingsPage *general = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_GENERAL)); { general->Add(new SettingEntry("gui.osk_activation")); - general->Add(new SettingEntry("gui.hover_delay_ms")); - general->Add(new ConditionallyHiddenSettingEntry("gui.instant_tile_tooltip", []() -> bool { return _settings_client.gui.hover_delay_ms != 0; })); general->Add(new SettingEntry("gui.errmsg_duration")); general->Add(new SettingEntry("gui.window_snap_radius")); general->Add(new SettingEntry("gui.window_soft_limit")); general->Add(new SettingEntry("gui.right_mouse_wnd_close")); } + SettingsPage *tooltips = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_TOOLTIPS)); + { + tooltips->Add(new SettingEntry("gui.hover_delay_ms")); + tooltips->Add(new ConditionallyHiddenSettingEntry("gui.instant_tile_tooltip", []() -> bool { return _settings_client.gui.hover_delay_ms != 0; })); + tooltips->Add(new SettingEntry("gui.station_rating_tooltip_mode")); + } + SettingsPage *save = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_SAVE)); { save->Add(new SettingEntry("gui.autosave")); @@ -2090,7 +2095,6 @@ static SettingsContainer &GetSettingsTree() interface->Add(new SettingEntry("gui.prefer_teamchat")); interface->Add(new SettingEntry("gui.sort_track_types_by_speed")); interface->Add(new SettingEntry("gui.allow_hiding_waypoint_labels")); - interface->Add(new SettingEntry("gui.station_rating_tooltip_mode")); } SettingsPage *advisors = main->Add(new SettingsPage(STR_CONFIG_SETTING_ADVISORS)); diff --git a/src/settings_type.h b/src/settings_type.h index 3cf3bd98ce..977025fcca 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -133,6 +133,7 @@ struct GUISettings : public TimeSettings { byte errmsg_duration; ///< duration of error message uint16 hover_delay_ms; ///< time required to activate a hover event, in milliseconds bool instant_tile_tooltip; ///< don't require a right click to activate a hover event to show a tooltip for an in-game tile (e.g. industry). + 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 uint8 scroll_mode; ///< viewport scroll mode @@ -249,7 +250,6 @@ struct GUISettings : public TimeSettings { uint8 linkgraph_colours; ///< linkgraph overlay colours uint8 vehicle_names; ///< Vehicle naming scheme bool shade_trees_on_slopes; ///< Shade trees on slopes - uint8 station_rating_tooltip_mode; ///< Station rating tooltip mode uint8 demolish_confirm_mode; ///< Demolition confirmation mode bool dual_pane_train_purchase_window; ///< Dual pane train purchase window bool dual_pane_train_purchase_window_dual_buttons; ///< Dual pane train purchase window: dual buttons diff --git a/src/table/settings/settings.ini b/src/table/settings/settings.ini index 44dccfe518..4f6aaad6f6 100644 --- a/src/table/settings/settings.ini +++ b/src/table/settings/settings.ini @@ -4552,6 +4552,17 @@ def = false str = STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP strhelp = STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP_HELPTEXT +[SDTC_VAR] +var = gui.station_rating_tooltip_mode +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_RATING_TOOLTIP_MODE +strhelp = STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_HELPTEXT +strval = STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_OFF + [SDTC_OMANY] var = gui.osk_activation type = SLE_UINT8 @@ -5724,17 +5735,6 @@ strhelp = STR_CONFIG_SETTING_SHADED_TREES_ON_SLOPES_HELPTEXT post_cb = [](auto) { MarkWholeScreenDirty(); } cat = SC_BASIC -[SDTC_VAR] -var = gui.station_rating_tooltip_mode -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_RATING_TOOLTIP_MODE -strhelp = STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_HELPTEXT -strval = STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_OFF - [SDTC_VAR] var = gui.demolish_confirm_mode type = SLE_UINT8 From 8eea01717fcd06ea18fcc93166df120d90794e48 Mon Sep 17 00:00:00 2001 From: RoqueDeicide Date: Wed, 28 Jun 2023 15:55:18 +0400 Subject: [PATCH 02/11] [Feature] A setting to allow town name tile tooltips to always or never be displayed. --- src/lang/extra/english.txt | 6 ++++++ src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings/settings.ini | 11 +++++++++++ src/viewport_gui.cpp | 18 +++++++++++++++--- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index f50b551b0f..f2e84bcf9c 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -2121,6 +2121,12 @@ STR_CONFIG_SETTING_INTERFACE_TOOLTIPS :{ORANGE}Tooltip STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP :Show viewport tooltips for tiles without a right-click: {STRING2} STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP_HELPTEXT :Show viewport tooltips for tile types such as industries without requiring a right-click, when the show tooltips setting is set to right-click. +STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE :Show viewport tooltips with town names: {STRING2} +STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_HELPTEXT :Show viewport tooltips for road and house tiles that belong to towns. +STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_OFF :Off +STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_ON_IF_HIDDEN :On, if town names are hidden +STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_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 b9fed63c4e..6898b11d05 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1933,6 +1933,7 @@ static SettingsContainer &GetSettingsTree() { tooltips->Add(new SettingEntry("gui.hover_delay_ms")); tooltips->Add(new ConditionallyHiddenSettingEntry("gui.instant_tile_tooltip", []() -> bool { return _settings_client.gui.hover_delay_ms != 0; })); + tooltips->Add(new SettingEntry("gui.town_name_tooltip_mode")); tooltips->Add(new SettingEntry("gui.station_rating_tooltip_mode")); } diff --git a/src/settings_type.h b/src/settings_type.h index 977025fcca..e8f5e4e189 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -133,6 +133,7 @@ struct GUISettings : public TimeSettings { byte errmsg_duration; ///< duration of error message uint16 hover_delay_ms; ///< time required to activate a hover event, in milliseconds bool instant_tile_tooltip; ///< don't require a right click to activate a hover event to show a tooltip for an in-game tile (e.g. industry). + uint8 town_name_tooltip_mode; ///< when to display town names when hovering over roads and houses. (0 = never, 1 = only if town names are hidden, 2 = always) 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/table/settings/settings.ini b/src/table/settings/settings.ini index 4f6aaad6f6..a5bee9dc01 100644 --- a/src/table/settings/settings.ini +++ b/src/table/settings/settings.ini @@ -4552,6 +4552,17 @@ def = false str = STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP strhelp = STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP_HELPTEXT +[SDTC_VAR] +var = gui.town_name_tooltip_mode +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_TOWN_NAME_TOOLTIP_MODE +strhelp = STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_HELPTEXT +strval = STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_OFF + [SDTC_VAR] var = gui.station_rating_tooltip_mode type = SLE_UINT8 diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp index feb961069d..6329fed9dc 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -219,6 +219,20 @@ void ShowExtraViewportWindowForTileUnderCursor() ShowExtraViewportWindow(pt.x != -1 ? TileVirtXY(pt.x, pt.y) : INVALID_TILE); } +enum TownNameTooltipMode : uint8 { + TNTM_OFF, + TNTM_ON_IF_HIDDEN, + TNTM_ALWAYS_ON +}; + +void ShowTownNameTooltip(Window *w, const TileIndex tile) +{ + if (_settings_client.gui.town_name_tooltip_mode == TNTM_OFF) return; + if (HasBit(_display_opt, DO_SHOW_TOWN_NAMES) && _settings_client.gui.town_name_tooltip_mode == TNTM_ON_IF_HIDDEN) return; // No need for a town name tooltip when it is already displayed + SetDParam(0, GetTownIndex(tile)); + GuiShowTooltips(w, STR_TOWN_NAME_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); +} + void ShowTooltipForTile(Window *w, const TileIndex tile) { switch (GetTileType(tile)) { @@ -226,9 +240,7 @@ void ShowTooltipForTile(Window *w, const TileIndex tile) if (IsRoadDepot(tile)) return; /* FALL THROUGH */ case MP_HOUSE: { - if (HasBit(_display_opt, DO_SHOW_TOWN_NAMES)) return; // No need for a town name tooltip when it is already displayed - SetDParam(0, GetTownIndex(tile)); - GuiShowTooltips(w, STR_TOWN_NAME_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); + ShowTownNameTooltip(w, tile); break; } case MP_INDUSTRY: { From 33ee78f9ac89c7228dfa357c9bed4d9205c5d57b Mon Sep 17 00:00:00 2001 From: RoqueDeicide Date: Thu, 29 Jun 2023 23:13:55 +0400 Subject: [PATCH 03/11] [Feature] Extended functionality of industry viewport tooltips. Added ability to turn them off or to show any combination of the following: name, required, stockpiled or produced cargoes. --- src/industry_gui.cpp | 136 ++++++++++++++++++++++++++++++++ src/lang/extra/english.txt | 23 +++++- src/settings_gui.cpp | 6 ++ src/settings_type.h | 6 ++ src/table/settings/settings.ini | 45 +++++++++++ src/viewport_gui.cpp | 37 ++++----- 6 files changed, 233 insertions(+), 20 deletions(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 9593234a9e..696d9ac306 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -3244,3 +3244,139 @@ void ShowIndustryCargoesWindow() { ShowIndustryCargoesWindow(NUM_INDUSTRYTYPES); } + +/** + * Fills given data buffer with a string of characters that describe given industry, to be used to display a tooltip, when hovering over the industry tile. + * @param tile Index of the industry tile. + * @param buffer_position Pointer to the beginning of the data buffer to output the string into. + * @param buffer_tail Pointer to the last byte of the data buffer to output the string into. + * @returns A boolean value that indicates whether to show the tooltip. + */ +bool GetIndustryTooltipString(const TileIndex tile, char *buffer_position, const char *buffer_tail) +{ + const Industry *industry = Industry::GetByTile(tile); + const IndustrySpec *industry_spec = GetIndustrySpec(industry->type); + + buffer_position[0] = 0; + auto current_buffer_position = buffer_position; + auto next = false; + + if (_settings_client.gui.industry_tooltip_show_name) { + // Print out the name of the industry. + SetDParam(0, industry_spec->name); + current_buffer_position = GetString(current_buffer_position, STR_INDUSTRY_VIEW_NAME_TOOLTIP, buffer_tail); + + next = true; + } + + if (_settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled) { + constexpr auto accepted_cargo_count = lengthof(industry->accepts_cargo); + + CargoSuffix suffixes[accepted_cargo_count]; + GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, industry, industry->type, industry_spec, industry->accepts_cargo, suffixes); + + // Have to query the stockpiling right now, in case callback 37 returns fail. + bool stockpiling = HasBit(industry_spec->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || + HasBit(industry_spec->callback_mask, CBM_IND_PRODUCTION_256_TICKS); + + if (_settings_client.gui.industry_tooltip_show_required) { + // Print out required cargo. + bool first = true; + std::string required_cargo_list; + auto cargo_list_start_buffer_position = current_buffer_position; + + for (byte i = 0; i < accepted_cargo_count; ++i) { + auto required_cargo = industry->accepts_cargo[i]; + if (required_cargo == CT_INVALID ) { + continue; + } + + auto suffix = &suffixes[i]; + + bool isStockpileWithSuffix = suffix->display == CSD_CARGO_AMOUNT_TEXT; + bool isStockpileWithoutSuffix = suffix->display == CSD_CARGO_AMOUNT; + bool isProperStockpileWithoutSuffix = isStockpileWithoutSuffix && stockpiling; // If callback 37 fails, the result is interpreted as a stockpile, for some reason. + if (isStockpileWithSuffix || isProperStockpileWithoutSuffix) { + if (_settings_client.gui.industry_tooltip_show_stockpiled || !_settings_client.gui.industry_tooltip_show_stockpiled_as_required) continue; + } + + auto format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT; + if (first) { + format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_FIRST; + first = false; + } + + SetDParam(0, CargoSpec::Get(required_cargo)->name); + SetDParamStr(1, suffix->text); + GetString(cargo_list_start_buffer_position, format, buffer_tail); + required_cargo_list += cargo_list_start_buffer_position; + } + + if (next && !required_cargo_list.empty()) { + current_buffer_position = GetString(current_buffer_position, STR_NEW_LINE, buffer_tail); + } + + current_buffer_position += required_cargo_list.copy(current_buffer_position, required_cargo_list.size()); + current_buffer_position[0] = '\0'; + //++current_buffer_position; + + if (!required_cargo_list.empty()) { + next = true; + } + } + + // Print out stockpiled cargo. + + if (stockpiling && _settings_client.gui.industry_tooltip_show_stockpiled) { + for (byte i = 0; i < accepted_cargo_count; ++i) { + auto stockpiled_cargo = industry->accepts_cargo[i]; + if (stockpiled_cargo == CT_INVALID) continue; + + auto suffix = &suffixes[i]; + + if (suffix->display == CSD_CARGO || suffix->display == CSD_CARGO_TEXT) { + continue; + } + + if (next) { + current_buffer_position = GetString(current_buffer_position, STR_NEW_LINE, buffer_tail); + } + + next = true; + + SetDParam(0, stockpiled_cargo); + SetDParam(1, industry->incoming_cargo_waiting[i]); + SetDParamStr(2, suffix->text); + current_buffer_position = GetString(current_buffer_position, STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP, buffer_tail); + } + } + } + + if (_settings_client.gui.industry_tooltip_show_produced) { + constexpr auto produced_cargo_count = lengthof(industry->produced_cargo); + + CargoSuffix suffixes[produced_cargo_count]; + GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_VIEW, industry, industry->type, industry_spec, industry->produced_cargo, suffixes); + + // Print out amounts of produced cargo. + + for (byte i = 0; i < produced_cargo_count; i++) { + auto produced_cargo = industry->produced_cargo[i]; + if (produced_cargo == CT_INVALID) continue; + + if (next) { + current_buffer_position = GetString(current_buffer_position, STR_NEW_LINE, buffer_tail); + } + + next = true; + + SetDParam(0, produced_cargo); + SetDParam(1, industry->last_month_production[i]); + SetDParamStr(2, suffixes[i].text); + SetDParam(3, ToPercent8(industry->last_month_pct_transported[i])); + current_buffer_position = GetString(current_buffer_position, STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION, buffer_tail); + } + } + + return next; +} diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index f2e84bcf9c..4add84010c 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -1383,12 +1383,18 @@ STR_FINANCES_REPAY_TOOLTIP_EXTRA :{BLACK}{STRING} STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}Enter the amount of money to borrow STR_FINANCES_REPAY_QUERY_CAPT :{WHITE}Enter the amount of money to repay -STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP :{BLACK}{STRING}{RAW_STRING} -STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{}{BLACK}{CARGO_LONG} ({COMMA}%) +STR_NEW_LINE :{} # Town tooltip STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN} +STR_INDUSTRY_VIEW_NAME_TOOLTIP :{STRING} +STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_FIRST :{STRING}{RAW_STRING} +STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT :, {STRING}{RAW_STRING} +STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP :{CARGO_LONG} waiting{RAW_STRING} +STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{CARGO_LONG}{RAW_STRING} ({COMMA}%) +STR_INDUSTRY_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} @@ -2127,6 +2133,19 @@ STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_OFF :Off STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_ON_IF_HIDDEN :On, if town names are hidden STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_ALWAYS_ON :Always on +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_SHOW :Show viewport tooltips for industries: {STRING2} +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_SHOW_HELPTEXT :Show tooltips when hovering over industry tiles. +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_NAME :Show names in industry viewport tooltips: {STRING2} +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_NAME_HELPTEXT :Show names of industries in viewport tooltips when hovering over industry tiles. +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED :Show required cargoes in industry viewport tooltips: {STRING2} +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED_HELPTEXT :Show a list of cargoes required by industries in viewport tooltips when hovering over industry tiles. +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED :Show stockpiled cargoes in industry viewport tooltips: {STRING2} +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_HELPTEXT :Show a list of cargoes stockpiled by industries in viewport tooltips when hovering over industry tiles. +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED :Show stockpiled cargoes as required in viewport tooltips: {STRING2} +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED_HELPTEXT:If normal display of stockpiled cargoes in viewport tooltips is disabled, then allow them to, at least, be displayed as required ones. +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED :Show produced cargoes in industry viewport tooltips: {STRING2} +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED_HELPTEXT :Show a list of cargoes produced by industries in viewport tooltips when hovering over industry tiles. + 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 6898b11d05..50873d5a00 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1934,6 +1934,12 @@ static SettingsContainer &GetSettingsTree() tooltips->Add(new SettingEntry("gui.hover_delay_ms")); tooltips->Add(new ConditionallyHiddenSettingEntry("gui.instant_tile_tooltip", []() -> bool { return _settings_client.gui.hover_delay_ms != 0; })); tooltips->Add(new SettingEntry("gui.town_name_tooltip_mode")); + tooltips->Add(new SettingEntry("gui.industry_tooltip_show")); + tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_name", []() -> bool { return !_settings_client.gui.industry_tooltip_show; })); + tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_required", []() -> bool { return !_settings_client.gui.industry_tooltip_show; })); + tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_stockpiled", []() -> bool { return !_settings_client.gui.industry_tooltip_show; })); + 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.station_rating_tooltip_mode")); } diff --git a/src/settings_type.h b/src/settings_type.h index e8f5e4e189..386c7df5fa 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -134,6 +134,12 @@ struct GUISettings : public TimeSettings { uint16 hover_delay_ms; ///< time required to activate a hover event, in milliseconds bool instant_tile_tooltip; ///< don't require a right click to activate a hover event to show a tooltip for an in-game tile (e.g. industry). uint8 town_name_tooltip_mode; ///< when to display town names when hovering over roads and houses. (0 = never, 1 = only if town names are hidden, 2 = always) + bool industry_tooltip_show; ///< whether to display tooltips, when hovering over industry tiles. + bool industry_tooltip_show_name; ///< whether to display the name of the industry, when hovering over one of its tiles. + bool industry_tooltip_show_required; ///< whether to display cargoes required by the industry, when hovering over one of its tiles. + bool industry_tooltip_show_stockpiled; ///< whether to display cargoes stockpiled by the industry, when hovering over one of its tiles. + 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 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/table/settings/settings.ini b/src/table/settings/settings.ini index a5bee9dc01..08be020a98 100644 --- a/src/table/settings/settings.ini +++ b/src/table/settings/settings.ini @@ -4563,6 +4563,51 @@ str = STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE strhelp = STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_HELPTEXT strval = STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_OFF +[SDTC_BOOL] +var = gui.industry_tooltip_show +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC +def = true +str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_SHOW +strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_SHOW_HELPTEXT +post_cb = [](auto) { InvalidateWindowClassesData(WC_GAME_OPTIONS); } + +[SDTC_BOOL] +var = gui.industry_tooltip_show_name +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC +def = true +str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_NAME +strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_NAME_HELPTEXT + +[SDTC_BOOL] +var = gui.industry_tooltip_show_required +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC +def = false +str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED +strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED_HELPTEXT +post_cb = [](auto) { InvalidateWindowClassesData(WC_GAME_OPTIONS); } + +[SDTC_BOOL] +var = gui.industry_tooltip_show_stockpiled +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC +def = false +str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED +strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_HELPTEXT +post_cb = [](auto) { InvalidateWindowClassesData(WC_GAME_OPTIONS); } + +[SDTC_BOOL] +var = gui.industry_tooltip_show_stockpiled_as_required +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC +def = true +str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED +strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED_HELPTEXT + +[SDTC_BOOL] +var = gui.industry_tooltip_show_produced +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC +def = true +str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED +strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED_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 6329fed9dc..8631f2a72e 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -233,8 +233,26 @@ void ShowTownNameTooltip(Window *w, const TileIndex tile) GuiShowTooltips(w, STR_TOWN_NAME_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); } +bool GetIndustryTooltipString(TileIndex tile, char *buffer_position, const char *buffer_tail); + +void ShowIndustryTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail) +{ + if (!_settings_client.gui.industry_tooltip_show || + !(_settings_client.gui.industry_tooltip_show_name || _settings_client.gui.industry_tooltip_show_produced || + _settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled)) return; + + if (!GetIndustryTooltipString(tile, buffer_position, buffer_tail)) return; + + SetDParamStr(0, buffer_position); + GuiShowTooltips(w, STR_INDUSTRY_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); +} + void ShowTooltipForTile(Window *w, const TileIndex tile) { + static char buffer[1024]; + char *buffer_start = buffer; + char *buffer_tail = lastof(buffer); + switch (GetTileType(tile)) { case MP_ROAD: if (IsRoadDepot(tile)) return; @@ -244,24 +262,7 @@ void ShowTooltipForTile(Window *w, const TileIndex tile) break; } case MP_INDUSTRY: { - static char buffer[1024]; - const Industry *ind = Industry::GetByTile(tile); - const IndustrySpec *indsp = GetIndustrySpec(ind->type); - - buffer[0] = 0; - char *buf_pos = buffer; - - for (byte i = 0; i < lengthof(ind->produced_cargo); i++) { - if (ind->produced_cargo[i] != CT_INVALID) { - SetDParam(0, ind->produced_cargo[i]); - SetDParam(1, ind->last_month_production[i]); - SetDParam(2, ToPercent8(ind->last_month_pct_transported[i])); - buf_pos = GetString(buf_pos, STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION, lastof(buffer)); - } - } - SetDParam(0, indsp->name); - SetDParamStr(1, buffer); - GuiShowTooltips(w, STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); + ShowIndustryTooltip(w, tile, buffer_start, buffer_tail); break; } default: From 1071235aee02d5206ca9361f23e9c23ad8a28047 Mon Sep 17 00:00:00 2001 From: RoqueDeicide Date: Fri, 30 Jun 2023 19:58:28 +0400 Subject: [PATCH 04/11] [Feature] Added depot viewport tooltips. --- src/depot_gui.cpp | 64 +++++++++++++++++++++++++++++++++ src/lang/extra/english.txt | 13 +++++++ src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings/settings.ini | 11 ++++++ src/viewport_gui.cpp | 31 +++++++++++++++- 6 files changed, 120 insertions(+), 1 deletion(-) diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 96dd9d65a4..65fddc05cd 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -1197,3 +1197,67 @@ void DeleteDepotHighlightOfVehicle(const Vehicle *v) if (w->sel == v->index) ResetObjectToPlace(); } } + +enum DepotTooltipMode : uint8 { + DTM_OFF, + DTM_SIMPLE, + DTM_DETAILED +}; + +bool GetDepotTooltipString(const TileIndex tile, char *buffer_position, const char *buffer_tail) +{ + if (_settings_client.gui.depot_tooltip_mode == DTM_OFF) { + return false; + } + + size_t total_vehicle_count = 0; + size_t stopped_vehicle_count = 0; + size_t waiting_vehicle_count = 0; + size_t consist_count = 0; + + for (const Vehicle *v : Vehicle::Iterate()) { + if (v->tile == tile && !HasBit(v->subtype, GVSF_VIRTUAL) && v->IsInDepot()) { + if (v->IsPrimaryVehicle()) { + ++total_vehicle_count; + if (v->IsWaitingInDepot()) ++waiting_vehicle_count; + if (v->IsStoppedInDepot()) ++stopped_vehicle_count; + } + if (v->type == VEH_TRAIN) { + const Train *loco_or_wago = Train::From(v); + if (loco_or_wago->IsFreeWagon()) { + ++consist_count; + ++total_vehicle_count; + } + } + } + } + + buffer_position[0] = '\0'; + + if (total_vehicle_count == 0) { + return false; + } + + SetDParam(0, total_vehicle_count); + + if (_settings_client.gui.depot_tooltip_mode == DTM_SIMPLE || stopped_vehicle_count == 0 && waiting_vehicle_count == 0 && consist_count == 0) { + GetString(buffer_position, STR_DEPOT_VIEW_COUNT_TOOLTIP, buffer_tail); + } else { + buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_TOTAL_TOOLTIP, buffer_tail); + if (stopped_vehicle_count > 0) { + SetDParam(0, stopped_vehicle_count); + buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_STOPPED_TOOLTIP, buffer_tail); + } + if (waiting_vehicle_count > 0) { + SetDParam(0, waiting_vehicle_count); + buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_WAITING_TOOLTIP, buffer_tail); + } + if (consist_count > 0) { + SetDParam(0, consist_count); + GetString(buffer_position, STR_DEPOT_VIEW_CONSISTS_TOOLTIP, buffer_tail); + } + + } + + return true; +} diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index 4add84010c..9347a48470 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -1395,6 +1395,13 @@ STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP :{CARGO_LONG} wa STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{CARGO_LONG}{RAW_STRING} ({COMMA}%) STR_INDUSTRY_VIEW_INFO_TOOLTIP :{BLACK}{RAW_STRING} +STR_DEPOT_VIEW_COUNT_TOOLTIP :{COMMA} indside +STR_DEPOT_VIEW_TOTAL_TOOLTIP :Of {COMMA} inside: +STR_DEPOT_VIEW_STOPPED_TOOLTIP :{}{COMMA} {P is are} stopped +STR_DEPOT_VIEW_WAITING_TOOLTIP :{}{COMMA} {P is are} waiting +STR_DEPOT_VIEW_CONSISTS_TOOLTIP :{}{COMMA} {P is are} {P "a " ""}consist{P "" s} +STR_DEPOT_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} @@ -2146,6 +2153,12 @@ STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED_HELPTEXT:If normal di STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED :Show produced cargoes in industry viewport tooltips: {STRING2} STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED_HELPTEXT :Show a list of cargoes produced by industries in viewport tooltips when hovering over industry tiles. +STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE :Depot viewport tooltips: {STRING2} +STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_HELPTEXT :Set whether to show viewport tooltips when hovering over depot tiles and how much information to display. +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_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 50873d5a00..743999f9a2 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1940,6 +1940,7 @@ static SettingsContainer &GetSettingsTree() tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_stockpiled", []() -> bool { return !_settings_client.gui.industry_tooltip_show; })); 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_rating_tooltip_mode")); } diff --git a/src/settings_type.h b/src/settings_type.h index 386c7df5fa..3fbdaa90c0 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -140,6 +140,7 @@ struct GUISettings : public TimeSettings { bool industry_tooltip_show_stockpiled; ///< whether to display cargoes stockpiled by the industry, when hovering over one of its tiles. 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_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/table/settings/settings.ini b/src/table/settings/settings.ini index 08be020a98..a29115a709 100644 --- a/src/table/settings/settings.ini +++ b/src/table/settings/settings.ini @@ -4608,6 +4608,17 @@ def = true str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED_HELPTEXT +[SDTC_VAR] +var = gui.depot_tooltip_mode +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_DEPOT_TOOLTIP_MODE +strhelp = STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_HELPTEXT +strval = STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_OFF + [SDTC_VAR] var = gui.station_rating_tooltip_mode type = SLE_UINT8 diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp index 8631f2a72e..169e725306 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -247,6 +247,16 @@ void ShowIndustryTooltip(Window *w, const TileIndex tile, char *buffer_position, GuiShowTooltips(w, STR_INDUSTRY_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); } +bool GetDepotTooltipString(TileIndex tile, char *buffer_position, const char *buffer_tail); + +void ShowDepotTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail) +{ + if (!GetDepotTooltipString(tile, buffer_position, buffer_tail)) return; + + SetDParamStr(0, buffer_position); + GuiShowTooltips(w, STR_DEPOT_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); +} + void ShowTooltipForTile(Window *w, const TileIndex tile) { static char buffer[1024]; @@ -255,7 +265,10 @@ void ShowTooltipForTile(Window *w, const TileIndex tile) switch (GetTileType(tile)) { case MP_ROAD: - if (IsRoadDepot(tile)) return; + if (IsRoadDepot(tile)) { + ShowDepotTooltip(w, tile, buffer_start, buffer_tail); + return; + } /* FALL THROUGH */ case MP_HOUSE: { ShowTownNameTooltip(w, tile); @@ -265,6 +278,22 @@ void ShowTooltipForTile(Window *w, const TileIndex tile) ShowIndustryTooltip(w, tile, buffer_start, buffer_tail); break; } + case MP_RAILWAY: { + if (!IsRailDepot(tile)) return; + ShowDepotTooltip(w, tile, buffer_start, buffer_tail); + break; + } + case MP_WATER: { + if (!IsShipDepot(tile)) return; + ShowDepotTooltip(w, tile, buffer_start, buffer_tail); + break; + } + case MP_STATION: { + if (IsHangar(tile)) { + ShowDepotTooltip(w, tile, buffer_start, buffer_tail); + } + break; + } default: return; } From 5af7be6d1763acbbe7f53d0aa80ba6c66d48a57b Mon Sep 17 00:00:00 2001 From: RoqueDeicide Date: Sat, 1 Jul 2023 22:59:00 +0400 Subject: [PATCH 05/11] [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; } From 736c650b6c2d2dc3a64e1542927fa11227d2bd3c Mon Sep 17 00:00:00 2001 From: RoqueDeicide Date: Mon, 3 Jul 2023 19:14:27 +0400 Subject: [PATCH 06/11] [Change] Make town viewport tooltips functionally equivalent to town labels. --- src/lang/extra/english.txt | 4 +++- src/viewport_gui.cpp | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index 0c5c70f6fd..83a00492c1 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -1386,7 +1386,9 @@ STR_FINANCES_REPAY_QUERY_CAPT :{WHITE}Enter th STR_NEW_LINE :{} # Town tooltip -STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN} +STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN}{RAW_STRING} +STR_TOWN_NAME_POP_TOOLTIP :{BLACK}{TOWN}: {COMMA}{RAW_STRING} +STR_TOWN_NAME_RATING_TOOLTIP :{}Your rating is {STRING} STR_INDUSTRY_VIEW_NAME_TOOLTIP :{STRING} STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_FIRST :{STRING}{RAW_STRING} diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp index 61cb6f6f16..21a7173772 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -18,6 +18,7 @@ #include "window_func.h" #include "gfx_func.h" #include "industry.h" +#include "town.h" #include "town_map.h" #include "widgets/viewport_widget.h" @@ -225,12 +226,38 @@ enum TownNameTooltipMode : uint8 { TNTM_ALWAYS_ON }; -void ShowTownNameTooltip(Window *w, const TileIndex tile) +void ShowTownNameTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail) { if (_settings_client.gui.town_name_tooltip_mode == TNTM_OFF) return; if (HasBit(_display_opt, DO_SHOW_TOWN_NAMES) && _settings_client.gui.town_name_tooltip_mode == TNTM_ON_IF_HIDDEN) return; // No need for a town name tooltip when it is already displayed - SetDParam(0, GetTownIndex(tile)); - GuiShowTooltips(w, STR_TOWN_NAME_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); + + StringID tooltip_string = STR_TOWN_NAME_TOOLTIP; + TownID town_id = GetTownIndex(tile); + const Town *town = Town::Get(town_id); + *buffer_position = '\0'; + + if (_game_mode != GM_EDITOR && _local_company < MAX_COMPANIES && HasBit(town->have_ratings, _local_company)) { + int local_authority_rating_thresholds[] = { RATING_APPALLING, RATING_VERYPOOR, RATING_POOR, RATING_MEDIOCRE, RATING_GOOD, RATING_VERYGOOD, + RATING_EXCELLENT, RATING_OUTSTANDING }; + constexpr size_t threshold_count = lengthof(local_authority_rating_thresholds); + + auto local_rating = town->ratings[_local_company]; + auto rating_string = STR_CARGO_RATING_APPALLING; + for (int i = 0; i < threshold_count && local_rating > local_authority_rating_thresholds[i]; ++i) ++rating_string; + SetDParam(0, rating_string); + GetString(buffer_position, STR_TOWN_NAME_RATING_TOOLTIP, buffer_tail); + } + + uint rating_string_parameter_index = 1; + + SetDParam(0, town_id); + if (_settings_client.gui.population_in_label) { + tooltip_string = STR_TOWN_NAME_POP_TOOLTIP; + SetDParam(1, town->cache.population); + rating_string_parameter_index = 2; + } + SetDParamStr(rating_string_parameter_index, buffer_position); + GuiShowTooltips(w, tooltip_string, 0, nullptr, TCC_HOVER_VIEWPORT); } bool GetIndustryTooltipString(TileIndex tile, char *buffer_position, const char *buffer_tail); @@ -281,7 +308,7 @@ void ShowTooltipForTile(Window *w, const TileIndex tile) } /* FALL THROUGH */ case MP_HOUSE: { - ShowTownNameTooltip(w, tile); + ShowTownNameTooltip(w, tile, buffer_start, buffer_tail); break; } case MP_INDUSTRY: { From cadb2f3afc80da4836fb5ca700c95ab1ee05d02c Mon Sep 17 00:00:00 2001 From: RoqueDeicide Date: Tue, 4 Jul 2023 08:49:18 +0400 Subject: [PATCH 07/11] [Change] Added ability for detailed depot viewport tooltips to show single lines, if possible. Made some suggested adjustments. --- src/depot_gui.cpp | 8 +++++++- src/lang/extra/english.txt | 7 +++++-- src/station_gui.cpp | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index af32d6a69f..de90312602 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -1237,8 +1237,14 @@ bool GetDepotTooltipString(const TileIndex tile, char *buffer_position, const ch SetDParam(0, total_vehicle_count); - if (_settings_client.gui.depot_tooltip_mode == DTM_SIMPLE || stopped_vehicle_count == 0 && waiting_vehicle_count == 0 && consist_count == 0) { + if (_settings_client.gui.depot_tooltip_mode == DTM_SIMPLE || (stopped_vehicle_count == 0 && waiting_vehicle_count == 0 && consist_count == 0)) { GetString(buffer_position, STR_DEPOT_VIEW_COUNT_TOOLTIP, buffer_tail); + } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && total_vehicle_count == stopped_vehicle_count) { + GetString(buffer_position, STR_DEPOT_VIEW_COUNT_STOPPED_TOOLTIP, buffer_tail); + } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && total_vehicle_count == waiting_vehicle_count) { + GetString(buffer_position, STR_DEPOT_VIEW_COUNT_WAITING_TOOLTIP, buffer_tail); + } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && total_vehicle_count == consist_count) { + GetString(buffer_position, STR_DEPOT_VIEW_COUNT_CONSISTS_TOOLTIP, buffer_tail); } else { buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_TOTAL_TOOLTIP, buffer_tail); if (stopped_vehicle_count > 0) { diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index 186c38203e..4f786e3395 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -1414,8 +1414,11 @@ STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP :{CARGO_LONG} wa STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{CARGO_LONG}{RAW_STRING} ({COMMA}%) STR_INDUSTRY_VIEW_INFO_TOOLTIP :{BLACK}{RAW_STRING} -STR_DEPOT_VIEW_COUNT_TOOLTIP :{COMMA} indside -STR_DEPOT_VIEW_TOTAL_TOOLTIP :Of {COMMA} inside: +STR_DEPOT_VIEW_COUNT_TOOLTIP :{COMMA} vehicle{P "" s} {P is are} inside +STR_DEPOT_VIEW_COUNT_STOPPED_TOOLTIP :{COMMA} stopped vehicle{P "" s} {P is are} inside +STR_DEPOT_VIEW_COUNT_WAITING_TOOLTIP :{COMMA} waiting vehicle{P "" s} {P is are} inside +STR_DEPOT_VIEW_COUNT_CONSISTS_TOOLTIP :{COMMA} consist{P "" s} {P is are} inside +STR_DEPOT_VIEW_TOTAL_TOOLTIP :Of {COMMA} vehicles inside: STR_DEPOT_VIEW_STOPPED_TOOLTIP :{}{COMMA} {P is are} stopped STR_DEPOT_VIEW_WAITING_TOOLTIP :{}{COMMA} {P is are} waiting STR_DEPOT_VIEW_CONSISTS_TOOLTIP :{}{COMMA} {P is are} {P "a " ""}consist{P "" s} diff --git a/src/station_gui.cpp b/src/station_gui.cpp index b85dfc2f28..f896d7be6e 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -3112,8 +3112,8 @@ bool GetStationViewportTooltipString(const TileIndex tile, char *buffer_position 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)) { + 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); From 84e5aba1d7329d930506046e7c5ef59b1dffbc03 Mon Sep 17 00:00:00 2001 From: RoqueDeicide Date: Tue, 4 Jul 2023 11:11:59 +0400 Subject: [PATCH 08/11] [Change] Reworked stockpile settings into 1 dropdown. --- src/industry_gui.cpp | 14 ++++++++++++-- src/lang/extra/english.txt | 4 ++++ src/settings_gui.cpp | 1 - src/settings_type.h | 3 +-- src/table/settings/settings.ini | 19 +++++++------------ src/viewport_gui.cpp | 4 ---- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 1329a1a668..c13095e73c 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -3239,6 +3239,12 @@ void ShowIndustryCargoesWindow() ShowIndustryCargoesWindow(NUM_INDUSTRYTYPES); } +enum DisplayStockpiledCargoesMode : uint8 { + DSCM_OFF, + DSCM_REQUIRED, + DSCM_STOCKPILED +}; + /** * Fills given data buffer with a string of characters that describe given industry, to be used to display a tooltip, when hovering over the industry tile. * @param tile Index of the industry tile. @@ -3248,6 +3254,10 @@ void ShowIndustryCargoesWindow() */ bool GetIndustryTooltipString(const TileIndex tile, char *buffer_position, const char *buffer_tail) { + if (!_settings_client.gui.industry_tooltip_show || + !(_settings_client.gui.industry_tooltip_show_name || _settings_client.gui.industry_tooltip_show_produced || + _settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled != DSCM_OFF)) return false; + const Industry *industry = Industry::GetByTile(tile); const IndustrySpec *industry_spec = GetIndustrySpec(industry->type); @@ -3291,7 +3301,7 @@ bool GetIndustryTooltipString(const TileIndex tile, char *buffer_position, const bool isStockpileWithoutSuffix = suffix->display == CSD_CARGO_AMOUNT; bool isProperStockpileWithoutSuffix = isStockpileWithoutSuffix && stockpiling; // If callback 37 fails, the result is interpreted as a stockpile, for some reason. if (isStockpileWithSuffix || isProperStockpileWithoutSuffix) { - if (_settings_client.gui.industry_tooltip_show_stockpiled || !_settings_client.gui.industry_tooltip_show_stockpiled_as_required) continue; + if (_settings_client.gui.industry_tooltip_show_stockpiled != DSCM_REQUIRED) continue; } auto format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT; @@ -3321,7 +3331,7 @@ bool GetIndustryTooltipString(const TileIndex tile, char *buffer_position, const // Print out stockpiled cargo. - if (stockpiling && _settings_client.gui.industry_tooltip_show_stockpiled) { + if (stockpiling && _settings_client.gui.industry_tooltip_show_stockpiled == DSCM_STOCKPILED) { for (byte i = 0; i < accepted_cargo_count; ++i) { auto stockpiled_cargo = industry->accepts_cargo[i]; if (stockpiled_cargo == CT_INVALID) continue; diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index 4f786e3395..ff3b56ea2d 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -2174,6 +2174,10 @@ STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED :Show required c STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED_HELPTEXT :Show a list of cargoes required by industries in viewport tooltips when hovering over industry tiles. STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED :Show stockpiled cargoes in industry viewport tooltips: {STRING2} STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_HELPTEXT :Show a list of cargoes stockpiled by industries in viewport tooltips when hovering over industry tiles. +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_OFF :Don't show +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_REQUIRED :Show in the list of required cargoes, if the latter is shown +STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_STOCKPILED :Show as a list of amounts waiting to be processed + STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED :Show stockpiled cargoes as required in viewport tooltips: {STRING2} STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED_HELPTEXT:If normal display of stockpiled cargoes in viewport tooltips is disabled, then allow them to, at least, be displayed as required ones. STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED :Show produced cargoes in industry viewport tooltips: {STRING2} diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 754bffcd96..fa30ccb1dc 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1982,7 +1982,6 @@ static SettingsContainer &GetSettingsTree() tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_name", []() -> bool { return !_settings_client.gui.industry_tooltip_show; })); tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_required", []() -> bool { return !_settings_client.gui.industry_tooltip_show; })); tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_stockpiled", []() -> bool { return !_settings_client.gui.industry_tooltip_show; })); - 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")); diff --git a/src/settings_type.h b/src/settings_type.h index 2903bc054a..3c348a0659 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -144,8 +144,7 @@ struct GUISettings : public TimeSettings { bool industry_tooltip_show; ///< whether to display tooltips, when hovering over industry tiles. bool industry_tooltip_show_name; ///< whether to display the name of the industry, when hovering over one of its tiles. bool industry_tooltip_show_required; ///< whether to display cargoes required by the industry, when hovering over one of its tiles. - bool industry_tooltip_show_stockpiled; ///< whether to display cargoes stockpiled by the industry, when hovering over one of its tiles. - 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. + uint8 industry_tooltip_show_stockpiled; ///< whether and how to display cargoes stockpiled by the industry, when hovering over one of its tiles. 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) diff --git a/src/table/settings/settings.ini b/src/table/settings/settings.ini index 83e115a01e..3755b0b3ff 100644 --- a/src/table/settings/settings.ini +++ b/src/table/settings/settings.ini @@ -4584,22 +4584,17 @@ flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC def = false str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED_HELPTEXT -post_cb = [](auto) { InvalidateWindowClassesData(WC_GAME_OPTIONS); } -[SDTC_BOOL] +[SDTC_VAR] var = gui.industry_tooltip_show_stockpiled -flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC -def = false +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_INDUSTRY_TOOLTIP_STOCKPILED strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_HELPTEXT -post_cb = [](auto) { InvalidateWindowClassesData(WC_GAME_OPTIONS); } - -[SDTC_BOOL] -var = gui.industry_tooltip_show_stockpiled_as_required -flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC -def = true -str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED -strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED_HELPTEXT +strval = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_OFF [SDTC_BOOL] var = gui.industry_tooltip_show_produced diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp index 21a7173772..2b3a81a0c2 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -264,10 +264,6 @@ bool GetIndustryTooltipString(TileIndex tile, char *buffer_position, const char void ShowIndustryTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail) { - if (!_settings_client.gui.industry_tooltip_show || - !(_settings_client.gui.industry_tooltip_show_name || _settings_client.gui.industry_tooltip_show_produced || - _settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled)) return; - if (!GetIndustryTooltipString(tile, buffer_position, buffer_tail)) return; SetDParamStr(0, buffer_position); From 359ba9de68a6c3fa6f6ad1a9f3e16d8e6eb07ee6 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 4 Jul 2023 21:40:02 +0100 Subject: [PATCH 09/11] String handling adjustments for PR #564 --- src/depot_gui.cpp | 88 ++++++++++---------- src/industry_gui.cpp | 103 +++++++++-------------- src/lang/extra/english.txt | 23 +++--- src/lang/extra/galician.txt | 3 - src/lang/extra/german.txt | 3 - src/lang/extra/korean.txt | 3 - src/lang/extra/simplified_chinese.txt | 3 - src/station_gui.cpp | 48 ----------- src/strings.cpp | 5 -- src/viewport_gui.cpp | 112 ++++++++++++++------------ 10 files changed, 154 insertions(+), 237 deletions(-) diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index de90312602..8536088dcd 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -1201,66 +1201,68 @@ enum DepotTooltipMode : uint8 { DTM_DETAILED }; -bool GetDepotTooltipString(const TileIndex tile, char *buffer_position, const char *buffer_tail) +void ShowDepotTooltip(Window *w, const TileIndex tile) { if (_settings_client.gui.depot_tooltip_mode == DTM_OFF) { - return false; + return; } - size_t total_vehicle_count = 0; - size_t stopped_vehicle_count = 0; - size_t waiting_vehicle_count = 0; - size_t consist_count = 0; + struct depot_totals { + size_t total_vehicle_count = 0; + size_t stopped_vehicle_count = 0; + size_t waiting_vehicle_count = 0; + size_t consist_count = 0; + }; + depot_totals totals; - for (const Vehicle *v : Vehicle::Iterate()) { - if (v->tile == tile && !HasBit(v->subtype, GVSF_VIRTUAL) && v->IsInDepot()) { + FindVehicleOnPos(tile, GetDepotVehicleType(tile), &totals, [](Vehicle *v, void *data) -> Vehicle * { + depot_totals *totals = static_cast(data); + if (v->IsInDepot()) { if (v->IsPrimaryVehicle()) { - ++total_vehicle_count; - if (v->IsWaitingInDepot()) ++waiting_vehicle_count; - if (v->IsStoppedInDepot()) ++stopped_vehicle_count; + totals->total_vehicle_count++; + if (v->IsWaitingInDepot()) totals->waiting_vehicle_count++; + if (v->IsStoppedInDepot()) totals->stopped_vehicle_count++; } if (v->type == VEH_TRAIN) { - const Train *loco_or_wago = Train::From(v); - if (loco_or_wago->IsFreeWagon()) { - ++consist_count; - ++total_vehicle_count; + if (Train::From(v)->IsFreeWagon()) { + totals->consist_count++; + totals->total_vehicle_count++; } } } + return nullptr; + }); + + if (totals.total_vehicle_count == 0) { + return; } - buffer_position[0] = '\0'; + StringID str; - if (total_vehicle_count == 0) { - return false; - } - - SetDParam(0, total_vehicle_count); - - if (_settings_client.gui.depot_tooltip_mode == DTM_SIMPLE || (stopped_vehicle_count == 0 && waiting_vehicle_count == 0 && consist_count == 0)) { - GetString(buffer_position, STR_DEPOT_VIEW_COUNT_TOOLTIP, buffer_tail); - } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && total_vehicle_count == stopped_vehicle_count) { - GetString(buffer_position, STR_DEPOT_VIEW_COUNT_STOPPED_TOOLTIP, buffer_tail); - } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && total_vehicle_count == waiting_vehicle_count) { - GetString(buffer_position, STR_DEPOT_VIEW_COUNT_WAITING_TOOLTIP, buffer_tail); - } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && total_vehicle_count == consist_count) { - GetString(buffer_position, STR_DEPOT_VIEW_COUNT_CONSISTS_TOOLTIP, buffer_tail); + SetDParam(0, totals.total_vehicle_count); + if (_settings_client.gui.depot_tooltip_mode == DTM_SIMPLE || (totals.stopped_vehicle_count == 0 && totals.waiting_vehicle_count == 0 && totals.consist_count == 0)) { + str = STR_DEPOT_VIEW_COUNT_TOOLTIP; + } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && totals.total_vehicle_count == totals.stopped_vehicle_count) { + str = STR_DEPOT_VIEW_COUNT_STOPPED_TOOLTIP; + } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && totals.total_vehicle_count == totals.waiting_vehicle_count) { + str = STR_DEPOT_VIEW_COUNT_WAITING_TOOLTIP; + } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && totals.total_vehicle_count == totals.consist_count) { + str = STR_DEPOT_VIEW_COUNT_CONSISTS_TOOLTIP; } else { - buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_TOTAL_TOOLTIP, buffer_tail); - if (stopped_vehicle_count > 0) { - SetDParam(0, stopped_vehicle_count); - buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_STOPPED_TOOLTIP, buffer_tail); + str = SPECSTR_TEMP_START; + _temp_special_strings[0] = GetString(STR_DEPOT_VIEW_TOTAL_TOOLTIP); + if (totals.stopped_vehicle_count > 0) { + SetDParam(0, totals.stopped_vehicle_count); + _temp_special_strings[0] += GetString(STR_DEPOT_VIEW_STOPPED_TOOLTIP); } - if (waiting_vehicle_count > 0) { - SetDParam(0, waiting_vehicle_count); - buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_WAITING_TOOLTIP, buffer_tail); + if (totals.waiting_vehicle_count > 0) { + SetDParam(0, totals.waiting_vehicle_count); + _temp_special_strings[0] += GetString(STR_DEPOT_VIEW_WAITING_TOOLTIP); } - if (consist_count > 0) { - SetDParam(0, consist_count); - GetString(buffer_position, STR_DEPOT_VIEW_CONSISTS_TOOLTIP, buffer_tail); + if (totals.consist_count > 0) { + SetDParam(0, totals.consist_count); + _temp_special_strings[0] += GetString(STR_DEPOT_VIEW_CONSISTS_TOOLTIP); } - } - - return true; + GuiShowTooltips(w, str, 0, nullptr, TCC_HOVER_VIEWPORT); } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index c13095e73c..7dada67c74 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -3245,142 +3245,117 @@ enum DisplayStockpiledCargoesMode : uint8 { DSCM_STOCKPILED }; -/** - * Fills given data buffer with a string of characters that describe given industry, to be used to display a tooltip, when hovering over the industry tile. - * @param tile Index of the industry tile. - * @param buffer_position Pointer to the beginning of the data buffer to output the string into. - * @param buffer_tail Pointer to the last byte of the data buffer to output the string into. - * @returns A boolean value that indicates whether to show the tooltip. - */ -bool GetIndustryTooltipString(const TileIndex tile, char *buffer_position, const char *buffer_tail) +void ShowIndustryTooltip(Window *w, const TileIndex tile) { - if (!_settings_client.gui.industry_tooltip_show || - !(_settings_client.gui.industry_tooltip_show_name || _settings_client.gui.industry_tooltip_show_produced || - _settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled != DSCM_OFF)) return false; + if (!_settings_client.gui.industry_tooltip_show) return; + if (!(_settings_client.gui.industry_tooltip_show_name || _settings_client.gui.industry_tooltip_show_produced || + _settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled != DSCM_OFF)) return; const Industry *industry = Industry::GetByTile(tile); const IndustrySpec *industry_spec = GetIndustrySpec(industry->type); - buffer_position[0] = 0; - auto current_buffer_position = buffer_position; - auto next = false; + std::string msg; if (_settings_client.gui.industry_tooltip_show_name) { // Print out the name of the industry. SetDParam(0, industry_spec->name); - current_buffer_position = GetString(current_buffer_position, STR_INDUSTRY_VIEW_NAME_TOOLTIP, buffer_tail); - - next = true; + msg = GetString(STR_INDUSTRY_VIEW_NAME_TOOLTIP); } if (_settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled) { - constexpr auto accepted_cargo_count = lengthof(industry->accepts_cargo); + const size_t accepted_cargo_count = lengthof(industry->accepts_cargo); CargoSuffix suffixes[accepted_cargo_count]; GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, industry, industry->type, industry_spec, industry->accepts_cargo, suffixes); // Have to query the stockpiling right now, in case callback 37 returns fail. bool stockpiling = HasBit(industry_spec->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || - HasBit(industry_spec->callback_mask, CBM_IND_PRODUCTION_256_TICKS); + HasBit(industry_spec->callback_mask, CBM_IND_PRODUCTION_256_TICKS); if (_settings_client.gui.industry_tooltip_show_required) { // Print out required cargo. bool first = true; std::string required_cargo_list; - auto cargo_list_start_buffer_position = current_buffer_position; - for (byte i = 0; i < accepted_cargo_count; ++i) { - auto required_cargo = industry->accepts_cargo[i]; - if (required_cargo == CT_INVALID ) { + for (size_t i = 0; i < accepted_cargo_count; ++i) { + CargoID required_cargo = industry->accepts_cargo[i]; + if (required_cargo == CT_INVALID) { continue; } - auto suffix = &suffixes[i]; + const CargoSuffix &suffix = suffixes[i]; - bool isStockpileWithSuffix = suffix->display == CSD_CARGO_AMOUNT_TEXT; - bool isStockpileWithoutSuffix = suffix->display == CSD_CARGO_AMOUNT; - bool isProperStockpileWithoutSuffix = isStockpileWithoutSuffix && stockpiling; // If callback 37 fails, the result is interpreted as a stockpile, for some reason. - if (isStockpileWithSuffix || isProperStockpileWithoutSuffix) { + const bool is_stockpile_with_suffix = (suffix.display == CSD_CARGO_AMOUNT_TEXT); + const bool is_stockpile_without_suffix = (suffix.display == CSD_CARGO_AMOUNT); + const bool is_proper_stockpile_without_suffix = (is_stockpile_without_suffix && stockpiling); // If callback 37 fails, the result is interpreted as a stockpile, for some reason. + if (is_stockpile_with_suffix || is_proper_stockpile_without_suffix) { if (_settings_client.gui.industry_tooltip_show_stockpiled != DSCM_REQUIRED) continue; } - auto format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT; + StringID format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT; if (first) { format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_FIRST; first = false; } SetDParam(0, CargoSpec::Get(required_cargo)->name); - SetDParamStr(1, suffix->text); - GetString(cargo_list_start_buffer_position, format, buffer_tail); - required_cargo_list += cargo_list_start_buffer_position; + SetDParamStr(1, suffix.text); + required_cargo_list += GetString(format); } - - if (next && !required_cargo_list.empty()) { - current_buffer_position = GetString(current_buffer_position, STR_NEW_LINE, buffer_tail); - } - - current_buffer_position += required_cargo_list.copy(current_buffer_position, required_cargo_list.size()); - current_buffer_position[0] = '\0'; - //++current_buffer_position; if (!required_cargo_list.empty()) { - next = true; + if (!msg.empty()) msg += '\n'; + msg += required_cargo_list; } } // Print out stockpiled cargo. if (stockpiling && _settings_client.gui.industry_tooltip_show_stockpiled == DSCM_STOCKPILED) { - for (byte i = 0; i < accepted_cargo_count; ++i) { - auto stockpiled_cargo = industry->accepts_cargo[i]; + for (size_t i = 0; i < accepted_cargo_count; ++i) { + CargoID stockpiled_cargo = industry->accepts_cargo[i]; if (stockpiled_cargo == CT_INVALID) continue; - auto suffix = &suffixes[i]; + const CargoSuffix &suffix = suffixes[i]; - if (suffix->display == CSD_CARGO || suffix->display == CSD_CARGO_TEXT) { + if (suffix.display == CSD_CARGO || suffix.display == CSD_CARGO_TEXT) { continue; } - if (next) { - current_buffer_position = GetString(current_buffer_position, STR_NEW_LINE, buffer_tail); - } - - next = true; + if (!msg.empty()) msg += '\n'; SetDParam(0, stockpiled_cargo); SetDParam(1, industry->incoming_cargo_waiting[i]); - SetDParamStr(2, suffix->text); - current_buffer_position = GetString(current_buffer_position, STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP, buffer_tail); + SetDParamStr(2, suffix.text); + msg += GetString(STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP); } } } if (_settings_client.gui.industry_tooltip_show_produced) { - constexpr auto produced_cargo_count = lengthof(industry->produced_cargo); + const size_t produced_cargo_count = lengthof(industry->produced_cargo); CargoSuffix suffixes[produced_cargo_count]; GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_VIEW, industry, industry->type, industry_spec, industry->produced_cargo, suffixes); - + // Print out amounts of produced cargo. - - for (byte i = 0; i < produced_cargo_count; i++) { - auto produced_cargo = industry->produced_cargo[i]; + + for (size_t i = 0; i < produced_cargo_count; i++) { + CargoID produced_cargo = industry->produced_cargo[i]; if (produced_cargo == CT_INVALID) continue; - if (next) { - current_buffer_position = GetString(current_buffer_position, STR_NEW_LINE, buffer_tail); - } - - next = true; + if (!msg.empty()) msg += '\n'; SetDParam(0, produced_cargo); SetDParam(1, industry->last_month_production[i]); SetDParamStr(2, suffixes[i].text); SetDParam(3, ToPercent8(industry->last_month_pct_transported[i])); - current_buffer_position = GetString(current_buffer_position, STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION, buffer_tail); + msg += GetString(STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION); } } - return next; + if (!msg.empty()) { + _temp_special_strings[0] = std::move(msg); + GuiShowTooltips(w, SPECSTR_TEMP_START, 0, nullptr, TCC_HOVER_VIEWPORT); + } } diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index ff3b56ea2d..5916afe6e8 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -1400,33 +1400,28 @@ STR_FINANCES_REPAY_TOOLTIP_EXTRA :{BLACK}{STRING} STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}Enter the amount of money to borrow STR_FINANCES_REPAY_QUERY_CAPT :{WHITE}Enter the amount of money to repay -STR_NEW_LINE :{} - # Town tooltip -STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN}{RAW_STRING} -STR_TOWN_NAME_POP_TOOLTIP :{BLACK}{TOWN}: {COMMA}{RAW_STRING} -STR_TOWN_NAME_RATING_TOOLTIP :{}Your rating is {STRING} +STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN} +STR_TOWN_NAME_POP_TOOLTIP :{BLACK}{TOWN}: {COMMA} +STR_TOWN_NAME_RATING_TOOLTIP :{STRING2}{}Your rating is {STRING} STR_INDUSTRY_VIEW_NAME_TOOLTIP :{STRING} STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_FIRST :{STRING}{RAW_STRING} STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT :, {STRING}{RAW_STRING} STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP :{CARGO_LONG} waiting{RAW_STRING} STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{CARGO_LONG}{RAW_STRING} ({COMMA}%) -STR_INDUSTRY_VIEW_INFO_TOOLTIP :{BLACK}{RAW_STRING} -STR_DEPOT_VIEW_COUNT_TOOLTIP :{COMMA} vehicle{P "" s} {P is are} inside -STR_DEPOT_VIEW_COUNT_STOPPED_TOOLTIP :{COMMA} stopped vehicle{P "" s} {P is are} inside -STR_DEPOT_VIEW_COUNT_WAITING_TOOLTIP :{COMMA} waiting vehicle{P "" s} {P is are} inside -STR_DEPOT_VIEW_COUNT_CONSISTS_TOOLTIP :{COMMA} consist{P "" s} {P is are} inside -STR_DEPOT_VIEW_TOTAL_TOOLTIP :Of {COMMA} vehicles inside: +STR_DEPOT_VIEW_COUNT_TOOLTIP :{BLACK}{COMMA} vehicle{P "" s} {P is are} inside +STR_DEPOT_VIEW_COUNT_STOPPED_TOOLTIP :{BLACK}{COMMA} stopped vehicle{P "" s} {P is are} inside +STR_DEPOT_VIEW_COUNT_WAITING_TOOLTIP :{BLACK}{COMMA} waiting vehicle{P "" s} {P is are} inside +STR_DEPOT_VIEW_COUNT_CONSISTS_TOOLTIP :{BLACK}{COMMA} consist{P "" s} {P is are} inside +STR_DEPOT_VIEW_TOTAL_TOOLTIP :{BLACK}Of {COMMA} vehicles inside: STR_DEPOT_VIEW_STOPPED_TOOLTIP :{}{COMMA} {P is are} stopped STR_DEPOT_VIEW_WAITING_TOOLTIP :{}{COMMA} {P is are} waiting 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_NAME_TOOLTIP :{STATION}{NBSP}{STATION_FEATURES} 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}) diff --git a/src/lang/extra/galician.txt b/src/lang/extra/galician.txt index fc3e4b86f3..76cbe167c0 100644 --- a/src/lang/extra/galician.txt +++ b/src/lang/extra/galician.txt @@ -1375,9 +1375,6 @@ STR_FINANCES_REPAY_TOOLTIP_EXTRA :{BLACK}{STRING} STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}Introduce a cantidade de cartos para pedir prestados STR_FINANCES_REPAY_QUERY_CAPT :{WHITE}Introduce a cantidade de cartos para devolver -STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP :{BLACK}{STRING}{STRING} -STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{}{BLACK}{CARGO_LONG} ({COMMA}%) - # Town tooltip STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN} diff --git a/src/lang/extra/german.txt b/src/lang/extra/german.txt index 9700a16950..0db289d3b9 100644 --- a/src/lang/extra/german.txt +++ b/src/lang/extra/german.txt @@ -1245,9 +1245,6 @@ STR_FINANCES_REPAY_TOOLTIP_EXTRA :{BLACK}{STRING} STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}Gib die zu leihende Summe ein STR_FINANCES_REPAY_QUERY_CAPT :{WHITE}Gib die zurückzuzahlende Summe ein -STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP :{BLACK}{STRING}{STRING} -STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{}{BLACK}{CARGO_LONG} ({COMMA}%) - # Town tooltip STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN} diff --git a/src/lang/extra/korean.txt b/src/lang/extra/korean.txt index 4b8eb5ff56..7449099c3d 100644 --- a/src/lang/extra/korean.txt +++ b/src/lang/extra/korean.txt @@ -1364,9 +1364,6 @@ STR_FINANCES_REPAY_TOOLTIP_EXTRA :{BLACK}{STRING} STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}빌릴 돈의 양을 입력하세요 STR_FINANCES_REPAY_QUERY_CAPT :{WHITE}갚을 돈의 양을 입력하세요 -STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP :{BLACK}{STRING}{STRING} -STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{}{BLACK}{CARGO_LONG} ({COMMA}%) - # Town tooltip STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN} diff --git a/src/lang/extra/simplified_chinese.txt b/src/lang/extra/simplified_chinese.txt index 13c154bd44..4212bee978 100644 --- a/src/lang/extra/simplified_chinese.txt +++ b/src/lang/extra/simplified_chinese.txt @@ -1312,9 +1312,6 @@ STR_FINANCES_REPAY_TOOLTIP_EXTRA :{BLACK}{STRING} STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}输入贷款总额 STR_FINANCES_REPAY_QUERY_CAPT :{WHITE}输入还款总额 -STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP :{BLACK}{STRING}{STRING} -STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{}{BLACK}{CARGO_LONG}({COMMA}%) - # Town tooltip STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN} diff --git a/src/station_gui.cpp b/src/station_gui.cpp index f896d7be6e..9bc75ea932 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -3096,51 +3096,3 @@ 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 41d8f891b6..b16d7d9691 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -2047,11 +2047,6 @@ 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/viewport_gui.cpp b/src/viewport_gui.cpp index 2b3a81a0c2..1c99549f1f 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -226,106 +226,116 @@ enum TownNameTooltipMode : uint8 { TNTM_ALWAYS_ON }; -void ShowTownNameTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail) +enum StationTooltipNameMode : uint8 { + STNM_OFF, + STNM_ON_IF_HIDDEN, + STNM_ALWAYS_ON +}; + +void ShowTownNameTooltip(Window *w, const TileIndex tile) { if (_settings_client.gui.town_name_tooltip_mode == TNTM_OFF) return; if (HasBit(_display_opt, DO_SHOW_TOWN_NAMES) && _settings_client.gui.town_name_tooltip_mode == TNTM_ON_IF_HIDDEN) return; // No need for a town name tooltip when it is already displayed - StringID tooltip_string = STR_TOWN_NAME_TOOLTIP; TownID town_id = GetTownIndex(tile); const Town *town = Town::Get(town_id); - *buffer_position = '\0'; - if (_game_mode != GM_EDITOR && _local_company < MAX_COMPANIES && HasBit(town->have_ratings, _local_company)) { - int local_authority_rating_thresholds[] = { RATING_APPALLING, RATING_VERYPOOR, RATING_POOR, RATING_MEDIOCRE, RATING_GOOD, RATING_VERYGOOD, + if (_settings_client.gui.population_in_label) { + SetDParam(0, STR_TOWN_NAME_POP_TOOLTIP); + SetDParam(1, town_id); + SetDParam(2, town->cache.population); + } else { + SetDParam(0, STR_TOWN_NAME_TOOLTIP); + SetDParam(1, town_id); + } + + StringID tooltip_string; + if (_game_mode == GM_NORMAL && _local_company < MAX_COMPANIES && HasBit(town->have_ratings, _local_company)) { + const int local_authority_rating_thresholds[] = { RATING_APPALLING, RATING_VERYPOOR, RATING_POOR, RATING_MEDIOCRE, RATING_GOOD, RATING_VERYGOOD, RATING_EXCELLENT, RATING_OUTSTANDING }; constexpr size_t threshold_count = lengthof(local_authority_rating_thresholds); - auto local_rating = town->ratings[_local_company]; - auto rating_string = STR_CARGO_RATING_APPALLING; - for (int i = 0; i < threshold_count && local_rating > local_authority_rating_thresholds[i]; ++i) ++rating_string; - SetDParam(0, rating_string); - GetString(buffer_position, STR_TOWN_NAME_RATING_TOOLTIP, buffer_tail); + int local_rating = town->ratings[_local_company]; + StringID rating_string = STR_CARGO_RATING_APPALLING; + for (size_t i = 0; i < threshold_count && local_rating > local_authority_rating_thresholds[i]; ++i) ++rating_string; + SetDParam(3, rating_string); + tooltip_string = STR_TOWN_NAME_RATING_TOOLTIP; + } else { + tooltip_string = STR_JUST_STRING2; } - - uint rating_string_parameter_index = 1; - - SetDParam(0, town_id); - if (_settings_client.gui.population_in_label) { - tooltip_string = STR_TOWN_NAME_POP_TOOLTIP; - SetDParam(1, town->cache.population); - rating_string_parameter_index = 2; - } - SetDParamStr(rating_string_parameter_index, buffer_position); GuiShowTooltips(w, tooltip_string, 0, nullptr, TCC_HOVER_VIEWPORT); } -bool GetIndustryTooltipString(TileIndex tile, char *buffer_position, const char *buffer_tail); - -void ShowIndustryTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail) +void ShowStationViewportTooltip(Window *w, const TileIndex tile) { - if (!GetIndustryTooltipString(tile, buffer_position, buffer_tail)) return; + const StationID station_id = GetStationIndex(tile); + const Station *station = Station::Get(station_id); - SetDParamStr(0, buffer_position); - GuiShowTooltips(w, STR_INDUSTRY_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); -} + std::string msg; -bool GetDepotTooltipString(TileIndex tile, char *buffer_position, const char *buffer_tail); + 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); + SetDParam(1, station->facilities); + msg = GetString(STR_STATION_VIEW_NAME_TOOLTIP); + } -void ShowDepotTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail) -{ - if (!GetDepotTooltipString(tile, buffer_position, buffer_tail)) return; + if (_settings_client.gui.station_viewport_tooltip_cargo) { + for (const CargoSpec *cs : _sorted_standard_cargo_specs) { + const GoodsEntry *goods_entry = &station->goods[cs->Index()]; + if (!goods_entry->HasRating()) continue; - SetDParamStr(0, buffer_position); - GuiShowTooltips(w, STR_DEPOT_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); -} + if (!msg.empty()) msg += '\n'; -bool GetStationViewportTooltipString(TileIndex tile, char *buffer_position, const char *buffer_tail); + SetDParam(0, cs->name); + SetDParam(1, ToPercent8(goods_entry->rating)); + SetDParam(2, cs->Index()); + SetDParam(3, goods_entry->cargo.TotalCount()); + msg += GetString(STR_STATION_VIEW_CARGO_LINE_TOOLTIP); + } + } -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); + if (!msg.empty()) { + _temp_special_strings[0] = std::move(msg); + GuiShowTooltips(w, SPECSTR_TEMP_START, 0, nullptr, TCC_HOVER_VIEWPORT); + } } void ShowTooltipForTile(Window *w, const TileIndex tile) { - static char buffer[1024]; - char *buffer_start = buffer; - char *buffer_tail = lastof(buffer); + extern void ShowDepotTooltip(Window *w, const TileIndex tile); + extern void ShowIndustryTooltip(Window *w, const TileIndex tile); switch (GetTileType(tile)) { case MP_ROAD: if (IsRoadDepot(tile)) { - ShowDepotTooltip(w, tile, buffer_start, buffer_tail); + ShowDepotTooltip(w, tile); return; } /* FALL THROUGH */ case MP_HOUSE: { - ShowTownNameTooltip(w, tile, buffer_start, buffer_tail); + ShowTownNameTooltip(w, tile); break; } case MP_INDUSTRY: { - ShowIndustryTooltip(w, tile, buffer_start, buffer_tail); + ShowIndustryTooltip(w, tile); break; } case MP_RAILWAY: { if (!IsRailDepot(tile)) return; - ShowDepotTooltip(w, tile, buffer_start, buffer_tail); + ShowDepotTooltip(w, tile); break; } case MP_WATER: { if (!IsShipDepot(tile)) return; - ShowDepotTooltip(w, tile, buffer_start, buffer_tail); + ShowDepotTooltip(w, tile); break; } case MP_STATION: { if (IsHangar(tile)) { - ShowDepotTooltip(w, tile, buffer_start, buffer_tail); + ShowDepotTooltip(w, tile); } else { - ShowStationViewportTooltip(w, tile, buffer_start, buffer_tail); + ShowStationViewportTooltip(w, tile); } break; } From 5d7721a2d4b9c7ea7b0381a49036d82ed3871be3 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 4 Jul 2023 22:10:32 +0100 Subject: [PATCH 10/11] Fix handling of free wagons in depot tooltip See: #564 --- src/depot_gui.cpp | 41 +++++++++++++++++++++++--------------- src/lang/extra/english.txt | 12 +++++------ 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 8536088dcd..76827f8546 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -1208,10 +1208,10 @@ void ShowDepotTooltip(Window *w, const TileIndex tile) } struct depot_totals { - size_t total_vehicle_count = 0; - size_t stopped_vehicle_count = 0; - size_t waiting_vehicle_count = 0; - size_t consist_count = 0; + uint total_vehicle_count = 0; + uint stopped_vehicle_count = 0; + uint waiting_vehicle_count = 0; + uint free_wagon_count = 0; }; depot_totals totals; @@ -1224,9 +1224,11 @@ void ShowDepotTooltip(Window *w, const TileIndex tile) if (v->IsStoppedInDepot()) totals->stopped_vehicle_count++; } if (v->type == VEH_TRAIN) { - if (Train::From(v)->IsFreeWagon()) { - totals->consist_count++; - totals->total_vehicle_count++; + const Train *t = Train::From(v); + if (t->IsFreeWagon()) { + for (const Train *u = t; u != nullptr; u = u->GetNextUnit()) { + totals->free_wagon_count++; + } } } } @@ -1234,20 +1236,22 @@ void ShowDepotTooltip(Window *w, const TileIndex tile) }); if (totals.total_vehicle_count == 0) { + if (totals.free_wagon_count > 0) { + SetDParam(0, totals.free_wagon_count); + GuiShowTooltips(w, STR_DEPOT_VIEW_FREE_WAGONS_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); + } return; } StringID str; SetDParam(0, totals.total_vehicle_count); - if (_settings_client.gui.depot_tooltip_mode == DTM_SIMPLE || (totals.stopped_vehicle_count == 0 && totals.waiting_vehicle_count == 0 && totals.consist_count == 0)) { + if (_settings_client.gui.depot_tooltip_mode == DTM_SIMPLE || (totals.stopped_vehicle_count == 0 && totals.waiting_vehicle_count == 0)) { str = STR_DEPOT_VIEW_COUNT_TOOLTIP; - } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && totals.total_vehicle_count == totals.stopped_vehicle_count) { + } else if (totals.total_vehicle_count == totals.stopped_vehicle_count) { str = STR_DEPOT_VIEW_COUNT_STOPPED_TOOLTIP; - } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && totals.total_vehicle_count == totals.waiting_vehicle_count) { + } else if (totals.total_vehicle_count == totals.waiting_vehicle_count) { str = STR_DEPOT_VIEW_COUNT_WAITING_TOOLTIP; - } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && totals.total_vehicle_count == totals.consist_count) { - str = STR_DEPOT_VIEW_COUNT_CONSISTS_TOOLTIP; } else { str = SPECSTR_TEMP_START; _temp_special_strings[0] = GetString(STR_DEPOT_VIEW_TOTAL_TOOLTIP); @@ -1259,10 +1263,15 @@ void ShowDepotTooltip(Window *w, const TileIndex tile) SetDParam(0, totals.waiting_vehicle_count); _temp_special_strings[0] += GetString(STR_DEPOT_VIEW_WAITING_TOOLTIP); } - if (totals.consist_count > 0) { - SetDParam(0, totals.consist_count); - _temp_special_strings[0] += GetString(STR_DEPOT_VIEW_CONSISTS_TOOLTIP); - } } + + if (totals.free_wagon_count > 0) { + SetDParam(0, str); + SetDParam(1, totals.total_vehicle_count); + SetDParam(2, STR_DEPOT_VIEW_FREE_WAGONS_TOOLTIP); + SetDParam(3, totals.free_wagon_count); + str = STR_DEPOT_VIEW_MIXED_CONTENTS_TOOLTIP; + } + GuiShowTooltips(w, str, 0, nullptr, TCC_HOVER_VIEWPORT); } diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index 5916afe6e8..e9db278b76 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -1411,14 +1411,14 @@ STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT :, {STRING}{RAW_ STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP :{CARGO_LONG} waiting{RAW_STRING} STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{CARGO_LONG}{RAW_STRING} ({COMMA}%) -STR_DEPOT_VIEW_COUNT_TOOLTIP :{BLACK}{COMMA} vehicle{P "" s} {P is are} inside -STR_DEPOT_VIEW_COUNT_STOPPED_TOOLTIP :{BLACK}{COMMA} stopped vehicle{P "" s} {P is are} inside -STR_DEPOT_VIEW_COUNT_WAITING_TOOLTIP :{BLACK}{COMMA} waiting vehicle{P "" s} {P is are} inside -STR_DEPOT_VIEW_COUNT_CONSISTS_TOOLTIP :{BLACK}{COMMA} consist{P "" s} {P is are} inside -STR_DEPOT_VIEW_TOTAL_TOOLTIP :{BLACK}Of {COMMA} vehicles inside: +STR_DEPOT_VIEW_COUNT_TOOLTIP :{BLACK}{COMMA} vehicle{P "" s} inside +STR_DEPOT_VIEW_COUNT_STOPPED_TOOLTIP :{BLACK}{COMMA} stopped vehicle{P "" s} inside +STR_DEPOT_VIEW_COUNT_WAITING_TOOLTIP :{BLACK}{COMMA} waiting vehicle{P "" s} inside +STR_DEPOT_VIEW_TOTAL_TOOLTIP :{BLACK}{COMMA} vehicles inside: STR_DEPOT_VIEW_STOPPED_TOOLTIP :{}{COMMA} {P is are} stopped STR_DEPOT_VIEW_WAITING_TOOLTIP :{}{COMMA} {P is are} waiting -STR_DEPOT_VIEW_CONSISTS_TOOLTIP :{}{COMMA} {P is are} {P "a " ""}consist{P "" s} +STR_DEPOT_VIEW_FREE_WAGONS_TOOLTIP :{BLACK}{COMMA} wagon{P "" s} inside +STR_DEPOT_VIEW_MIXED_CONTENTS_TOOLTIP :{BLACK}{STRING1}{}{STRING1} STR_STATION_VIEW_NAME_TOOLTIP :{STATION}{NBSP}{STATION_FEATURES} STR_STATION_VIEW_CARGO_LINE_TOOLTIP :{STRING} ({COMMA}%): {CARGO_SHORT} From 3e03cebad15646ba27e7921402c3916df9f5d3bc Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 4 Jul 2023 22:32:35 +0100 Subject: [PATCH 11/11] Simplify industry_tooltip_show_stockpiled setting See: #564 --- src/industry_gui.cpp | 12 +++--------- src/lang/extra/english.txt | 5 ----- src/settings_type.h | 2 +- src/table/settings/settings.ini | 10 +++------- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 7dada67c74..4dffaefca5 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -3239,17 +3239,11 @@ void ShowIndustryCargoesWindow() ShowIndustryCargoesWindow(NUM_INDUSTRYTYPES); } -enum DisplayStockpiledCargoesMode : uint8 { - DSCM_OFF, - DSCM_REQUIRED, - DSCM_STOCKPILED -}; - void ShowIndustryTooltip(Window *w, const TileIndex tile) { if (!_settings_client.gui.industry_tooltip_show) return; if (!(_settings_client.gui.industry_tooltip_show_name || _settings_client.gui.industry_tooltip_show_produced || - _settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled != DSCM_OFF)) return; + _settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled)) return; const Industry *industry = Industry::GetByTile(tile); const IndustrySpec *industry_spec = GetIndustrySpec(industry->type); @@ -3289,7 +3283,7 @@ void ShowIndustryTooltip(Window *w, const TileIndex tile) const bool is_stockpile_without_suffix = (suffix.display == CSD_CARGO_AMOUNT); const bool is_proper_stockpile_without_suffix = (is_stockpile_without_suffix && stockpiling); // If callback 37 fails, the result is interpreted as a stockpile, for some reason. if (is_stockpile_with_suffix || is_proper_stockpile_without_suffix) { - if (_settings_client.gui.industry_tooltip_show_stockpiled != DSCM_REQUIRED) continue; + if (_settings_client.gui.industry_tooltip_show_stockpiled) continue; } StringID format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT; @@ -3311,7 +3305,7 @@ void ShowIndustryTooltip(Window *w, const TileIndex tile) // Print out stockpiled cargo. - if (stockpiling && _settings_client.gui.industry_tooltip_show_stockpiled == DSCM_STOCKPILED) { + if (stockpiling && _settings_client.gui.industry_tooltip_show_stockpiled) { for (size_t i = 0; i < accepted_cargo_count; ++i) { CargoID stockpiled_cargo = industry->accepts_cargo[i]; if (stockpiled_cargo == CT_INVALID) continue; diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index e9db278b76..060fb598f3 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -2169,12 +2169,7 @@ STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED :Show required c STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED_HELPTEXT :Show a list of cargoes required by industries in viewport tooltips when hovering over industry tiles. STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED :Show stockpiled cargoes in industry viewport tooltips: {STRING2} STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_HELPTEXT :Show a list of cargoes stockpiled by industries in viewport tooltips when hovering over industry tiles. -STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_OFF :Don't show -STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_REQUIRED :Show in the list of required cargoes, if the latter is shown -STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_STOCKPILED :Show as a list of amounts waiting to be processed -STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED :Show stockpiled cargoes as required in viewport tooltips: {STRING2} -STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED_HELPTEXT:If normal display of stockpiled cargoes in viewport tooltips is disabled, then allow them to, at least, be displayed as required ones. STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED :Show produced cargoes in industry viewport tooltips: {STRING2} STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED_HELPTEXT :Show a list of cargoes produced by industries in viewport tooltips when hovering over industry tiles. diff --git a/src/settings_type.h b/src/settings_type.h index 3c348a0659..93b25804bc 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -144,7 +144,7 @@ struct GUISettings : public TimeSettings { bool industry_tooltip_show; ///< whether to display tooltips, when hovering over industry tiles. bool industry_tooltip_show_name; ///< whether to display the name of the industry, when hovering over one of its tiles. bool industry_tooltip_show_required; ///< whether to display cargoes required by the industry, when hovering over one of its tiles. - uint8 industry_tooltip_show_stockpiled; ///< whether and how to display cargoes stockpiled by the industry, when hovering over one of its tiles. + bool industry_tooltip_show_stockpiled; ///< whether to display cargoes stockpiled by the industry, when hovering over one of its tiles. 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) diff --git a/src/table/settings/settings.ini b/src/table/settings/settings.ini index 3755b0b3ff..9b05e66bc2 100644 --- a/src/table/settings/settings.ini +++ b/src/table/settings/settings.ini @@ -4585,16 +4585,12 @@ def = false str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED_HELPTEXT -[SDTC_VAR] +[SDTC_BOOL] var = gui.industry_tooltip_show_stockpiled -type = SLE_UINT8 -flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN -def = 1 -min = 0 -max = 2 +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC +def = false str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_HELPTEXT -strval = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_OFF [SDTC_BOOL] var = gui.industry_tooltip_show_produced