String handling adjustments for PR #564

This commit is contained in:
Jonathan G Rennison
2023-07-04 21:40:02 +01:00
parent 84e5aba1d7
commit 359ba9de68
10 changed files with 154 additions and 237 deletions

View File

@@ -1201,66 +1201,68 @@ enum DepotTooltipMode : uint8 {
DTM_DETAILED 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) { if (_settings_client.gui.depot_tooltip_mode == DTM_OFF) {
return false; return;
} }
struct depot_totals {
size_t total_vehicle_count = 0; size_t total_vehicle_count = 0;
size_t stopped_vehicle_count = 0; size_t stopped_vehicle_count = 0;
size_t waiting_vehicle_count = 0; size_t waiting_vehicle_count = 0;
size_t consist_count = 0; size_t consist_count = 0;
};
depot_totals totals;
for (const Vehicle *v : Vehicle::Iterate()) { FindVehicleOnPos(tile, GetDepotVehicleType(tile), &totals, [](Vehicle *v, void *data) -> Vehicle * {
if (v->tile == tile && !HasBit(v->subtype, GVSF_VIRTUAL) && v->IsInDepot()) { depot_totals *totals = static_cast<depot_totals *>(data);
if (v->IsInDepot()) {
if (v->IsPrimaryVehicle()) { if (v->IsPrimaryVehicle()) {
++total_vehicle_count; totals->total_vehicle_count++;
if (v->IsWaitingInDepot()) ++waiting_vehicle_count; if (v->IsWaitingInDepot()) totals->waiting_vehicle_count++;
if (v->IsStoppedInDepot()) ++stopped_vehicle_count; if (v->IsStoppedInDepot()) totals->stopped_vehicle_count++;
} }
if (v->type == VEH_TRAIN) { if (v->type == VEH_TRAIN) {
const Train *loco_or_wago = Train::From(v); if (Train::From(v)->IsFreeWagon()) {
if (loco_or_wago->IsFreeWagon()) { totals->consist_count++;
++consist_count; totals->total_vehicle_count++;
++total_vehicle_count;
} }
} }
} }
return nullptr;
});
if (totals.total_vehicle_count == 0) {
return;
} }
buffer_position[0] = '\0'; StringID str;
if (total_vehicle_count == 0) { SetDParam(0, totals.total_vehicle_count);
return false; 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) {
SetDParam(0, total_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) {
if (_settings_client.gui.depot_tooltip_mode == DTM_SIMPLE || (stopped_vehicle_count == 0 && waiting_vehicle_count == 0 && consist_count == 0)) { str = STR_DEPOT_VIEW_COUNT_WAITING_TOOLTIP;
GetString(buffer_position, STR_DEPOT_VIEW_COUNT_TOOLTIP, buffer_tail); } else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && totals.total_vehicle_count == totals.consist_count) {
} else if (_settings_client.gui.depot_tooltip_mode == DTM_DETAILED && total_vehicle_count == stopped_vehicle_count) { str = STR_DEPOT_VIEW_COUNT_CONSISTS_TOOLTIP;
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 { } else {
buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_TOTAL_TOOLTIP, buffer_tail); str = SPECSTR_TEMP_START;
if (stopped_vehicle_count > 0) { _temp_special_strings[0] = GetString(STR_DEPOT_VIEW_TOTAL_TOOLTIP);
SetDParam(0, stopped_vehicle_count); if (totals.stopped_vehicle_count > 0) {
buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_STOPPED_TOOLTIP, buffer_tail); SetDParam(0, totals.stopped_vehicle_count);
_temp_special_strings[0] += GetString(STR_DEPOT_VIEW_STOPPED_TOOLTIP);
} }
if (waiting_vehicle_count > 0) { if (totals.waiting_vehicle_count > 0) {
SetDParam(0, waiting_vehicle_count); SetDParam(0, totals.waiting_vehicle_count);
buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_WAITING_TOOLTIP, buffer_tail); _temp_special_strings[0] += GetString(STR_DEPOT_VIEW_WAITING_TOOLTIP);
} }
if (consist_count > 0) { if (totals.consist_count > 0) {
SetDParam(0, consist_count); SetDParam(0, totals.consist_count);
GetString(buffer_position, STR_DEPOT_VIEW_CONSISTS_TOOLTIP, buffer_tail); _temp_special_strings[0] += GetString(STR_DEPOT_VIEW_CONSISTS_TOOLTIP);
} }
} }
GuiShowTooltips(w, str, 0, nullptr, TCC_HOVER_VIEWPORT);
return true;
} }

