From 971a917c7ab73f9a609cc52c2d374520720307fe Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 5 Sep 2024 20:33:05 +0100 Subject: [PATCH] Departures: Add departures support for depots --- src/departures_gui.cpp | 86 +++++++++++++++++++++++---- src/departures_gui.h | 3 + src/departures_type.h | 6 +- src/depot.cpp | 4 ++ src/depot_gui.cpp | 5 ++ src/lang/extra/czech.txt | 3 +- src/lang/extra/english.txt | 3 +- src/lang/extra/galician.txt | 3 +- src/lang/extra/german.txt | 3 +- src/lang/extra/japanese.txt | 3 +- src/lang/extra/korean.txt | 3 +- src/lang/extra/russian.txt | 3 +- src/lang/extra/simplified_chinese.txt | 3 +- src/widgets/depot_widget.h | 1 + 14 files changed, 101 insertions(+), 28 deletions(-) diff --git a/src/departures_gui.cpp b/src/departures_gui.cpp index 239cb4b77d..4ad8c1b045 100644 --- a/src/departures_gui.cpp +++ b/src/departures_gui.cpp @@ -33,6 +33,7 @@ #include "departures_func.h" #include "cargotype.h" #include "zoom_func.h" +#include "depot_map.h" #include "core/backup_type.hpp" #include "table/sprites.h" @@ -117,6 +118,7 @@ static const StringID _departure_mode_strings[DM_END] = { enum DepartureSourceType : uint8_t { DST_STATION, DST_WAYPOINT, + DST_DEPOT, }; struct DeparturesWindow : public Window { @@ -141,6 +143,7 @@ protected: int veh_width; ///< current width of vehicle field int group_width; ///< current width of group field int toc_width; ///< current width of company field + std::array title_params{};///< title string parameters virtual uint GetMinWidth() const; static void RecomputeDateWidth(); @@ -228,21 +231,33 @@ protected: this->calc_tick_countdown = 0; } -public: - - DeparturesWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc) + void ConstructWidgetLayout(WindowNumber window_number) { this->SetupValues(); this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_DB_SCROLLBAR); this->FinishInitNested(window_number); + } + + void PostConstructSetup() + { + this->RefreshVehicleList(); + + if (_pause_mode != PM_UNPAUSED) this->OnGameTick(); + } + +public: + DeparturesWindow(WindowDesc &desc, StationID station) : Window(desc) + { + this->ConstructWidgetLayout(station); + + this->title_params[1] = station; - if (Waypoint::IsValidID(window_number)) { + if (Waypoint::IsValidID(station)) { this->source_type = DST_WAYPOINT; SetBit(this->source.order_type_mask, OT_GOTO_WAYPOINT); - this->source.destination = window_number; - - this->GetWidget(WID_DB_CAPTION)->SetDataTip(STR_DEPARTURES_CAPTION_WAYPOINT, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS); + this->source.destination = station; + this->title_params[0] = STR_WAYPOINT_NAME; const Waypoint *wp = Waypoint::Get(window_number); VehicleType vt; @@ -267,6 +282,7 @@ public: SetBit(this->source.order_type_mask, OT_GOTO_STATION); SetBit(this->source.order_type_mask, OT_IMPLICIT); this->source.destination = window_number; + this->title_params[0] = STR_STATION_NAME; for (uint i = 0; i < 4; ++i) { show_types[i] = true; @@ -278,9 +294,40 @@ public: this->SetWidgetLoweredState(WID_DB_SHOW_VIA, this->show_via); } - this->RefreshVehicleList(); + this->PostConstructSetup(); + } - if (_pause_mode != PM_UNPAUSED) this->OnGameTick(); + static WindowNumber GetDepotWindowNumber(TileIndex tile) + { + static constexpr WindowNumber DEPARTURE_WINDOW_NUMBER_DEPOT_TAG = 1 << 31; + return tile | DEPARTURE_WINDOW_NUMBER_DEPOT_TAG; + } + + struct DepotTag{}; + DeparturesWindow(WindowDesc &desc, DepotTag tag, TileIndex tile, VehicleType vt) : Window(desc) + { + this->ConstructWidgetLayout(DeparturesWindow::GetDepotWindowNumber(tile)); + + this->source_type = DST_DEPOT; + SetBit(this->source.order_type_mask, OT_GOTO_DEPOT); + this->source.destination = (vt == VEH_AIRCRAFT) ? GetStationIndex(tile) : GetDepotIndex(tile); + this->title_params[0] = STR_DEPOT_NAME; + this->title_params[1] = vt; + this->title_params[2] = this->source.destination; + + for (uint i = 0; i < 4; ++i) { + if (i == vt) { + show_types[i] = true; + this->LowerWidget(WID_DB_SHOW_TRAINS + i); + } + this->DisableWidget(WID_DB_SHOW_TRAINS + i); + } + + this->show_via = true; + this->LowerWidget(WID_DB_SHOW_VIA); + this->DisableWidget(WID_DB_SHOW_VIA); + + this->PostConstructSetup(); } void SetupValues() @@ -317,7 +364,9 @@ public: { switch (widget) { case WID_DB_CAPTION: { - SetDParam(0, this->window_number); + SetDParam(0, this->title_params[0]); + SetDParam(1, this->title_params[1]); + SetDParam(2, this->title_params[2]); break; } @@ -506,7 +555,7 @@ public: ClrBit(list_source.order_type_mask, OT_IMPLICIT); // Not interested in implicit orders in this phase DepartureCallingSettings settings; - settings.allow_via = (this->source_type == DST_WAYPOINT) || this->show_via; + settings.allow_via = (this->source_type != DST_STATION) || this->show_via; settings.departure_no_load_test = (this->source_type == DST_WAYPOINT) || _settings_client.gui.departure_show_all_stops; settings.show_all_stops = _settings_client.gui.departure_show_all_stops; settings.show_pax = show_pax; @@ -600,6 +649,21 @@ void ShowDeparturesWindow(StationID station) AllocateWindowDescFront(_departures_desc, station); } +/** + * Shows a window of scheduled departures for a station. + * @param station the station to show a departures window for + */ +void ShowDepotDeparturesWindow(TileIndex tile, VehicleType vt) +{ + if (BringWindowToFrontById(_departures_desc.cls, DeparturesWindow::GetDepotWindowNumber(tile)) != nullptr) return; + new DeparturesWindow(_departures_desc, DeparturesWindow::DepotTag{}, tile, vt); +} + +void CloseDepotDeparturesWindow(TileIndex tile) +{ + CloseWindowById(WC_DEPARTURES_BOARD, DeparturesWindow::GetDepotWindowNumber(tile)); +} + void DeparturesWindow::RecomputeDateWidth() { cached_date_width = 0; diff --git a/src/departures_gui.h b/src/departures_gui.h index d2f2cbc5cc..f1a2b1723c 100644 --- a/src/departures_gui.h +++ b/src/departures_gui.h @@ -14,8 +14,11 @@ #include "departures_type.h" #include "station_base.h" +#include "vehicle_type.h" #include "widgets/departures_widget.h" void ShowDeparturesWindow(StationID station); +void ShowDepotDeparturesWindow(TileIndex tile, VehicleType vt); +void CloseDepotDeparturesWindow(TileIndex tile); #endif /* DEPARTURES_GUI_H */ diff --git a/src/departures_type.h b/src/departures_type.h index 58d7bd3fbe..3756e8dc5b 100644 --- a/src/departures_type.h +++ b/src/departures_type.h @@ -120,7 +120,11 @@ struct DepartureOrderDestinationDetector { bool OrderMatches(const Order *order) const { - return HasBit(this->order_type_mask, order->GetType()) && order->GetDestination() == this->destination; + if (!(HasBit(this->order_type_mask, order->GetType()) && order->GetDestination() == this->destination)) return false; + + if (order->IsType(OT_GOTO_DEPOT) && (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return false; // Filter out go to nearest depot orders + + return true; } bool StationMatches(StationID station) const diff --git a/src/depot.cpp b/src/depot.cpp index a6633f1061..6f65ed5cde 100644 --- a/src/depot.cpp +++ b/src/depot.cpp @@ -16,6 +16,7 @@ #include "vehicle_gui.h" #include "vehiclelist.h" #include "tracerestrict.h" +#include "departures_gui.h" #include "safeguards.h" @@ -49,4 +50,7 @@ Depot::~Depot() /* Delete the depot list */ VehicleType vt = GetDepotVehicleType(this->xy); CloseWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(this->xy), this->index).Pack()); + + /* Delete any depot departure window */ + CloseDepotDeparturesWindow(this->xy); } diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 3625bc661a..49151d9b91 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -31,6 +31,7 @@ #include "error.h" #include "tbtr_template_vehicle.h" #include "core/geometry_func.hpp" +#include "departures_gui.h" #include "widgets/depot_widget.h" @@ -77,6 +78,7 @@ static constexpr NWidgetPart _nested_train_depot_widgets[] = { NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_D_BUILD), SetDataTip(0x0, STR_NULL), SetFill(1, 1), SetResize(1, 0), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_D_CLONE), SetDataTip(0x0, STR_NULL), SetFill(1, 1), SetResize(1, 0), + NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_D_DEPARTURES), SetFill(0, 1), SetDataTip(STR_STATION_VIEW_DEPARTURES_BUTTON, STR_STATION_VIEW_DEPARTURES_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_D_VEHICLE_LIST), SetDataTip(0x0, STR_NULL), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetFill(0, 1), NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_D_STOP_ALL), SetDataTip(SPR_FLAG_VEH_STOPPED, STR_NULL), SetAspect(WidgetDimensions::ASPECT_VEHICLE_FLAG), SetFill(0, 1), NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_D_START_ALL), SetDataTip(SPR_FLAG_VEH_RUNNING, STR_NULL), SetAspect(WidgetDimensions::ASPECT_VEHICLE_FLAG), SetFill(0, 1), @@ -844,6 +846,9 @@ struct DepotWindow : Window { DoCommandP(this->window_number, this->type, 0, CMD_DEPOT_MASS_AUTOREPLACE); break; + case WID_D_DEPARTURES: + ShowDepotDeparturesWindow((TileIndex)this->window_number, this->type); + break; } } diff --git a/src/lang/extra/czech.txt b/src/lang/extra/czech.txt index c4ad5d5642..00e0a11cac 100644 --- a/src/lang/extra/czech.txt +++ b/src/lang/extra/czech.txt @@ -1168,8 +1168,7 @@ STR_STATION_VIEW_DEPARTURES_TOOLTIP :{BLACK}Zobrazit STR_STATION_VIEW_HISTORY_BUTTON :{BLACK}Historie STR_STATION_VIEW_HISTORY_TOOLTIP :{BLACK}Zobrazit historii čekajícího nákladu -STR_DEPARTURES_CAPTION :{WHITE}Aktuální dopravní informace - {STATION} -STR_DEPARTURES_CAPTION_WAYPOINT :{WHITE}Aktuální dopravní informace - {WAYPOINT} +STR_DEPARTURES_CAPTION :{WHITE}Aktuální dopravní informace - {STRING} STR_DEPARTURES_DEPARTURES :{BLACK}{TINY_FONT}O STR_DEPARTURES_ARRIVALS :{BLACK}{TINY_FONT}P STR_DEPARTURES_VIA_BUTTON :{BLACK}přes diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index 09bdcc5505..a3387dfd54 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -1344,8 +1344,7 @@ STR_STATION_VIEW_DEPARTURES_TOOLTIP :{BLACK}Show lis STR_STATION_VIEW_HISTORY_BUTTON :{BLACK}History STR_STATION_VIEW_HISTORY_TOOLTIP :{BLACK}Show waiting cargo history -STR_DEPARTURES_CAPTION :{WHITE}{STATION} Live Travel Information -STR_DEPARTURES_CAPTION_WAYPOINT :{WHITE}{WAYPOINT} Live Travel Information +STR_DEPARTURES_CAPTION :{WHITE}{STRING2} Live Travel Information STR_DEPARTURES_CARGO_MODE_TOOLTIP :{BLACK}Set cargo filter mode for arrivals/departures STR_DEPARTURES_DEPARTURES :Departures STR_DEPARTURES_ARRIVALS :Arrivals diff --git a/src/lang/extra/galician.txt b/src/lang/extra/galician.txt index dfb3f8f4d7..52651d362f 100644 --- a/src/lang/extra/galician.txt +++ b/src/lang/extra/galician.txt @@ -1290,8 +1290,7 @@ STR_STATION_VIEW_DEPARTURES_TOOLTIP :{BLACK}Amosa a STR_STATION_VIEW_HISTORY_BUTTON :{BLACK}Historial STR_STATION_VIEW_HISTORY_TOOLTIP :{BLACK}Amosa o historial de carga a espera -STR_DEPARTURES_CAPTION :{WHITE}{STATION} Informaciónd a viaxe en directo -STR_DEPARTURES_CAPTION_WAYPOINT :{WHITE}{WAYPOINT} Informaciónd a viaxe en directo +STR_DEPARTURES_CAPTION :{WHITE}{STRING} Informaciónd a viaxe en directo STR_DEPARTURES_DEPARTURES :{BLACK}{TINY_FONT}D STR_DEPARTURES_ARRIVALS :{BLACK}{TINY_FONT}A STR_DEPARTURES_VIA_BUTTON :{BLACK}vía diff --git a/src/lang/extra/german.txt b/src/lang/extra/german.txt index d278c3694e..9ce5194075 100644 --- a/src/lang/extra/german.txt +++ b/src/lang/extra/german.txt @@ -1054,8 +1054,7 @@ STR_STATION_VIEW_DEPARTURES_TOOLTIP :{BLACK}Zeige Li STR_STATION_VIEW_HISTORY_BUTTON :{BLACK}Historie STR_STATION_VIEW_HISTORY_TOOLTIP :{BLACK}Zeige Verlauf der wartenden Frachten -STR_DEPARTURES_CAPTION :{WHITE}{STATION} Ankunfts- und Abfahrtszeiten -STR_DEPARTURES_CAPTION_WAYPOINT :{WHITE}{WAYPOINT} Ankunfts- und Abfahrtszeiten +STR_DEPARTURES_CAPTION :{WHITE}{STRING} Ankunfts- und Abfahrtszeiten STR_DEPARTURES_DEPARTURES :{BLACK}{TINY_FONT}Ab STR_DEPARTURES_ARRIVALS :{BLACK}{TINY_FONT}An STR_DEPARTURES_VIA_BUTTON :{BLACK}Durch diff --git a/src/lang/extra/japanese.txt b/src/lang/extra/japanese.txt index d31bb873b6..d403dd83bc 100644 --- a/src/lang/extra/japanese.txt +++ b/src/lang/extra/japanese.txt @@ -36,8 +36,7 @@ STR_MAPGEN_SNOW_LINE_QUERY_CAPT :{WHITE}雪線 STR_STATION_VIEW_DEPARTURES_BUTTON :{BLACK}発車標 STR_STATION_VIEW_DEPARTURES_TOOLTIP :{BLACK}発車標を表示します。 -STR_DEPARTURES_CAPTION :{WHITE}{STATION} 発車標 -STR_DEPARTURES_CAPTION_WAYPOINT :{WHITE}{WAYPOINT} 発車標 +STR_DEPARTURES_CAPTION :{WHITE}{STRING} 発車標 STR_DEPARTURES_DEPARTURES :{BLACK}{TINY_FONT}発車 STR_DEPARTURES_ARRIVALS :{BLACK}{TINY_FONT}到着 STR_DEPARTURES_VIA_BUTTON :{BLACK}経由 diff --git a/src/lang/extra/korean.txt b/src/lang/extra/korean.txt index a27612828c..52bbfd075b 100644 --- a/src/lang/extra/korean.txt +++ b/src/lang/extra/korean.txt @@ -1290,8 +1290,7 @@ STR_STATION_VIEW_DEPARTURES_TOOLTIP :{BLACK}출발/ STR_STATION_VIEW_HISTORY_BUTTON :{BLACK}화물량 이력 STR_STATION_VIEW_HISTORY_TOOLTIP :{BLACK}대기 화물량 이력을 보여줍니다 -STR_DEPARTURES_CAPTION :{WHITE}{STATION} - 실시간 운행 정보 -STR_DEPARTURES_CAPTION_WAYPOINT :{WHITE}{WAYPOINT} - 실시간 운행 정보 +STR_DEPARTURES_CAPTION :{WHITE}{STRING} - 실시간 운행 정보 STR_DEPARTURES_DEPARTURES :{BLACK}{TINY_FONT}발 STR_DEPARTURES_ARRIVALS :{BLACK}{TINY_FONT}착 STR_DEPARTURES_VIA_BUTTON :{BLACK}경유 diff --git a/src/lang/extra/russian.txt b/src/lang/extra/russian.txt index 4ad5d11f76..7e83b5ca90 100644 --- a/src/lang/extra/russian.txt +++ b/src/lang/extra/russian.txt @@ -1292,8 +1292,7 @@ STR_STATION_VIEW_DEPARTURES_TOOLTIP :{BLACK}Пока STR_STATION_VIEW_HISTORY_BUTTON :{BLACK}История STR_STATION_VIEW_HISTORY_TOOLTIP :{BLACK}Показать историю ожидающих грузов -STR_DEPARTURES_CAPTION :{WHITE}{STATION} Информация о путешествиях в прямом эфире -STR_DEPARTURES_CAPTION_WAYPOINT :{WHITE}{WAYPOINT} Информация о путешествиях в прямом эфире +STR_DEPARTURES_CAPTION :{WHITE}{STRING} Информация о путешествиях в прямом эфире STR_DEPARTURES_DEPARTURES :{BLACK}{TINY_FONT}О STR_DEPARTURES_ARRIVALS :{BLACK}{TINY_FONT}П STR_DEPARTURES_VIA_BUTTON :{BLACK}через diff --git a/src/lang/extra/simplified_chinese.txt b/src/lang/extra/simplified_chinese.txt index 3d4ea04f66..57fb48fc54 100644 --- a/src/lang/extra/simplified_chinese.txt +++ b/src/lang/extra/simplified_chinese.txt @@ -1292,8 +1292,7 @@ STR_STATION_VIEW_DEPARTURES_TOOLTIP :{BLACK}显示 STR_STATION_VIEW_HISTORY_BUTTON :{BLACK}货物记录 STR_STATION_VIEW_HISTORY_TOOLTIP :{BLACK}显示货物等待记录 -STR_DEPARTURES_CAPTION :{WHITE}{STATION} - 实时运输信息 -STR_DEPARTURES_CAPTION_WAYPOINT :{WHITE}{WAYPOINT} - 实时运输信息 +STR_DEPARTURES_CAPTION :{WHITE}{STRING} - 实时运输信息 STR_DEPARTURES_DEPARTURES :{BLACK}{TINY_FONT}发 STR_DEPARTURES_ARRIVALS :{BLACK}{TINY_FONT}抵 STR_DEPARTURES_VIA_BUTTON :{BLACK}经 diff --git a/src/widgets/depot_widget.h b/src/widgets/depot_widget.h index f94f1263d2..fd156f71fa 100644 --- a/src/widgets/depot_widget.h +++ b/src/widgets/depot_widget.h @@ -30,6 +30,7 @@ enum DepotWidgets : WidgetID { WID_D_VEHICLE_LIST, ///< List of vehicles. WID_D_STOP_ALL, ///< Stop all button. WID_D_START_ALL, ///< Start all button. + WID_D_DEPARTURES, ///< Departures button. }; #endif /* WIDGETS_DEPOT_WIDGET_H */