summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/order_cmd.cpp23
-rw-r--r--src/order_gui.cpp2
-rw-r--r--src/vehicle.cpp8
-rw-r--r--src/vehicle_gui.cpp9
-rw-r--r--src/vehiclelist.cpp12
5 files changed, 17 insertions, 37 deletions
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index ed759c79a..37ade0deb 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -596,25 +596,6 @@ static CommandCost DecloneOrder(Vehicle *dst, uint32 flags)
return CommandCost();
}
-/**
- * Remove the VehicleList that shows all the vehicles with the same shared
- * orders.
- */
-void RemoveSharedOrderVehicleList(Vehicle *v)
-{
- assert(v->orders != NULL);
- WindowClass window_class = WC_NONE;
-
- switch (v->type) {
- default: NOT_REACHED();
- case VEH_TRAIN: window_class = WC_TRAINS_LIST; break;
- case VEH_ROAD: window_class = WC_ROADVEH_LIST; break;
- case VEH_SHIP: window_class = WC_SHIPS_LIST; break;
- case VEH_AIRCRAFT: window_class = WC_AIRCRAFT_LIST; break;
- }
- DeleteWindowById(window_class, (v->orders->index << 16) | (v->type << 11) | VLW_SHARED_ORDERS | v->owner);
-}
-
/** Delete an order from the orderlist of a vehicle.
* @param tile unused
* @param flags operation to perform
@@ -650,10 +631,6 @@ CommandCost CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
order = GetVehicleOrder(v, sel_ord + 1);
SwapOrders(v->orders, order);
} else {
- /* XXX -- The system currently can't handle a shared-order vehicle list
- * open when there aren't any orders in the list, so close the window
- * in this case. Of course it needs a better fix later */
- RemoveSharedOrderVehicleList(v);
/* Last item, so clean the list */
v->orders = NULL;
}
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index 765efa1e7..9b840ffbf 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -654,7 +654,7 @@ public:
this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD, order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD_DROPDOWN, this->IsWidgetDisabled(ORDER_WIDGET_UNLOAD));
/* Disable list of vehicles with the same shared orders if there is no list */
- this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders || this->vehicle->orders == NULL);
+ this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders);
this->SetWidgetDisabledState(ORDER_WIDGET_REFIT, order == NULL); // Refit
this->SetWidgetDisabledState(ORDER_WIDGET_SERVICE, order == NULL); // Refit
this->HideWidget(ORDER_WIDGET_REFIT); // Refit
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index ae77872a9..80ddeb032 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -2614,11 +2614,15 @@ void Vehicle::RemoveFromShared()
if (this->next_shared != NULL) this->next_shared->previous_shared = this->previous_shared;
+ uint32 old_window_number = (this->FirstShared()->index << 16) | (this->type << 11) | VLW_SHARED_ORDERS | this->owner;
+
if (new_first->NextShared() == NULL) {
/* When there is only one vehicle, remove the shared order list window. */
- extern void RemoveSharedOrderVehicleList(Vehicle *v);
- if (new_first->orders != NULL) RemoveSharedOrderVehicleList(new_first);
+ DeleteWindowById(GetWindowClassForVehicleType(this->type), old_window_number);
InvalidateVehicleOrder(new_first);
+ } else if (this->FirstShared() == this) {
+ /* If we were the first one, update to the new first one. */
+ InvalidateWindowData(GetWindowClassForVehicleType(this->type), old_window_number, (new_first->index << 16) | (1 << 15));
}
this->first_shared = this;
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 076e626d3..84ff470b9 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1074,6 +1074,12 @@ struct VehicleListWindow : public Window, public VehicleListBase {
virtual void OnInvalidateData(int data)
{
+ if (HasBit(data, 15) && (this->window_number & VLW_MASK) == VLW_SHARED_ORDERS) {
+ SB(this->window_number, 16, 16, GB(data, 16, 16));
+ this->vehicles.ForceRebuild();
+ return;
+ }
+
if (data == 0) {
this->vehicles.ForceRebuild();
} else {
@@ -1163,8 +1169,7 @@ void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type)
void ShowVehicleListWindow(const Vehicle *v)
{
- if (v->orders == NULL) return; // no shared list to show
- ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->orders->index);
+ ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->FirstShared()->index);
}
void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, StationID station)
diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp
index 9f2d09c35..2341a31ad 100644
--- a/src/vehiclelist.cpp
+++ b/src/vehiclelist.cpp
@@ -93,15 +93,9 @@ void GenerateVehicleSortList(VehicleList *list, VehicleType type, PlayerID owner
break;
case VLW_SHARED_ORDERS:
- FOR_ALL_VEHICLES(v) {
- /* Find a vehicle with the order in question */
- if (v->orders != NULL && v->orders->index == index) {
- /* Add all vehicles from this vehicle's shared order list */
- for (v = v->FirstShared(); v != NULL; v = v->NextShared()) {
- *list->Append() = v;
- }
- break;
- }
+ /* Add all vehicles from this vehicle's shared order list */
+ for (v = GetVehicle(index); v != NULL; v = v->NextShared()) {
+ *list->Append() = v;
}
break;