View File

@@ -3245,36 +3245,25 @@ enum DisplayStockpiledCargoesMode : uint8 {
DSCM_STOCKPILED DSCM_STOCKPILED
}; };
/** void ShowIndustryTooltip(Window *w, const TileIndex tile)
* 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)
{ {
if (!_settings_client.gui.industry_tooltip_show || if (!_settings_client.gui.industry_tooltip_show) return;
!(_settings_client.gui.industry_tooltip_show_name || _settings_client.gui.industry_tooltip_show_produced || 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 false; _settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled != DSCM_OFF)) return;
const Industry *industry = Industry::GetByTile(tile); const Industry *industry = Industry::GetByTile(tile);
const IndustrySpec *industry_spec = GetIndustrySpec(industry->type); const IndustrySpec *industry_spec = GetIndustrySpec(industry->type);
buffer_position[0] = 0; std::string msg;
auto current_buffer_position = buffer_position;
auto next = false;
if (_settings_client.gui.industry_tooltip_show_name) { if (_settings_client.gui.industry_tooltip_show_name) {
// Print out the name of the industry. // Print out the name of the industry.
SetDParam(0, industry_spec->name); SetDParam(0, industry_spec->name);
current_buffer_position = GetString(current_buffer_position, STR_INDUSTRY_VIEW_NAME_TOOLTIP, buffer_tail); msg = GetString(STR_INDUSTRY_VIEW_NAME_TOOLTIP);
next = true;
} }
if (_settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled) { 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]; CargoSuffix suffixes[accepted_cargo_count];
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, industry, industry->type, industry_spec, industry->accepts_cargo, suffixes); GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, industry, industry->type, industry_spec, industry->accepts_cargo, suffixes);
@@ -3287,100 +3276,86 @@ bool GetIndustryTooltipString(const TileIndex tile, char *buffer_position, const
// Print out required cargo. // Print out required cargo.
bool first = true; bool first = true;
std::string required_cargo_list; std::string required_cargo_list;
auto cargo_list_start_buffer_position = current_buffer_position;
for (byte i = 0; i < accepted_cargo_count; ++i) { for (size_t i = 0; i < accepted_cargo_count; ++i) {
auto required_cargo = industry->accepts_cargo[i]; CargoID required_cargo = industry->accepts_cargo[i];
if (required_cargo == CT_INVALID ) { if (required_cargo == CT_INVALID) {
continue; continue;
} }
auto suffix = &suffixes[i]; const CargoSuffix &suffix = suffixes[i];
bool isStockpileWithSuffix = suffix->display == CSD_CARGO_AMOUNT_TEXT; const bool is_stockpile_with_suffix = (suffix.display == CSD_CARGO_AMOUNT_TEXT);
bool isStockpileWithoutSuffix = suffix->display == CSD_CARGO_AMOUNT; const bool is_stockpile_without_suffix = (suffix.display == CSD_CARGO_AMOUNT);
bool isProperStockpileWithoutSuffix = isStockpileWithoutSuffix && stockpiling; // If callback 37 fails, the result is interpreted as a stockpile, for some reason. 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 (isStockpileWithSuffix || isProperStockpileWithoutSuffix) { 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 != DSCM_REQUIRED) continue;
} }
auto format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT; StringID format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT;
if (first) { if (first) {
format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_FIRST; format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_FIRST;
first = false; first = false;
} }
SetDParam(0, CargoSpec::Get(required_cargo)->name); SetDParam(0, CargoSpec::Get(required_cargo)->name);
SetDParamStr(1, suffix->text); SetDParamStr(1, suffix.text);
GetString(cargo_list_start_buffer_position, format, buffer_tail); required_cargo_list += GetString(format);
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()) { if (!required_cargo_list.empty()) {
next = true; if (!msg.empty()) msg += '\n';
msg += required_cargo_list;
} }
} }
// Print out stockpiled cargo. // Print out stockpiled cargo.
if (stockpiling && _settings_client.gui.industry_tooltip_show_stockpiled == DSCM_STOCKPILED) { if (stockpiling && _settings_client.gui.industry_tooltip_show_stockpiled == DSCM_STOCKPILED) {
for (byte i = 0; i < accepted_cargo_count; ++i) { for (size_t i = 0; i < accepted_cargo_count; ++i) {
auto stockpiled_cargo = industry->accepts_cargo[i]; CargoID stockpiled_cargo = industry->accepts_cargo[i];
if (stockpiled_cargo == CT_INVALID) continue; 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; continue;
} }
if (next) { if (!msg.empty()) msg += '\n';
current_buffer_position = GetString(current_buffer_position, STR_NEW_LINE, buffer_tail);
}
next = true;
SetDParam(0, stockpiled_cargo); SetDParam(0, stockpiled_cargo);
SetDParam(1, industry->incoming_cargo_waiting[i]); SetDParam(1, industry->incoming_cargo_waiting[i]);
SetDParamStr(2, suffix->text); SetDParamStr(2, suffix.text);
current_buffer_position = GetString(current_buffer_position, STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP, buffer_tail); msg += GetString(STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP);
} }
} }
} }
if (_settings_client.gui.industry_tooltip_show_produced) { 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]; CargoSuffix suffixes[produced_cargo_count];
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_VIEW, industry, industry->type, industry_spec, industry->produced_cargo, suffixes); GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_VIEW, industry, industry->type, industry_spec, industry->produced_cargo, suffixes);
// Print out amounts of produced cargo. // Print out amounts of produced cargo.
for (byte i = 0; i < produced_cargo_count; i++) { for (size_t i = 0; i < produced_cargo_count; i++) {
auto produced_cargo = industry->produced_cargo[i]; CargoID produced_cargo = industry->produced_cargo[i];
if (produced_cargo == CT_INVALID) continue; if (produced_cargo == CT_INVALID) continue;
if (next) { if (!msg.empty()) msg += '\n';
current_buffer_position = GetString(current_buffer_position, STR_NEW_LINE, buffer_tail);
}
next = true;
SetDParam(0, produced_cargo); SetDParam(0, produced_cargo);
SetDParam(1, industry->last_month_production[i]); SetDParam(1, industry->last_month_production[i]);
SetDParamStr(2, suffixes[i].text); SetDParamStr(2, suffixes[i].text);
SetDParam(3, ToPercent8(industry->last_month_pct_transported[i])); 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);
}
} }

View File

@@ -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_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_FINANCES_REPAY_QUERY_CAPT :{WHITE}Enter the amount of money to repay
STR_NEW_LINE :{}
# Town tooltip # Town tooltip
STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN}{RAW_STRING} STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN}
STR_TOWN_NAME_POP_TOOLTIP :{BLACK}{TOWN}: {COMMA}{RAW_STRING} STR_TOWN_NAME_POP_TOOLTIP :{BLACK}{TOWN}: {COMMA}
STR_TOWN_NAME_RATING_TOOLTIP :{}Your rating is {STRING} STR_TOWN_NAME_RATING_TOOLTIP :{STRING2}{}Your rating is {STRING}
STR_INDUSTRY_VIEW_NAME_TOOLTIP :{STRING} STR_INDUSTRY_VIEW_NAME_TOOLTIP :{STRING}
STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_FIRST :{STRING}{RAW_STRING} STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_FIRST :{STRING}{RAW_STRING}
STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT :, {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_STOCKPILED_TOOLTIP :{CARGO_LONG} waiting{RAW_STRING}
STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{CARGO_LONG}{RAW_STRING} ({COMMA}%) 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_TOOLTIP :{BLACK}{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_STOPPED_TOOLTIP :{BLACK}{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_WAITING_TOOLTIP :{BLACK}{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_COUNT_CONSISTS_TOOLTIP :{BLACK}{COMMA} consist{P "" s} {P is are} inside
STR_DEPOT_VIEW_TOTAL_TOOLTIP :Of {COMMA} vehicles inside: STR_DEPOT_VIEW_TOTAL_TOOLTIP :{BLACK}Of {COMMA} vehicles inside:
STR_DEPOT_VIEW_STOPPED_TOOLTIP :{}{COMMA} {P is are} stopped STR_DEPOT_VIEW_STOPPED_TOOLTIP :{}{COMMA} {P is are} stopped
STR_DEPOT_VIEW_WAITING_TOOLTIP :{}{COMMA} {P is are} waiting 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_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_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 :{STRING2}, Age: {COMMA} year{P "" s} ({COMMA})
STR_VEHICLE_LIST_AGE_RED :{STRING2}, Age: {RED}{COMMA} {BLACK}year{P "" s} ({COMMA}) STR_VEHICLE_LIST_AGE_RED :{STRING2}, Age: {RED}{COMMA} {BLACK}year{P "" s} ({COMMA})

View File

@@ -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_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_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 # Town tooltip
STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN} STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN}

View File

@@ -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_BORROW_QUERY_CAPT :{WHITE}Gib die zu leihende Summe ein
STR_FINANCES_REPAY_QUERY_CAPT :{WHITE}Gib die zurückzuzahlende 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 # Town tooltip
STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN} STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN}

View File

@@ -1364,9 +1364,6 @@ STR_FINANCES_REPAY_TOOLTIP_EXTRA :{BLACK}{STRING}
STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}빌릴 돈의 양을 입력하세요 STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}빌릴 돈의 양을 입력하세요
STR_FINANCES_REPAY_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 # Town tooltip
STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN} STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN}

View File

@@ -1312,9 +1312,6 @@ STR_FINANCES_REPAY_TOOLTIP_EXTRA :{BLACK}{STRING}
STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}输入贷款总额 STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}输入贷款总额
STR_FINANCES_REPAY_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 # Town tooltip
STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN} STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN}

View File

@@ -3096,51 +3096,3 @@ bool ShouldShowBaseStationViewportLabel(const BaseStation *bst)
!HasBit(_extra_display_opt, XDO_SHOW_HIDDEN_SIGNS)) return false; !HasBit(_extra_display_opt, XDO_SHOW_HIDDEN_SIGNS)) return false;
return true; 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;
}

View File

@@ -2047,11 +2047,6 @@ static char *StationGetSpecialString(char *buff, int x, const char *last)
return buff; 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) static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last)
{ {
return GenerateTownNameString(buff, last, ind, seed); return GenerateTownNameString(buff, last, ind, seed);

View File

@@ -226,106 +226,116 @@ enum TownNameTooltipMode : uint8 {
TNTM_ALWAYS_ON 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 (_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 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); TownID town_id = GetTownIndex(tile);
const Town *town = Town::Get(town_id); 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)) { if (_settings_client.gui.population_in_label) {
int local_authority_rating_thresholds[] = { RATING_APPALLING, RATING_VERYPOOR, RATING_POOR, RATING_MEDIOCRE, RATING_GOOD, RATING_VERYGOOD, 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 }; RATING_EXCELLENT, RATING_OUTSTANDING };
constexpr size_t threshold_count = lengthof(local_authority_rating_thresholds); constexpr size_t threshold_count = lengthof(local_authority_rating_thresholds);
auto local_rating = town->ratings[_local_company]; int local_rating = town->ratings[_local_company];
auto rating_string = STR_CARGO_RATING_APPALLING; StringID rating_string = STR_CARGO_RATING_APPALLING;
for (int i = 0; i < threshold_count && local_rating > local_authority_rating_thresholds[i]; ++i) ++rating_string; for (size_t i = 0; i < threshold_count && local_rating > local_authority_rating_thresholds[i]; ++i) ++rating_string;
SetDParam(0, rating_string); SetDParam(3, rating_string);
GetString(buffer_position, STR_TOWN_NAME_RATING_TOOLTIP, buffer_tail); 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); GuiShowTooltips(w, tooltip_string, 0, nullptr, TCC_HOVER_VIEWPORT);
} }
bool GetIndustryTooltipString(TileIndex tile, char *buffer_position, const char *buffer_tail); void ShowStationViewportTooltip(Window *w, const TileIndex tile)
void ShowIndustryTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail)
{ {
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); std::string msg;
GuiShowTooltips(w, STR_INDUSTRY_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT);
}
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 (_settings_client.gui.station_viewport_tooltip_cargo) {
{ for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
if (!GetDepotTooltipString(tile, buffer_position, buffer_tail)) return; const GoodsEntry *goods_entry = &station->goods[cs->Index()];
if (!goods_entry->HasRating()) continue;
SetDParamStr(0, buffer_position); if (!msg.empty()) msg += '\n';
GuiShowTooltips(w, STR_DEPOT_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT);
}
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 (!msg.empty()) {
{ _temp_special_strings[0] = std::move(msg);
if (!GetStationViewportTooltipString(tile, buffer_position, buffer_tail)) return; GuiShowTooltips(w, SPECSTR_TEMP_START, 0, nullptr, TCC_HOVER_VIEWPORT);
}
SetDParamStr(0, buffer_position);
GuiShowTooltips(w, STR_STATION_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT);
} }
void ShowTooltipForTile(Window *w, const TileIndex tile) void ShowTooltipForTile(Window *w, const TileIndex tile)
{ {
static char buffer[1024]; extern void ShowDepotTooltip(Window *w, const TileIndex tile);
char *buffer_start = buffer; extern void ShowIndustryTooltip(Window *w, const TileIndex tile);
char *buffer_tail = lastof(buffer);
switch (GetTileType(tile)) { switch (GetTileType(tile)) {
case MP_ROAD: case MP_ROAD:
if (IsRoadDepot(tile)) { if (IsRoadDepot(tile)) {
ShowDepotTooltip(w, tile, buffer_start, buffer_tail); ShowDepotTooltip(w, tile);
return; return;
} }
/* FALL THROUGH */ /* FALL THROUGH */
case MP_HOUSE: { case MP_HOUSE: {
ShowTownNameTooltip(w, tile, buffer_start, buffer_tail); ShowTownNameTooltip(w, tile);
break; break;
} }
case MP_INDUSTRY: { case MP_INDUSTRY: {
ShowIndustryTooltip(w, tile, buffer_start, buffer_tail); ShowIndustryTooltip(w, tile);
break; break;
} }
case MP_RAILWAY: { case MP_RAILWAY: {
if (!IsRailDepot(tile)) return; if (!IsRailDepot(tile)) return;
ShowDepotTooltip(w, tile, buffer_start, buffer_tail); ShowDepotTooltip(w, tile);
break; break;
} }
case MP_WATER: { case MP_WATER: {
if (!IsShipDepot(tile)) return; if (!IsShipDepot(tile)) return;
ShowDepotTooltip(w, tile, buffer_start, buffer_tail); ShowDepotTooltip(w, tile);
break; break;
} }
case MP_STATION: { case MP_STATION: {
if (IsHangar(tile)) { if (IsHangar(tile)) {
ShowDepotTooltip(w, tile, buffer_start, buffer_tail); ShowDepotTooltip(w, tile);
} else { } else {
ShowStationViewportTooltip(w, tile, buffer_start, buffer_tail); ShowStationViewportTooltip(w, tile);
} }
break; break;
} }