mirror of https://github.com/OpenTTD/OpenTTD
(svn r19714) -Feature: ctrl+click on a vehicle to start/stop it
parent
82136fbc62
commit
e3c89df398
|
@ -140,5 +140,6 @@ CommandCallback CcFoundRandomTown;
|
||||||
|
|
||||||
/* vehicle_gui.cpp */
|
/* vehicle_gui.cpp */
|
||||||
CommandCallback CcBuildPrimaryVehicle;
|
CommandCallback CcBuildPrimaryVehicle;
|
||||||
|
CommandCallback CcStartStopVehicle;
|
||||||
|
|
||||||
#endif /* COMMAND_FUNC_H */
|
#endif /* COMMAND_FUNC_H */
|
||||||
|
|
|
@ -509,7 +509,7 @@ struct DepotWindow : Window {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_START_STOP: // click start/stop flag
|
case MODE_START_STOP: // click start/stop flag
|
||||||
StartStopVehicle(v);
|
StartStopVehicle(v, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
|
|
@ -2967,6 +2967,12 @@ STR_VEHICLE_STATUS_HEADING_FOR_SHIP_DEPOT_SERVICE_VEL :{LTBLUE}Service
|
||||||
STR_VEHICLE_STATUS_HEADING_FOR_HANGAR_SERVICE :{LTBLUE}Service at {STATION} Hangar
|
STR_VEHICLE_STATUS_HEADING_FOR_HANGAR_SERVICE :{LTBLUE}Service at {STATION} Hangar
|
||||||
STR_VEHICLE_STATUS_HEADING_FOR_HANGAR_SERVICE_VEL :{LTBLUE}Service at {STATION} Hangar, {VELOCITY}
|
STR_VEHICLE_STATUS_HEADING_FOR_HANGAR_SERVICE_VEL :{LTBLUE}Service at {STATION} Hangar, {VELOCITY}
|
||||||
|
|
||||||
|
# Vehicle stopped/started animations
|
||||||
|
STR_VEHICLE_COMMAND_STOPPED_SMALL :{TINYFONT}{RED}Stopped
|
||||||
|
STR_VEHICLE_COMMAND_STOPPED :{RED}Stopped
|
||||||
|
STR_VEHICLE_COMMAND_STARTED_SMALL :{TINYFONT}{GREEN}Started
|
||||||
|
STR_VEHICLE_COMMAND_STARTED :{GREEN}Started
|
||||||
|
|
||||||
# Vehicle details
|
# Vehicle details
|
||||||
STR_VEHICLE_DETAILS_CAPTION :{WHITE}{VEHICLE} (Details)
|
STR_VEHICLE_DETAILS_CAPTION :{WHITE}{VEHICLE} (Details)
|
||||||
STR_VEHICLE_NAME_BUTTON :{BLACK}Name
|
STR_VEHICLE_NAME_BUTTON :{BLACK}Name
|
||||||
|
|
|
@ -49,6 +49,7 @@ static CommandCallback * const _callback_table[] = {
|
||||||
/* 0x16 */ CcFoundRandomTown,
|
/* 0x16 */ CcFoundRandomTown,
|
||||||
/* 0x17 */ CcRoadStop,
|
/* 0x17 */ CcRoadStop,
|
||||||
/* 0x18 */ CcBuildIndustry,
|
/* 0x18 */ CcBuildIndustry,
|
||||||
|
/* 0x19 */ CcStartStopVehicle,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Local queue of packets */
|
/** Local queue of packets */
|
||||||
|
|
|
@ -64,7 +64,7 @@ const uint32 _send_to_depot_proc_table[] = {
|
||||||
/** Start/Stop a vehicle
|
/** Start/Stop a vehicle
|
||||||
* @param tile unused
|
* @param tile unused
|
||||||
* @param flags type of operation
|
* @param flags type of operation
|
||||||
* @param p1 vehicle to start/stop
|
* @param p1 vehicle to start/stop, don't forget to change CcStartStopVehicle if you modify this!
|
||||||
* @param p2 bit 0: Shall the start/stop newgrf callback be evaluated (only valid with DC_AUTOREPLACE for network safety)
|
* @param p2 bit 0: Shall the start/stop newgrf callback be evaluated (only valid with DC_AUTOREPLACE for network safety)
|
||||||
* @param text unused
|
* @param text unused
|
||||||
* @return the cost of this operation or an error
|
* @return the cost of this operation or an error
|
||||||
|
|
|
@ -1868,14 +1868,34 @@ static const uint32 _vehicle_command_translation_table[][4] = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the Callback method after the cloning attempt of a vehicle
|
||||||
|
* @param result the result of the cloning command
|
||||||
|
* @param tile unused
|
||||||
|
* @param p1 vehicle ID
|
||||||
|
* @param p2 unused
|
||||||
|
*/
|
||||||
|
void CcStartStopVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
|
||||||
|
{
|
||||||
|
if (result.Failed()) return;
|
||||||
|
|
||||||
|
const Vehicle *v = Vehicle::GetIfValid(p1);
|
||||||
|
if (v == NULL || !v->IsPrimaryVehicle() || v->owner != _local_company) return;
|
||||||
|
|
||||||
|
StringID msg = (v->vehstatus & VS_STOPPED) ? STR_VEHICLE_COMMAND_STOPPED : STR_VEHICLE_COMMAND_STARTED;
|
||||||
|
Point pt = RemapCoords(v->x_pos, v->y_pos, v->z_pos);
|
||||||
|
AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes #CMD_START_STOP_VEHICLE for given vehicle.
|
* Executes #CMD_START_STOP_VEHICLE for given vehicle.
|
||||||
* @param v Vehicle to start/stop
|
* @param v Vehicle to start/stop
|
||||||
|
* @param texteffect Should a texteffect be shown?
|
||||||
*/
|
*/
|
||||||
void StartStopVehicle(const Vehicle *v)
|
void StartStopVehicle(const Vehicle *v, bool texteffect)
|
||||||
{
|
{
|
||||||
assert(v->IsPrimaryVehicle());
|
assert(v->IsPrimaryVehicle());
|
||||||
DoCommandP(v->tile, v->index, 0, _vehicle_command_translation_table[VCT_CMD_START_STOP][v->type]);
|
DoCommandP(v->tile, v->index, 0, _vehicle_command_translation_table[VCT_CMD_START_STOP][v->type], texteffect ? CcStartStopVehicle : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks whether the vehicle may be refitted at the moment.*/
|
/** Checks whether the vehicle may be refitted at the moment.*/
|
||||||
|
@ -2129,7 +2149,7 @@ public:
|
||||||
if (tile != INVALID_TILE) ScrollMainWindowToTile(tile);
|
if (tile != INVALID_TILE) ScrollMainWindowToTile(tile);
|
||||||
} else {
|
} else {
|
||||||
/* Start/Stop */
|
/* Start/Stop */
|
||||||
StartStopVehicle(v);
|
StartStopVehicle(v, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VVW_WIDGET_CENTER_MAIN_VIEH: {// center main view
|
case VVW_WIDGET_CENTER_MAIN_VIEH: {// center main view
|
||||||
|
|
|
@ -108,7 +108,7 @@ static inline WindowClass GetWindowClassForVehicleType(VehicleType vt)
|
||||||
|
|
||||||
/* Unified window procedure */
|
/* Unified window procedure */
|
||||||
void ShowVehicleViewWindow(const Vehicle *v);
|
void ShowVehicleViewWindow(const Vehicle *v);
|
||||||
void StartStopVehicle(const Vehicle *v);
|
void StartStopVehicle(const Vehicle *v, bool texteffect);
|
||||||
|
|
||||||
Vehicle *CheckClickOnVehicle(const struct ViewPort *vp, int x, int y);
|
Vehicle *CheckClickOnVehicle(const struct ViewPort *vp, int x, int y);
|
||||||
|
|
||||||
|
|
|
@ -1811,7 +1811,14 @@ 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);
|
||||||
if (IsCompanyBuildableVehicleType(v)) ShowVehicleViewWindow(v->First());
|
if (IsCompanyBuildableVehicleType(v)) {
|
||||||
|
v = v->First();
|
||||||
|
if (_ctrl_pressed && v->owner == _local_company) {
|
||||||
|
StartStopVehicle(v, true);
|
||||||
|
} else {
|
||||||
|
ShowVehicleViewWindow(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return CheckClickOnLandscape(vp, x, y);
|
return CheckClickOnLandscape(vp, x, y);
|
||||||
|
|
Loading…
Reference in New Issue