1
0
Fork 0

Codechange: Use {COLOUR} to simplify drawing of timetables

pull/11049/head
glx22 2023-04-16 22:55:03 +02:00 committed by Loïc Guilloux
parent b1fb209bed
commit 6c7f977197
2 changed files with 11 additions and 24 deletions

View File

@ -4572,8 +4572,8 @@ STR_TIMETABLE_EXPECTED :{BLACK}Expected
STR_TIMETABLE_SCHEDULED :{BLACK}Scheduled STR_TIMETABLE_SCHEDULED :{BLACK}Scheduled
STR_TIMETABLE_EXPECTED_TOOLTIP :{BLACK}Switch between expected and scheduled STR_TIMETABLE_EXPECTED_TOOLTIP :{BLACK}Switch between expected and scheduled
STR_TIMETABLE_ARRIVAL_ABBREVIATION :A: STR_TIMETABLE_ARRIVAL :A: {COLOUR}{DATE_TINY}
STR_TIMETABLE_DEPARTURE_ABBREVIATION :D: STR_TIMETABLE_DEPARTURE :D: {COLOUR}{DATE_TINY}
# Date window (for timetable) # Date window (for timetable)

View File

@ -153,8 +153,6 @@ struct TimetableWindow : Window {
VehicleTimetableWidgets query_widget; ///< Which button was clicked to open the query text input? VehicleTimetableWidgets query_widget; ///< Which button was clicked to open the query text input?
const Vehicle *vehicle; ///< Vehicle monitored by the window. const Vehicle *vehicle; ///< Vehicle monitored by the window.
bool show_expected; ///< Whether we show expected arrival or scheduled. bool show_expected; ///< Whether we show expected arrival or scheduled.
uint deparr_time_width; ///< The width of the departure/arrival time
uint deparr_abbr_width; ///< The width of the departure/arrival abbreviation
Scrollbar *vscroll; ///< The scrollbar. Scrollbar *vscroll; ///< The scrollbar.
bool set_start_date_all; ///< Set start date using minutes text entry for all timetable entries (ctrl-click) action. bool set_start_date_all; ///< Set start date using minutes text entry for all timetable entries (ctrl-click) action.
bool change_timetable_all; ///< Set wait time or speed for all timetable entries (ctrl-click) action. bool change_timetable_all; ///< Set wait time or speed for all timetable entries (ctrl-click) action.
@ -195,10 +193,8 @@ struct TimetableWindow : Window {
{ {
switch (widget) { switch (widget) {
case WID_VT_ARRIVAL_DEPARTURE_PANEL: case WID_VT_ARRIVAL_DEPARTURE_PANEL:
SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR, 0, FS_SMALL); SetDParamMaxValue(1, MAX_YEAR * DAYS_IN_YEAR, 0, FS_SMALL);
this->deparr_time_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width; size->width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE).width) + WidgetDimensions::scaled.hsep_wide + padding.width;
this->deparr_abbr_width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL_ABBREVIATION).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE_ABBREVIATION).width);
size->width = this->deparr_abbr_width + WidgetDimensions::scaled.hsep_wide + this->deparr_time_width + padding.width;
FALLTHROUGH; FALLTHROUGH;
case WID_VT_ARRIVAL_DEPARTURE_SELECTION: case WID_VT_ARRIVAL_DEPARTURE_SELECTION:
@ -442,44 +438,35 @@ struct TimetableWindow : Window {
bool show_late = this->show_expected && v->lateness_counter > DAY_TICKS; bool show_late = this->show_expected && v->lateness_counter > DAY_TICKS;
Ticks offset = show_late ? 0 : -v->lateness_counter; Ticks offset = show_late ? 0 : -v->lateness_counter;
bool rtl = _current_text_dir == TD_RTL;
Rect abbr = tr.WithWidth(this->deparr_abbr_width, rtl);
Rect time = tr.WithWidth(this->deparr_time_width, !rtl);
for (int i = this->vscroll->GetPosition(); i / 2 < v->GetNumOrders(); ++i) { // note: i is also incremented in the loop for (int i = this->vscroll->GetPosition(); i / 2 < v->GetNumOrders(); ++i) { // note: i is also incremented in the loop
/* Don't draw anything if it extends past the end of the window. */ /* Don't draw anything if it extends past the end of the window. */
if (!this->vscroll->IsVisible(i)) break; if (!this->vscroll->IsVisible(i)) break;
/* TC_INVALID will skip the colour change. */
SetDParam(0, show_late ? TC_RED : TC_INVALID);
if (i % 2 == 0) { if (i % 2 == 0) {
/* Draw an arrival time. */ /* Draw an arrival time. */
if (arr_dep[i / 2].arrival != INVALID_TICKS) { if (arr_dep[i / 2].arrival != INVALID_TICKS) {
/* First draw the arrival abbreviation. */
DrawString(abbr.left, abbr.right, tr.top, STR_TIMETABLE_ARRIVAL_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
/* First set the offset and text colour based on the expected/scheduled mode and some other things. */ /* First set the offset and text colour based on the expected/scheduled mode and some other things. */
Ticks this_offset; Ticks this_offset;
TextColour colour;
if (this->show_expected && i / 2 == earlyID) { if (this->show_expected && i / 2 == earlyID) {
/* Show expected arrival. */ /* Show expected arrival. */
this_offset = 0; this_offset = 0;
colour = TC_GREEN; SetDParam(0, TC_GREEN);
} else { } else {
/* Show scheduled arrival. */ /* Show scheduled arrival. */
this_offset = offset; this_offset = offset;
colour = show_late ? TC_RED : (i == selected ? TC_WHITE : TC_BLACK);
} }
/* Now actually draw the arrival time. */ /* Now actually draw the arrival time. */
SetDParam(0, TimerGameCalendar::date + (arr_dep[i / 2].arrival + this_offset) / DAY_TICKS); SetDParam(1, TimerGameCalendar::date + (arr_dep[i / 2].arrival + this_offset) / DAY_TICKS);
DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY, colour); DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_ARRIVAL, i == selected ? TC_WHITE : TC_BLACK);
} }
} else { } else {
/* Draw a departure time. */ /* Draw a departure time. */
if (arr_dep[i / 2].departure != INVALID_TICKS) { if (arr_dep[i / 2].departure != INVALID_TICKS) {
DrawString(abbr.left, abbr.right, tr.top, STR_TIMETABLE_DEPARTURE_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK); SetDParam(1, TimerGameCalendar::date + (arr_dep[i / 2].departure + offset) / DAY_TICKS);
TextColour colour = show_late ? TC_RED : (i == selected ? TC_WHITE : TC_BLACK); DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_DEPARTURE, i == selected ? TC_WHITE : TC_BLACK);
SetDParam(0, TimerGameCalendar::date + (arr_dep[i / 2].departure + offset) / DAY_TICKS);
DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY, colour);
} }
} }
tr.top += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;