diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 28a0d6f9fd..76827f8546 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -1194,3 +1194,84 @@ void DeleteDepotHighlightOfVehicle(const Vehicle *v) if (w->sel == v->index) ResetObjectToPlace(); } } + +enum DepotTooltipMode : uint8 { + DTM_OFF, + DTM_SIMPLE, + DTM_DETAILED +}; + +void ShowDepotTooltip(Window *w, const TileIndex tile) +{ + if (_settings_client.gui.depot_tooltip_mode == DTM_OFF) { + return; + } + + struct depot_totals { + uint total_vehicle_count = 0; + uint stopped_vehicle_count = 0; + uint waiting_vehicle_count = 0; + uint free_wagon_count = 0; + }; + depot_totals totals; + + FindVehicleOnPos(tile, GetDepotVehicleType(tile), &totals, [](Vehicle *v, void *data) -> Vehicle * { + depot_totals *totals = static_cast(data); + if (v->IsInDepot()) { + if (v->IsPrimaryVehicle()) { + 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 *t = Train::From(v); + if (t->IsFreeWagon()) { + for (const Train *u = t; u != nullptr; u = u->GetNextUnit()) { + totals->free_wagon_count++; + } + } + } + } + return nullptr; + }); + + 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)) { + str = STR_DEPOT_VIEW_COUNT_TOOLTIP; + } else if (totals.total_vehicle_count == totals.stopped_vehicle_count) { + str = STR_DEPOT_VIEW_COUNT_STOPPED_TOOLTIP; + } else if (totals.total_vehicle_count == totals.waiting_vehicle_count) { + str = STR_DEPOT_VIEW_COUNT_WAITING_TOOLTIP; + } else { + 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 (totals.waiting_vehicle_count > 0) { + SetDParam(0, totals.waiting_vehicle_count); + _temp_special_strings[0] += GetString(STR_DEPOT_VIEW_WAITING_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/industry_gui.cpp b/src/industry_gui.cpp index eabcbb7a7e..4dffaefca5 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -3238,3 +3238,118 @@ void ShowIndustryCargoesWindow() { ShowIndustryCargoesWindow(NUM_INDUSTRYTYPES); } + +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)) return; + + const Industry *industry = Industry::GetByTile(tile); + const IndustrySpec *industry_spec = GetIndustrySpec(industry->type); + + std::string msg; + + if (_settings_client.gui.industry_tooltip_show_name) { + // Print out the name of the industry. + SetDParam(0, industry_spec->name); + msg = GetString(STR_INDUSTRY_VIEW_NAME_TOOLTIP); + } + + if (_settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled) { + 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); + + if (_settings_client.gui.industry_tooltip_show_required) { + // Print out required cargo. + bool first = true; + std::string required_cargo_list; + + for (size_t i = 0; i < accepted_cargo_count; ++i) { + CargoID required_cargo = industry->accepts_cargo[i]; + if (required_cargo == CT_INVALID) { + continue; + } + + const CargoSuffix &suffix = suffixes[i]; + + 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) continue; + } + + 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); + required_cargo_list += GetString(format); + } + + if (!required_cargo_list.empty()) { + if (!msg.empty()) msg += '\n'; + msg += required_cargo_list; + } + } + + // Print out stockpiled cargo. + + 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; + + const CargoSuffix &suffix = suffixes[i]; + + if (suffix.display == CSD_CARGO || suffix.display == CSD_CARGO_TEXT) { + continue; + } + + if (!msg.empty()) msg += '\n'; + + SetDParam(0, stockpiled_cargo); + SetDParam(1, industry->incoming_cargo_waiting[i]); + SetDParamStr(2, suffix.text); + msg += GetString(STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP); + } + } + } + + if (_settings_client.gui.industry_tooltip_show_produced) { + 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 (size_t i = 0; i < produced_cargo_count; i++) { + CargoID produced_cargo = industry->produced_cargo[i]; + if (produced_cargo == CT_INVALID) continue; + + 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])); + msg += GetString(STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION); + } + } + + 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 2e4254f369..060fb598f3 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 @@ -1406,11 +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_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP :{BLACK}{STRING}{RAW_STRING} -STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{}{BLACK}{CARGO_LONG} ({COMMA}%) - # Town tooltip 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_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_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} 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}) @@ -2139,5 +2150,45 @@ 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_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_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_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_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 +STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_SIMPLE :Simple +STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_DETAILED :Detailed 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/settings_gui.cpp b/src/settings_gui.cpp index 8b290d4275..fa30ccb1dc 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1967,14 +1967,28 @@ 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.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_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")); + } + SettingsPage *save = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_SAVE)); { save->Add(new SettingEntry("gui.autosave")); @@ -2134,7 +2148,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 3e52040561..93b25804bc 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -140,6 +140,16 @@ 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) + 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_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 uint8 scroll_mode; ///< viewport scroll mode @@ -256,7 +266,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 6e6c86ea6b..9b05e66bc2 100644 --- a/src/table/settings/settings.ini +++ b/src/table/settings/settings.ini @@ -4552,6 +4552,93 @@ 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_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 + +[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 + +[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.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_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 +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 @@ -5732,17 +5819,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 diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp index feb961069d..1c99549f1f 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" @@ -219,37 +220,123 @@ 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 +}; + +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 + + TownID town_id = GetTownIndex(tile); + const Town *town = Town::Get(town_id); + + 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); + + 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; + } + GuiShowTooltips(w, tooltip_string, 0, nullptr, TCC_HOVER_VIEWPORT); +} + +void ShowStationViewportTooltip(Window *w, const TileIndex tile) +{ + const StationID station_id = GetStationIndex(tile); + const Station *station = Station::Get(station_id); + + std::string msg; + + 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); + } + + 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; + + if (!msg.empty()) msg += '\n'; + + 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); + } + } + + 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) { + 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)) return; + if (IsRoadDepot(tile)) { + ShowDepotTooltip(w, 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: { - 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)); - } + ShowIndustryTooltip(w, tile); + break; + } + case MP_RAILWAY: { + if (!IsRailDepot(tile)) return; + ShowDepotTooltip(w, tile); + break; + } + case MP_WATER: { + if (!IsShipDepot(tile)) return; + ShowDepotTooltip(w, tile); + break; + } + case MP_STATION: { + if (IsHangar(tile)) { + ShowDepotTooltip(w, tile); + } else { + ShowStationViewportTooltip(w, tile); } - SetDParam(0, indsp->name); - SetDParamStr(1, buffer); - GuiShowTooltips(w, STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT); break; } default: