Changeset - r27620:4c49cac38db4
[Not reviewed]
master
0 2 0
glx22 - 14 months ago 2023-04-16 20:55:03
glx@openttd.org
Codechange: Use {COLOUR} to simplify drawing of timetables
2 files changed with 11 insertions and 24 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -4563,26 +4563,26 @@ STR_TIMETABLE_CLEAR_SPEED               
 
STR_TIMETABLE_CLEAR_SPEED_TOOLTIP                               :{BLACK}Clear the maximum travel speed of the highlighted order. Ctrl+Click clears the speed for all orders
 

	
 
STR_TIMETABLE_RESET_LATENESS                                    :{BLACK}Reset Late Counter
 
STR_TIMETABLE_RESET_LATENESS_TOOLTIP                            :{BLACK}Reset the lateness counter, so the vehicle will be on time. Ctrl+Click will reset the entire group so the latest vehicle will be on time and all others will be early
 

	
 
STR_TIMETABLE_AUTOFILL                                          :{BLACK}Autofill
 
STR_TIMETABLE_AUTOFILL_TOOLTIP                                  :{BLACK}Fill the timetable automatically with the values from the next journey. Ctrl+Click to try to keep waiting times
 

	
 
STR_TIMETABLE_EXPECTED                                          :{BLACK}Expected
 
STR_TIMETABLE_SCHEDULED                                         :{BLACK}Scheduled
 
STR_TIMETABLE_EXPECTED_TOOLTIP                                  :{BLACK}Switch between expected and scheduled
 

	
 
STR_TIMETABLE_ARRIVAL_ABBREVIATION                              :A:
 
STR_TIMETABLE_DEPARTURE_ABBREVIATION                            :D:
 
STR_TIMETABLE_ARRIVAL                                           :A: {COLOUR}{DATE_TINY}
 
STR_TIMETABLE_DEPARTURE                                         :D: {COLOUR}{DATE_TINY}
 

	
 

	
 
# Date window (for timetable)
 
STR_DATE_CAPTION                                                :{WHITE}Set date
 
STR_DATE_SET_DATE                                               :{BLACK}Set date
 
STR_DATE_SET_DATE_TOOLTIP                                       :{BLACK}Use the selected date as starting date for the timetable
 
STR_DATE_DAY_TOOLTIP                                            :{BLACK}Select day
 
STR_DATE_MONTH_TOOLTIP                                          :{BLACK}Select month
 
STR_DATE_YEAR_TOOLTIP                                           :{BLACK}Select year
 

	
 

	
 
# AI debug window
src/timetable_gui.cpp
Show inline comments
 
@@ -144,26 +144,24 @@ static void FillTimetableArrivalDepartur
 
 */
 
static void ChangeTimetableStartCallback(const Window *w, TimerGameCalendar::Date date, void *data)
 
{
 
	Command<CMD_SET_TIMETABLE_START>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, (VehicleID)w->window_number, reinterpret_cast<std::uintptr_t>(data) != 0, date);
 
}
 

	
 

	
 
struct TimetableWindow : Window {
 
	int sel_index;
 
	VehicleTimetableWidgets query_widget; ///< Which button was clicked to open the query text input?
 
	const Vehicle *vehicle;    ///< Vehicle monitored by the window.
 
	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.
 
	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.
 

	
 
	TimetableWindow(WindowDesc *desc, WindowNumber window_number) :
 
			Window(desc),
 
			sel_index(-1),
 
			vehicle(Vehicle::Get(window_number)),
 
			show_expected(true)
 
