OpenTTD Source: src/timetable_gui.cpp Source File

OpenTTD Source 14.0-RC3

timetable_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "command_func.h"
12 #include "gui.h"
13 #include "window_gui.h"
14 #include "window_func.h"
15 #include "textbuf_gui.h"
16 #include "strings_func.h"
17 #include "vehicle_base.h"
18 #include "string_func.h"
19 #include "gfx_func.h"
20 #include "company_func.h"
21 #include "timer/timer.h"
22 #include "timer/timer_game_tick.h"
23 #include "timer/timer_game_economy.h"
24 #include "timer/timer_window.h"
25 #include "date_gui.h"
26 #include "vehicle_gui.h"
27 #include "settings_type.h"
28 #include "timetable_cmd.h"
29 #include "timetable.h"
30
31 #include "widgets/timetable_widget.h"
32
33 #include "table/sprites.h"
34 #include "table/strings.h"
35
36 #include "safeguards.h"
37
39 struct TimetableArrivalDeparture {
40 TimerGameTick::Ticks arrival;
41 TimerGameTick::Ticks departure;
42 };
43
50 void SetTimetableParams(int param1, int param2, TimerGameTick::Ticks ticks)
51 {
52 switch (_settings_client.gui.timetable_mode) {
53 case TimetableMode::Days:
54 SetDParam(param1, STR_UNITS_DAYS);
55 SetDParam(param2, ticks / Ticks::DAY_TICKS);
56 break;
57 case TimetableMode::Seconds:
58 SetDParam(param1, STR_UNITS_SECONDS);
59 SetDParam(param2, ticks / Ticks::TICKS_PER_SECOND);
60 break;
61 case TimetableMode::Ticks:
62 SetDParam(param1, STR_UNITS_TICKS);
63 SetDParam(param2, ticks);
64 break;
65 default:
66 NOT_REACHED();
67 }
68 }
69
74 static inline TimerGameTick::Ticks TicksPerTimetableUnit()
75 {
76 switch (_settings_client.gui.timetable_mode) {
77 case TimetableMode::Days:
78 return Ticks::DAY_TICKS;
79 case TimetableMode::Seconds:
80 return Ticks::TICKS_PER_SECOND;
81 case TimetableMode::Ticks:
82 return 1;
83 default:
84 NOT_REACHED();
85 }
86 }
87
94 bool VehicleIsAboveLatenessThreshold(const Vehicle *v, bool round_to_day)
95 {
96 switch (_settings_client.gui.timetable_mode) {
97 case TimetableMode::Days:
98 return v->lateness_counter > Ticks::DAY_TICKS;
99 case TimetableMode::Seconds:
100 return v->lateness_counter > Ticks::TICKS_PER_SECOND;
101 case TimetableMode::Ticks:
102 return v->lateness_counter > (round_to_day ? Ticks::DAY_TICKS : 0);
103 default:
104 NOT_REACHED();
105 }
106 }
107
114 static bool CanDetermineTimeTaken(const Order *order, bool travelling)
115 {
116 /* Current order is conditional */
117 if (order->IsType(OT_CONDITIONAL) || order->IsType(OT_IMPLICIT)) return false;
118 /* No travel time and we have not already finished travelling */
119 if (travelling && !order->IsTravelTimetabled()) return false;
120 /* No wait time but we are loading at this timetabled station */
121 if (!travelling && !order->IsWaitTimetabled() && order->IsType(OT_GOTO_STATION) &&
122 !(order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) {
123 return false;
124 }
125
126 return true;
127 }
128
129
138 static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID start, bool travelling, std::vector<TimetableArrivalDeparture> &table, TimerGameTick::Ticks offset)
139 {
140 assert(!table.empty());
141 assert(v->GetNumOrders() >= 2);
142 assert(start < v->GetNumOrders());
143
144 /* Pre-initialize with unknown time */
145 for (int i = 0; i < v->GetNumOrders(); ++i) {
146 table[i].arrival = table[i].departure = Ticks::INVALID_TICKS;
147 }
148
149 TimerGameTick::Ticks sum = offset;
150 VehicleOrderID i = start;
151 const Order *order = v->GetOrder(i);
152
153 /* Cyclically loop over all orders until we reach the current one again.
154 * As we may start at the current order, do a post-checking loop */
155 do {
156 /* Automatic orders don't influence the overall timetable;
157 * they just add some untimetabled entries, but the time till
158 * the next non-implicit order can still be known. */
159 if (!order->IsType(OT_IMPLICIT)) {
160 if (travelling || i != start) {
161 if (!CanDetermineTimeTaken(order, true)) return;
162 sum += order->GetTimetabledTravel();
163 table[i].arrival = sum;
164 }
165
166 if (!CanDetermineTimeTaken(order, false)) return;
167 sum += order->GetTimetabledWait();
168 table[i].departure = sum;
169 }
170
171 ++i;
172 order = order->next;
173 if (i >= v->GetNumOrders()) {
174 i = 0;
175 assert(order == nullptr);
176 order = v->orders->GetFirstOrder();
177 }
178 } while (i != start);
179
180 /* When loading at a scheduled station we still have to treat the
181 * travelling part of the first order. */
182 if (!travelling) {
183 if (!CanDetermineTimeTaken(order, true)) return;
184 sum += order->GetTimetabledTravel();
185 table[i].arrival = sum;
186 }
187 }
188
189
195 static void ChangeTimetableStartCallback(const Window *w, TimerGameEconomy::Date date, void *data)
196 {
197 Command<CMD_SET_TIMETABLE_START>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, (VehicleID)w->window_number, reinterpret_cast<std::uintptr_t>(data) != 0, GetStartTickFromDate(date));
198 }
199
200
201 struct TimetableWindow : Window {
202 int sel_index;
203 VehicleTimetableWidgets query_widget;
204 const Vehicle *vehicle;
205 bool show_expected;
206 Scrollbar *vscroll;
207 bool set_start_date_all;
208 bool change_timetable_all;
209
210 TimetableWindow(WindowDesc *desc, WindowNumber window_number) :
211 Window(desc),
212 sel_index(-1),
213 vehicle(Vehicle::Get(window_number)),
214 show_expected(true)
215 {
216 this->CreateNestedTree();
217 this->vscroll = this->GetScrollbar(WID_VT_SCROLLBAR);
218
219 /* When using wallclock units, we must ensure the client displays timetables in seconds. */
220 if (TimerGameEconomy::UsingWallclockUnits()) {
221 _settings_client.gui.timetable_mode = TimetableMode::Seconds;
222 }
223
224 this->UpdateSelectionStates();
225 this->FinishInitNested(window_number);
226
227 this->owner = this->vehicle->owner;
228 }
229
236 static bool BuildArrivalDepartureList(const Vehicle *v, std::vector<TimetableArrivalDeparture> &table)
237 {
238 assert(HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED));
239
240 bool travelling = (!v->current_order.IsType(OT_LOADING) || v->current_order.GetNonStopType() == ONSF_STOP_EVERYWHERE);
241 TimerGameTick::Ticks start_time = -v->current_order_time;
242
243 /* If arrival and departure times are in days, compensate for the current date_fract. */
244 if (_settings_client.gui.timetable_mode != TimetableMode::Seconds) start_time += TimerGameEconomy::date_fract;
245
246 FillTimetableArrivalDepartureTable(v, v->cur_real_order_index % v->GetNumOrders(), travelling, table, start_time);
247
248 return (travelling && v->lateness_counter < 0);
249 }
250
251 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
252 {
253 switch (widget) {
254 case WID_VT_ARRIVAL_DEPARTURE_PANEL:
255 /* We handle this differently depending on the timetable mode. */
256 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
257 /* A five-digit number would fit a timetable lasting 2.7 real-world hours, which should be plenty. */
258 SetDParamMaxDigits(1, 4, FS_SMALL);
259 size->width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL_SECONDS_IN_FUTURE).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE_SECONDS_IN_FUTURE).width) + WidgetDimensions::scaled.hsep_wide + padding.width;
260 } else {
261 SetDParamMaxValue(1, TimerGameEconomy::DateAtStartOfYear(EconomyTime::MAX_YEAR), 0, FS_SMALL);
262 size->width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL_DATE).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE_DATE).width) + WidgetDimensions::scaled.hsep_wide + padding.width;
263 }
264 [[fallthrough]];
265
266 case WID_VT_ARRIVAL_DEPARTURE_SELECTION:
267 case WID_VT_TIMETABLE_PANEL:
268 resize->height = GetCharacterHeight(FS_NORMAL);
269 size->height = 8 * resize->height + padding.height;
270 break;
271
272 case WID_VT_SUMMARY_PANEL:
273 size->height = 2 * GetCharacterHeight(FS_NORMAL) + padding.height;
274 break;
275 }
276 }
277
278 int GetOrderFromTimetableWndPt(int y, [[maybe_unused]] const Vehicle *v)
279 {
280 int sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_VT_TIMETABLE_PANEL, WidgetDimensions::scaled.framerect.top);
281 if (sel == INT_MAX) return INVALID_ORDER;
282 assert(IsInsideBS(sel, 0, v->GetNumOrders() * 2));
283 return sel;
284 }
285
291 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
292 {
293 switch (data) {
294 case VIWD_AUTOREPLACE:
295 /* Autoreplace replaced the vehicle */
296 this->vehicle = Vehicle::Get(this->window_number);
297 break;
298
299 case VIWD_REMOVE_ALL_ORDERS:
300 /* Removed / replaced all orders (after deleting / sharing) */
301 if (this->sel_index == -1) break;
302
303 this->CloseChildWindows();
304 this->sel_index = -1;
305 break;
306
307 case VIWD_MODIFY_ORDERS:
308 if (!gui_scope) break;
309 this->UpdateSelectionStates();
310 this->ReInit();
311 break;
312
313 default: {
314 if (gui_scope) break; // only do this once; from command scope
315
316 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
317 * the order is being created / removed */
318 if (this->sel_index == -1) break;
319
320 VehicleOrderID from = GB(data, 0, 8);
321 VehicleOrderID to = GB(data, 8, 8);
322
323 if (from == to) break; // no need to change anything
324
325 /* if from == INVALID_VEH_ORDER_ID, one order was added; if to == INVALID_VEH_ORDER_ID, one order was removed */
326 uint old_num_orders = this->vehicle->GetNumOrders() - (uint)(from == INVALID_VEH_ORDER_ID) + (uint)(to == INVALID_VEH_ORDER_ID);
327
328 VehicleOrderID selected_order = (this->sel_index + 1) / 2;
329 if (selected_order == old_num_orders) selected_order = 0; // when last travel time is selected, it belongs to order 0
330
331 bool travel = HasBit(this->sel_index, 0);
332
333 if (from != selected_order) {
334 /* Moving from preceding order? */
335 selected_order -= (int)(from <= selected_order);
336 /* Moving to preceding order? */
337 selected_order += (int)(to <= selected_order);
338 } else {
339 /* Now we are modifying the selected order */
340 if (to == INVALID_VEH_ORDER_ID) {
341 /* Deleting selected order */
342 this->CloseChildWindows();
343 this->sel_index = -1;
344 break;
345 } else {
346 /* Moving selected order */
347 selected_order = to;
348 }
349 }
350
351 /* recompute new sel_index */
352 this->sel_index = 2 * selected_order - (int)travel;
353 /* travel time of first order needs special handling */
354 if (this->sel_index == -1) this->sel_index = this->vehicle->GetNumOrders() * 2 - 1;
355 break;
356 }
357 }
358 }
359
360
361 void OnPaint() override
362 {
363 const Vehicle *v = this->vehicle;
364 int selected = this->sel_index;
365
366 this->vscroll->SetCount(v->GetNumOrders() * 2);
367
368 if (v->owner == _local_company) {
369 bool disable = true;
370 if (selected != -1) {
371 const Order *order = v->GetOrder(((selected + 1) / 2) % v->GetNumOrders());
372 if (selected % 2 != 0) {
373 disable = order != nullptr && (order->IsType(OT_CONDITIONAL) || order->IsType(OT_IMPLICIT));
374 } else {
375 disable = order == nullptr || ((!order->IsType(OT_GOTO_STATION) || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) && !order->IsType(OT_CONDITIONAL));
376 }
377 }
378 bool disable_speed = disable || selected % 2 == 0 || v->type == VEH_AIRCRAFT;
379
380 this->SetWidgetDisabledState(WID_VT_CHANGE_TIME, disable);
381 this->SetWidgetDisabledState(WID_VT_CLEAR_TIME, disable);
382 this->SetWidgetDisabledState(WID_VT_CHANGE_SPEED, disable_speed);
383 this->SetWidgetDisabledState(WID_VT_CLEAR_SPEED, disable_speed);
384 this->SetWidgetDisabledState(WID_VT_SHARED_ORDER_LIST, !v->IsOrderListShared());
385
386 this->SetWidgetDisabledState(WID_VT_START_DATE, v->orders == nullptr);
387 this->SetWidgetDisabledState(WID_VT_RESET_LATENESS, v->orders == nullptr);
388 this->SetWidgetDisabledState(WID_VT_AUTOFILL, v->orders == nullptr);
389 } else {
390 this->DisableWidget(WID_VT_START_DATE);
391 this->DisableWidget(WID_VT_CHANGE_TIME);
392 this->DisableWidget(WID_VT_CLEAR_TIME);
393 this->DisableWidget(WID_VT_CHANGE_SPEED);
394 this->DisableWidget(WID_VT_CLEAR_SPEED);
395 this->DisableWidget(WID_VT_RESET_LATENESS);
396 this->DisableWidget(WID_VT_AUTOFILL);
397 this->DisableWidget(WID_VT_SHARED_ORDER_LIST);
398 }
399
400 this->SetWidgetLoweredState(WID_VT_AUTOFILL, HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE));
401
402 this->DrawWidgets();
403 }
404
405 void SetStringParameters(WidgetID widget) const override
406 {
407 switch (widget) {
408 case WID_VT_CAPTION: SetDParam(0, this->vehicle->index); break;
409 case WID_VT_EXPECTED: SetDParam(0, this->show_expected ? STR_TIMETABLE_EXPECTED : STR_TIMETABLE_SCHEDULED); break;
410 }
411 }
412
417 void DrawTimetablePanel(const Rect &r) const
418 {
419 const Vehicle *v = this->vehicle;
420 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
421 int i = this->vscroll->GetPosition();
422 VehicleOrderID order_id = (i + 1) / 2;
423 bool final_order = false;
424 int selected = this->sel_index;
425
426 bool rtl = _current_text_dir == TD_RTL;
427 SetDParamMaxValue(0, v->GetNumOrders(), 2);
428 int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + WidgetDimensions::scaled.hsep_normal;
429 int middle = rtl ? tr.right - index_column_width : tr.left + index_column_width;
430
431 const Order *order = v->GetOrder(order_id);
432 while (order != nullptr) {
433 /* Don't draw anything if it extends past the end of the window. */
434 if (!this->vscroll->IsVisible(i)) break;
435
436 if (i % 2 == 0) {
437 DrawOrderString(v, order, order_id, tr.top, i == selected, true, tr.left, middle, tr.right);
438
439 order_id++;
440
441 if (order_id >= v->GetNumOrders()) {
442 order = v->GetOrder(0);
443 final_order = true;
444 } else {
445 order = order->next;
446 }
447 } else {
448 StringID string;
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;
455 } else if (!order->IsTravelTimetabled()) {
456 if (order->GetTravelTime() > 0) {
457 SetTimetableParams(0, 1, order->GetTravelTime());
458 string = order->GetMaxSpeed() != UINT16_MAX ?
459 STR_TIMETABLE_TRAVEL_FOR_SPEED_ESTIMATED :
460 STR_TIMETABLE_TRAVEL_FOR_ESTIMATED;
461 } else {
462 string = order->GetMaxSpeed() != UINT16_MAX ?
463 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED :
464 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED;
465 }
466 } else {
467 SetTimetableParams(0, 1, order->GetTimetabledTravel());
468 string = order->GetMaxSpeed() != UINT16_MAX ?
469 STR_TIMETABLE_TRAVEL_FOR_SPEED : STR_TIMETABLE_TRAVEL_FOR;
470 }
471 SetDParam(2, PackVelocity(order->GetMaxSpeed(), v->type));
472
473 DrawString(rtl ? tr.left : middle, rtl ? middle : tr.right, tr.top, string, colour);
474
475 if (final_order) break;
476 }
477
478 i++;
479 tr.top += GetCharacterHeight(FS_NORMAL);
480 }
481 }
482
487 void DrawArrivalDeparturePanel(const Rect &r) const
488 {
489 const Vehicle *v = this->vehicle;
490
491 /* Arrival and departure times are handled in an all-or-nothing approach,
492 * i.e. are only shown if we can calculate all times.
493 * Excluding order lists with only one order makes some things easier. */
494 TimerGameTick::Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0;
495 if (total_time <= 0 || v->GetNumOrders() <= 1 || !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return;
496
497 std::vector<TimetableArrivalDeparture> arr_dep(v->GetNumOrders());
498 const VehicleOrderID cur_order = v->cur_real_order_index % v->GetNumOrders();
499
500 VehicleOrderID earlyID = BuildArrivalDepartureList(v, arr_dep) ? cur_order : (VehicleOrderID)INVALID_VEH_ORDER_ID;
501 int selected = this->sel_index;
502
503 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
504 bool show_late = this->show_expected && VehicleIsAboveLatenessThreshold(v, true);
505 TimerGameTick::Ticks offset = show_late ? 0 : -v->lateness_counter;
506
507 for (int i = this->vscroll->GetPosition(); i / 2 < v->GetNumOrders(); ++i) { // note: i is also incremented in the loop
508 /* Don't draw anything if it extends past the end of the window. */
509 if (!this->vscroll->IsVisible(i)) break;
510
511 /* TC_INVALID will skip the colour change. */
512 SetDParam(0, show_late ? TC_RED : TC_INVALID);
513 if (i % 2 == 0) {
514 /* Draw an arrival time. */
515 if (arr_dep[i / 2].arrival != Ticks::INVALID_TICKS) {
516 /* First set the offset and text colour based on the expected/scheduled mode and some other things. */
517 TimerGameTick::Ticks this_offset;
518 if (this->show_expected && i / 2 == earlyID) {
519 /* Show expected arrival. */
520 this_offset = 0;
521 SetDParam(0, TC_GREEN);
522 } else {
523 /* Show scheduled arrival. */
524 this_offset = offset;
525 }
526
527 /* Now actually draw the arrival time. */
528 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
529 /* Display seconds from now. */
530 SetDParam(1, ((arr_dep[i / 2].arrival + offset) / Ticks::TICKS_PER_SECOND));
531 DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_ARRIVAL_SECONDS_IN_FUTURE, i == selected ? TC_WHITE : TC_BLACK);
532 } else {
533 /* Show a date. */
534 SetDParam(1, TimerGameEconomy::date + (arr_dep[i / 2].arrival + this_offset) / Ticks::DAY_TICKS);
535 DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_ARRIVAL_DATE, i == selected ? TC_WHITE : TC_BLACK);
536 }
537 }
538 } else {
539 /* Draw a departure time. */
540 if (arr_dep[i / 2].departure != Ticks::INVALID_TICKS) {
541 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
542 /* Display seconds from now. */
543 SetDParam(1, ((arr_dep[i / 2].departure + offset) / Ticks::TICKS_PER_SECOND));
544 DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_DEPARTURE_SECONDS_IN_FUTURE, i == selected ? TC_WHITE : TC_BLACK);
545 } else {
546 /* Show a date. */
547 SetDParam(1, TimerGameEconomy::date + (arr_dep[i / 2].departure + offset) / Ticks::DAY_TICKS);
548 DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_DEPARTURE_DATE, i == selected ? TC_WHITE : TC_BLACK);
549 }
550 }
551 }
552 tr.top += GetCharacterHeight(FS_NORMAL);
553 }
554 }
555
560 void DrawSummaryPanel(const Rect &r) const
561 {
562 const Vehicle *v = this->vehicle;
563 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
564
565 TimerGameTick::Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0;
566 if (total_time != 0) {
567 SetTimetableParams(0, 1, total_time);
568 DrawString(tr, v->orders->IsCompleteTimetable() ? STR_TIMETABLE_TOTAL_TIME : STR_TIMETABLE_TOTAL_TIME_INCOMPLETE);
569 }
570 tr.top += GetCharacterHeight(FS_NORMAL);
571
572 /* Draw the lateness display, or indicate that the timetable has not started yet. */
573 if (v->timetable_start != 0) {
574 /* We are running towards the first station so we can start the
575 * timetable at the given time. */
576 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
577 /* Real time units use seconds relative to now. */
578 SetDParam(0, (static_cast<TimerGameTick::Ticks>(v->timetable_start - TimerGameTick::counter) / Ticks::TICKS_PER_SECOND));
579 DrawString(tr, STR_TIMETABLE_STATUS_START_IN_SECONDS);
580 } else {
581 /* Other units use dates. */
582 SetDParam(0, STR_JUST_DATE_TINY);
583 SetDParam(1, GetDateFromStartTick(v->timetable_start));
584 DrawString(tr, STR_TIMETABLE_STATUS_START_AT_DATE);
585 }
586 } else if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
587 /* We aren't running on a timetable yet. */
588 DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED);
589 } else if (!VehicleIsAboveLatenessThreshold(v, false)) {
590 /* We are on time. */
591 DrawString(tr, STR_TIMETABLE_STATUS_ON_TIME);
592 } else {
593 /* We are late. */
594 SetTimetableParams(0, 1, abs(v->lateness_counter));
595 DrawString(tr, v->lateness_counter < 0 ? STR_TIMETABLE_STATUS_EARLY : STR_TIMETABLE_STATUS_LATE);
596 }
597 }
598
599 void DrawWidget(const Rect &r, WidgetID widget) const override
600 {
601 switch (widget) {
602 case WID_VT_TIMETABLE_PANEL: {
603 this->DrawTimetablePanel(r);
604 break;
605 }
606
607 case WID_VT_ARRIVAL_DEPARTURE_PANEL: {
608 this->DrawArrivalDeparturePanel(r);
609 break;
610 }
611
612 case WID_VT_SUMMARY_PANEL: {
613 this->DrawSummaryPanel(r);
614 break;
615 }
616 }
617 }
618
619 static inline std::tuple<VehicleOrderID, ModifyTimetableFlags> PackTimetableArgs(const Vehicle *v, uint selected, bool speed)
620 {
621 uint order_number = (selected + 1) / 2;
622 ModifyTimetableFlags mtf = (selected % 2 != 0) ? (speed ? MTF_TRAVEL_SPEED : MTF_TRAVEL_TIME) : MTF_WAIT_TIME;
623
624 if (order_number >= v->GetNumOrders()) order_number = 0;
625
626 return { order_number, mtf };
627 }
628
629 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
630 {
631 const Vehicle *v = this->vehicle;
632
633 switch (widget) {
634 case WID_VT_ORDER_VIEW: // Order view button
635 ShowOrdersWindow(v);
636 break;
637
638 case WID_VT_TIMETABLE_PANEL: { // Main panel.
639 int selected = GetOrderFromTimetableWndPt(pt.y, v);
640
641 this->CloseChildWindows();
642 this->sel_index = (selected == INVALID_ORDER || selected == this->sel_index) ? -1 : selected;
643 break;
644 }
645
646 case WID_VT_START_DATE: // Change the date that the timetable starts.
647 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
648 this->query_widget = WID_VT_START_DATE;
649 this->change_timetable_all = _ctrl_pressed;
650 ShowQueryString(STR_EMPTY, STR_TIMETABLE_START_SECONDS_QUERY, 6, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
651 } else {
652 ShowSetDateWindow(this, v->index, TimerGameEconomy::date, TimerGameEconomy::year, TimerGameEconomy::year + MAX_TIMETABLE_START_YEARS, ChangeTimetableStartCallback, reinterpret_cast<void*>(static_cast<uintptr_t>(_ctrl_pressed)));
653 }
654 break;
655
656 case WID_VT_CHANGE_TIME: { // "Wait For" button.
657 this->query_widget = WID_VT_CHANGE_TIME;
658 int selected = this->sel_index;
659 VehicleOrderID real = (selected + 1) / 2;
660
661 if (real >= v->GetNumOrders()) real = 0;
662
663 const Order *order = v->GetOrder(real);
664 StringID current = STR_EMPTY;
665
666 if (order != nullptr) {
667 uint time = (selected % 2 != 0) ? order->GetTravelTime() : order->GetWaitTime();
668 time /= TicksPerTimetableUnit();
669
670 if (time != 0) {
671 SetDParam(0, time);
672 current = STR_JUST_INT;
673 }
674 }
675
676 this->change_timetable_all = _ctrl_pressed && (order != nullptr);
677 ShowQueryString(current, STR_TIMETABLE_CHANGE_TIME, 31, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
678 break;
679 }
680
681 case WID_VT_CHANGE_SPEED: { // Change max speed button.
682 this->query_widget = WID_VT_CHANGE_SPEED;
683 int selected = this->sel_index;
684 VehicleOrderID real = (selected + 1) / 2;
685
686 if (real >= v->GetNumOrders()) real = 0;
687
688 StringID current = STR_EMPTY;
689 const Order *order = v->GetOrder(real);
690 if (order != nullptr) {
691 if (order->GetMaxSpeed() != UINT16_MAX) {
692 SetDParam(0, ConvertKmhishSpeedToDisplaySpeed(order->GetMaxSpeed(), v->type));
693 current = STR_JUST_INT;
694 }
695 }
696
697 this->change_timetable_all = _ctrl_pressed && (order != nullptr);
698 ShowQueryString(current, STR_TIMETABLE_CHANGE_SPEED, 31, this, CS_NUMERAL, QSF_NONE);
699 break;
700 }
701
702 case WID_VT_CLEAR_TIME: { // Clear waiting time.
703 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, false);
704 if (_ctrl_pressed) {
705 Command<CMD_BULK_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, mtf, 0);
706 } else {
707 Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, 0);
708 }
709 break;
710 }
711
712 case WID_VT_CLEAR_SPEED: { // Clear max speed button.
713 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, true);
714 if (_ctrl_pressed) {
715 Command<CMD_BULK_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, mtf, UINT16_MAX);
716 } else {
717 Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, UINT16_MAX);
718 }
719 break;
720 }
721
722 case WID_VT_RESET_LATENESS: // Reset the vehicle's late counter.
723 Command<CMD_SET_VEHICLE_ON_TIME>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, _ctrl_pressed);
724 break;
725
726 case WID_VT_AUTOFILL: { // Autofill the timetable.
727 Command<CMD_AUTOFILL_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, !HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE), _ctrl_pressed);
728 break;
729 }
730
731 case WID_VT_EXPECTED:
732 this->show_expected = !this->show_expected;
733 break;
734
735 case WID_VT_SHARED_ORDER_LIST:
736 ShowVehicleListWindow(v);
737 break;
738 }
739
740 this->SetDirty();
741 }
742
743 void OnQueryTextFinished(char *str) override
744 {
745 if (str == nullptr) return;
746
747 const Vehicle *v = this->vehicle;
748 uint64_t val = StrEmpty(str) ? 0 : std::strtoul(str, nullptr, 10);
749 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, query_widget == WID_VT_CHANGE_SPEED);
750
751 switch (query_widget) {
752 case WID_VT_CHANGE_SPEED: {
753 val = ConvertDisplaySpeedToKmhishSpeed(val, v->type);
754
755 if (this->change_timetable_all) {
756 Command<CMD_BULK_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, mtf, ClampTo<uint16_t>(val));
757 } else {
758 Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, ClampTo<uint16_t>(val));
759 }
760 break;
761 }
762
763 case WID_VT_CHANGE_TIME:
764 val *= TicksPerTimetableUnit();
765
766 if (this->change_timetable_all) {
767 Command<CMD_BULK_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, mtf, ClampTo<uint16_t>(val));
768 } else {
769 Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, ClampTo<uint16_t>(val));
770 }
771 break;
772
773 case WID_VT_START_DATE: {
774 TimerGameTick::TickCounter start_tick = TimerGameTick::counter + (val * Ticks::TICKS_PER_SECOND);
775 Command<CMD_SET_TIMETABLE_START>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, this->change_timetable_all, start_tick);
776 break;
777 }
778
779 default:
780 NOT_REACHED();
781 }
782 }
783
784 void OnResize() override
785 {
786 /* Update the scroll bar */
787 this->vscroll->SetCapacityFromWidget(this, WID_VT_TIMETABLE_PANEL, WidgetDimensions::scaled.framerect.Vertical());
788 }
789
793 void UpdateSelectionStates()
794 {
795 this->GetWidget<NWidgetStacked>(WID_VT_ARRIVAL_DEPARTURE_SELECTION)->SetDisplayedPlane(_settings_client.gui.timetable_arrival_departure ? 0 : SZSP_NONE);
796 this->GetWidget<NWidgetStacked>(WID_VT_EXPECTED_SELECTION)->SetDisplayedPlane(_settings_client.gui.timetable_arrival_departure ? 0 : 1);
797 }
798
802 IntervalTimer<TimerGameTick> redraw_interval = {Ticks::TICKS_PER_SECOND, [this](auto) {
803 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
804 this->SetDirty();
805 }
806 }};
807 };
808
809 static constexpr NWidgetPart _nested_timetable_widgets[] = {
810 NWidget(NWID_HORIZONTAL),
811 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
812 NWidget(WWT_CAPTION, COLOUR_GREY, WID_VT_CAPTION), SetDataTip(STR_TIMETABLE_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
813 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_ORDER_VIEW), SetMinimalSize(61, 14), SetDataTip( STR_TIMETABLE_ORDER_VIEW, STR_TIMETABLE_ORDER_VIEW_TOOLTIP),
814 NWidget(WWT_SHADEBOX, COLOUR_GREY),
815 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
816 NWidget(WWT_STICKYBOX, COLOUR_GREY),
817 EndContainer(),
818 NWidget(NWID_HORIZONTAL),
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(),
820 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VT_ARRIVAL_DEPARTURE_SELECTION),
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(),
822 EndContainer(),
823 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_VT_SCROLLBAR),
824 EndContainer(),
825 NWidget(WWT_PANEL, COLOUR_GREY, WID_VT_SUMMARY_PANEL), SetMinimalSize(400, 22), SetResize(1, 0), EndContainer(),
826 NWidget(NWID_HORIZONTAL),
827 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
828 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
829 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_CHANGE_TIME), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_TIMETABLE_CHANGE_TIME, STR_TIMETABLE_WAIT_TIME_TOOLTIP),
830 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_CLEAR_TIME), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_TIMETABLE_CLEAR_TIME, STR_TIMETABLE_CLEAR_TIME_TOOLTIP),
831 EndContainer(),
832 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
833 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_CHANGE_SPEED), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_TIMETABLE_CHANGE_SPEED, STR_TIMETABLE_CHANGE_SPEED_TOOLTIP),
834 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_CLEAR_SPEED), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_TIMETABLE_CLEAR_SPEED, STR_TIMETABLE_CLEAR_SPEED_TOOLTIP),
835 EndContainer(),
836 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
837 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_START_DATE), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_TIMETABLE_START, STR_TIMETABLE_START_TOOLTIP),
838 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_RESET_LATENESS), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_TIMETABLE_RESET_LATENESS, STR_TIMETABLE_RESET_LATENESS_TOOLTIP),
839 EndContainer(),
840 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
841 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_AUTOFILL), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_TIMETABLE_AUTOFILL, STR_TIMETABLE_AUTOFILL_TOOLTIP),
842 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VT_EXPECTED_SELECTION),
843 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_EXPECTED), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TIMETABLE_EXPECTED_TOOLTIP),
844 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
845 EndContainer(),
846 EndContainer(),
847 EndContainer(),
848 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
849 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VT_SHARED_ORDER_LIST), SetFill(0, 1), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
850 NWidget(WWT_RESIZEBOX, COLOUR_GREY), SetFill(0, 1),
851 EndContainer(),
852 EndContainer(),
853 };
854
855 static WindowDesc _timetable_desc(__FILE__, __LINE__,
856 WDP_AUTO, "view_vehicle_timetable", 400, 130,
857 WC_VEHICLE_TIMETABLE, WC_VEHICLE_VIEW,
858 WDF_CONSTRUCTION,
859 std::begin(_nested_timetable_widgets), std::end(_nested_timetable_widgets)
860 );
861
866 void ShowTimetableWindow(const Vehicle *v)
867 {
868 CloseWindowById(WC_VEHICLE_DETAILS, v->index, false);
869 CloseWindowById(WC_VEHICLE_ORDERS, v->index, false);
870 AllocateWindowDescFront<TimetableWindow>(&_timetable_desc, v->index);
871 }
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:469
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
TimetableWindow::vscroll
Scrollbar * vscroll
The scrollbar.
Definition: timetable_gui.cpp:206
MTF_TRAVEL_SPEED
@ MTF_TRAVEL_SPEED
Set max travel speed.
Definition: order_type.h:174
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1143
VehicleOrderID
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:15
timetable_widget.h
WID_VT_CHANGE_TIME
@ WID_VT_CHANGE_TIME
Change time button.
Definition: timetable_widget.h:22
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
vehicle_gui.h
TimerGameTick::counter
static TickCounter counter
Monotonic counter, in ticks, since start of game.
Definition: timer_game_tick.h:33
SetDParamMaxDigits
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:143
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
command_func.h
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
MTF_WAIT_TIME
@ MTF_WAIT_TIME
Set wait time.
Definition: order_type.h:172
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:197
QSF_ACCEPT_UNCHANGED
@ QSF_ACCEPT_UNCHANGED
return success even when the text didn't change
Definition: textbuf_gui.h:20
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
ModifyTimetableFlags
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
Definition: order_type.h:171
TimetableWindow::BuildArrivalDepartureList
static bool BuildArrivalDepartureList(const Vehicle *v, std::vector< TimetableArrivalDeparture > &table)
Build the arrival-departure list for a given vehicle.
Definition: timetable_gui.cpp:236
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
IntervalTimer< TimerGameTick >
GB
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.
Definition: bitmath_func.hpp:32
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:238
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
VehicleTimetableWidgets
VehicleTimetableWidgets
Widgets of the TimetableWindow class.
Definition: timetable_widget.h:14
TimetableArrivalDeparture::arrival
TimerGameTick::Ticks arrival
The arrival time.
Definition: timetable_gui.cpp:40
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1153
WID_VT_START_DATE
@ WID_VT_START_DATE
Start date button.
Definition: timetable_widget.h:21
BaseConsist::vehicle_flags
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:34
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
BaseConsist::lateness_counter
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
Definition: base_consist.h:22
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
vehicle_base.h
WID_VT_TIMETABLE_PANEL
@ WID_VT_TIMETABLE_PANEL
Timetable panel.
Definition: timetable_widget.h:17
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2341
TimerGameEconomy::date_fract
static DateFract date_fract
Fractional part of the day.
Definition: timer_game_economy.h:38
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
OrderList::IsCompleteTimetable
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
Definition: order_cmd.cpp:578
TimetableArrivalDeparture::departure
TimerGameTick::Ticks departure
The departure time.
Definition: timetable_gui.cpp:41
BaseConsist::current_order_time
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
Definition: base_consist.h:21
WC_VEHICLE_TIMETABLE
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
Definition: window_type.h:224
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition: timer_game_economy.cpp:97
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:310
ChangeTimetableStartCallback
static void ChangeTimetableStartCallback(const Window *w, TimerGameEconomy::Date date, void *data)
Callback for when a time has been chosen to start the time table.
Definition: timetable_gui.cpp:195
GetDateFromStartTick
TimerGameEconomy::Date GetDateFromStartTick(TimerGameTick::TickCounter start_tick)
Get a date from a given start tick of timetable.
Definition: timetable_cmd.cpp:46
TimetableWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: timetable_gui.cpp:291
WID_VT_CAPTION
@ WID_VT_CAPTION
Caption of the window.
Definition: timetable_widget.h:15
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:305
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:680
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
TimerGameTick::TickCounter
uint64_t TickCounter
The type that the tick counter is stored in.
Definition: timer_game_tick.h:25
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:56
TimetableWindow::UpdateSelectionStates
void UpdateSelectionStates()
Update the selection state of the arrival/departure data.
Definition: timetable_gui.cpp:793
TimetableWindow
Definition: timetable_gui.cpp:201
VehicleIsAboveLatenessThreshold
bool VehicleIsAboveLatenessThreshold(const Vehicle *v, bool round_to_day)
Determine if a vehicle should be shown as late, depending on the timetable display setting.
Definition: timetable_gui.cpp:94
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
TimetableWindow::DrawTimetablePanel
void DrawTimetablePanel(const Rect &r) const
Helper function to draw the timetable panel.
Definition: timetable_gui.cpp:417
OrderList::GetTimetableDurationIncomplete
TimerGameTick::Ticks GetTimetableDurationIncomplete() const
Gets the known duration of the vehicles timetable even if the timetable is not complete.
Definition: order_base.h:375
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:722
textbuf_gui.h
INVALID_ORDER
static const OrderID INVALID_ORDER
Invalid order (sentinel)
Definition: order_type.h:26
ConvertDisplaySpeedToKmhishSpeed
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type)
Convert the given display speed to the km/h-ish speed.
Definition: strings.cpp:898
gfx_func.h
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
timetable_cmd.h
window_gui.h
VF_AUTOFILL_TIMETABLE
@ VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
Definition: vehicle_base.h:49
Order::GetNonStopType
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition: order_base.h:141
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:510
IsInsideBS
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.
Definition: math_func.hpp:252
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1088
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
timetable.h
TimetableWindow::change_timetable_all
bool change_timetable_all
Set wait time or speed for all timetable entries (ctrl-click) action.
Definition: timetable_gui.cpp:208
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
ONSF_STOP_EVERYWHERE
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
Definition: order_type.h:73
WC_VEHICLE_VIEW
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
Definition: window_type.h:339
WID_VT_SCROLLBAR
@ WID_VT_SCROLLBAR
Scrollbar for the panel.
Definition: timetable_widget.h:19
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
INVALID_VEH_ORDER_ID
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
Definition: order_type.h:21
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1246
Order::GetTravelTime
uint16_t GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
Definition: order_base.h:195
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
WID_VT_EXPECTED_SELECTION
@ WID_VT_EXPECTED_SELECTION
Disable/hide the expected selection button.
Definition: timetable_widget.h:29
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:350
Ticks::INVALID_TICKS
static constexpr TimerGameTick::Ticks INVALID_TICKS
Representation of an invalid number of ticks.
Definition: timer_game_tick.h:41
ShowTimetableWindow
void ShowTimetableWindow(const Vehicle *v)
Show the timetable for a given vehicle.
Definition: timetable_gui.cpp:866
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:953
timer_game_tick.h
WC_VEHICLE_DETAILS
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Definition: window_type.h:200
TimetableWindow::query_widget
VehicleTimetableWidgets query_widget
Which button was clicked to open the query text input?
Definition: timetable_gui.cpp:203
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1260
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:50
safeguards.h
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1087
timer.h
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition: gfx_type.h:277
VehicleID
uint32_t VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
settings_type.h
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
TimerGameConst< struct Economy >::MAX_YEAR
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,...
Definition: timer_game_common.h:173
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
date_gui.h
WID_VT_RESET_LATENESS
@ WID_VT_RESET_LATENESS
Reset lateness button.
Definition: timetable_widget.h:24
Vehicle::IsOrderListShared
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition: vehicle_base.h:728
WID_VT_EXPECTED
@ WID_VT_EXPECTED
Toggle between expected and scheduled arrivals.
Definition: timetable_widget.h:26
CanDetermineTimeTaken
static bool CanDetermineTimeTaken(const Order *order, bool travelling)
Check whether it is possible to determine how long the order takes.
Definition: timetable_gui.cpp:114
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:441
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2267
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
Order::IsTravelTimetabled
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
Definition: order_base.h:186
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:937
TimetableWindow::show_expected
bool show_expected
Whether we show expected arrival or scheduled.
Definition: timetable_gui.cpp:205
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:31
ONSF_NO_STOP_AT_DESTINATION_STATION
@ ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
Definition: order_type.h:75
Order::GetWaitTime
uint16_t GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
Definition: order_base.h:193
string_func.h
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
TimerGameTick::Ticks
int32_t Ticks
The type to store ticks in.
Definition: timer_game_tick.h:24
WID_VT_SUMMARY_PANEL
@ WID_VT_SUMMARY_PANEL
Summary panel.
Definition: timetable_widget.h:20
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
TimerGameEconomy::year
static Year year
Current year, starting at 0.
Definition: timer_game_economy.h:35
TimerGame< struct Economy >::DateAtStartOfYear
static constexpr Date DateAtStartOfYear(Year year)
Calculate the date of the first day of a given year.
Definition: timer_game_common.h:88
TimetableArrivalDeparture
Container for the arrival/departure dates of a vehicle.
Definition: timetable_gui.cpp:39
ShowSetDateWindow
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.
Definition: date_gui.cpp:215
Scrollbar::IsVisible
bool IsVisible(uint16_t item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:732
TimetableWindow::redraw_interval
IntervalTimer< TimerGameTick > redraw_interval
In real-time mode, the timetable GUI shows relative times and needs to be redrawn every second.
Definition: timetable_gui.cpp:802
Window::DisableWidget
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition: window_gui.h:391
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1036
SetDParamMaxValue
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.
Definition: strings.cpp:127
abs
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:23
VIWD_AUTOREPLACE
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
Definition: vehicle_gui.h:38
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
Order::GetTimetabledTravel
uint16_t GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
Definition: order_base.h:191
Order::GetTimetabledWait
uint16_t GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
Definition: order_base.h:189
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:762
TimetableWindow::vehicle
const Vehicle * vehicle
Vehicle monitored by the window.
Definition: timetable_gui.cpp:204
WID_VT_CLEAR_SPEED
@ WID_VT_CLEAR_SPEED
Clear speed limit button.
Definition: timetable_widget.h:31
PackVelocity
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
Definition: strings_func.h:74
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
TimetableWindow::set_start_date_all
bool set_start_date_all
Set start date using minutes text entry for all timetable entries (ctrl-click) action.
Definition: timetable_gui.cpp:207
WID_VT_ARRIVAL_DEPARTURE_SELECTION
@ WID_VT_ARRIVAL_DEPARTURE_SELECTION
Disable/hide the arrival departure panel.
Definition: timetable_widget.h:28
company_func.h
Order::GetMaxSpeed
uint16_t GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
Definition: order_base.h:202
Ticks::TICKS_PER_SECOND
static constexpr TimerGameTick::Ticks TICKS_PER_SECOND
Estimation of how many ticks fit in a single second.
Definition: timer_game_tick.h:49
GUISettings::timetable_arrival_departure
bool timetable_arrival_departure
show arrivals and departures in vehicle timetables
Definition: settings_type.h:171
GUISettings::timetable_mode
TimetableMode timetable_mode
Time units for timetables: days, seconds, or ticks.
Definition: settings_type.h:178
VF_TIMETABLE_STARTED
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
Definition: vehicle_base.h:48
OrderList::GetFirstOrder
Order * GetFirstOrder() const
Get the first order of the order chain.
Definition: order_base.h:298
CommandHelper
Definition: command_func.h:93
window_func.h
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1099
DrawString
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.
Definition: gfx.cpp:654
timer_window.h
WID_VT_CHANGE_SPEED
@ WID_VT_CHANGE_SPEED
Change speed limit button.
Definition: timetable_widget.h:30
BaseConsist::timetable_start
TimerGameTick::TickCounter timetable_start
At what tick of TimerGameTick::counter the vehicle should start its timetable.
Definition: base_consist.h:23
gui.h
WID_VT_CLEAR_TIME
@ WID_VT_CLEAR_TIME
Clear time button.
Definition: timetable_widget.h:23
Window
Data structure for an opened window.
Definition: window_gui.h:267
WID_VT_AUTOFILL
@ WID_VT_AUTOFILL
Autofill button.
Definition: timetable_widget.h:25
Ticks::DAY_TICKS
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
Definition: timer_game_tick.h:48
DrawOrderString
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.
Definition: order_gui.cpp:222
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
Vehicle::GetOrder
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
Definition: vehicle_base.h:913
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
TimetableWindow::DrawSummaryPanel
void DrawSummaryPanel(const Rect &r) const
Helper function to draw the summary panel.
Definition: timetable_gui.cpp:560
VIWD_MODIFY_ORDERS
@ VIWD_MODIFY_ORDERS
Other order modifications.
Definition: vehicle_gui.h:36
WID_VT_SHARED_ORDER_LIST
@ WID_VT_SHARED_ORDER_LIST
Show the shared order list.
Definition: timetable_widget.h:27
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1164
TimetableWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: timetable_gui.cpp:784
ConvertKmhishSpeedToDisplaySpeed
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type)
Convert the given km/h-ish speed to the display speed.
Definition: strings.cpp:888
TimetableWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: timetable_gui.cpp:361
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
WID_VT_ORDER_VIEW
@ WID_VT_ORDER_VIEW
Order view.
Definition: timetable_widget.h:16
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
SetTimetableParams
void SetTimetableParams(int param1, int param2, TimerGameTick::Ticks ticks)
Set the timetable parameters in the format as described by the setting.
Definition: timetable_gui.cpp:50
Vehicle::GetNumOrders
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:734
VIWD_REMOVE_ALL_ORDERS
@ VIWD_REMOVE_ALL_ORDERS
Removed / replaced all orders (after deleting / sharing).
Definition: vehicle_gui.h:35
Vehicle::orders
OrderList * orders
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:353
FillTimetableArrivalDepartureTable
static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID start, bool travelling, std::vector< TimetableArrivalDeparture > &table, TimerGameTick::Ticks offset)
Fill the table with arrivals and departures.
Definition: timetable_gui.cpp:138
Order::next
Order * next
Pointer to next order. If nullptr, end of list.
Definition: order_base.h:59
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
Order
Definition: order_base.h:36
TimetableWindow::DrawArrivalDeparturePanel
void DrawArrivalDeparturePanel(const Rect &r) const
Helper function to draw the arrival and departure panel.
Definition: timetable_gui.cpp:487
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:26
Order::IsWaitTimetabled
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition: order_base.h:184
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:848
WID_VT_ARRIVAL_DEPARTURE_PANEL
@ WID_VT_ARRIVAL_DEPARTURE_PANEL
Panel with the expected/scheduled arrivals.
Definition: timetable_widget.h:18
timer_game_economy.h
WC_VEHICLE_ORDERS
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
Definition: window_type.h:212
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:635
GetStartTickFromDate
TimerGameTick::TickCounter GetStartTickFromDate(TimerGameEconomy::Date start_date)
Get the TimerGameTick::TickCounter tick of a given date.
Definition: timetable_cmd.cpp:29
TicksPerTimetableUnit
static TimerGameTick::Ticks TicksPerTimetableUnit()
Get the number of ticks in the current timetable display unit.
Definition: timetable_gui.cpp:74
MTF_TRAVEL_TIME
@ MTF_TRAVEL_TIME
Set travel time.
Definition: order_type.h:173
MAX_TIMETABLE_START_YEARS
static const TimerGameEconomy::Year MAX_TIMETABLE_START_YEARS
The maximum start date offset, in economy years.
Definition: timetable.h:17
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
TimerGameEconomy::date
static Date date
Current date in days (day counter).
Definition: timer_game_economy.h:37
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103