MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawArrivalDeparturePanel

Method DrawArrivalDeparturePanel

src/timetable_gui.cpp:467–538  ·  view source on GitHub ↗

* Helper function to draw the arrival and departure panel. * @param r The rect to draw within. */

Source from the content-addressed store, hash-verified

465 * @param r The rect to draw within.
466 */
467 void DrawArrivalDeparturePanel(const Rect &r) const
468 {
469 const Vehicle *v = this->vehicle;
470
471 /* Arrival and departure times are handled in an all-or-nothing approach,
472 * i.e. are only shown if we can calculate all times.
473 * Excluding order lists with only one order makes some things easier. */
474 TimerGameTick::Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0;
475 if (total_time <= 0 || v->GetNumOrders() <= 1 || !v->vehicle_flags.Test(VehicleFlag::TimetableStarted)) return;
476
477 std::vector<TimetableArrivalDeparture> arr_dep(v->GetNumOrders());
478 const VehicleOrderID cur_order = v->cur_real_order_index % v->GetNumOrders();
479
480 VehicleOrderID early_id = BuildArrivalDepartureList(v, arr_dep) ? cur_order : (VehicleOrderID)INVALID_VEH_ORDER_ID;
481 int selected = this->sel_index;
482
483 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
484 bool show_late = this->show_expected && VehicleIsAboveLatenessThreshold(v->lateness_counter, true);
485 TimerGameTick::Ticks offset = show_late ? 0 : -v->lateness_counter;
486
487 for (int i = this->vscroll->GetPosition(); i / 2 < v->GetNumOrders(); ++i) { // note: i is also incremented in the loop
488 /* Don't draw anything if it extends past the end of the window. */
489 if (!this->vscroll->IsVisible(i)) break;
490
491 /* TC_INVALID will skip the colour change. */
492 TextColour tc = show_late ? TC_RED : TC_INVALID;
493 if (i % 2 == 0) {
494 /* Draw an arrival time. */
495 if (arr_dep[i / 2].arrival != Ticks::INVALID_TICKS) {
496 /* First set the offset and text colour based on the expected/scheduled mode and some other things. */
497 TimerGameTick::Ticks this_offset;
498 if (this->show_expected && i / 2 == early_id) {
499 /* Show expected arrival. */
500 this_offset = 0;
501 tc = TC_GREEN;
502 } else {
503 /* Show scheduled arrival. */
504 this_offset = offset;
505 }
506
507 /* Now actually draw the arrival time. */
508 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
509 /* Display seconds from now. */
510 DrawString(tr,
511 GetString(STR_TIMETABLE_ARRIVAL_SECONDS_IN_FUTURE, tc, (arr_dep[i / 2].arrival + offset) / Ticks::TICKS_PER_SECOND),
512 i == selected ? TC_WHITE : TC_BLACK);
513 } else {
514 /* Show a date. */
515 DrawString(tr,
516 GetString(STR_TIMETABLE_ARRIVAL_DATE, tc, TimerGameEconomy::date + (arr_dep[i / 2].arrival + this_offset) / Ticks::DAY_TICKS),
517 i == selected ? TC_WHITE : TC_BLACK);
518 }
519 }
520 } else {
521 /* Draw a departure time. */
522 if (arr_dep[i / 2].departure != Ticks::INVALID_TICKS) {
523 if (_settings_client.gui.timetable_mode == TimetableMode::Seconds) {
524 /* Display seconds from now. */

Callers 1

DrawWidgetMethod · 0.95

Calls 10

GetCharacterHeightFunction · 0.85
TestMethod · 0.80
ShrinkMethod · 0.80
GetPositionMethod · 0.80
DrawStringFunction · 0.70
GetStringFunction · 0.70
GetNumOrdersMethod · 0.45
IsVisibleMethod · 0.45

Tested by

no test coverage detected