	{
 
		this->CreateNestedTree();
 
		this->vscroll = this->GetScrollbar(WID_VT_SCROLLBAR);
 
@@ -186,28 +184,26 @@ struct TimetableWindow : Window {
 
		bool travelling = (!v->current_order.IsType(OT_LOADING) || v->current_order.GetNonStopType() == ONSF_STOP_EVERYWHERE);
 
		Ticks start_time = TimerGameCalendar::date_fract - v->current_order_time;
 

	
 
		FillTimetableArrivalDepartureTable(v, v->cur_real_order_index % v->GetNumOrders(), travelling, table, start_time);
 

	
 
		return (travelling && v->lateness_counter < 0);
 
	}
 

	
 
	void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
 
	{
 
		switch (widget) {
 
			case WID_VT_ARRIVAL_DEPARTURE_PANEL:
 
				SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR, 0, FS_SMALL);
 
				this->deparr_time_width = GetStringBoundingBox(STR_JUST_DATE_TINY).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;
 
				SetDParamMaxValue(1, MAX_YEAR * DAYS_IN_YEAR, 0, FS_SMALL);
 
				size->width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE).width) + WidgetDimensions::scaled.hsep_wide + padding.width;
 
				FALLTHROUGH;
 

	
 
			case WID_VT_ARRIVAL_DEPARTURE_SELECTION:
 
			case WID_VT_TIMETABLE_PANEL:
 
				resize->height = FONT_HEIGHT_NORMAL;
 
				size->height = 8 * resize->height + padding.height;
 
				break;
 

	
 
			case WID_VT_SUMMARY_PANEL:
 
				size->height = 2 * FONT_HEIGHT_NORMAL + padding.height;
 
				break;
 
		}
 
@@ -433,62 +429,53 @@ struct TimetableWindow : Window {
 
		if (total_time <= 0 || v->GetNumOrders() <= 1 || !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return;
 

	
 
		std::vector<TimetableArrivalDeparture> arr_dep(v->GetNumOrders());
 
		const VehicleOrderID cur_order = v->cur_real_order_index % v->GetNumOrders();
 

	
 
		VehicleOrderID earlyID = BuildArrivalDepartureList(v, arr_dep) ? cur_order : (VehicleOrderID)INVALID_VEH_ORDER_ID;
 
		int selected = this->sel_index;
 

	
 
		Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
 
		bool show_late = this->show_expected && v->lateness_counter > DAY_TICKS;
 
		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
 
			/* Don't draw anything if it extends past the end of the window. */
 
			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) {
 
				/* Draw an arrival time. */
 
				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. */
 
					Ticks this_offset;
 
					TextColour colour;
 
					if (this->show_expected && i / 2 == earlyID) {
 
						/* Show expected arrival. */
 
						this_offset = 0;
 
						colour = TC_GREEN;
 
						SetDParam(0, TC_GREEN);
 
					} else {
 
						/* Show scheduled arrival. */
 
						this_offset = offset;
 
						colour = show_late ? TC_RED : (i == selected ? TC_WHITE : TC_BLACK);
 
					}
 

	
 
					/* Now actually draw the arrival time. */
 
					SetDParam(0, TimerGameCalendar::date + (arr_dep[i / 2].arrival + this_offset) / DAY_TICKS);
 
					DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY, colour);
 
					SetDParam(1, TimerGameCalendar::date + (arr_dep[i / 2].arrival + this_offset) / DAY_TICKS);
 
					DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_ARRIVAL, i == selected ? TC_WHITE : TC_BLACK);
 
				}
 
			} else {
 
				/* Draw a departure time. */
 
				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);
 
					TextColour colour = show_late ? TC_RED : (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);
 
					SetDParam(1, TimerGameCalendar::date + (arr_dep[i / 2].departure + offset) / DAY_TICKS);
 
					DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_DEPARTURE, i == selected ? TC_WHITE : TC_BLACK);
 
				}
 
			}
 
			tr.top += FONT_HEIGHT_NORMAL;
 
		}
 
	}
 

	
 
	/**
 
	 * Helper function to draw the summary panel.
 
	 * @param r The rect to draw within.
 
	 */
 
	void DrawSummaryPanel(const Rect &r) const
 
	{
0 comments (0 inline, 0 general)