OpenTTD Source: src/timetable_gui.cpp Source File

OpenTTD Source 13.1

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 "date_func.h"
22 #include "date_gui.h"
23 #include "vehicle_gui.h"
24 #include "settings_type.h"
25 #include "timetable_cmd.h"
26 #include <cstdint>
27
28 #include "widgets/timetable_widget.h"
29
30 #include "table/sprites.h"
31 #include "table/strings.h"
32
33 #include "safeguards.h"
34
36 struct TimetableArrivalDeparture {
37 Ticks arrival;
38 Ticks departure;
39 };
40
47 void SetTimetableParams(int param1, int param2, Ticks ticks)
48 {
49 if (_settings_client.gui.timetable_in_ticks) {
50 SetDParam(param1, STR_TIMETABLE_TICKS);
51 SetDParam(param2, ticks);
52 } else {
53 SetDParam(param1, STR_TIMETABLE_DAYS);
54 SetDParam(param2, ticks / DAY_TICKS);
55 }
56 }
57
64 static bool CanDetermineTimeTaken(const Order *order, bool travelling)
65 {
66 /* Current order is conditional */
67 if (order->IsType(OT_CONDITIONAL) || order->IsType(OT_IMPLICIT)) return false;
68 /* No travel time and we have not already finished travelling */
69 if (travelling && !order->IsTravelTimetabled()) return false;
70 /* No wait time but we are loading at this timetabled station */
71 if (!travelling && !order->IsWaitTimetabled() && order->IsType(OT_GOTO_STATION) &&
72 !(order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) {
73 return false;
74 }
75
76 return true;
77 }
78
79
88 static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID start, bool travelling, TimetableArrivalDeparture *table, Ticks offset)
89 {
90 assert(table != nullptr);
91 assert(v->GetNumOrders() >= 2);
92 assert(start < v->GetNumOrders());
93
94 Ticks sum = offset;
95 VehicleOrderID i = start;
96 const Order *order = v->GetOrder(i);
97
98 /* Pre-initialize with unknown time */
99 for (int i = 0; i < v->GetNumOrders(); ++i) {
100 table[i].arrival = table[i].departure = INVALID_TICKS;
101 }
102
103 /* Cyclically loop over all orders until we reach the current one again.
104 * As we may start at the current order, do a post-checking loop */
105 do {
106 /* Automatic orders don't influence the overall timetable;
107 * they just add some untimetabled entries, but the time till
108 * the next non-implicit order can still be known. */
109 if (!order->IsType(OT_IMPLICIT)) {
110 if (travelling || i != start) {
111 if (!CanDetermineTimeTaken(order, true)) return;
112 sum += order->GetTimetabledTravel();
113 table[i].arrival = sum;
114 }
115
116 if (!CanDetermineTimeTaken(order, false)) return;
117 sum += order->GetTimetabledWait();
118 table[i].departure = sum;
119 }
120
121 ++i;
122 order = order->next;
123 if (i >= v->GetNumOrders()) {
124 i = 0;
125 assert(order == nullptr);
126 order = v->orders->GetFirstOrder();
127 }
128 } while (i != start);
129
130 /* When loading at a scheduled station we still have to treat the
131 * travelling part of the first order. */
132 if (!travelling) {
133 if (!CanDetermineTimeTaken(order, true)) return;
134 sum += order->GetTimetabledTravel();
135 table[i].arrival = sum;
136 }
137 }
138
139
145 static void ChangeTimetableStartCallback(const Window *w, Date date, void *data)
146 {
147 Command<CMD_SET_TIMETABLE_START>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, (VehicleID)w->window_number, reinterpret_cast<std::uintptr_t>(data) != 0, date);
148 }
149
150
151 struct TimetableWindow : Window {
152 int sel_index;
153 const Vehicle *vehicle;
154 bool show_expected;
155 uint deparr_time_width;
156 uint deparr_abbr_width;
157 Scrollbar *vscroll;
158 bool query_is_speed_query;
159 bool set_start_date_all;
160 bool change_timetable_all;
161
162 TimetableWindow(WindowDesc *desc, WindowNumber window_number) :
163 Window(desc),
164 sel_index(-1),
165 vehicle(Vehicle::Get(window_number)),
166 show_expected(true)
167 {
168 this->CreateNestedTree();
169 this->vscroll = this->GetScrollbar(WID_VT_SCROLLBAR);
170 this->UpdateSelectionStates();
171 this->FinishInitNested(window_number);
172
173 this->owner = this->vehicle->owner;
174 }
175
182 static bool BuildArrivalDepartureList(const Vehicle *v, TimetableArrivalDeparture *table)
183 {
184 assert(HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED));
185
186 bool travelling = (!v->current_order.IsType(OT_LOADING) || v->current_order.GetNonStopType() == ONSF_STOP_EVERYWHERE);
187 Ticks start_time = _date_fract - v->current_order_time;
188
189 FillTimetableArrivalDepartureTable(v, v->cur_real_order_index % v->GetNumOrders(), travelling, table, start_time);
190
191 return (travelling && v->lateness_counter < 0);
192 }
193
194 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
195 {
196 switch (widget) {
197 case WID_VT_ARRIVAL_DEPARTURE_PANEL:
198 SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR, 0, FS_SMALL);
199 this->deparr_time_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width;
200 this->deparr_abbr_width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL_ABBREVIATION).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE_ABBREVIATION).width);
201 size->width = this->deparr_abbr_width + WidgetDimensions::scaled.hsep_wide + this->deparr_time_width + padding.width;
202 FALLTHROUGH;
203
204 case WID_VT_ARRIVAL_DEPARTURE_SELECTION:
205 case WID_VT_TIMETABLE_PANEL:
206 resize->height = FONT_HEIGHT_NORMAL;
207 size->height = 8 * resize->height + padding.height;
208 break;
209
210 case WID_VT_SUMMARY_PANEL:
211 size->height = 2 * FONT_HEIGHT_NORMAL + padding.height;
212 break;
213 }
214 }
215
216 int GetOrderFromTimetableWndPt(int y, const Vehicle *v)
217 {
218 uint sel = (y - this->GetWidget<NWidgetBase>(WID_VT_TIMETABLE_PANEL)->pos_y - WidgetDimensions::scaled.framerect.top) / FONT_HEIGHT_NORMAL;
219
220 if (sel >= this->vscroll->GetCapacity()) return INVALID_ORDER;
221
222 sel += this->vscroll->GetPosition();
223
224 return (sel < v->GetNumOrders() * 2u) ? sel : INVALID_ORDER;
225 }
226
232 void OnInvalidateData(int data = 0, bool gui_scope = true) override
233 {
234 switch (data) {
235 case VIWD_AUTOREPLACE:
236 /* Autoreplace replaced the vehicle */
237 this->vehicle = Vehicle::Get(this->window_number);
238 break;
239
240 case VIWD_REMOVE_ALL_ORDERS:
241 /* Removed / replaced all orders (after deleting / sharing) */
242 if (this->sel_index == -1) break;
243
244 this->CloseChildWindows();
245 this->sel_index = -1;
246 break;
247
248 case VIWD_MODIFY_ORDERS:
249 if (!gui_scope) break;
250 this->UpdateSelectionStates();
251 this->ReInit();
252 break;
253
254 default: {
255 if (gui_scope) break; // only do this once; from command scope
256
257 /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
258 * the order is being created / removed */
259 if (this->sel_index == -1) break;
260
261 VehicleOrderID from = GB(data, 0, 8);
262 VehicleOrderID to = GB(data, 8, 8);
263
264 if (from == to) break; // no need to change anything
265
266 /* if from == INVALID_VEH_ORDER_ID, one order was added; if to == INVALID_VEH_ORDER_ID, one order was removed */
267 uint old_num_orders = this->vehicle->GetNumOrders() - (uint)(from == INVALID_VEH_ORDER_ID) + (uint)(to == INVALID_VEH_ORDER_ID);
268
269 VehicleOrderID selected_order = (this->sel_index + 1) / 2;
270 if (selected_order == old_num_orders) selected_order = 0; // when last travel time is selected, it belongs to order 0
271
272 bool travel = HasBit(this->sel_index, 0);
273
274 if (from != selected_order) {
275 /* Moving from preceding order? */
276 selected_order -= (int)(from <= selected_order);
277 /* Moving to preceding order? */
278 selected_order += (int)(to <= selected_order);
279 } else {
280 /* Now we are modifying the selected order */
281 if (to == INVALID_VEH_ORDER_ID) {
282 /* Deleting selected order */
283 this->CloseChildWindows();
284 this->sel_index = -1;
285 break;
286 } else {
287 /* Moving selected order */
288 selected_order = to;
289 }
290 }
291
292 /* recompute new sel_index */
293 this->sel_index = 2 * selected_order - (int)travel;
294 /* travel time of first order needs special handling */
295 if (this->sel_index == -1) this->sel_index = this->vehicle->GetNumOrders() * 2 - 1;
296 break;
297 }
298 }
299 }
300
301
302 void OnPaint() override
303 {
304 const Vehicle *v = this->vehicle;
305 int selected = this->sel_index;
306
307 this->vscroll->SetCount(v->GetNumOrders() * 2);
308
309 if (v->owner == _local_company) {
310 bool disable = true;
311 if (selected != -1) {
312 const Order *order = v->GetOrder(((selected + 1) / 2) % v->GetNumOrders());
313 if (selected % 2 == 1) {
314 disable = order != nullptr && (order->IsType(OT_CONDITIONAL) || order->IsType(OT_IMPLICIT));
315 } else {
316 disable = order == nullptr || ((!order->IsType(OT_GOTO_STATION) || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) && !order->IsType(OT_CONDITIONAL));
317 }
318 }
319 bool disable_speed = disable || selected % 2 != 1 || v->type == VEH_AIRCRAFT;
320
321 this->SetWidgetDisabledState(WID_VT_CHANGE_TIME, disable);
322 this->SetWidgetDisabledState(WID_VT_CLEAR_TIME, disable);
323 this->SetWidgetDisabledState(WID_VT_CHANGE_SPEED, disable_speed);
324 this->SetWidgetDisabledState(WID_VT_CLEAR_SPEED, disable_speed);
325 this->SetWidgetDisabledState(WID_VT_SHARED_ORDER_LIST, !v->IsOrderListShared());
326
327 this->SetWidgetDisabledState(WID_VT_START_DATE, v->orders == nullptr);
328 this->SetWidgetDisabledState(WID_VT_RESET_LATENESS, v->orders == nullptr);
329 this->SetWidgetDisabledState(WID_VT_AUTOFILL, v->orders == nullptr);
330 } else {
331 this->DisableWidget(WID_VT_START_DATE);
332 this->DisableWidget(WID_VT_CHANGE_TIME);
333 this->DisableWidget(WID_VT_CLEAR_TIME);
334 this->DisableWidget(WID_VT_CHANGE_SPEED);
335 this->DisableWidget(WID_VT_CLEAR_SPEED);
336 this->DisableWidget(WID_VT_RESET_LATENESS);
337 this->DisableWidget(WID_VT_AUTOFILL);
338 this->DisableWidget(WID_VT_SHARED_ORDER_LIST);
339 }
340
341 this->SetWidgetLoweredState(WID_VT_AUTOFILL, HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE));
342
343 this->DrawWidgets();
344 }
345
346 void SetStringParameters(int widget) const override
347 {
348 switch (widget) {
349 case WID_VT_CAPTION: SetDParam(0, this->vehicle->index); break;
350 case WID_VT_EXPECTED: SetDParam(0, this->show_expected ? STR_TIMETABLE_EXPECTED : STR_TIMETABLE_SCHEDULED); break;
351 }
352 }
353
354 void DrawWidget(const Rect &r, int widget) const override
355 {
356 const Vehicle *v = this->vehicle;
357 int selected = this->sel_index;
358
359 switch (widget) {
360 case WID_VT_TIMETABLE_PANEL: {
361 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
362 int i = this->vscroll->GetPosition();
363 VehicleOrderID order_id = (i + 1) / 2;
364 bool final_order = false;
365
366 bool rtl = _current_text_dir == TD_RTL;
367 SetDParamMaxValue(0, v->GetNumOrders(), 2);
368 int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + WidgetDimensions::scaled.hsep_normal;
369 int middle = rtl ? tr.right - index_column_width : tr.left + index_column_width;
370
371 const Order *order = v->GetOrder(order_id);
372 while (order != nullptr) {
373 /* Don't draw anything if it extends past the end of the window. */
374 if (!this->vscroll->IsVisible(i)) break;
375
376 if (i % 2 == 0) {
377 DrawOrderString(v, order, order_id, tr.top, i == selected, true, tr.left, middle, tr.right);
378
379 order_id++;
380
381 if (order_id >= v->GetNumOrders()) {
382 order = v->GetOrder(0);
383 final_order = true;
384 } else {
385 order = order->next;
386 }
387 } else {
388 StringID string;
389 TextColour colour = (i == selected) ? TC_WHITE : TC_BLACK;
390 if (order->IsType(OT_CONDITIONAL)) {
391 string = STR_TIMETABLE_NO_TRAVEL;
392 } else if (order->IsType(OT_IMPLICIT)) {
393 string = STR_TIMETABLE_NOT_TIMETABLEABLE;
394 colour = ((i == selected) ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
395 } else if (!order->IsTravelTimetabled()) {
396 if (order->GetTravelTime() > 0) {
397 SetTimetableParams(0, 1, order->GetTravelTime());
398 string = order->GetMaxSpeed() != UINT16_MAX ?
399 STR_TIMETABLE_TRAVEL_FOR_SPEED_ESTIMATED :
400 STR_TIMETABLE_TRAVEL_FOR_ESTIMATED;
401 } else {
402 string = order->GetMaxSpeed() != UINT16_MAX ?
403 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED :
404 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED;
405 }
406 } else {
407 SetTimetableParams(0, 1, order->GetTimetabledTravel());
408 string = order->GetMaxSpeed() != UINT16_MAX ?
409 STR_TIMETABLE_TRAVEL_FOR_SPEED : STR_TIMETABLE_TRAVEL_FOR;
410 }
411 SetDParam(2, order->GetMaxSpeed());
412
413 DrawString(rtl ? tr.left : middle, rtl ? middle : tr.right, tr.top, string, colour);
414
415 if (final_order) break;
416 }
417
418 i++;
419 tr.top += FONT_HEIGHT_NORMAL;
420 }
421 break;
422 }
423
424 case WID_VT_ARRIVAL_DEPARTURE_PANEL: {
425 /* Arrival and departure times are handled in an all-or-nothing approach,
426 * i.e. are only shown if we can calculate all times.
427 * Excluding order lists with only one order makes some things easier.
428 */
429 Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0;
430 if (total_time <= 0 || v->GetNumOrders() <= 1 || !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) break;
431
432 TimetableArrivalDeparture *arr_dep = AllocaM(TimetableArrivalDeparture, v->GetNumOrders());
433 const VehicleOrderID cur_order = v->cur_real_order_index % v->GetNumOrders();
434
435 VehicleOrderID earlyID = BuildArrivalDepartureList(v, arr_dep) ? cur_order : (VehicleOrderID)INVALID_VEH_ORDER_ID;
436
437 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
438 bool show_late = this->show_expected && v->lateness_counter > DAY_TICKS;
439 Ticks offset = show_late ? 0 : -v->lateness_counter;
440
441 bool rtl = _current_text_dir == TD_RTL;
442 Rect abbr = tr.WithWidth(this->deparr_abbr_width, rtl);
443 Rect time = tr.WithWidth(this->deparr_time_width, !rtl);
444
445 for (int i = this->vscroll->GetPosition(); i / 2 < v->GetNumOrders(); ++i) { // note: i is also incremented in the loop
446 /* Don't draw anything if it extends past the end of the window. */
447 if (!this->vscroll->IsVisible(i)) break;
448
449 if (i % 2 == 0) {
450 if (arr_dep[i / 2].arrival != INVALID_TICKS) {
451 DrawString(abbr.left, abbr.right, tr.top, STR_TIMETABLE_ARRIVAL_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
452 if (this->show_expected && i / 2 == earlyID) {
453 SetDParam(0, _date + arr_dep[i / 2].arrival / DAY_TICKS);
454 DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY, TC_GREEN);
455 } else {
456 SetDParam(0, _date + (arr_dep[i / 2].arrival + offset) / DAY_TICKS);
457 DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY,
458 show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
459 }
460 }
461 } else {
462 if (arr_dep[i / 2].departure != INVALID_TICKS) {
463 DrawString(abbr.left, abbr.right, tr.top, STR_TIMETABLE_DEPARTURE_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
464 SetDParam(0, _date + (arr_dep[i/2].departure + offset) / DAY_TICKS);
465 DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY,
466 show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
467 }
468 }
469 tr.top += FONT_HEIGHT_NORMAL;
470 }
471 break;
472 }
473
474 case WID_VT_SUMMARY_PANEL: {
475 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
476
477 Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0;
478 if (total_time != 0) {
479 SetTimetableParams(0, 1, total_time);
480 DrawString(tr, v->orders->IsCompleteTimetable() ? STR_TIMETABLE_TOTAL_TIME : STR_TIMETABLE_TOTAL_TIME_INCOMPLETE);
481 }
482 tr.top += FONT_HEIGHT_NORMAL;
483
484 if (v->timetable_start != 0) {
485 /* We are running towards the first station so we can start the
486 * timetable at the given time. */
487 SetDParam(0, STR_JUST_DATE_TINY);
488 SetDParam(1, v->timetable_start);
489 DrawString(tr, STR_TIMETABLE_STATUS_START_AT);
490 } else if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
491 /* We aren't running on a timetable yet, so how can we be "on time"
492 * when we aren't even "on service"/"on duty"? */
493 DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED);
494 } else if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / DAY_TICKS == 0)) {
495 DrawString(tr, STR_TIMETABLE_STATUS_ON_TIME);
496 } else {
497 SetTimetableParams(0, 1, abs(v->lateness_counter));
498 DrawString(tr, v->lateness_counter < 0 ? STR_TIMETABLE_STATUS_EARLY : STR_TIMETABLE_STATUS_LATE);
499 }
500 break;
501 }
502 }
503 }
504
505 static inline std::tuple<VehicleOrderID, ModifyTimetableFlags> PackTimetableArgs(const Vehicle *v, uint selected, bool speed)
506 {
507 uint order_number = (selected + 1) / 2;
508 ModifyTimetableFlags mtf = (selected % 2 == 1) ? (speed ? MTF_TRAVEL_SPEED : MTF_TRAVEL_TIME) : MTF_WAIT_TIME;
509
510 if (order_number >= v->GetNumOrders()) order_number = 0;
511
512 return { order_number, mtf };
513 }
514
515 void OnClick(Point pt, int widget, int click_count) override
516 {
517 const Vehicle *v = this->vehicle;
518
519 switch (widget) {
520 case WID_VT_ORDER_VIEW: // Order view button
521 ShowOrdersWindow(v);
522 break;
523
524 case WID_VT_TIMETABLE_PANEL: { // Main panel.
525 int selected = GetOrderFromTimetableWndPt(pt.y, v);
526
527 this->CloseChildWindows();
528 this->sel_index = (selected == INVALID_ORDER || selected == this->sel_index) ? -1 : selected;
529 break;
530 }
531
532 case WID_VT_START_DATE: // Change the date that the timetable starts.
533 ShowSetDateWindow(this, v->index, _date, _cur_year, _cur_year + 15, ChangeTimetableStartCallback, reinterpret_cast<void *>(static_cast<uintptr_t>(v->orders->IsCompleteTimetable() && _ctrl_pressed)));
534 break;
535
536 case WID_VT_CHANGE_TIME: { // "Wait For" button.
537 int selected = this->sel_index;
538 VehicleOrderID real = (selected + 1) / 2;
539
540 if (real >= v->GetNumOrders()) real = 0;
541
542 const Order *order = v->GetOrder(real);
543 StringID current = STR_EMPTY;
544
545 if (order != nullptr) {
546 uint time = (selected % 2 == 1) ? order->GetTravelTime() : order->GetWaitTime();
547 if (!_settings_client.gui.timetable_in_ticks) time /= DAY_TICKS;
548
549 if (time != 0) {
550 SetDParam(0, time);
551 current = STR_JUST_INT;
552 }
553 }
554
555 this->query_is_speed_query = false;
556 this->change_timetable_all = _ctrl_pressed && (order != nullptr);
557 ShowQueryString(current, STR_TIMETABLE_CHANGE_TIME, 31, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
558 break;
559 }
560
561 case WID_VT_CHANGE_SPEED: { // Change max speed button.
562 int selected = this->sel_index;
563 VehicleOrderID real = (selected + 1) / 2;
564
565 if (real >= v->GetNumOrders()) real = 0;
566
567 StringID current = STR_EMPTY;
568 const Order *order = v->GetOrder(real);
569 if (order != nullptr) {
570 if (order->GetMaxSpeed() != UINT16_MAX) {
571 SetDParam(0, ConvertKmhishSpeedToDisplaySpeed(order->GetMaxSpeed()));
572 current = STR_JUST_INT;
573 }
574 }
575
576 this->query_is_speed_query = true;
577 this->change_timetable_all = _ctrl_pressed && (order != nullptr);
578 ShowQueryString(current, STR_TIMETABLE_CHANGE_SPEED, 31, this, CS_NUMERAL, QSF_NONE);
579 break;
580 }
581
582 case WID_VT_CLEAR_TIME: { // Clear waiting time.
583 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, false);
584 if (_ctrl_pressed) {
585 Command<CMD_BULK_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, mtf, 0);
586 } else {
587 Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, 0);
588 }
589 break;
590 }
591
592 case WID_VT_CLEAR_SPEED: { // Clear max speed button.
593 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, true);
594 if (_ctrl_pressed) {
595 Command<CMD_BULK_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, mtf, UINT16_MAX);
596 } else {
597 Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, UINT16_MAX);
598 }
599 break;
600 }
601
602 case WID_VT_RESET_LATENESS: // Reset the vehicle's late counter.
603 Command<CMD_SET_VEHICLE_ON_TIME>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index);
604 break;
605
606 case WID_VT_AUTOFILL: { // Autofill the timetable.
607 Command<CMD_AUTOFILL_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, !HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE), _ctrl_pressed);
608 break;
609 }
610
611 case WID_VT_EXPECTED:
612 this->show_expected = !this->show_expected;
613 break;
614
615 case WID_VT_SHARED_ORDER_LIST:
616 ShowVehicleListWindow(v);
617 break;
618 }
619
620 this->SetDirty();
621 }
622
623 void OnQueryTextFinished(char *str) override
624 {
625 if (str == nullptr) return;
626
627 const Vehicle *v = this->vehicle;
628
629 uint64 val = StrEmpty(str) ? 0 : strtoul(str, nullptr, 10);
630 if (this->query_is_speed_query) {
631 val = ConvertDisplaySpeedToKmhishSpeed(val);
632 } else {
633 if (!_settings_client.gui.timetable_in_ticks) val *= DAY_TICKS;
634 }
635
636 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, this->query_is_speed_query);
637
638 if (this->change_timetable_all) {
639 Command<CMD_BULK_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, mtf, std::min<uint32>(val, UINT16_MAX));
640 } else {
641 Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, std::min<uint32>(val, UINT16_MAX));
642 }
643 }
644
645 void OnResize() override
646 {
647 /* Update the scroll bar */
648 this->vscroll->SetCapacityFromWidget(this, WID_VT_TIMETABLE_PANEL, WidgetDimensions::scaled.framerect.Vertical());
649 }
650
654 void UpdateSelectionStates()
655 {
656 this->GetWidget<NWidgetStacked>(WID_VT_ARRIVAL_DEPARTURE_SELECTION)->SetDisplayedPlane(_settings_client.gui.timetable_arrival_departure ? 0 : SZSP_NONE);
657 this->GetWidget<NWidgetStacked>(WID_VT_EXPECTED_SELECTION)->SetDisplayedPlane(_settings_client.gui.timetable_arrival_departure ? 0 : 1);
658 }
659 };
660
661 static const NWidgetPart _nested_timetable_widgets[] = {
662 NWidget(NWID_HORIZONTAL),
663 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
664 NWidget(WWT_CAPTION, COLOUR_GREY, WID_VT_CAPTION), SetDataTip(STR_TIMETABLE_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
665 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_ORDER_VIEW), SetMinimalSize(61, 14), SetDataTip( STR_TIMETABLE_ORDER_VIEW, STR_TIMETABLE_ORDER_VIEW_TOOLTIP),
666 NWidget(WWT_SHADEBOX, COLOUR_GREY),
667 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
668 NWidget(WWT_STICKYBOX, COLOUR_GREY),
669 EndContainer(),
670 NWidget(NWID_HORIZONTAL),
671 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(),
672 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VT_ARRIVAL_DEPARTURE_SELECTION),
673 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(),
674 EndContainer(),
675 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_VT_SCROLLBAR),
676 EndContainer(),
677 NWidget(WWT_PANEL, COLOUR_GREY, WID_VT_SUMMARY_PANEL), SetMinimalSize(400, 22), SetResize(1, 0), EndContainer(),
678 NWidget(NWID_HORIZONTAL),
679 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
680 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
681 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),
682 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),
683 EndContainer(),
684 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
685 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),
686 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),
687 EndContainer(),
688 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
689 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_START_DATE), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_TIMETABLE_STARTING_DATE, STR_TIMETABLE_STARTING_DATE_TOOLTIP),
690 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),
691 EndContainer(),
692 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
693 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_AUTOFILL), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_TIMETABLE_AUTOFILL, STR_TIMETABLE_AUTOFILL_TOOLTIP),
694 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VT_EXPECTED_SELECTION),
695 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VT_EXPECTED), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_BLACK_STRING, STR_TIMETABLE_EXPECTED_TOOLTIP),
696 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
697 EndContainer(),
698 EndContainer(),
699 EndContainer(),
700 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
701 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),
702 NWidget(WWT_RESIZEBOX, COLOUR_GREY), SetFill(0, 1),
703 EndContainer(),
704 EndContainer(),
705 };
706
707 static WindowDesc _timetable_desc(
708 WDP_AUTO, "view_vehicle_timetable", 400, 130,
709 WC_VEHICLE_TIMETABLE, WC_VEHICLE_VIEW,
710 WDF_CONSTRUCTION,
711 _nested_timetable_widgets, lengthof(_nested_timetable_widgets)
712 );
713
718 void ShowTimetableWindow(const Vehicle *v)
719 {
720 CloseWindowById(WC_VEHICLE_DETAILS, v->index, false);
721 CloseWindowById(WC_VEHICLE_ORDERS, v->index, false);
722 AllocateWindowDescFront<TimetableWindow>(&_timetable_desc, v->index);
723 }
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:426
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
MTF_TRAVEL_SPEED
@ MTF_TRAVEL_SPEED
Set max travel speed.
Definition: order_type.h:173
TimetableWindow::BuildArrivalDepartureList
static bool BuildArrivalDepartureList(const Vehicle *v, TimetableArrivalDeparture *table)
Build the arrival-departure list for a given vehicle.
Definition: timetable_gui.cpp:182
VehicleOrderID
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:15
timetable_widget.h
Order::GetWaitTime
uint16 GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
Definition: order_base.h:193
TimetableWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: timetable_gui.cpp:515
WID_VT_SCROLLBAR
@ WID_VT_SCROLLBAR
Scrollbar for the panel.
Definition: timetable_widget.h:19
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
vehicle_gui.h
TimetableWindow::deparr_time_width
uint deparr_time_width
The width of the departure/arrival time.
Definition: timetable_gui.cpp:155
FillTimetableArrivalDepartureTable
static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID start, bool travelling, TimetableArrivalDeparture *table, Ticks offset)
Fill the table with arrivals and departures.
Definition: timetable_gui.cpp:88
Order::GetTimetabledWait
uint16 GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
Definition: order_base.h:189
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1208
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
TimetableWindow::query_is_speed_query
bool query_is_speed_query
The currently open query window is a speed query and not a time query.
Definition: timetable_gui.cpp:158
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:667
command_func.h
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
MTF_WAIT_TIME
@ MTF_WAIT_TIME
Set wait time.
Definition: order_type.h:171
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:320
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:144
WID_VT_ARRIVAL_DEPARTURE_PANEL
@ WID_VT_ARRIVAL_DEPARTURE_PANEL
Panel with the expected/scheduled arrivals.
Definition: timetable_widget.h:18
QSF_ACCEPT_UNCHANGED
@ QSF_ACCEPT_UNCHANGED
return success even when the text didn't change
Definition: textbuf_gui.h:20
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
ModifyTimetableFlags
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
Definition: order_type.h:170
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:1015
_cur_year
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
_date_fract
DateFract _date_fract
Fractional part of the day.
Definition: date.cpp:29
Order::GetTimetabledTravel
uint16 GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
Definition: order_base.h:191
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
WID_VT_CAPTION
@ WID_VT_CAPTION
Caption of the window.
Definition: timetable_widget.h:15
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1771
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:715
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:257
vehicle_base.h
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:995
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
OrderList::IsCompleteTimetable
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
Definition: order_cmd.cpp:603
WC_VEHICLE_TIMETABLE
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
Definition: window_type.h:217
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:253
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:713
GUISettings::timetable_in_ticks
bool timetable_in_ticks
whether to show the timetable in ticks rather than days
Definition: settings_type.h:155
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
WID_VT_EXPECTED
@ WID_VT_EXPECTED
Toggle between expected and scheduled arrivals.
Definition: timetable_widget.h:26
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:288
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:634
TimetableWindow::UpdateSelectionStates
void UpdateSelectionStates()
Update the selection state of the arrival/departure data.
Definition: timetable_gui.cpp:654
TimetableWindow
Definition: timetable_gui.cpp:151
ShowSetDateWindow
void ShowSetDateWindow(Window *parent, int window_number, Date initial_date, Year min_year, Year max_year, SetDateCallback *callback, void *callback_data)
Create the new 'set date' window.
Definition: date_gui.cpp:216
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
WID_VT_SUMMARY_PANEL
@ WID_VT_SUMMARY_PANEL
Summary panel.
Definition: timetable_widget.h:20
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1109
WID_VT_ARRIVAL_DEPARTURE_SELECTION
@ WID_VT_ARRIVAL_DEPARTURE_SELECTION
Disable/hide the arrival departure panel.
Definition: timetable_widget.h:28
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
textbuf_gui.h
INVALID_ORDER
static const OrderID INVALID_ORDER
Invalid order (sentinel)
Definition: order_type.h:26
Order::GetMaxSpeed
uint16 GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
Definition: order_base.h:202
gfx_func.h
WindowDesc
High level window description.
Definition: window_gui.h:102
WID_VT_SHARED_ORDER_LIST
@ WID_VT_SHARED_ORDER_LIST
Show the shared order list.
Definition: timetable_widget.h:27
timetable_cmd.h
ChangeTimetableStartCallback
static void ChangeTimetableStartCallback(const Window *w, Date date, void *data)
Callback for when a time has been chosen to start the time table.
Definition: timetable_gui.cpp:145
window_gui.h
ConvertDisplaySpeedToKmhishSpeed
uint ConvertDisplaySpeedToKmhishSpeed(uint speed)
Convert the given display speed to the km/h-ish speed.
Definition: strings.cpp:798
VF_AUTOFILL_TIMETABLE
@ VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
Definition: vehicle_base.h:50
Order::GetNonStopType
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition: order_base.h:141
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:467
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
WID_VT_CHANGE_SPEED
@ WID_VT_CHANGE_SPEED
Change speed limit button.
Definition: timetable_widget.h:30
TimetableWindow::change_timetable_all
bool change_timetable_all
Set wait time or speed for all timetable entries (ctrl-click) action.
Definition: timetable_gui.cpp:160
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
ONSF_STOP_EVERYWHERE
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
Definition: order_type.h:73
WID_VT_ORDER_VIEW
@ WID_VT_ORDER_VIEW
Order view.
Definition: timetable_widget.h:16
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
WC_VEHICLE_VIEW
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
Definition: window_type.h:332
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
INVALID_VEH_ORDER_ID
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
Definition: order_type.h:21
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1004
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:208
Order::GetTravelTime
uint16 GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
Definition: order_base.h:195
TimetableWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: timetable_gui.cpp:354
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
TimetableWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: timetable_gui.cpp:194
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:333
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
ShowTimetableWindow
void ShowTimetableWindow(const Vehicle *v)
Show the timetable for a given vehicle.
Definition: timetable_gui.cpp:718
WC_VEHICLE_DETAILS
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Definition: window_type.h:193
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
WID_VT_CLEAR_SPEED
@ WID_VT_CLEAR_SPEED
Clear speed limit button.
Definition: timetable_widget.h:31
safeguards.h
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1115
SetTimetableParams
void SetTimetableParams(int param1, int param2, Ticks ticks)
Set the timetable parameters in the format as described by the setting.
Definition: timetable_gui.cpp:47
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:67
Ticks
int32 Ticks
The type to store ticks in.
Definition: date_type.h:16
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition: gfx_type.h:281
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:179
settings_type.h
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
date_func.h
stdafx.h
BaseConsist::vehicle_flags
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:31
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:241
date_gui.h
Vehicle::IsOrderListShared
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition: vehicle_base.h:710
TimetableArrivalDeparture::arrival
Ticks arrival
The arrival time.
Definition: timetable_gui.cpp:37
TimetableWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: timetable_gui.cpp:232
TimetableWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: timetable_gui.cpp:346
CanDetermineTimeTaken
static bool CanDetermineTimeTaken(const Order *order, bool travelling)
Check whether it is possible to determine how long the order takes.
Definition: timetable_gui.cpp:64
INVALID_TICKS
static const Ticks INVALID_TICKS
Representation of an invalid number of ticks.
Definition: date_type.h:112
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
Order::IsTravelTimetabled
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
Definition: order_base.h:186
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:993
TimetableWindow::show_expected
bool show_expected
Whether we show expected arrival or scheduled.
Definition: timetable_gui.cpp:154
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:28
ONSF_NO_STOP_AT_DESTINATION_STATION
@ ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
Definition: order_type.h:75
string_func.h
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1094
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
ConvertKmhishSpeedToDisplaySpeed
uint ConvertKmhishSpeedToDisplaySpeed(uint speed)
Convert the given km/h-ish speed to the display speed.
Definition: strings.cpp:788
BaseConsist::lateness_counter
int32 lateness_counter
How many ticks late (or early if negative) this vehicle is.
Definition: base_consist.h:23
TimetableArrivalDeparture
Container for the arrival/departure dates of a vehicle.
Definition: timetable_gui.cpp:36
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1091
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
VIWD_AUTOREPLACE
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
Definition: vehicle_gui.h:37
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1227
Scrollbar::IsVisible
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:686
SetDParamMaxValue
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:95
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1012
OrderList::GetTimetableDurationIncomplete
Ticks GetTimetableDurationIncomplete() const
Gets the known duration of the vehicles timetable even if the timetable is not complete.
Definition: order_base.h:380
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
BaseConsist::current_order_time
uint32 current_order_time
How many ticks have passed since this order started.
Definition: base_consist.h:22
BaseConsist::timetable_start
Date timetable_start
When the vehicle is supposed to start the timetable.
Definition: base_consist.h:24
TimetableWindow::vehicle
const Vehicle * vehicle
Vehicle monitored by the window.
Definition: timetable_gui.cpp:153
WID_VT_TIMETABLE_PANEL
@ WID_VT_TIMETABLE_PANEL
Timetable panel.
Definition: timetable_widget.h:17
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:676
TimetableArrivalDeparture::departure
Ticks departure
The departure time.
Definition: timetable_gui.cpp:38
DAYS_IN_YEAR
static const int DAYS_IN_YEAR
days per year
Definition: date_type.h:29
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1787
TimetableWindow::set_start_date_all
bool set_start_date_all
Set start date using minutes text entry for all timetable entries (ctrl-click) action.
Definition: timetable_gui.cpp:159
company_func.h
WID_VT_RESET_LATENESS
@ WID_VT_RESET_LATENESS
Reset lateness button.
Definition: timetable_widget.h:24
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:21
WidgetDimensions::framerect
RectPadding framerect
Offsets within frame area.
Definition: window_gui.h:47
GUISettings::timetable_arrival_departure
bool timetable_arrival_departure
show arrivals and departures in vehicle timetables
Definition: settings_type.h:148
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
VF_TIMETABLE_STARTED
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
Definition: vehicle_base.h:49
OrderList::GetFirstOrder
Order * GetFirstOrder() const
Get the first order of the order chain.
Definition: order_base.h:300
WID_VT_START_DATE
@ WID_VT_START_DATE
Start date button.
Definition: timetable_widget.h:21
CommandHelper
Definition: command_func.h:94
window_func.h
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:248
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2427
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1187
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1078
gui.h
WID_VT_CLEAR_TIME
@ WID_VT_CLEAR_TIME
Clear time button.
Definition: timetable_widget.h:23
Window
Data structure for an opened window.
Definition: window_gui.h:213
DrawOrderString
void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
Draws an order in order or timetable GUI.
Definition: order_gui.cpp:219
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
Vehicle::GetOrder
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
Definition: vehicle_base.h:890
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
VIWD_MODIFY_ORDERS
@ VIWD_MODIFY_ORDERS
Other order modifications.
Definition: vehicle_gui.h:35
TimetableWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: timetable_gui.cpp:623
TimetableWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: timetable_gui.cpp:645
TimetableWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: timetable_gui.cpp:302
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
WID_VT_EXPECTED_SELECTION
@ WID_VT_EXPECTED_SELECTION
Disable/hide the expected selection button.
Definition: timetable_widget.h:29
WID_VT_AUTOFILL
@ WID_VT_AUTOFILL
Autofill button.
Definition: timetable_widget.h:25
Vehicle::GetNumOrders
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:716
VIWD_REMOVE_ALL_ORDERS
@ VIWD_REMOVE_ALL_ORDERS
Removed / replaced all orders (after deleting / sharing).
Definition: vehicle_gui.h:34
Vehicle::orders
OrderList * orders
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:336
Window::DisableWidget
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:331
Order::next
Order * next
Pointer to next order. If nullptr, end of list.
Definition: order_base.h:59
Order
Definition: order_base.h:36
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:382
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
DAY_TICKS
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:28
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:49
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:28
Order::IsWaitTimetabled
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition: order_base.h:184
WID_VT_CHANGE_TIME
@ WID_VT_CHANGE_TIME
Change time button.
Definition: timetable_widget.h:22
WC_VEHICLE_ORDERS
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
Definition: window_type.h:205
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
MTF_TRAVEL_TIME
@ MTF_TRAVEL_TIME
Set travel time.
Definition: order_type.h:172
MAX_YEAR
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
Definition: date_type.h:95
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
TimetableWindow::deparr_abbr_width
uint deparr_abbr_width
The width of the departure/arrival abbreviation.
Definition: timetable_gui.cpp:156
AllocaM
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
Definition: alloc_func.hpp:132