Go to the documentation of this file.
31 #include "table/strings.h"
67 if (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT))
return false;
90 assert(table !=
nullptr);
92 assert(start < v->GetNumOrders());
109 if (!order->
IsType(OT_IMPLICIT)) {
110 if (travelling || i != start) {
125 assert(order ==
nullptr);
128 }
while (i != start);
207 size->height = 8 *
resize->height + padding.height;
216 int GetOrderFromTimetableWndPt(
int y,
const Vehicle *v)
242 if (this->sel_index == -1)
break;
245 this->sel_index = -1;
249 if (!gui_scope)
break;
255 if (gui_scope)
break;
259 if (this->sel_index == -1)
break;
264 if (from == to)
break;
270 if (selected_order == old_num_orders) selected_order = 0;
272 bool travel =
HasBit(this->sel_index, 0);
274 if (from != selected_order) {
276 selected_order -= (int)(from <= selected_order);
278 selected_order += (int)(to <= selected_order);
284 this->sel_index = -1;
293 this->sel_index = 2 * selected_order - (int)travel;
295 if (this->sel_index == -1) this->sel_index = this->vehicle->
GetNumOrders() * 2 - 1;
305 int selected = this->sel_index;
311 if (selected != -1) {
313 if (selected % 2 == 1) {
314 disable = order !=
nullptr && (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT));
319 bool disable_speed = disable || selected % 2 != 1 || v->
type ==
VEH_AIRCRAFT;
357 int selected = this->sel_index;
364 bool final_order =
false;
369 int middle = rtl ? tr.right - index_column_width : tr.left + index_column_width;
372 while (order !=
nullptr) {
377 DrawOrderString(v, order, order_id, tr.top, i == selected,
true, tr.left, middle, tr.right);
389 TextColour colour = (i == selected) ? TC_WHITE : TC_BLACK;
390 if (order->
IsType(OT_CONDITIONAL)) {
391 string = STR_TIMETABLE_NO_TRAVEL;
392 }
else if (order->
IsType(OT_IMPLICIT)) {
393 string = STR_TIMETABLE_NOT_TIMETABLEABLE;
394 colour = ((i == selected) ? TC_SILVER : TC_GREY) |
TC_NO_SHADE;
399 STR_TIMETABLE_TRAVEL_FOR_SPEED_ESTIMATED :
400 STR_TIMETABLE_TRAVEL_FOR_ESTIMATED;
403 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED :
404 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED;
409 STR_TIMETABLE_TRAVEL_FOR_SPEED : STR_TIMETABLE_TRAVEL_FOR;
413 DrawString(rtl ? tr.left : middle, rtl ? middle : tr.right, tr.top,
string, colour);
415 if (final_order)
break;
451 DrawString(abbr.left, abbr.right, tr.top, STR_TIMETABLE_ARRIVAL_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
452 if (this->show_expected && i / 2 == earlyID) {
454 DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY, TC_GREEN);
457 DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY,
458 show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
463 DrawString(abbr.left, abbr.right, tr.top, STR_TIMETABLE_DEPARTURE_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
465 DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY,
466 show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
478 if (total_time != 0) {
489 DrawString(tr, STR_TIMETABLE_STATUS_START_AT);
493 DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED);
505 static inline std::tuple<VehicleOrderID, ModifyTimetableFlags> PackTimetableArgs(
const Vehicle *v, uint selected,
bool speed)
507 uint order_number = (selected + 1) / 2;
510 if (order_number >= v->
GetNumOrders()) order_number = 0;
512 return { order_number, mtf };
525 int selected = GetOrderFromTimetableWndPt(pt.y, v);
528 this->sel_index = (selected ==
INVALID_ORDER || selected == this->sel_index) ? -1 : selected;
537 int selected = this->sel_index;
545 if (order !=
nullptr) {
551 current = STR_JUST_INT;
555 this->query_is_speed_query =
false;
556 this->change_timetable_all =
_ctrl_pressed && (order !=
nullptr);
562 int selected = this->sel_index;
569 if (order !=
nullptr) {
572 current = STR_JUST_INT;
576 this->query_is_speed_query =
true;
577 this->change_timetable_all =
_ctrl_pressed && (order !=
nullptr);
583 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index,
false);
593 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index,
true);
616 ShowVehicleListWindow(v);
625 if (str ==
nullptr)
return;
629 uint64 val =
StrEmpty(str) ? 0 : strtoul(str,
nullptr, 10);
630 if (this->query_is_speed_query) {
636 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, this->query_is_speed_query);
638 if (this->change_timetable_all) {
661 static const NWidgetPart _nested_timetable_widgets[] = {
671 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(),
673 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(),
708 WDP_AUTO,
"view_vehicle_timetable", 400, 130,
711 _nested_timetable_widgets,
lengthof(_nested_timetable_widgets)
722 AllocateWindowDescFront<TimetableWindow>(&_timetable_desc, v->
index);
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ MTF_TRAVEL_SPEED
Set max travel speed.
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
uint16 GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
bool IsType(OrderType type) const
Check whether this order is of the given type.
static Titem * Get(size_t index)
Returns Titem with given index.
uint16 GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Dimensions (a width and height) of a rectangle in 2D.
@ MTF_WAIT_TIME
Set wait time.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ QSF_ACCEPT_UNCHANGED
return success even when the text didn't change
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Year _cur_year
Current year, starting at 0.
DateFract _date_fract
Fractional part of the day.
uint16 GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Tindex index
Index of this pool item.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
bool _ctrl_pressed
Is Ctrl pressed?
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
ClientSettings _settings_client
The current settings for this game.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
int32 WindowNumber
Number to differentiate different windows of the same class.
bool timetable_in_ticks
whether to show the timetable in ticks rather than days
Owner owner
Which company owns the vehicle?
void ShowSetDateWindow(Window *parent, int window_number, Date initial_date, Year min_year, Year max_year, SetDateCallback *callback, void *callback_data)
Create the new 'set date' window.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
static const OrderID INVALID_ORDER
Invalid order (sentinel)
uint16 GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
High level window description.
uint ConvertDisplaySpeedToKmhishSpeed(uint speed)
Convert the given display speed to the km/h-ish speed.
@ VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
@ WDP_AUTO
Find a place automatically.
ResizeInfo resize
Resize information.
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
Date _date
Current date in days (day counter)
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
@ FS_SMALL
Index of the small font in the font tables.
uint16 GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
Order current_order
The current order (+ status, like: loading)
int32 Date
The type to store our dates in.
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
int32 Ticks
The type to store ticks in.
@ TC_NO_SHADE
Do not add shading to this text colour.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Coordinates of a point in 2D.
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
WindowNumber window_number
Window number within the window class.
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
static const Ticks INVALID_TICKS
Representation of an invalid number of ticks.
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
@ ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
uint ConvertKmhishSpeedToDisplaySpeed(uint speed)
Convert the given km/h-ish speed to the display speed.
int32 lateness_counter
How many ticks late (or early if negative) this vehicle is.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Ticks GetTimetableDurationIncomplete() const
Gets the known duration of the vehicles timetable even if the timetable is not complete.
uint32 current_order_time
How many ticks have passed since this order started.
Date timetable_start
When the vehicle is supposed to start the timetable.
static const int DAYS_IN_YEAR
days per year
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
bool timetable_arrival_departure
show arrivals and departures in vehicle timetables
uint32 VehicleID
The type all our vehicle IDs have.
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
Order * GetFirstOrder() const
Get the first order of the order chain.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Data structure for an opened window.
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.
VehicleType type
Type of vehicle.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
void DrawWidgets() const
Paint all widgets of a window.
@ VIWD_MODIFY_ORDERS
Other order modifications.
Specification of a rectangle with absolute coordinates of all edges.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
@ VIWD_REMOVE_ALL_ORDERS
Removed / replaced all orders (after deleting / sharing).
OrderList * orders
Pointer to the order list for this vehicle.
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Order * next
Pointer to next order. If nullptr, end of list.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
@ TD_RTL
Text is written right-to-left by default.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
TextDirection _current_text_dir
Text direction of the currently selected language.
@ CS_NUMERAL
Only numeric ones.
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
GUISettings gui
settings related to the GUI
@ MTF_TRAVEL_TIME
Set travel time.
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro