From 5d7721a2d4b9c7ea7b0381a49036d82ed3871be3 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 4 Jul 2023 22:10:32 +0100 Subject: [PATCH] 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}