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; }