OpenTTD Source  20241120-master-g6d3adc6169
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"
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 
32 
33 #include "table/sprites.h"
34 #include "table/strings.h"
35 
36 #include "safeguards.h"
37 
42 };
43 
50 void SetTimetableParams(int param1, int param2, TimerGameTick::Ticks ticks)
51 {
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 
75 {
77  case TimetableMode::Days:
78  return Ticks::DAY_TICKS;
79  case TimetableMode::Seconds:
81  case TimetableMode::Ticks:
82  return 1;
83  default:
84  NOT_REACHED();
85  }
86 }
87 
95 {
97  case TimetableMode::Days:
98  return ticks > Ticks::DAY_TICKS;
99  case TimetableMode::Seconds:
100  return ticks > Ticks::TICKS_PER_SECOND;
101  case TimetableMode::Ticks:
102  return ticks > (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) &&
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 
202  int sel_index;
204  const Vehicle *vehicle;
209 
211  Window(desc),
212  sel_index(-1),
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. */
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  {
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) {
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. */
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 {
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 
269  size.height = 8 * resize.height + padding.height;
270  break;
271 
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  int32_t sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_VT_TIMETABLE_PANEL, WidgetDimensions::scaled.framerect.top);
281  if (sel == INT32_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 
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 
382  this->SetWidgetDisabledState(WID_VT_CHANGE_SPEED, disable_speed);
383  this->SetWidgetDisabledState(WID_VT_CLEAR_SPEED, disable_speed);
385 
386  this->SetWidgetDisabledState(WID_VT_START_DATE, v->orders == nullptr);
388  this->SetWidgetDisabledState(WID_VT_AUTOFILL, v->orders == nullptr);
389  } else {
398  }
399 
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 
501  int selected = this->sel_index;
502 
503  Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
504  bool show_late = this->show_expected && VehicleIsAboveLatenessThreshold(v->lateness_counter, 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. */
579  DrawString(tr, STR_TIMETABLE_STATUS_START_IN_SECONDS);
580  } else {
581  /* Other units use dates. */
582  SetDParam(0, STR_JUST_DATE_TINY);
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(abs(v->lateness_counter), false)) {
590  /* We are on time. */
591  DrawString(tr, STR_TIMETABLE_STATUS_ON_TIME);
592  } else {
593  /* We are late. */
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 
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 {
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) {
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.
728  break;
729  }
730 
731  case WID_VT_EXPECTED:
732  this->show_expected = !this->show_expected;
733  break;
734 
736  ShowVehicleListWindow(v);
737  break;
738  }
739 
740  this->SetDirty();
741  }
742 
743  void OnQueryTextFinished(std::optional<std::string> str) override
744  {
745  if (!str.has_value()) return;
746 
747  const Vehicle *v = this->vehicle;
748  uint64_t val = str->empty() ? 0 : std::strtoul(str->c_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: {
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 
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 = { { TimerGameTick::Priority::NONE, 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[] = {
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(),
819  NWidget(WWT_PANEL, COLOUR_GREY, WID_VT_TIMETABLE_PANEL), SetMinimalSize(388, 82), SetResize(1, 10), SetDataTip(STR_NULL, STR_TIMETABLE_TOOLTIP), SetScrollbar(WID_VT_SCROLLBAR), EndContainer(),
821  NWidget(WWT_PANEL, COLOUR_GREY, WID_VT_ARRIVAL_DEPARTURE_PANEL), SetMinimalSize(110, 0), SetFill(0, 1), SetDataTip(STR_NULL, STR_TIMETABLE_TOOLTIP), SetScrollbar(WID_VT_SCROLLBAR), EndContainer(),
822  EndContainer(),
824  EndContainer(),
825  NWidget(WWT_PANEL, COLOUR_GREY, WID_VT_SUMMARY_PANEL), SetMinimalSize(400, 22), SetResize(1, 0), EndContainer(),
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(),
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(),
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(),
841  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_AUTOFILL), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_TIMETABLE_AUTOFILL, STR_TIMETABLE_AUTOFILL_TOOLTIP),
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(),
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(
856  WDP_AUTO, "view_vehicle_timetable", 400, 130,
859  _nested_timetable_widgets
860 );
861 
867 {
870  AllocateWindowDescFront<TimetableWindow>(_timetable_desc, v->index);
871 }
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
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.
Scrollbar data structure.
Definition: widget_type.h:694
bool IsVisible(size_type item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:750
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:780
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:2320
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:2394
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:740
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
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
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.
static constexpr Date DateAtStartOfYear(Year year)
Calculate the date of the first day of a given year.
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
Functions related to commands.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:52
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, void *callback_data)
Create the new 'set date' window.
Definition: date_gui.cpp:216
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:77
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:922
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:851
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:657
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
Functions related to the gfx engine.
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:210
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:209
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:260
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition: gfx_type.h:284
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1181
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1284
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1202
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1137
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1309
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1191
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1126
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:940
GUI functions that shouldn't be here.
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
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:23
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:1079
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:214
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:15
static const OrderID INVALID_ORDER
Invalid order (sentinel)
Definition: order_type.h:26
@ ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
Definition: order_type.h:75
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
Definition: order_type.h:73
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
Definition: order_type.h:21
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
Definition: order_type.h:171
@ MTF_TRAVEL_TIME
Set travel time.
Definition: order_type.h:173
@ MTF_WAIT_TIME
Set wait time.
Definition: order_type.h:172
@ MTF_TRAVEL_SPEED
Set max travel speed.
Definition: order_type.h:174
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:56
Types related to global configuration settings.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:26
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
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
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type)
Convert the given display speed to the km/h-ish speed.
Definition: strings.cpp:902
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type)
Convert the given km/h-ish speed to the display speed.
Definition: strings.cpp:892
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
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
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.
Definition: strings_func.h:75
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
Definition: base_consist.h:21
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:31
TimerGameTick::TickCounter timetable_start
At what tick of TimerGameTick::counter the vehicle should start its timetable.
Definition: base_consist.h:23
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
Definition: base_consist.h:22
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:34
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
GUISettings gui
settings related to the GUI
Dimensions (a width and height) of a rectangle in 2D.
bool timetable_arrival_departure
show arrivals and departures in vehicle timetables
TimetableMode timetable_mode
Time units for timetables: days, seconds, or ticks.
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1075
TimerGameTick::Ticks GetTimetableDurationIncomplete() const
Gets the known duration of the vehicles timetable even if the timetable is not complete.
Definition: order_base.h:374
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
Definition: order_cmd.cpp:562
Order * GetFirstOrder() const
Get the first order of the order chain.
Definition: order_base.h:297
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:190
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:201
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:70
uint16_t GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
Definition: order_base.h:192
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition: order_base.h:183
Order * next
Pointer to next order. If nullptr, end of list.
Definition: order_base.h:59
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
Definition: order_base.h:185
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:188
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:194
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition: order_base.h:140
Coordinates of a point in 2D.
Tindex index
Index of this pool item.
Definition: pool_type.hpp:238
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
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.
IntervalTimer< TimerGameTick > redraw_interval
In real-time mode, the timetable GUI shows relative times and needs to be redrawn every second.
void DrawSummaryPanel(const Rect &r) const
Helper function to draw the summary panel.
const Vehicle * vehicle
Vehicle monitored by the window.
void UpdateSelectionStates()
Update the selection state of the arrival/departure data.
Scrollbar * vscroll
The scrollbar.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
bool show_expected
Whether we show expected arrival or scheduled.
void OnPaint() override
The window must be repainted.
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.
static bool BuildArrivalDepartureList(const Vehicle *v, std::vector< TimetableArrivalDeparture > &table)
Build the arrival-departure list for a given vehicle.
Vehicle data structure.
Definition: vehicle_base.h:244
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition: vehicle_base.h:732
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:738
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
Definition: vehicle_base.h:922
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:356
OrderList * orders
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:359
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:309
High level window description.
Definition: window_gui.h:159
Data structure for an opened window.
Definition: window_gui.h:273
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:952
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1733
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1035
ResizeInfo resize
Resize information.
Definition: window_gui.h:314
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition: window_gui.h:397
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1723
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:316
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:447
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:314
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:387
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:311
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:302
Stuff related to the text buffer GUI.
@ QSF_ACCEPT_UNCHANGED
return success even when the text didn't change
Definition: textbuf_gui.h:20
Definition of Interval and OneShot timers.
Definition of the game-economy-timer.
Definition of the tick-based game-timer.
Definition of the Window system.
Functions related to time tabling.
static const TimerGameEconomy::Year MAX_TIMETABLE_START_YEARS
The maximum start date offset, in economy years.
Definition: timetable.h:17
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.
Command definitions related to timetables.
static TimerGameTick::Ticks TicksPerTimetableUnit()
Get the number of ticks in the current timetable display unit.
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.
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 void ChangeTimetableStartCallback(const Window *w, TimerGameEconomy::Date date, void *data)
Callback for when a time has been chosen to start the time table.
void SetTimetableParams(int param1, int param2, TimerGameTick::Ticks ticks)
Set the timetable parameters in the format as described by the setting.
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.
@ VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
Definition: vehicle_base.h:49
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
Definition: vehicle_base.h:48
Functions related to the vehicle's GUIs.
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
Definition: vehicle_gui.h:38
@ VIWD_MODIFY_ORDERS
Other order modifications.
Definition: vehicle_gui.h:36
@ VIWD_REMOVE_ALL_ORDERS
Removed / replaced all orders (after deleting / sharing).
Definition: vehicle_gui.h:35
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
uint32_t VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:483
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:524
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:112
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:113
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:84
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:77
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:65
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:80
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:1140
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:203
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:147
int WidgetID
Widget ID.
Definition: window_type.h:18
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:737
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
Definition: window_type.h:212
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Definition: window_type.h:200
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
Definition: window_type.h:339
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
Definition: window_type.h:224