34 #include "table/strings.h"
53 case TimetableMode::Days:
57 case TimetableMode::Seconds:
61 case TimetableMode::Ticks:
77 case TimetableMode::Days:
79 case TimetableMode::Seconds:
81 case TimetableMode::Ticks:
97 case TimetableMode::Days:
99 case TimetableMode::Seconds:
101 case TimetableMode::Ticks:
117 if (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT))
return false;
140 assert(!table.empty());
142 assert(start < v->GetNumOrders());
159 if (!order->
IsType(OT_IMPLICIT)) {
160 if (travelling || i != start) {
163 table[i].arrival = sum;
168 table[i].departure = sum;
175 assert(order ==
nullptr);
178 }
while (i != start);
185 table[i].arrival = sum;
269 size.height = 8 *
resize.height + padding.height;
278 int GetOrderFromTimetableWndPt(
int y, [[maybe_unused]]
const Vehicle *v)
282 assert(
IsInsideBS(sel, 0, v->GetNumOrders() * 2));
291 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
301 if (this->sel_index == -1)
break;
304 this->sel_index = -1;
308 if (!gui_scope)
break;
314 if (gui_scope)
break;
318 if (this->sel_index == -1)
break;
323 if (from == to)
break;
329 if (selected_order == old_num_orders) selected_order = 0;
331 bool travel =
HasBit(this->sel_index, 0);
333 if (from != selected_order) {
335 selected_order -= (int)(from <= selected_order);
337 selected_order += (int)(to <= selected_order);
343 this->sel_index = -1;
352 this->sel_index = 2 * selected_order - (int)travel;
354 if (this->sel_index == -1) this->sel_index = this->vehicle->
GetNumOrders() * 2 - 1;
364 int selected = this->sel_index;
370 if (selected != -1) {
372 if (selected % 2 != 0) {
373 disable = order !=
nullptr && (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT));
378 bool disable_speed = disable || selected % 2 == 0 || v->
type ==
VEH_AIRCRAFT;
405 void SetStringParameters(
WidgetID widget)
const override
423 bool final_order =
false;
424 int selected = this->sel_index;
429 int middle = rtl ? tr.right - index_column_width : tr.left + index_column_width;
432 while (order !=
nullptr) {
437 DrawOrderString(v, order, order_id, tr.top, i == selected,
true, tr.left, middle, tr.right);
449 TextColour colour = (i == selected) ? TC_WHITE : TC_BLACK;
450 if (order->
IsType(OT_CONDITIONAL)) {
451 string = STR_TIMETABLE_NO_TRAVEL;
452 }
else if (order->
IsType(OT_IMPLICIT)) {
453 string = STR_TIMETABLE_NOT_TIMETABLEABLE;
454 colour = ((i == selected) ? TC_SILVER : TC_GREY) |
TC_NO_SHADE;
459 STR_TIMETABLE_TRAVEL_FOR_SPEED_ESTIMATED :
460 STR_TIMETABLE_TRAVEL_FOR_ESTIMATED;
463 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED :
464 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED;
469 STR_TIMETABLE_TRAVEL_FOR_SPEED : STR_TIMETABLE_TRAVEL_FOR;
473 DrawString(rtl ? tr.left : middle, rtl ? middle : tr.right, tr.top,
string, colour);
475 if (final_order)
break;
497 std::vector<TimetableArrivalDeparture> arr_dep(v->
GetNumOrders());
501 int selected = this->sel_index;
512 SetDParam(0, show_late ? TC_RED : TC_INVALID);
518 if (this->show_expected && i / 2 == earlyID) {
524 this_offset = offset;
531 DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_ARRIVAL_SECONDS_IN_FUTURE, i == selected ? TC_WHITE : TC_BLACK);
535 DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_ARRIVAL_DATE, i == selected ? TC_WHITE : TC_BLACK);
544 DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_DEPARTURE_SECONDS_IN_FUTURE, i == selected ? TC_WHITE : TC_BLACK);
548 DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_DEPARTURE_DATE, i == selected ? TC_WHITE : TC_BLACK);
566 if (total_time != 0) {
579 DrawString(tr, STR_TIMETABLE_STATUS_START_IN_SECONDS);
584 DrawString(tr, STR_TIMETABLE_STATUS_START_AT_DATE);
588 DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED);
599 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
619 static inline std::tuple<VehicleOrderID, ModifyTimetableFlags> PackTimetableArgs(
const Vehicle *v, uint selected,
bool speed)
621 uint order_number = (selected + 1) / 2;
624 if (order_number >= v->
GetNumOrders()) order_number = 0;
626 return { order_number, mtf };
629 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
639 int selected = GetOrderFromTimetableWndPt(pt.y, v);
642 this->sel_index = (selected ==
INVALID_ORDER || selected == this->sel_index) ? -1 : selected;
658 int selected = this->sel_index;
666 if (order !=
nullptr) {
672 current = STR_JUST_INT;
676 this->change_timetable_all =
_ctrl_pressed && (order !=
nullptr);
683 int selected = this->sel_index;
690 if (order !=
nullptr) {
693 current = STR_JUST_INT;
697 this->change_timetable_all =
_ctrl_pressed && (order !=
nullptr);
703 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index,
false);
713 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index,
true);
736 ShowVehicleListWindow(v);
743 void OnQueryTextFinished(std::optional<std::string> str)
override
745 if (!str.has_value())
return;
748 uint64_t val = str->empty() ? 0 : std::strtoul(str->c_str(),
nullptr, 10);
755 if (this->change_timetable_all) {
766 if (this->change_timetable_all) {
809 static constexpr
NWidgetPart _nested_timetable_widgets[] = {
819 NWidget(
WWT_PANEL, COLOUR_GREY,
WID_VT_TIMETABLE_PANEL),
SetMinimalSize(388, 82),
SetResize(1, 10),
SetDataTip(STR_NULL, STR_TIMETABLE_TOOLTIP),
SetScrollbar(
WID_VT_SCROLLBAR),
EndContainer(),
821 NWidget(
WWT_PANEL, COLOUR_GREY,
WID_VT_ARRIVAL_DEPARTURE_PANEL),
SetMinimalSize(110, 0),
SetFill(0, 1),
SetDataTip(STR_NULL, STR_TIMETABLE_TOOLTIP),
SetScrollbar(
WID_VT_SCROLLBAR),
EndContainer(),
856 WDP_AUTO,
"view_vehicle_timetable", 400, 130,
859 _nested_timetable_widgets
870 AllocateWindowDescFront<TimetableWindow>(_timetable_desc, v->
index);
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static constexpr TimerGameTick::Ticks INVALID_TICKS
Representation of an invalid number of ticks.
static constexpr TimerGameTick::Ticks TICKS_PER_SECOND
Estimation of how many ticks fit in a single second.
static constexpr TimerGame< struct Economy >::Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
static Date date
Current date in days (day counter).
static Year year
Current year, starting at 0.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static DateFract date_fract
Fractional part of the day.
uint64_t TickCounter
The type that the tick counter is stored in.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
int32_t Ticks
The type to store ticks in.
static constexpr Date DateAtStartOfYear(Year year)
Calculate the date of the first day of a given year.
Functions related to commands.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
void ShowSetDateWindow(Window *parent, int window_number, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback *callback, void *callback_data)
Create the new 'set date' window.
Functions related to the graphical selection of a date.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool _ctrl_pressed
Is Ctrl pressed?
Functions related to the gfx engine.
@ FS_SMALL
Index of the small font in the font tables.
@ FS_NORMAL
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ TC_NO_SHADE
Do not add shading to this text colour.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
GUI functions that shouldn't be here.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
Draws an order in order or timetable GUI.
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
static const OrderID INVALID_ORDER
Invalid order (sentinel)
@ ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
@ MTF_TRAVEL_TIME
Set travel time.
@ MTF_WAIT_TIME
Set wait time.
@ MTF_TRAVEL_SPEED
Set max travel speed.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.
@ CS_NUMERAL
Only numeric ones.
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type)
Convert the given display speed to the km/h-ish speed.
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type)
Convert the given km/h-ish speed to the display speed.
TextDirection _current_text_dir
Text direction of the currently selected language.
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
@ TD_RTL
Text is written right-to-left by default.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
TimerGameTick::TickCounter timetable_start
At what tick of TimerGameTick::counter the vehicle should start its timetable.
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
VehicleType type
Type of vehicle.
GUISettings gui
settings related to the GUI
Dimensions (a width and height) of a rectangle in 2D.
bool timetable_arrival_departure
show arrivals and departures in vehicle timetables
TimetableMode timetable_mode
Time units for timetables: days, seconds, or ticks.
TimerGameTick::Ticks GetTimetableDurationIncomplete() const
Gets the known duration of the vehicles timetable even if the timetable is not complete.
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
Order * GetFirstOrder() const
Get the first order of the order chain.
uint16_t GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
uint16_t GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
bool IsType(OrderType type) const
Check whether this order is of the given type.
uint16_t GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Order * next
Pointer to next order. If nullptr, end of list.
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
uint16_t GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
uint16_t GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Coordinates of a point in 2D.
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
Order current_order
The current order (+ status, like: loading)
OrderList * orders
Pointer to the order list for this vehicle.
Owner owner
Which company owns the vehicle?
High level window description.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void DrawWidgets() const
Paint all widgets of a window.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
ResizeInfo resize
Resize information.
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
Stuff related to the text buffer GUI.
@ QSF_ACCEPT_UNCHANGED
return success even when the text didn't change
Definition of Interval and OneShot timers.
Definition of the game-economy-timer.
Definition of the tick-based game-timer.
Definition of the Window system.
Base class for all vehicles.
@ VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
Functions related to the vehicle's GUIs.
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
@ VIWD_MODIFY_ORDERS
Other order modifications.
@ VIWD_REMOVE_ALL_ORDERS
Removed / replaced all orders (after deleting / sharing).
@ VEH_AIRCRAFT
Aircraft vehicle type.
uint32_t VehicleID
The type all our vehicle IDs have.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
int32_t WindowNumber
Number to differentiate different windows of the same class.
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers: