OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
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);
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.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Dimensions (a width and height) of a rectangle in 2D.
@ 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.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
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.
@ MTF_TRAVEL_TIME
Set travel time.
Tindex index
Index of this pool item.
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
bool _ctrl_pressed
Is Ctrl pressed?
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
static DateFract date_fract
Fractional part of the day.
ClientSettings _settings_client
The current settings for this game.
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Owner owner
Which company owns the vehicle?
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
uint64_t TickCounter
The type that the tick counter is stored in.
TimerGameTick::Ticks GetTimetableDurationIncomplete() const
Gets the known duration of the vehicles timetable even if the timetable is not complete.
static const OrderID INVALID_ORDER
Invalid order (sentinel)
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type)
Convert the given display speed to the km/h-ish speed.
High level window description.
@ VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
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.
@ 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.
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
int32_t WindowNumber
Number to differentiate different windows of the same class.
@ FS_NORMAL
Index of the normal font in the font tables.
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
uint16_t GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
@ FS_SMALL
Index of the small font in the font tables.
Order current_order
The current order (+ status, like: loading)
static constexpr TimerGameTick::Ticks INVALID_TICKS
Representation of an invalid number of ticks.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
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.
@ TC_NO_SHADE
Do not add shading to this text colour.
uint32_t VehicleID
The type all our vehicle IDs have.
Coordinates of a point in 2D.
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,...
WindowNumber window_number
Window number within the window class.
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
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.
uint16_t GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
int32_t Ticks
The type to store ticks in.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
static Year year
Current year, starting at 0.
static constexpr Date DateAtStartOfYear(Year year)
Calculate the date of the first day of a given year.
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.
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
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.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
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 GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
@ MTF_TRAVEL_SPEED
Set max travel speed.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
uint16_t GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
static constexpr TimerGameTick::Ticks TICKS_PER_SECOND
Estimation of how many ticks fit in a single second.
bool timetable_arrival_departure
show arrivals and departures in vehicle timetables
TimetableMode timetable_mode
Time units for timetables: days, seconds, or ticks.
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
Order * GetFirstOrder() const
Get the first order of the order chain.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
int width
width of the window (number of pixels to the right in x direction)
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.
@ VEH_AIRCRAFT
Aircraft vehicle type.
TimerGameTick::TickCounter timetable_start
At what tick of TimerGameTick::counter the vehicle should start its timetable.
Data structure for an opened window.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
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.
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type)
Convert the given km/h-ish speed to the display speed.
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.
Order * next
Pointer to next order. If nullptr, end of list.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
@ MTF_WAIT_TIME
Set wait time.
@ CS_NUMERAL
Only numeric ones.
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
GUISettings gui
settings related to the GUI
static Date date
Current date in days (day counter).
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.