OpenTTD Source 20261112-master-gbcbec5e63f
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
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 "gfx_func.h"
19#include "company_func.h"
20#include "timer/timer.h"
23#include "date_gui.h"
24#include "vehicle_gui.h"
25#include "settings_type.h"
26#include "timetable_cmd.h"
27#include "timetable.h"
29
31
32#include "table/sprites.h"
33#include "table/strings.h"
34
35#include "safeguards.h"
36
42
48std::pair<StringParameter, StringParameter> GetTimetableParameters(TimerGameTick::Ticks ticks)
49{
50 switch (_settings_client.gui.timetable_mode) {
51 case TimetableMode::Days: return {STR_UNITS_DAYS, ticks / Ticks::DAY_TICKS};
52 case TimetableMode::Seconds: return {STR_UNITS_SECONDS, ticks / Ticks::TICKS_PER_SECOND};
53 case TimetableMode::Ticks: return {STR_UNITS_TICKS, ticks};
54 default:
55 NOT_REACHED();
56 }
57}
58
64{
65 switch (_settings_client.gui.timetable_mode) {
67 return Ticks::DAY_TICKS;
71 return 1;
72 default:
73 NOT_REACHED();
74 }
75}
76
84{
85 switch (_settings_client.gui.timetable_mode) {
87 return ticks > Ticks::DAY_TICKS;
89 return ticks > Ticks::TICKS_PER_SECOND;
91 return ticks > (round_to_day ? Ticks::DAY_TICKS : 0);
92 default:
93 NOT_REACHED();
94 }
95}
96
103static bool CanDetermineTimeTaken(const Order &order, bool travelling)
104{
105 /* Current order is conditional */
106 if (order.IsType(OT_CONDITIONAL) || order.IsType(OT_IMPLICIT)) return false;
107 /* No travel time and we have not already finished travelling */
108 if (travelling && !order.IsTravelTimetabled()) return false;
109 /* No wait time but we are loading at this timetabled station */
110 if (!travelling && !order.IsWaitTimetabled() && order.IsType(OT_GOTO_STATION) &&
112 return false;
113 }
114
115 return true;
116}
117
118
127static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID start, bool travelling, std::vector<TimetableArrivalDeparture> &table, TimerGameTick::Ticks offset)
128{
129 assert(!table.empty());
130 assert(v->GetNumOrders() >= 2);
131 assert(start < v->GetNumOrders());
132
133 /* Pre-initialize with unknown time */
134 for (int i = 0; i < v->GetNumOrders(); ++i) {
135 table[i].arrival = table[i].departure = Ticks::INVALID_TICKS;
136 }
137
138 TimerGameTick::Ticks sum = offset;
139 VehicleOrderID i = start;
140 auto orders = v->Orders();
141
142 /* Cyclically loop over all orders until we reach the current one again.
143 * As we may start at the current order, do a post-checking loop */
144 do {
145 /* Automatic orders don't influence the overall timetable;
146 * they just add some untimetabled entries, but the time till
147 * the next non-implicit order can still be known. */
148 if (!orders[i].IsType(OT_IMPLICIT)) {
149 if (travelling || i != start) {
150 if (!CanDetermineTimeTaken(orders[i], true)) return;
151 sum += orders[i].GetTimetabledTravel();
152 table[i].arrival = sum;
153 }
154
155 if (!CanDetermineTimeTaken(orders[i], false)) return;
156 sum += orders[i].GetTimetabledWait();
157 table[i].departure = sum;
158 }
159
160 i = v->orders->GetNext(i);
161 } while (i != start);
162
163 /* When loading at a scheduled station we still have to treat the
164 * travelling part of the first order. */
165 if (!travelling) {
166 if (!CanDetermineTimeTaken(orders[i], true)) return;
167 sum += orders[i].GetTimetabledTravel();
168 table[i].arrival = sum;
169 }
170}
171
172struct TimetableWindow : Window {
173 int sel_index = -1;
175 const Vehicle *vehicle = nullptr;
176 bool show_expected = true;
177 Scrollbar *vscroll = nullptr;
178 bool set_start_date_all = false;
179 bool change_timetable_all = false;
180
181 TimetableWindow(WindowDesc &desc, WindowNumber window_number) :
182 Window(desc),
184 {
185 this->CreateNestedTree();
186 this->vscroll = this->GetScrollbar(WID_VT_SCROLLBAR);
187
188 /* When using wallclock units, we must ensure the client displays timetables in seconds. */
190 _settings_client.gui.timetable_mode = TimetableMode::Seconds;
191 }
192
193 this->UpdateSelectionStates();
194 this->FinishInitNested(window_number);
195
196 this->owner = this->vehicle->owner;
197 }
198
205 static bool BuildArrivalDepartureList(const Vehicle *v, std::vector<TimetableArrivalDeparture> &table)
206 {
208
209 bool travelling = (!v->current_order.IsType(OT_LOADING) || v->current_order.GetNonStopType().None());
211
212 /* If arrival and departure times are in days, compensate for the current date_fract. */
213 if (_settings_client.gui.timetable_mode != TimetableMode::Seconds) start_time += TimerGameEconomy::date_fract;
214
215 FillTimetableArrivalDepartureTable(v, v->cur_real_order_index % v->GetNumOrders(), travelling, table, start_time);
216
217 return (travelling && v->lateness_counter < 0);
218 }
219
220 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
221 {
222 switch (widget) {
224 /* We handle this differently depending on the timetable mode. */
225 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
226 /* A five-digit number would fit a timetable lasting 2.7 real-world hours, which should be plenty. */
227 uint64_t max_digits = GetParamMaxDigits(4, FontSize::Small);
228 size.width = std::max(
229 GetStringBoundingBox(GetString(STR_TIMETABLE_ARRIVAL_SECONDS_IN_FUTURE, TextColour::Black, max_digits)).width,
230 GetStringBoundingBox(GetString(STR_TIMETABLE_DEPARTURE_SECONDS_IN_FUTURE, TextColour::Black, max_digits)).width)
231 + WidgetDimensions::scaled.hsep_wide + padding.width;
232 } else {
234 size.width = std::max(
235 GetStringBoundingBox(GetString(STR_TIMETABLE_ARRIVAL_DATE, TextColour::Black, max_value)).width,
236 GetStringBoundingBox(GetString(STR_TIMETABLE_DEPARTURE_DATE, TextColour::Black, max_value)).width)
237 + WidgetDimensions::scaled.hsep_wide + padding.width;
238 }
239 [[fallthrough]];
240
242 fill.height = resize.height = GetCharacterHeight(FontSize::Normal);
243 size.height = 8 * resize.height + padding.height;
244 break;
245
247 size.height = 2 * GetCharacterHeight(FontSize::Normal) + padding.height;
248 break;
249 }
250 }
251
252 int GetOrderFromTimetableWndPt(int y, [[maybe_unused]] const Vehicle *v)
253 {
254 int32_t sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_VT_TIMETABLE_PANEL, WidgetDimensions::scaled.framerect.top);
255 if (sel == INT32_MAX) return sel;
256 assert(IsInsideBS(sel, 0, v->GetNumOrders() * 2));
257 return sel;
258 }
259
265 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
266 {
267 switch (data) {
268 case VIWD_AUTOREPLACE:
269 /* Autoreplace replaced the vehicle */
270 this->vehicle = Vehicle::Get(this->window_number);
271 break;
272
274 /* Removed / replaced all orders (after deleting / sharing) */
275 if (this->sel_index == -1) break;
276
277 this->CloseChildWindows();
278 this->sel_index = -1;
279 break;
280
282 if (!gui_scope) break;
283 this->UpdateSelectionStates();
284 this->ReInit();
285 break;
286
287 default: {
288 if (gui_scope) break; // only do this once; from command scope
289
290 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
291 * the order is being created / removed */
292 if (this->sel_index == -1) break;
293
294 VehicleOrderID from = GB(data, 0, 8);
295 VehicleOrderID to = GB(data, 8, 8);
296
297 if (from == to) break; // no need to change anything
298
299 /* if from == INVALID_VEH_ORDER_ID, one order was added; if to == INVALID_VEH_ORDER_ID, one order was removed */
300 uint old_num_orders = this->vehicle->GetNumOrders() - (uint)(from == INVALID_VEH_ORDER_ID) + (uint)(to == INVALID_VEH_ORDER_ID);
301
302 VehicleOrderID selected_order = (this->sel_index + 1) / 2;
303 if (selected_order == old_num_orders) selected_order = 0; // when last travel time is selected, it belongs to order 0
304
305 bool travel = HasBit(this->sel_index, 0);
306
307 if (from != selected_order) {
308 /* Moving from preceding order? */
309 selected_order -= (int)(from <= selected_order);
310 /* Moving to preceding order? */
311 selected_order += (int)(to <= selected_order);
312 } else {
313 /* Now we are modifying the selected order */
314 if (to == INVALID_VEH_ORDER_ID) {
315 /* Deleting selected order */
316 this->CloseChildWindows();
317 this->sel_index = -1;
318 break;
319 } else {
320 /* Moving selected order */
321 selected_order = to;
322 }
323 }
324
325 /* recompute new sel_index */
326 this->sel_index = 2 * selected_order - (int)travel;
327 /* travel time of first order needs special handling */
328 if (this->sel_index == -1) this->sel_index = this->vehicle->GetNumOrders() * 2 - 1;
329 break;
330 }
331 }
332 }
333
334
335 void OnPaint() override
336 {
337 const Vehicle *v = this->vehicle;
338 int selected = this->sel_index;
339
340 this->vscroll->SetCount(v->GetNumOrders() * 2);
341
342 if (v->owner == _local_company) {
343 bool disable = true;
344 if (selected != -1) {
345 const Order *order = v->GetOrder(((selected + 1) / 2) % v->GetNumOrders());
346 if (selected % 2 != 0) {
347 disable = order != nullptr && (order->IsType(OT_CONDITIONAL) || order->IsType(OT_IMPLICIT));
348 } else {
349 disable = order == nullptr || ((!order->IsType(OT_GOTO_STATION) || order->GetNonStopType().Test(OrderNonStopFlag::GoVia)) && !order->IsType(OT_CONDITIONAL));
350 }
351 }
352 bool disable_speed = disable || selected % 2 == 0 || v->type == VehicleType::Aircraft;
353
356 this->SetWidgetDisabledState(WID_VT_CHANGE_SPEED, disable_speed);
357 this->SetWidgetDisabledState(WID_VT_CLEAR_SPEED, disable_speed);
359
360 this->SetWidgetDisabledState(WID_VT_START_DATE, v->orders == nullptr);
362 this->SetWidgetDisabledState(WID_VT_AUTOFILL, v->orders == nullptr);
363 } else {
372 }
373
375
376 this->DrawWidgets();
377 }
378
379 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
380 {
381 switch (widget) {
382 case WID_VT_CAPTION: return GetString(STR_TIMETABLE_TITLE, this->vehicle->index);
383 case WID_VT_EXPECTED: return GetString(this->show_expected ? STR_TIMETABLE_EXPECTED : STR_TIMETABLE_SCHEDULED);
384 default: return this->Window::GetWidgetString(widget, stringid);
385 }
386 }
387
395 std::string GetTimetableTravelString(const Order &order, int i, ExtendedTextColour &colour) const
396 {
397 colour = (i == this->sel_index) ? TextColour::White : TextColour::Black;
398
399 if (order.IsType(OT_CONDITIONAL)) {
400 return GetString(STR_TIMETABLE_NO_TRAVEL);
401 }
402
403 if (order.IsType(OT_IMPLICIT)) {
405 return GetString(STR_TIMETABLE_NOT_TIMETABLEABLE);
406 }
407
408 if (order.IsTravelTimetabled()) {
409 auto [str, value] = GetTimetableParameters(order.GetTimetabledTravel());
410 return order.GetMaxSpeed() != UINT16_MAX
411 ? GetString(STR_TIMETABLE_TRAVEL_FOR_SPEED, str, value, PackVelocity(order.GetMaxSpeed(), this->vehicle->type))
412 : GetString(STR_TIMETABLE_TRAVEL_FOR, str, value);
413 }
414
415 if (order.GetTravelTime() > 0) {
416 auto [str, value] = GetTimetableParameters(order.GetTravelTime());
417 return order.GetMaxSpeed() != UINT16_MAX
418 ? GetString(STR_TIMETABLE_TRAVEL_FOR_SPEED_ESTIMATED, str, value, PackVelocity(order.GetMaxSpeed(), this->vehicle->type))
419 : GetString(STR_TIMETABLE_TRAVEL_FOR_ESTIMATED, str, value);
420 }
421
422 return order.GetMaxSpeed() != UINT16_MAX
423 ? GetString(STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED, PackVelocity(order.GetMaxSpeed(), this->vehicle->type))
424 : GetString(STR_TIMETABLE_TRAVEL_NOT_TIMETABLED);
425 }
426
431 void DrawTimetablePanel(const Rect &r) const
432 {
433 const Vehicle *v = this->vehicle;
434 if (v->GetNumOrders() == 0) return;
435 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
436 int i = this->vscroll->GetPosition();
437 VehicleOrderID order_id = (i + 1) / 2;
438 bool final_order = false;
439 int selected = this->sel_index;
440
441 bool rtl = _current_text_dir == TD_RTL;
442 int index_column_width = GetStringBoundingBox(GetString(STR_ORDER_INDEX, GetParamMaxValue(v->GetNumOrders(), 2))).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + WidgetDimensions::scaled.hsep_normal;
443 int middle = rtl ? tr.right - index_column_width : tr.left + index_column_width;
444
445 auto orders = v->Orders();
446 while (true) {
447 /* Don't draw anything if it extends past the end of the window. */
448 if (!this->vscroll->IsVisible(i)) break;
449
450 if (i % 2 == 0) {
451 DrawOrderString(v, &orders[order_id], order_id, tr.top, i == selected, true, tr.left, middle, tr.right);
452 if (v->orders->GetNext(order_id) == 0) final_order = true;
453 order_id = v->orders->GetNext(order_id);
454 } else {
455 ExtendedTextColour colour;
456 std::string string = GetTimetableTravelString(orders[order_id], i, colour);
457
458 DrawString(rtl ? tr.left : middle, rtl ? middle : tr.right, tr.top, string, colour);
459
460 if (final_order) break;
461 }
462
463 i++;
465 }
466 }
467
472 void DrawArrivalDeparturePanel(const Rect &r) const
473 {
474 const Vehicle *v = this->vehicle;
475
476 /* Arrival and departure times are handled in an all-or-nothing approach,
477 * i.e. are only shown if we can calculate all times.
478 * Excluding order lists with only one order makes some things easier. */
479 TimerGameTick::Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0;
480 if (total_time <= 0 || v->GetNumOrders() <= 1 || !v->vehicle_flags.Test(VehicleFlag::TimetableStarted)) return;
481
482 std::vector<TimetableArrivalDeparture> arr_dep(v->GetNumOrders());
483 const VehicleOrderID cur_order = v->cur_real_order_index % v->GetNumOrders();
484
486 int selected = this->sel_index;
487
488 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
489 bool show_late = this->show_expected && VehicleIsAboveLatenessThreshold(v->lateness_counter, true);
490 TimerGameTick::Ticks offset = show_late ? 0 : -v->lateness_counter;
491
492 for (int i = this->vscroll->GetPosition(); i / 2 < v->GetNumOrders(); ++i) { // note: i is also incremented in the loop
493 /* Don't draw anything if it extends past the end of the window. */
494 if (!this->vscroll->IsVisible(i)) break;
495
496 /* TextColour::Invalid will skip the colour change. */
498 if (i % 2 == 0) {
499 /* Draw an arrival time. */
500 if (arr_dep[i / 2].arrival != Ticks::INVALID_TICKS) {
501 /* First set the offset and text colour based on the expected/scheduled mode and some other things. */
502 TimerGameTick::Ticks this_offset;
503 if (this->show_expected && i / 2 == early_id) {
504 /* Show expected arrival. */
505 this_offset = 0;
507 } else {
508 /* Show scheduled arrival. */
509 this_offset = offset;
510 }
511
512 /* Now actually draw the arrival time. */
513 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
514 /* Display seconds from now. */
515 DrawString(tr,
516 GetString(STR_TIMETABLE_ARRIVAL_SECONDS_IN_FUTURE, tc, (arr_dep[i / 2].arrival + offset) / Ticks::TICKS_PER_SECOND),
517 i == selected ? TextColour::White : TextColour::Black);
518 } else {
519 /* Show a date. */
520 DrawString(tr,
521 GetString(STR_TIMETABLE_ARRIVAL_DATE, tc, TimerGameEconomy::date + (arr_dep[i / 2].arrival + this_offset) / Ticks::DAY_TICKS),
522 i == selected ? TextColour::White : TextColour::Black);
523 }
524 }
525 } else {
526 /* Draw a departure time. */
527 if (arr_dep[i / 2].departure != Ticks::INVALID_TICKS) {
528 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
529 /* Display seconds from now. */
530 DrawString(tr,
531 GetString(STR_TIMETABLE_DEPARTURE_SECONDS_IN_FUTURE, tc, (arr_dep[i / 2].departure + offset) / Ticks::TICKS_PER_SECOND),
532 i == selected ? TextColour::White : TextColour::Black);
533 } else {
534 /* Show a date. */
535 DrawString(tr,
536 GetString(STR_TIMETABLE_DEPARTURE_DATE, tc, TimerGameEconomy::date + (arr_dep[i / 2].departure + offset) / Ticks::DAY_TICKS),
537 i == selected ? TextColour::White : TextColour::Black);
538 }
539 }
540 }
542 }
543 }
544
545 std::string GetTimetableTotalTimeString(TimerGameTick::Ticks total_time) const
546 {
547 auto [str, value] = GetTimetableParameters(total_time);
548 if (!this->vehicle->orders->IsCompleteTimetable()) return GetString(STR_TIMETABLE_TOTAL_TIME_INCOMPLETE, str, value);
549 if (total_time % TicksPerTimetableUnit() == 0) return GetString(STR_TIMETABLE_TOTAL_TIME, str, value);
550 return GetString(STR_TIMETABLE_APPROX_TIME, str, value);
551 }
552
557 void DrawSummaryPanel(const Rect &r) const
558 {
559 const Vehicle *v = this->vehicle;
560 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
561
562 TimerGameTick::Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0;
563 if (total_time != 0) {
564 DrawString(tr, GetTimetableTotalTimeString(total_time));
565 }
567
568 /* Draw the lateness display, or indicate that the timetable has not started yet. */
569 if (v->timetable_start != 0) {
570 /* We are running towards the first station so we can start the
571 * timetable at the given time. */
572 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
573 /* Real time units use seconds relative to now. */
574 DrawString(tr, GetString(STR_TIMETABLE_STATUS_START_IN_SECONDS, static_cast<TimerGameTick::Ticks>(v->timetable_start - TimerGameTick::counter) / Ticks::TICKS_PER_SECOND));
575 } else {
576 /* Other units use dates. */
577 DrawString(tr, GetString(STR_TIMETABLE_STATUS_START_AT_DATE, STR_JUST_DATE_TINY, GetDateFromStartTick(v->timetable_start)));
578 }
580 /* We aren't running on a timetable yet. */
581 DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED);
582 } else if (!VehicleIsAboveLatenessThreshold(abs(v->lateness_counter), false)) {
583 /* We are on time. */
584 DrawString(tr, STR_TIMETABLE_STATUS_ON_TIME);
585 } else {
586 /* We are late. */
587 auto [str, value] = GetTimetableParameters(abs(v->lateness_counter));
588 DrawString(tr, GetString(v->lateness_counter < 0 ? STR_TIMETABLE_STATUS_EARLY : STR_TIMETABLE_STATUS_LATE, str, value));
589 }
590 }
591
592 void DrawWidget(const Rect &r, WidgetID widget) const override
593 {
594 switch (widget) {
596 this->DrawTimetablePanel(r);
597 break;
598 }
599
602 break;
603 }
604
606 this->DrawSummaryPanel(r);
607 break;
608 }
609 }
610 }
611
612 static inline std::tuple<VehicleOrderID, ModifyTimetableFlags> PackTimetableArgs(const Vehicle *v, uint selected, bool speed)
613 {
614 uint order_number = (selected + 1) / 2;
615 ModifyTimetableFlags mtf = (selected % 2 != 0) ? (speed ? MTF_TRAVEL_SPEED : MTF_TRAVEL_TIME) : MTF_WAIT_TIME;
616
617 if (order_number >= v->GetNumOrders()) order_number = 0;
618
619 return { order_number, mtf };
620 }
621
622 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
623 {
624 const Vehicle *v = this->vehicle;
625
626 switch (widget) {
627 case WID_VT_ORDER_VIEW: // Order view button
628 ShowOrdersWindow(v);
629 break;
630
631 case WID_VT_TIMETABLE_PANEL: { // Main panel.
632 int selected = GetOrderFromTimetableWndPt(pt.y, v);
633
634 this->CloseChildWindows();
635 this->sel_index = (selected == INT32_MAX || selected == this->sel_index) ? -1 : selected;
636 break;
637 }
638
639 case WID_VT_START_DATE: // Change the date that the timetable starts.
640 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
641 this->query_widget = WID_VT_START_DATE;
642 this->change_timetable_all = IsCtrlPressed();
643 ShowQueryString({}, STR_TIMETABLE_START_SECONDS_QUERY, 6, this, CS_NUMERAL, QueryStringFlag::AcceptUnchanged);
644 } else {
646 [ctrl=IsCtrlPressed()](const Window *w, TimerGameEconomy::Date date) {
647 Command<Commands::SetTimetableStart>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, w->window_number, ctrl, GetStartTickFromDate(date));
648 }
649 );
650 }
651 break;
652
653 case WID_VT_CHANGE_TIME: { // "Wait For" button.
654 this->query_widget = WID_VT_CHANGE_TIME;
655 int selected = this->sel_index;
656 VehicleOrderID real = (selected + 1) / 2;
657
658 if (real >= v->GetNumOrders()) real = 0;
659
660 const Order *order = v->GetOrder(real);
661 std::string current;
662
663 if (order != nullptr) {
664 uint time = (selected % 2 != 0) ? order->GetTravelTime() : order->GetWaitTime();
665 time /= TicksPerTimetableUnit();
666
667 if (time != 0) {
668 current = GetString(STR_JUST_INT, time);
669 }
670 }
671
672 this->change_timetable_all = IsCtrlPressed() && (order != nullptr);
673 ShowQueryString(current, STR_TIMETABLE_CHANGE_TIME_QUERY, 31, this, CS_NUMERAL, QueryStringFlag::AcceptUnchanged);
674 break;
675 }
676
677 case WID_VT_CHANGE_SPEED: { // Change max speed button.
678 this->query_widget = WID_VT_CHANGE_SPEED;
679 int selected = this->sel_index;
680 VehicleOrderID real = (selected + 1) / 2;
681
682 if (real >= v->GetNumOrders()) real = 0;
683
684 std::string current;
685 const Order *order = v->GetOrder(real);
686 if (order != nullptr) {
687 if (order->GetMaxSpeed() != UINT16_MAX) {
688 current = GetString(STR_JUST_INT, ConvertKmhishSpeedToDisplaySpeed(order->GetMaxSpeed(), v->type));
689 }
690 }
691
692 this->change_timetable_all = IsCtrlPressed() && (order != nullptr);
693 ShowQueryString(current, STR_TIMETABLE_CHANGE_SPEED_QUERY, 31, this, CS_NUMERAL, {});
694 break;
695 }
696
697 case WID_VT_CLEAR_TIME: { // Clear waiting time.
698 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, false);
699 if (IsCtrlPressed()) {
700 Command<Commands::ChangeTimetableBulk>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, mtf, 0);
701 } else {
702 Command<Commands::ChangeTimetable>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, 0);
703 }
704 break;
705 }
706
707 case WID_VT_CLEAR_SPEED: { // Clear max speed button.
708 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, true);
709 if (IsCtrlPressed()) {
710 Command<Commands::ChangeTimetableBulk>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, mtf, UINT16_MAX);
711 } else {
712 Command<Commands::ChangeTimetable>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, UINT16_MAX);
713 }
714 break;
715 }
716
717 case WID_VT_RESET_LATENESS: // Reset the vehicle's late counter.
718 Command<Commands::SetVehicleOnTime>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, IsCtrlPressed());
719 break;
720
721 case WID_VT_AUTOFILL: { // Autofill the timetable.
722 Command<Commands::AutofillTimetable>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, !v->vehicle_flags.Test(VehicleFlag::AutofillTimetable), IsCtrlPressed());
723 break;
724 }
725
726 case WID_VT_EXPECTED:
727 this->show_expected = !this->show_expected;
728 break;
729
731 ShowVehicleListWindow(v);
732 break;
733 }
734
735 this->SetDirty();
736 }
737
738 void OnQueryTextFinished(std::optional<std::string> str) override
739 {
740 if (!str.has_value()) return;
741
742 const Vehicle *v = this->vehicle;
743 uint64_t val = ParseInteger<uint64_t>(*str, 10, true).value_or(0);
744 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, query_widget == WID_VT_CHANGE_SPEED);
745
746 switch (query_widget) {
747 case WID_VT_CHANGE_SPEED: {
749
750 if (this->change_timetable_all) {
751 Command<Commands::ChangeTimetableBulk>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, mtf, ClampTo<uint16_t>(val));
752 } else {
753 Command<Commands::ChangeTimetable>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, ClampTo<uint16_t>(val));
754 }
755 break;
756 }
757
759 val *= TicksPerTimetableUnit();
760
761 if (this->change_timetable_all) {
762 Command<Commands::ChangeTimetableBulk>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, mtf, ClampTo<uint16_t>(val));
763 } else {
764 Command<Commands::ChangeTimetable>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, ClampTo<uint16_t>(val));
765 }
766 break;
767
768 case WID_VT_START_DATE: {
770 Command<Commands::SetTimetableStart>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, this->change_timetable_all, start_tick);
771 break;
772 }
773
774 default:
775 NOT_REACHED();
776 }
777 }
778
779 void OnResize() override
780 {
781 /* Update the scroll bar */
782 this->vscroll->SetCapacityFromWidget(this, WID_VT_TIMETABLE_PANEL, WidgetDimensions::scaled.framerect.Vertical());
783 }
784
789 {
790 this->GetWidget<NWidgetStacked>(WID_VT_ARRIVAL_DEPARTURE_SELECTION)->SetDisplayedPlane(_settings_client.gui.timetable_arrival_departure ? 0 : SZSP_NONE);
791 this->GetWidget<NWidgetStacked>(WID_VT_EXPECTED_SELECTION)->SetDisplayedPlane(_settings_client.gui.timetable_arrival_departure ? 0 : 1);
792 }
793
798 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
799 this->SetDirty();
800 }
801 }};
802};
803
804static constexpr std::initializer_list<NWidgetPart> _nested_timetable_widgets = {
808 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_VT_ORDER_VIEW), SetStringTip(STR_TIMETABLE_ORDER_VIEW, STR_TIMETABLE_ORDER_VIEW_TOOLTIP),
812 EndContainer(),
815 EndContainer(),
818 EndContainer(),
819 EndContainer(),
821 EndContainer(),
826 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_VT_CHANGE_TIME), SetResize(1, 0), SetFill(1, 1), SetStringTip(STR_TIMETABLE_CHANGE_TIME, STR_TIMETABLE_WAIT_TIME_TOOLTIP),
827 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_VT_CLEAR_TIME), SetResize(1, 0), SetFill(1, 1), SetStringTip(STR_TIMETABLE_CLEAR_TIME, STR_TIMETABLE_CLEAR_TIME_TOOLTIP),
828 EndContainer(),
830 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_VT_CHANGE_SPEED), SetResize(1, 0), SetFill(1, 1), SetStringTip(STR_TIMETABLE_CHANGE_SPEED, STR_TIMETABLE_CHANGE_SPEED_TOOLTIP),
831 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_VT_CLEAR_SPEED), SetResize(1, 0), SetFill(1, 1), SetStringTip(STR_TIMETABLE_CLEAR_SPEED, STR_TIMETABLE_CLEAR_SPEED_TOOLTIP),
832 EndContainer(),
834 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_VT_START_DATE), SetResize(1, 0), SetFill(1, 1), SetStringTip(STR_TIMETABLE_START, STR_TIMETABLE_START_TOOLTIP),
835 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_VT_RESET_LATENESS), SetResize(1, 0), SetFill(1, 1), SetStringTip(STR_TIMETABLE_RESET_LATENESS, STR_TIMETABLE_RESET_LATENESS_TOOLTIP),
836 EndContainer(),
838 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_VT_AUTOFILL), SetResize(1, 0), SetFill(1, 1), SetStringTip(STR_TIMETABLE_AUTOFILL, STR_TIMETABLE_AUTOFILL_TOOLTIP),
840 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_VT_EXPECTED), SetResize(1, 0), SetFill(1, 1), SetToolTip(STR_TIMETABLE_EXPECTED_TOOLTIP),
842 EndContainer(),
843 EndContainer(),
844 EndContainer(),
846 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_VT_SHARED_ORDER_LIST), SetFill(0, 1), SetSpriteTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
848 EndContainer(),
849 EndContainer(),
850};
851
854 WindowPosition::Automatic, "view_vehicle_timetable", 400, 130,
855 WindowClass::VehicleTimetable, WindowClass::VehicleView,
857 _nested_timetable_widgets
858);
859
865{
866 CloseWindowById(WindowClass::VehicleDetails, v->index, false);
867 CloseWindowById(WindowClass::VehicleOrders, v->index, false);
869}
@ AutofillTimetable
Whether the vehicle should fill in the timetable automatically.
@ TimetableStarted
Whether the vehicle has started running on the timetable yet.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr bool None() const
Test if none of the values are set.
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
Scrollbar data structure.
bool IsVisible(size_type item) const
Checks whether given current item is visible in the list.
void SetCount(size_t num)
Sets the number of elements in the list.
size_type 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:2474
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:2548
size_type GetPosition() const
Gets the position of the first visible element in the list.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static constexpr TimerGameTick::Ticks INVALID_TICKS
Representation of an invalid number of ticks.
static constexpr TimerGameTick::Ticks TICKS_PER_SECOND
Estimation of how many ticks fit in a single second.
static constexpr TimerGame< struct Economy >::Year MAX_YEAR
static Date date
Current date in days (day counter).
static Year year
Current year, starting at 0.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static DateFract date_fract
Fractional part of the day.
uint64_t TickCounter
The type that the tick counter is stored in.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
int32_t Ticks
The type to store ticks in.
@ None
These timers can be executed in any order; the order is not relevant.
static constexpr Date DateAtStartOfYear(Year year)
StrongType::Typedef< int32_t, DateTag< struct Economy >, StrongType::Compare, StrongType::Integer > Date
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
Functions related to commands.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
void ShowSetDateWindow(Window *parent, int window_number, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback &&callback)
Create the new 'set date' window.
Definition date_gui.cpp:214
Functions related to the graphical selection of a date.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:966
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:663
Functions related to the gfx engine.
bool IsCtrlPressed()
Test if the ctrl key is pressed.
Definition gfx_func.h:82
@ Small
Index of the small font in the font tables.
Definition gfx_type.h:250
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Grey
Grey.
Definition gfx_type.h:299
@ NoShade
Do not add shading to this text colour.
Definition gfx_type.h:342
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:315
@ White
White colour.
Definition gfx_type.h:330
@ Invalid
Invalid colour.
Definition gfx_type.h:336
@ Grey
Grey colour.
Definition gfx_type.h:332
@ Green
Green colour.
Definition gfx_type.h:325
@ Black
Black colour.
Definition gfx_type.h:334
@ Red
Red colour.
Definition gfx_type.h:321
@ Silver
Silver colour.
Definition gfx_type.h:319
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:1013
GUI functions that shouldn't be here.
#define Point
Macro that prevents name conflicts between included headers.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition math_func.hpp:23
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_index, int y, bool selected, bool timetable, int left, int middle, int right)
Draws an order in order or timetable GUI.
@ GoVia
The vehicle will stop at any station it passes except the destination, aka via.
Definition order_type.h:89
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related).
Definition order_type.h:18
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel).
Definition order_type.h:39
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
Definition order_type.h:190
@ MTF_TRAVEL_TIME
Set travel time.
Definition order_type.h:192
@ MTF_WAIT_TIME
Set wait time.
Definition order_type.h:191
@ MTF_TRAVEL_SPEED
Set max travel speed.
Definition order_type.h:193
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
Types related to global configuration settings.
This file contains all sprite-related enums and defines.
static const SpriteID SPR_ARROW_RIGHT
Definition sprites.h:88
static const SpriteID SPR_ARROW_LEFT
Definition sprites.h:87
Definition of base types and functions in a cross-platform compatible way.
Parse strings.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
Definition strings.cpp:235
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type)
Convert the given display speed to the km/h-ish speed.
Definition strings.cpp:1000
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:423
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type)
Convert the given km/h-ish speed to the display speed.
Definition strings.cpp:989
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:55
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
Definition strings.cpp:217
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
VehicleFlags vehicle_flags
Used for gradual loading and other miscellaneous things (.
TimerGameTick::TickCounter timetable_start
At what tick of TimerGameTick::counter the vehicle should start its timetable.
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
VehicleType type
Type of vehicle.
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
Container for the text colour and some text colour related flags for drawing.
Definition gfx_type.h:349
TimerGameTick::Ticks GetTimetableDurationIncomplete() const
Gets the known duration of the vehicles timetable even if the timetable is not complete.
Definition order_base.h:537
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
VehicleOrderID GetNext(VehicleOrderID cur) const
Get the order after the given one or the first one, if the given one is the last one.
Definition order_base.h:472
If you change this, keep in mind that it is also saved in 2 other places:
Definition order_base.h:33
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:287
uint16_t GetMaxSpeed() const
Get the maximum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
Definition order_base.h:306
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition order_base.h:66
uint16_t GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
Definition order_base.h:293
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition order_base.h:270
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
Definition order_base.h:276
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:299
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition order_base.h:157
static Vehicle * Get(auto index)
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Container for the arrival/departure dates of a vehicle.
TimerGameTick::Ticks arrival
The arrival time.
TimerGameTick::Ticks departure
The departure time.
void OnResize() override
Called after the window got resized.
void DrawTimetablePanel(const Rect &r) const
Helper function to draw the timetable panel.
bool set_start_date_all
Set start date using minutes text entry for all timetable entries (ctrl-click) action.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void DrawSummaryPanel(const Rect &r) const
Helper function to draw the summary panel.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
const Vehicle * vehicle
Vehicle monitored by the window.
void UpdateSelectionStates()
Update the selection state of the arrival/departure data.
Scrollbar * vscroll
The scrollbar.
bool show_expected
Whether we show expected arrival or scheduled.
const IntervalTimer< TimerGameTick > redraw_interval
In real-time mode, the timetable GUI shows relative times and needs to be redrawn every second.
void OnPaint() override
The window must be repainted.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void DrawArrivalDeparturePanel(const Rect &r) const
Helper function to draw the arrival and departure panel.
VehicleTimetableWidgets query_widget
Which button was clicked to open the query text input?
bool change_timetable_all
Set wait time or speed for all timetable entries (ctrl-click) action.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
static bool BuildArrivalDepartureList(const Vehicle *v, std::vector< TimetableArrivalDeparture > &table)
Build the arrival-departure list for a given vehicle.
std::string GetTimetableTravelString(const Order &order, int i, ExtendedTextColour &colour) const
Get the time table travel string.
Vehicle data structure.
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Order current_order
The current order (+ status, like: loading).
OrderList * orders
Pointer to the order list for this vehicle.
Owner owner
Which company owns the vehicle?
High level window description.
Definition window_gui.h:171
Number to differentiate different windows of the same class.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:1025
void CloseChildWindows(WindowClass wc=WindowClass::Invalid) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1122
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1855
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:513
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:390
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1845
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:315
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:440
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:322
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:380
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:310
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
Stuff related to the text buffer GUI.
@ AcceptUnchanged
return success even when the text didn't change
Definition textbuf_gui.h:19
Definition of Interval and OneShot timers.
Definition of the game-economy-timer.
Definition of the tick-based game-timer.
Functions related to time tabling.
static const TimerGameEconomy::Year MAX_TIMETABLE_START_YEARS
The maximum start date offset, in economy years.
Definition timetable.h:18
TimerGameTick::TickCounter GetStartTickFromDate(TimerGameEconomy::Date start_date)
Get the TimerGameTick::TickCounter tick of a given date.
TimerGameEconomy::Date GetDateFromStartTick(TimerGameTick::TickCounter start_tick)
Get a date from a given start tick of timetable.
@ Ticks
In game ticks.
Definition timetable.h:24
@ Seconds
In wall clock seconds.
Definition timetable.h:23
@ Days
In in-game days.
Definition timetable.h:22
Command definitions related to timetables.
static TimerGameTick::Ticks TicksPerTimetableUnit()
Get the number of ticks in the current timetable display unit.
static WindowDesc _timetable_desc(WindowPosition::Automatic, "view_vehicle_timetable", 400, 130, WindowClass::VehicleTimetable, WindowClass::VehicleView, WindowDefaultFlag::Construction, _nested_timetable_widgets)
Window definition for the timetable window.
void ShowTimetableWindow(const Vehicle *v)
Show the timetable for a given vehicle.
static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID start, bool travelling, std::vector< TimetableArrivalDeparture > &table, TimerGameTick::Ticks offset)
Fill the table with arrivals and departures.
std::pair< StringParameter, StringParameter > GetTimetableParameters(TimerGameTick::Ticks ticks)
Get parameters to format timetable time.
bool VehicleIsAboveLatenessThreshold(TimerGameTick::Ticks ticks, bool round_to_day)
Determine if a vehicle should be shown as late or early, using a threshold depending on the timetable...
static bool CanDetermineTimeTaken(const Order &order, bool travelling)
Check whether it is possible to determine how long the order takes.
Types related to the timetable widgets.
VehicleTimetableWidgets
Widgets of the TimetableWindow class.
@ WID_VT_CHANGE_TIME
Change time button.
@ WID_VT_ARRIVAL_DEPARTURE_PANEL
Panel with the expected/scheduled arrivals.
@ WID_VT_ARRIVAL_DEPARTURE_SELECTION
Disable/hide the arrival departure panel.
@ WID_VT_CLEAR_SPEED
Clear speed limit button.
@ WID_VT_EXPECTED
Toggle between expected and scheduled arrivals.
@ WID_VT_CHANGE_SPEED
Change speed limit button.
@ WID_VT_TIMETABLE_PANEL
Timetable panel.
@ WID_VT_AUTOFILL
Autofill button.
@ WID_VT_SCROLLBAR
Scrollbar for the panel.
@ WID_VT_RESET_LATENESS
Reset lateness button.
@ WID_VT_SHARED_ORDER_LIST
Show the shared order list.
@ WID_VT_SUMMARY_PANEL
Summary panel.
@ WID_VT_CAPTION
Caption of the window.
@ WID_VT_START_DATE
Start date button.
@ WID_VT_EXPECTED_SELECTION
Disable/hide the expected selection button.
@ WID_VT_ORDER_VIEW
Order view.
@ WID_VT_CLEAR_TIME
Clear time button.
Base class for all vehicles.
Functions related to the vehicle's GUIs.
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
Definition vehicle_gui.h:37
@ VIWD_MODIFY_ORDERS
Other order modifications.
Definition vehicle_gui.h:35
@ VIWD_REMOVE_ALL_ORDERS
Removed / replaced all orders (after deleting / sharing).
Definition vehicle_gui.h:34
@ Aircraft
Aircraft vehicle type.
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX).
Definition widget_type.h:57
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX).
Definition widget_type.h:55
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window).
Definition widget_type.h:59
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX).
Definition widget_type.h:56
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
@ EqualSize
Containers should keep all their (resizing) children equally large.
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:1242
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
Definition window_gui.h:154
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Automatic
Find a place automatically.
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:21