Ensure that timetable and scheduled dispatch windows redrawn as required

Reduce inefficient window and shared order list iteration
This commit is contained in:
Jonathan G Rennison
2022-01-15 00:21:31 +00:00
parent fe522f193b
commit 543433218c
10 changed files with 67 additions and 45 deletions

View File

@@ -289,9 +289,8 @@ void ProcessTimetableWarnings(const Vehicle *v, std::function<void(StringID, boo
}
struct TimetableWindow : Window {
struct TimetableWindow : GeneralVehicleWindow {
int sel_index;
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
@@ -307,9 +306,8 @@ struct TimetableWindow : Window {
};
TimetableWindow(WindowDesc *desc, WindowNumber window_number) :
Window(desc),
GeneralVehicleWindow(desc, Vehicle::Get(window_number)),
sel_index(-1),
vehicle(Vehicle::Get(window_number)),
show_expected(true)
{
this->CreateNestedTree();
@@ -1197,3 +1195,13 @@ void ShowTimetableWindow(const Vehicle *v)
DeleteWindowById(WC_VEHICLE_ORDERS, v->index, false);
AllocateWindowDescFront<TimetableWindow>(&_timetable_desc, v->index);
}
void SetTimetableWindowsDirty(const Vehicle *v, bool include_scheduled_dispatch)
{
v = v->FirstShared();
for (Window *w : Window::IterateFromBack()) {
if (w->window_class == WC_VEHICLE_TIMETABLE || (include_scheduled_dispatch && w->window_class == WC_SCHDISPATCH_SLOTS)) {
if (static_cast<GeneralVehicleWindow *>(w)->vehicle->FirstShared() == v) w->SetDirty();
}
}
}