Changeset - r19878:34102534d9f9
[Not reviewed]
master
0 7 0
michi_cc - 12 years ago 2012-12-20 19:44:02
michi_cc@openttd.org
(svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
7 files changed with 32 insertions and 24 deletions:
0 comments (0 inline, 0 general)
src/order_cmd.cpp
Show inline comments
 
@@ -912,13 +912,13 @@ void InsertOrder(Vehicle *v, Order *new_
 
 * @param flags execution flags
 
 */
 
static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlag flags)
 
{
 
	if (flags & DC_EXEC) {
 
		DeleteVehicleOrders(dst);
 
		InvalidateVehicleOrder(dst, -1);
 
		InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
 
		InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
 
	}
 
	return CommandCost();
 
}
 

	
 
/**
 
@@ -1051,13 +1051,13 @@ CommandCost CmdSkipToOrder(TileIndex til
 
	if (flags & DC_EXEC) {
 
		v->cur_implicit_order_index = v->cur_real_order_index = sel_ord;
 
		v->UpdateRealOrderIndex();
 

	
 
		if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
 

	
 
		InvalidateVehicleOrder(v, -2);
 
		InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS);
 
	}
 

	
 
	/* We have an aircraft/ship, they have a mini-schedule, so update them all */
 
	if (v->type == VEH_AIRCRAFT) SetWindowClassesDirty(WC_AIRCRAFT_LIST);
 
	if (v->type == VEH_SHIP) SetWindowClassesDirty(WC_SHIPS_LIST);
 

	
 
@@ -1390,13 +1390,13 @@ CommandCost CmdModifyOrder(TileIndex til
 
			 */
 
			if (sel_ord == u->cur_real_order_index &&
 
					(u->current_order.IsType(OT_GOTO_STATION) || u->current_order.IsType(OT_LOADING)) &&
 
					u->current_order.GetLoadType() != order->GetLoadType()) {
 
				u->current_order.SetLoadType(order->GetLoadType());
 
			}
 
			InvalidateVehicleOrder(u, -2);
 
			InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS);
 
		}
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
@@ -1500,14 +1500,14 @@ CommandCost CmdCloneOrder(TileIndex tile
 

	
 
				dst->orders.list = src->orders.list;
 

	
 
				/* Link this vehicle in the shared-list */
 
				dst->AddToShared(src);
 

	
 
				InvalidateVehicleOrder(dst, -1);
 
				InvalidateVehicleOrder(src, -2);
 
				InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
 
				InvalidateVehicleOrder(src, VIWD_MODIFY_ORDERS);
 

	
 
				InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
 
			}
 
			break;
 
		}
 

	
 
@@ -1563,13 +1563,13 @@ CommandCost CmdCloneOrder(TileIndex tile
 
					assert(!dst->orders.list->IsShared());
 
					delete dst->orders.list;
 
					assert(OrderList::CanAllocateItem());
 
					dst->orders.list = new OrderList(first, dst);
 
				}
 

	
 
				InvalidateVehicleOrder(dst, -1);
 
				InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
 

	
 
				InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
 
			}
 
			break;
 
		}
 

	
 
@@ -1621,13 +1621,13 @@ CommandCost CmdOrderRefit(TileIndex tile
 
			order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
 
			order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
 
		}
 

	
 
		for (Vehicle *u = v->FirstShared(); u != NULL; u = u->NextShared()) {
 
			/* Update any possible open window of the vehicle */
 
			InvalidateVehicleOrder(u, -2);
 
			InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS);
 

	
 
			/* If the vehicle already got the current depot set as current order, then update current order as well */
 
			if (u->cur_real_order_index == order_number && (u->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) {
 
				u->current_order.SetRefit(cargo, subtype);
 
			}
 
		}
 
