changeset 12892:2245b86757b7 draft

(svn r17384) -Fix [FS#2859]: remove all order window state changes out of the drawing routine and call them immediately when changes happen instead of on the next OnPaint. This prevents pressing buttons when they should've been already disabled.
author rubidium <rubidium@openttd.org>
date Wed, 02 Sep 2009 17:54:40 +0000
parents 427288b91ab5
children 334cc3380d11
files src/order_cmd.cpp src/order_gui.cpp
diffstat 2 files changed, 37 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -791,7 +791,7 @@
 
 		if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
 
-		InvalidateVehicleOrder(v, 0);
+		InvalidateVehicleOrder(v, -2);
 	}
 
 	/* We have an aircraft/ship, they have a mini-schedule, so update them all */
@@ -1097,7 +1097,7 @@
 					u->current_order.GetLoadType() != order->GetLoadType()) {
 				u->current_order.SetLoadType(order->GetLoadType());
 			}
-			InvalidateVehicleOrder(u, 0);
+			InvalidateVehicleOrder(u, -2);
 		}
 	}
 
@@ -1158,7 +1158,7 @@
 				dst->AddToShared(src);
 
 				InvalidateVehicleOrder(dst, -1);
-				InvalidateVehicleOrder(src, 0);
+				InvalidateVehicleOrder(src, -2);
 
 				InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
 			}
@@ -1252,7 +1252,7 @@
 
 		for (Vehicle *u = v->FirstShared(); u != NULL; u = u->NextShared()) {
 			/* Update any possible open window of the vehicle */
-			InvalidateVehicleOrder(u, 0);
+			InvalidateVehicleOrder(u, -2);
 
 			/* If the vehicle already got the current depot set as current order, then update current order as well */
 			if (u->cur_order_index == order_number && (u->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) {
@@ -1795,7 +1795,7 @@
 	/* Otherwise set it, and determine the destination tile. */
 	v->current_order = *order;
 
-	InvalidateVehicleOrder(v, 0);
+	InvalidateVehicleOrder(v, -2);
 	switch (v->type) {
 		default:
 			NOT_REACHED();
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -661,6 +661,8 @@
 			this->HideWidget(ORDER_WIDGET_TIMETABLE_VIEW);
 		}
 		this->FindWindowPlacementAndResize(desc);
+
+		this->OnInvalidateData(-2);
 	}
 
 	virtual void OnInvalidateData(int data)
@@ -680,6 +682,10 @@
 				this->selected_order = -1;
 				break;
 
+			case -2:
+				/* Some other order changes */
+				break;
+
 			default: {
 				/* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
 				 * the order is being created / removed */
@@ -711,14 +717,14 @@
 				this->selected_order = to;
 			} break;
 		}
+
+		this->vscroll.SetCount(this->vehicle->GetNumOrders() + 1);
+		this->UpdateButtonState();
 	}
 
-	virtual void OnPaint()
+	void UpdateButtonState()
 	{
 		bool shared_orders = this->vehicle->IsOrderListShared();
-
-		this->vscroll.SetCount(this->vehicle->GetNumOrders() + 1);
-
 		int sel = OrderGetSel();
 		const Order *order = this->vehicle->GetOrder(sel);
 
@@ -808,10 +814,6 @@
 					OrderConditionVariable ocv = order->GetConditionVariable();
 					this->SetWidgetDisabledState(ORDER_WIDGET_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
 					this->SetWidgetDisabledState(ORDER_WIDGET_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
-
-					uint value = order->GetConditionValue();
-					if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
-					SetDParam(1, value);
 				} break;
 
 				default: // every other orders
@@ -821,10 +823,31 @@
 					this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
 					this->DisableWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
 					this->DisableWidget(ORDER_WIDGET_UNLOAD);
+					break;
 			}
 		}
 
+		this->SetDirty();
+	}
+
+	virtual void OnPaint()
+	{
+		bool shared_orders = this->vehicle->IsOrderListShared();
+		int sel = OrderGetSel();
+		const Order *order = this->vehicle->GetOrder(sel);
+
+		if (this->vehicle->owner == _local_company) {
+			/* Set the strings for the dropdown boxes. */
+			this->widget[ORDER_WIDGET_COND_VARIABLE].data   = _order_conditional_variable[order == NULL ? 0 : order->GetConditionVariable()];
+			this->widget[ORDER_WIDGET_COND_COMPARATOR].data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
+		}
+
 		SetDParam(0, this->vehicle->index);
+		if (order != NULL && order->IsType(OT_CONDITIONAL)) {
+			uint value = order->GetConditionValue();
+			if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
+			SetDParam(1, value);
+		}
 		this->DrawWidgets();
 
 		int y = 15;
@@ -907,7 +930,7 @@
 					}
 				}
 
-				this->SetDirty();
+				this->UpdateButtonState();
 			} break;
 
 			case ORDER_WIDGET_SKIP: