Changeset - r10630:c2fe714742fe
[Not reviewed]
master
0 3 0
frosch - 15 years ago 2009-01-08 21:16:19
frosch@openttd.org
(svn r14925) -Fix [FS#2500]: Abort dragging of vehicles in the group window when they are deleted.
3 files changed with 32 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/group_gui.cpp
Show inline comments
 
@@ -694,6 +694,16 @@ public:
 
		this->vehicle_sel = INVALID_VEHICLE;
 
		this->InvalidateWidget(GRP_WIDGET_LIST_VEHICLE);
 
	}
 

	
 
	/**
 
	 * Tests whether a given vehicle is selected in the window, and unselects it if necessary.
 
	 * Called when the vehicle is deleted.
 
	 * @param vehicle Vehicle that is going to be deleted
 
	 */
 
	void UnselectVehicle(VehicleID vehicle)
 
	{
 
		if (this->vehicle_sel == vehicle) ResetObjectToPlace();
 
	}
 
};
 

	
 

	
 
@@ -712,3 +722,22 @@ void ShowCompanyGroup(CompanyID company,
 
	WindowNumber num = (vehicle_type << 11) | VLW_GROUP_LIST | company;
 
	AllocateWindowDescFront<VehicleGroupWindow>(&_group_desc, num);
 
}
 

	
 
/**
 
 * Removes the highlight of a vehicle in a group window
 
 * @param *v Vehicle to remove all highlights from
 
 */
 
void DeleteGroupHighlightOfVehicle(const Vehicle *v)
 
{
 
	VehicleGroupWindow *w;
 

	
 
	/* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any group windows either
 
	 * If that is the case, we can skip looping though the windows and save time
 
	 */
 
	if (_special_mouse_mode != WSM_DRAGDROP) return;
 

	
 
	VehicleType vehicle_type = v->type;
 
	w = dynamic_cast<VehicleGroupWindow *>(FindWindowById(GetWindowClassForVehicleType(vehicle_type), (vehicle_type << 11) | VLW_GROUP_LIST | v->owner));
 
	if (w != NULL) w->UnselectVehicle(v->index);
 
}
 

	
src/group_gui.h
Show inline comments
 
@@ -8,5 +8,6 @@
 
#include "vehicle_type.h"
 

	
 
void ShowCompanyGroup(CompanyID company, VehicleType veh);
 
void DeleteGroupHighlightOfVehicle(const Vehicle *v);
 

	
 
#endif /* GROUP_GUI_H */
src/vehicle.cpp
Show inline comments
 
@@ -32,6 +32,7 @@
 
#include "newgrf_station.h"
 
#include "newgrf_text.h"
 
#include "group.h"
 
#include "group_gui.h"
 
#include "order_func.h"
 
#include "strings_func.h"
 
#include "zoom_func.h"
 
@@ -571,6 +572,7 @@ void Vehicle::PreDestructor()
 
		GetCompany(this->owner)->num_engines[this->engine_type]--;
 
		if (this->owner == _local_company) InvalidateAutoreplaceWindow(this->engine_type, this->group_id);
 

	
 
		DeleteGroupHighlightOfVehicle(this);
 
		if (IsValidGroupID(this->group_id)) GetGroup(this->group_id)->num_engines[this->engine_type]--;
 
		if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id);
 
	}
0 comments (0 inline, 0 general)