(svn r14884) -Codechange: simplify code responsible for opening vehicle view windows

This commit is contained in:
smatz 2009-01-07 02:03:07 +00:00
parent 828675bf0e
commit 1ada1a4ff2

View File

@ -1994,30 +1994,6 @@ static bool CheckClickOnLandscape(const ViewPort *vp, int x, int y)
} }
static void SafeShowTrainViewWindow(const Vehicle* v)
{
if (!IsFrontEngine(v)) v = v->First();
ShowVehicleViewWindow(v);
}
static void SafeShowRoadVehViewWindow(const Vehicle *v)
{
if (!IsRoadVehFront(v)) v = v->First();
ShowVehicleViewWindow(v);
}
static void Nop(const Vehicle *v) {}
typedef void OnVehicleClickProc(const Vehicle *v);
static OnVehicleClickProc* const _on_vehicle_click_proc[] = {
SafeShowTrainViewWindow,
SafeShowRoadVehViewWindow,
ShowVehicleViewWindow,
ShowVehicleViewWindow,
Nop, // Special vehicles
Nop // Disaster vehicles
};
bool HandleViewportClicked(const ViewPort *vp, int x, int y) bool HandleViewportClicked(const ViewPort *vp, int x, int y)
{ {
const Vehicle *v; const Vehicle *v;
@ -2031,7 +2007,7 @@ bool HandleViewportClicked(const ViewPort *vp, int x, int y)
v = CheckClickOnVehicle(vp, x, y); v = CheckClickOnVehicle(vp, x, y);
if (v != NULL) { if (v != NULL) {
DEBUG(misc, 2, "Vehicle %d (index %d) at %p", v->unitnumber, v->index, v); DEBUG(misc, 2, "Vehicle %d (index %d) at %p", v->unitnumber, v->index, v);
_on_vehicle_click_proc[v->type](v); if (IsCompanyBuildableVehicleType(v)) ShowVehicleViewWindow(v->First());
return true; return true;
} }
return CheckClickOnLandscape(vp, x, y); return CheckClickOnLandscape(vp, x, y);