@@ -2090,13 +2090,13 @@ bool ProcessOrders(Vehicle *v)
 
		return false;
 
	}
 

	
 
	/* Otherwise set it, and determine the destination tile. */
 
	v->current_order = *order;
 

	
 
	InvalidateVehicleOrder(v, -2);
 
	InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS);
 
	switch (v->type) {
 
		default:
 
			NOT_REACHED();
 

	
 
		case VEH_ROAD:
 
		case VEH_TRAIN:
src/order_gui.cpp
Show inline comments
 
@@ -817,13 +817,13 @@ public:
 
			FOR_VEHICLE_ORDERS(v, order) {
 
				if (order->IsType(OT_GOTO_STATION)) station_orders++;
 
			}
 

	
 
			if (station_orders < 2) this->OrderClick_Goto(0);
 
		}
 
		this->OnInvalidateData(-2);
 
		this->OnInvalidateData(VIWD_MODIFY_ORDERS);
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		switch (widget) {
 
			case WID_O_ORDER_LIST:
 
@@ -863,28 +863,28 @@ public:
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		VehicleOrderID from = INVALID_VEH_ORDER_ID;
 
		VehicleOrderID to   = INVALID_VEH_ORDER_ID;
 

	
 
		switch (data) {
 
			case -666:
 
			case VIWD_AUTOREPLACE:
 
				/* Autoreplace replaced the vehicle */
 
				this->vehicle = Vehicle::Get(this->window_number);
 
				this->UpdateAutoRefitState();
 
				break;
 

	
 
			case -1:
 
			case VIWD_REMOVE_ALL_ORDERS:
 
				/* Removed / replaced all orders (after deleting / sharing) */
 
				if (this->selected_order == -1) break;
 

	
 
				this->DeleteChildWindows();
 
				HideDropDownMenu(this);
 
				this->selected_order = -1;
 
				break;
 

	
 
			case -2:
 
			case VIWD_MODIFY_ORDERS:
 
				/* Some other order changes */
 
				break;
 

	
 
			default:
 
				if (data < 0) break;
 

	
src/settings.cpp
Show inline comments
 
@@ -957,13 +957,13 @@ static bool TownFoundingChanged(int32 p1
 
	InvalidateWindowData(WC_FOUND_TOWN, 0);
 
	return true;
 
}
 

	
 
static bool InvalidateVehTimetableWindow(int32 p1)
 
{
 
	InvalidateWindowClassesData(WC_VEHICLE_TIMETABLE, -2);
 
	InvalidateWindowClassesData(WC_VEHICLE_TIMETABLE, VIWD_MODIFY_ORDERS);
 
	return true;
 
}
 

	
 
static bool ZoomMinMaxChanged(int32 p1)
 
{
 
	extern void ConstrainAllViewportsZoom();
src/timetable_gui.cpp
Show inline comments
 
@@ -233,26 +233,26 @@ struct TimetableWindow : Window {
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		switch (data) {
 
			case -666:
 
			case VIWD_AUTOREPLACE:
 
				/* Autoreplace replaced the vehicle */
 
				this->vehicle = Vehicle::Get(this->window_number);
 
				break;
 

	
 
			case -1:
 
			case VIWD_REMOVE_ALL_ORDERS:
 
				/* Removed / replaced all orders (after deleting / sharing) */
 
				if (this->sel_index == -1) break;
 

	
 
				this->DeleteChildWindows();
 
				this->sel_index = -1;
 
				break;
 

	
 
			case -2:
 
			case VIWD_MODIFY_ORDERS:
 
				if (!gui_scope) break;
 
				this->UpdateSelectionStates();
 
				this->ReInit();
 
				break;
 

	
 
			default: {
src/train_cmd.cpp
Show inline comments
 
@@ -238,13 +238,13 @@ void Train::ConsistChanged(bool same_len
 
	/* recalculate cached weights and power too (we do this *after* the rest, so it is known which wagons are powered and need extra weight added) */
 
	this->CargoChanged();
 

	
 
	if (this->IsFrontEngine()) {
 
		this->UpdateAcceleration();
 
		SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
 
		InvalidateWindowData(WC_VEHICLE_REFIT, this->index);
 
		InvalidateWindowData(WC_VEHICLE_REFIT, this->index, VIWD_CONSIST_CHANGED);
 
	}
 
}
 

	
 
/**
 
 * Get the stop location of (the center) of the front vehicle of a train at
 
 * a platform of a station.
 
@@ -1073,13 +1073,13 @@ static void NormaliseTrainHead(Train *he
 
	UpdateTrainGroupID(head);
 

	
 
	/* Not a front engine, i.e. a free wagon chain. No need to do more. */
 
	if (!head->IsFrontEngine()) return;
 

	
 
	/* Update the refit button and window */
 
	InvalidateWindowData(WC_VEHICLE_REFIT, head->index);
 
	InvalidateWindowData(WC_VEHICLE_REFIT, head->index, VIWD_CONSIST_CHANGED);
 
	SetWindowWidgetDirty(WC_VEHICLE_VIEW, head->index, WID_VV_REFIT);
 

	
 
	/* If we don't have a unit number yet, set one. */
 
	if (head->unitnumber != 0) return;
 
	head->unitnumber = GetFreeUnitNumber(VEH_TRAIN);
 
}
src/vehicle_gui.cpp
Show inline comments
 
@@ -531,13 +531,13 @@ struct RefitWindow : public Window {
 

	
 
			this->SetWidgetDisabledState(WID_VR_REFIT, this->sel == -1);
 
			/* If the selected refit option was not found, scroll the window to the initial position. */
 
			if (this->sel == -1) this->vscroll->ScrollTowards(0);
 
		} else {
 
			/* Rebuild the refit list */
 
			this->OnInvalidateData(0);
 
			this->OnInvalidateData(VIWD_CONSIST_CHANGED);
 
		}
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		/* Determine amount of items for scroller. */
 
@@ -704,14 +704,14 @@ struct RefitWindow : public Window {
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		switch (data) {
 
			case -666: // Autoreplace replaced the vehicle; selected_vehicle became invalid.
 
			case 0: { // The consist has changed; rebuild the entire list.
 
			case VIWD_AUTOREPLACE: // Autoreplace replaced the vehicle; selected_vehicle became invalid.
 
			case VIWD_CONSIST_CHANGED: { // The consist has changed; rebuild the entire list.
 
				/* Clear the selection. */
 
				Vehicle *v = Vehicle::Get(this->window_number);
 
				this->selected_vehicle = v->index;
 
				this->num_vehicles = UINT8_MAX;
 
				/* FALL THROUGH */
 
			}
 
@@ -1124,13 +1124,13 @@ static inline void ChangeVehicleWindow(W
 
		/* Update vehicle drag data */
 
		if (_thd.window_class == window_class && _thd.window_number == (WindowNumber)from_index) {
 
			_thd.window_number = to_index;
 
		}
 

	
 
		/* Notify the window. */
 
		w->InvalidateData(-666, false);
 
		w->InvalidateData(VIWD_AUTOREPLACE, false);
 
	}
 
}
 

	
 
/**
 
 * Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows.
 
 * @param from_index the old vehicle ID
 
@@ -1757,13 +1757,13 @@ struct VehicleDetailsWindow : Window {
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		if (data == -666) {
 
		if (data == VIWD_AUTOREPLACE) {
 
			/* Autoreplace replaced the vehicle.
 
			 * Nothing to do for this window. */
 
			return;
 
		}
 
		if (!gui_scope) return;
 
		const Vehicle *v = Vehicle::Get(this->window_number);
 
@@ -2582,13 +2582,13 @@ public:
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		if (data == -666) {
 
		if (data == VIWD_AUTOREPLACE) {
 
			/* Autoreplace replaced the vehicle.
 
			 * Nothing to do for this window. */
 
			return;
 
		}
 
	}
 

	
src/vehicle_gui.h
Show inline comments
 
@@ -26,12 +26,20 @@ enum TrainDetailsWindowTabs {
 
	TDW_TAB_CARGO = 0, ///< Tab with cargo carried by the vehicles
 
	TDW_TAB_INFO,      ///< Tab with name and value of the vehicles
 
	TDW_TAB_CAPACITY,  ///< Tab with cargo capacity of the vehicles
 
	TDW_TAB_TOTALS,    ///< Tab with sum of total cargo transported
 
};
 

	
 
/** Special values for vehicle-related windows for the data parameter of #InvalidateWindowData. */
 
enum VehicleInvalidateWindowData {
 
	VIWD_REMOVE_ALL_ORDERS = -1, ///< Removed / replaced all orders (after deleting / sharing).
 
	VIWD_MODIFY_ORDERS     = -2, ///< Other order modifications.
 
	VIWD_CONSIST_CHANGED   = -3, ///< Vehicle composition was changed.
 
	VIWD_AUTOREPLACE       = -4, ///< Autoreplace replaced the vehicle.
 
};
 

	
 
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number);
 

	
 
void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest = INVALID_VEHICLE);
 
void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip = 0);
 
void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type);
 
void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type);
0 comments (0 inline, 0 general)