Departures: Add departures support for depots

This commit is contained in:
Jonathan G Rennison 2024-09-05 20:33:05 +01:00
parent 4bb0279c0a
commit 971a917c7a
14 changed files with 101 additions and 28 deletions

View File

@ -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<uint32_t, 3> 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);
}
if (Waypoint::IsValidID(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(station)) {
this->source_type = DST_WAYPOINT;
SetBit(this->source.order_type_mask, OT_GOTO_WAYPOINT);
this->source.destination = window_number;
this->GetWidget<NWidgetCore>(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<DeparturesWindow>(_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;

View File

@ -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 */

View File

@ -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

View File

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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}経由

View File

@ -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}경유

View File

@ -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}через

View File

@ -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}经

View File

@ -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 */