OpenTTD Source 20250312-master-gcdcc6b491d
timetable_gui.cpp File Reference

GUI for time tabling. More...

#include "stdafx.h"
#include "command_func.h"
#include "gui.h"
#include "window_gui.h"
#include "window_func.h"
#include "textbuf_gui.h"
#include "strings_func.h"
#include "vehicle_base.h"
#include "string_func.h"
#include "gfx_func.h"
#include "company_func.h"
#include "timer/timer.h"
#include "timer/timer_game_tick.h"
#include "timer/timer_game_economy.h"
#include "timer/timer_window.h"
#include "date_gui.h"
#include "vehicle_gui.h"
#include "settings_type.h"
#include "timetable_cmd.h"
#include "timetable.h"
#include "widgets/timetable_widget.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  TimetableArrivalDeparture
 Container for the arrival/departure dates of a vehicle. More...
 
struct  TimetableWindow
 

Functions

std::pair< StringParameter, StringParameterGetTimetableParameters (TimerGameTick::Ticks ticks)
 Get parameters to format timetable time.
 
static TimerGameTick::Ticks TicksPerTimetableUnit ()
 Get the number of ticks in the current timetable display unit.
 
bool VehicleIsAboveLatenessThreshold (TimerGameTick::Ticks ticks, bool round_to_day)
 Determine if a vehicle should be shown as late or early, using a threshold depending on the timetable display setting.
 
static bool CanDetermineTimeTaken (const Order *order, bool travelling)
 Check whether it is possible to determine how long the order takes.
 
static void FillTimetableArrivalDepartureTable (const Vehicle *v, VehicleOrderID start, bool travelling, std::vector< TimetableArrivalDeparture > &table, TimerGameTick::Ticks offset)
 Fill the table with arrivals and departures.
 
static void ChangeTimetableStartCallback (const Window *w, TimerGameEconomy::Date date, void *data)
 Callback for when a time has been chosen to start the time table.
 
void ShowTimetableWindow (const Vehicle *v)
 Show the timetable for a given vehicle.
 

Variables

static constexpr NWidgetPart _nested_timetable_widgets []
 
static WindowDesc _timetable_desc (WDP_AUTO, "view_vehicle_timetable", 400, 130, WC_VEHICLE_TIMETABLE, WC_VEHICLE_VIEW, WindowDefaultFlag::Construction, _nested_timetable_widgets)
 

Detailed Description

GUI for time tabling.

Definition in file timetable_gui.cpp.

Function Documentation

◆ CanDetermineTimeTaken()

static bool CanDetermineTimeTaken ( const Order order,
bool  travelling 
)
static

Check whether it is possible to determine how long the order takes.

Parameters
orderthe order to check.
travellingwhether we are interested in the travel or the wait part.
Returns
true if the travel/wait time can be used.

Definition at line 104 of file timetable_gui.cpp.

References Order::GetNonStopType(), Order::IsTravelTimetabled(), Order::IsType(), Order::IsWaitTimetabled(), and ONSF_NO_STOP_AT_DESTINATION_STATION.

Referenced by FillTimetableArrivalDepartureTable().

◆ ChangeTimetableStartCallback()

static void ChangeTimetableStartCallback ( const Window w,
TimerGameEconomy::Date  date,
void *  data 
)
static

Callback for when a time has been chosen to start the time table.

Parameters
wthe window related to the setting of the date
datethe actually chosen date

Definition at line 185 of file timetable_gui.cpp.

References GetStartTickFromDate(), and Window::window_number.

Referenced by TimetableWindow::OnClick().

◆ FillTimetableArrivalDepartureTable()

static void FillTimetableArrivalDepartureTable ( const Vehicle v,
VehicleOrderID  start,
bool  travelling,
std::vector< TimetableArrivalDeparture > &  table,
TimerGameTick::Ticks  offset 
)
static

Fill the table with arrivals and departures.

Parameters
vVehicle which must have at least 2 orders.
startorder index to start at
travellingAre we still in the travelling part of the start order
tableFill in arrival and departures including intermediate orders
offsetAdd this value to result and all arrivals and departures

Definition at line 128 of file timetable_gui.cpp.

References CanDetermineTimeTaken(), OrderList::GetFirstOrder(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), Order::GetTimetabledTravel(), Order::GetTimetabledWait(), Ticks::INVALID_TICKS, Order::IsType(), Order::next, and Vehicle::orders.

Referenced by TimetableWindow::BuildArrivalDepartureList().

◆ GetTimetableParameters()

std::pair< StringParameter, StringParameter > GetTimetableParameters ( TimerGameTick::Ticks  ticks)

Get parameters to format timetable time.

Parameters
ticksNumber of ticks to format.
Returns
Pair of parameters to format timetable time.

Definition at line 49 of file timetable_gui.cpp.

References _settings_client, Ticks::DAY_TICKS, ClientSettings::gui, Ticks::TICKS_PER_SECOND, and GUISettings::timetable_mode.

Referenced by DrawOrderString(), and TimetableWindow::DrawSummaryPanel().

◆ ShowTimetableWindow()

void ShowTimetableWindow ( const Vehicle v)

Show the timetable for a given vehicle.

Parameters
vThe vehicle to show the timetable for.

Definition at line 876 of file timetable_gui.cpp.

References CloseWindowById(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, WC_VEHICLE_DETAILS, and WC_VEHICLE_ORDERS.

Referenced by OrdersWindow::OnClick(), and VehicleViewWindow::OnClick().

◆ TicksPerTimetableUnit()

static TimerGameTick::Ticks TicksPerTimetableUnit ( )
inlinestatic

Get the number of ticks in the current timetable display unit.

Returns
The number of ticks per day, second, or tick, to match the timetable display.

Definition at line 64 of file timetable_gui.cpp.

References _settings_client, Ticks::DAY_TICKS, ClientSettings::gui, Ticks::TICKS_PER_SECOND, and GUISettings::timetable_mode.

Referenced by TimetableWindow::OnClick(), and TimetableWindow::OnQueryTextFinished().

◆ VehicleIsAboveLatenessThreshold()

bool VehicleIsAboveLatenessThreshold ( TimerGameTick::Ticks  ticks,
bool  round_to_day 
)

Determine if a vehicle should be shown as late or early, using a threshold depending on the timetable display setting.

Parameters
ticksThe number of ticks that the vehicle is late or early.
round_to_dayWhen using ticks, if we should round up to the nearest day.
Returns
True if the vehicle is outside the "on time" threshold, either early or late.

Definition at line 84 of file timetable_gui.cpp.

References _settings_client, Ticks::DAY_TICKS, ClientSettings::gui, Ticks::TICKS_PER_SECOND, and GUISettings::timetable_mode.

Referenced by TimetableWindow::DrawArrivalDeparturePanel(), and TimetableWindow::DrawSummaryPanel().

Variable Documentation

◆ _nested_timetable_widgets

constexpr NWidgetPart _nested_timetable_widgets[]
staticconstexpr

Definition at line 819 of file timetable_gui.cpp.