Go to the documentation of this file.
29 #include "table/strings.h"
65 if (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT))
return false;
88 assert(table !=
nullptr);
90 assert(start < v->GetNumOrders());
107 if (!order->
IsType(OT_IMPLICIT)) {
108 if (travelling || i != start) {
123 assert(order ==
nullptr);
126 }
while (i != start);
212 int GetOrderFromTimetableWndPt(
int y,
const Vehicle *v)
220 return (sel < v->GetNumOrders() * 2 && sel >= 0) ? sel :
INVALID_ORDER;
238 if (this->sel_index == -1)
break;
241 this->sel_index = -1;
245 if (!gui_scope)
break;
251 if (gui_scope)
break;
255 if (this->sel_index == -1)
break;
260 if (from == to)
break;
266 if (selected_order == old_num_orders) selected_order = 0;
268 bool travel =
HasBit(this->sel_index, 0);
270 if (from != selected_order) {
272 selected_order -= (int)(from <= selected_order);
274 selected_order += (int)(to <= selected_order);
280 this->sel_index = -1;
289 this->sel_index = 2 * selected_order - (int)travel;
291 if (this->sel_index == -1) this->sel_index = this->vehicle->
GetNumOrders() * 2 - 1;
301 int selected = this->sel_index;
307 if (selected != -1) {
309 if (selected % 2 == 1) {
310 disable = order !=
nullptr && (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT));
315 bool disable_speed = disable || selected % 2 != 1 || v->
type ==
VEH_AIRCRAFT;
353 int selected = this->sel_index;
360 bool final_order =
false;
368 while (order !=
nullptr) {
385 TextColour colour = (i == selected) ? TC_WHITE : TC_BLACK;
386 if (order->
IsType(OT_CONDITIONAL)) {
387 string = STR_TIMETABLE_NO_TRAVEL;
388 }
else if (order->
IsType(OT_IMPLICIT)) {
389 string = STR_TIMETABLE_NOT_TIMETABLEABLE;
390 colour = ((i == selected) ? TC_SILVER : TC_GREY) |
TC_NO_SHADE;
395 STR_TIMETABLE_TRAVEL_FOR_SPEED_ESTIMATED :
396 STR_TIMETABLE_TRAVEL_FOR_ESTIMATED;
399 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED :
400 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED;
405 STR_TIMETABLE_TRAVEL_FOR_SPEED : STR_TIMETABLE_TRAVEL_FOR;
411 if (final_order)
break;
450 DrawString(abbr_left, abbr_right, y, STR_TIMETABLE_ARRIVAL_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
451 if (this->show_expected && i / 2 == earlyID) {
453 DrawString(time_left, time_right, y, STR_JUST_DATE_TINY, TC_GREEN);
456 DrawString(time_left, time_right, y, STR_JUST_DATE_TINY,
457 show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
462 DrawString(abbr_left, abbr_right, y, STR_TIMETABLE_DEPARTURE_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
464 DrawString(time_left, time_right, y, STR_JUST_DATE_TINY,
465 show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
477 if (total_time != 0) {
504 static inline uint32 PackTimetableArgs(
const Vehicle *v, uint selected,
bool speed)
506 uint order_number = (selected + 1) / 2;
509 if (order_number >= v->
GetNumOrders()) order_number = 0;
511 return v->
index | (order_number << 20) | (mtf << 28);
524 int selected = GetOrderFromTimetableWndPt(pt.y, v);
527 this->sel_index = (selected ==
INVALID_ORDER || selected == this->sel_index) ? -1 : selected;
536 int selected = this->sel_index;
544 if (order !=
nullptr) {
550 current = STR_JUST_INT;
554 this->query_is_speed_query =
false;
560 int selected = this->sel_index;
567 if (order !=
nullptr) {
570 current = STR_JUST_INT;
574 this->query_is_speed_query =
true;
580 uint32 p1 = PackTimetableArgs(v, this->sel_index,
false);
586 uint32 p1 = PackTimetableArgs(v, this->sel_index,
true);
608 ShowVehicleListWindow(v);
617 if (str ==
nullptr)
return;
621 uint32 p1 = PackTimetableArgs(v, this->sel_index, this->query_is_speed_query);
623 uint64 val =
StrEmpty(str) ? 0 : strtoul(str,
nullptr, 10);
624 if (this->query_is_speed_query) {
630 uint32 p2 = std::min<uint32>(val, UINT16_MAX);
651 static const NWidgetPart _nested_timetable_widgets[] = {
661 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(),
663 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(),
698 WDP_AUTO,
"view_vehicle_timetable", 400, 130,
701 _nested_timetable_widgets,
lengthof(_nested_timetable_widgets)
712 AllocateWindowDescFront<TimetableWindow>(&_timetable_desc, v->
index);
@ VEH_AIRCRAFT
Aircraft vehicle type.
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
#define CMD_MSG(x)
Used to combine a StringID with the command.
@ MTF_TRAVEL_SPEED
Set max travel speed.
@ CMD_AUTOFILL_TIMETABLE
autofill the timetable
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.
void DeleteChildWindows(WindowClass wc=WC_INVALID) const
Delete all children a window might have in a head-recursive manner.
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
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.
@ MTF_WAIT_TIME
Set wait time.
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?
@ MTF_TRAVEL_TIME
Set travel time.
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:
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
@ CMD_CHANGE_TIMETABLE
change the timetable for a vehicle
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
@ FS_SMALL
Index of the small font in the font tables.
void ShowSetDateWindow(Window *parent, int window_number, Date initial_date, Year min_year, Year max_year, SetDateCallback *callback)
Create the new 'set date' window.
uint16 GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
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.
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.
OrderList * list
Pointer to the order list for this vehicle.
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.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
int32 lateness_counter
How many ticks late (or early if negative) this vehicle is.
#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.
union Vehicle::@51 orders
The orders currently assigned to the vehicle.
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.
@ CMD_SET_TIMETABLE_START
set the date that a timetable should start
static T abs(const T a)
Returns the absolute value of (scalar) variable.
bool timetable_arrival_departure
show arrivals and departures in vehicle timetables
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
Order * GetFirstOrder() const
Get the first order of the order chain.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
#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)
@ CMD_SET_VEHICLE_ON_TIME
set the vehicle on time feature (timetable)
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).
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
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