diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 94a505fab2..70c01c273d 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2540,12 +2540,30 @@ void DirtyVehicleListWindowForVehicle(const Vehicle *v) FOR_ALL_WINDOWS_FROM_BACK(w) { if (w->window_class == cls || w->window_class == cls2) { BaseVehicleListWindow *listwin = static_cast(w); - uint max = std::min(listwin->vscroll->GetPosition() + listwin->vscroll->GetCapacity(), (uint)listwin->vehicles.size()); - for (uint i = listwin->vscroll->GetPosition(); i < max; ++i) { - if (v == listwin->vehicles[i]) { - listwin->SetWidgetDirty(0); + uint max = std::min(listwin->vscroll->GetPosition() + listwin->vscroll->GetCapacity(), (uint)listwin->vehgroups.size()); + switch (listwin->grouping) { + case BaseVehicleListWindow::GB_NONE: + for (uint i = listwin->vscroll->GetPosition(); i < max; ++i) { + if (v == listwin->vehgroups[i].vehicles_begin[0]) { + listwin->SetWidgetDirty(0); + break; + } + } + break; + + case BaseVehicleListWindow::GB_SHARED_ORDERS: { + const Vehicle *v_first_shared = v->FirstShared(); + for (uint i = listwin->vscroll->GetPosition(); i < max; ++i) { + if (v_first_shared == listwin->vehgroups[i].vehicles_begin[0]->FirstShared()) { + listwin->SetWidgetDirty(0); + break; + } + } break; } + + default: + NOT_REACHED(); } } } diff --git a/src/vehicle_gui_base.h b/src/vehicle_gui_base.h index b370276c8d..b2bb11e3f2 100644 --- a/src/vehicle_gui_base.h +++ b/src/vehicle_gui_base.h @@ -54,7 +54,9 @@ struct BaseVehicleListWindow : public Window { }; GroupBy grouping; ///< How we want to group the list. +protected: VehicleList vehicles; ///< List of vehicles. This is the buffer for `vehgroups` to point into; if this is structurally modified, `vehgroups` must be rebuilt. +public: uint own_vehicles = 0; ///< Count of vehicles of the local company CompanyID own_company; ///< Company ID used for own_vehicles GUIVehicleGroupList vehgroups; ///< List of (groups of) vehicles. This stores iterators of `vehicles`, and should be rebuilt if `vehicles` is structurally changed.