Changeset - r15078:76a51dd49982
[Not reviewed]
master
0 8 0
smatz - 15 years ago 2010-04-24 20:55:51
smatz@openttd.org
(svn r19714) -Feature: ctrl+click on a vehicle to start/stop it
8 files changed with 42 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/command_func.h
Show inline comments
 
@@ -137,8 +137,9 @@ CommandCallback CcBuildWagon;
 
/* town_gui.cpp */
 
CommandCallback CcFoundTown;
 
CommandCallback CcFoundRandomTown;
 

	
 
/* vehicle_gui.cpp */
 
CommandCallback CcBuildPrimaryVehicle;
 
CommandCallback CcStartStopVehicle;
 

	
 
#endif /* COMMAND_FUNC_H */
src/depot_gui.cpp
Show inline comments
 
@@ -506,13 +506,13 @@ struct DepotWindow : Window {
 

	
 
			case MODE_SHOW_VEHICLE: // show info window
 
				ShowVehicleViewWindow(v);
 
				break;
 

	
 
			case MODE_START_STOP: // click start/stop flag
 
				StartStopVehicle(v);
 
				StartStopVehicle(v, false);
 
				break;
 

	
 
			default: NOT_REACHED();
 
		}
 
	}
 

	
src/lang/english.txt
Show inline comments
 
@@ -2964,12 +2964,18 @@ STR_VEHICLE_STATUS_HEADING_FOR_ROAD_VEHI
 
STR_VEHICLE_STATUS_HEADING_FOR_ROAD_VEHICLE_DEPOT_SERVICE_VEL   :{LTBLUE}Service at {TOWN} Road Depot, {VELOCITY}
 
STR_VEHICLE_STATUS_HEADING_FOR_SHIP_DEPOT_SERVICE               :{LTBLUE}Service at {TOWN} Ship Depot
 
STR_VEHICLE_STATUS_HEADING_FOR_SHIP_DEPOT_SERVICE_VEL           :{LTBLUE}Service at {TOWN} Ship Depot, {VELOCITY}
 
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}
 

	
 
# 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
 
STR_VEHICLE_DETAILS_CAPTION                                     :{WHITE}{VEHICLE} (Details)
 
STR_VEHICLE_NAME_BUTTON                                         :{BLACK}Name
 

	
 
STR_VEHICLE_DETAILS_TRAIN_RENAME                                :{BLACK}Name train
 
STR_VEHICLE_DETAILS_ROAD_VEHICLE_RENAME                         :{BLACK}Name road vehicle
src/network/network_command.cpp
Show inline comments
 
@@ -46,12 +46,13 @@ static CommandCallback * const _callback
 
	/* 0x13 */ CcCloneVehicle,
 
	/* 0x14 */ CcGiveMoney,
 
	/* 0x15 */ CcCreateGroup,
 
	/* 0x16 */ CcFoundRandomTown,
 
	/* 0x17 */ CcRoadStop,
 
	/* 0x18 */ CcBuildIndustry,
 
	/* 0x19 */ CcStartStopVehicle,
 
};
 

	
 
/** Local queue of packets */
 
static CommandPacket *_local_command_queue = NULL;
 

	
 
/**
src/vehicle_cmd.cpp
Show inline comments
 
@@ -61,13 +61,13 @@ const uint32 _send_to_depot_proc_table[]
 
	CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_MSG(STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR),
 
};
 

	
 
/** Start/Stop a vehicle
 
 * @param tile unused
 
 * @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 text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
src/vehicle_gui.cpp
Show inline comments
 
@@ -1866,19 +1866,39 @@ static const uint32 _vehicle_command_tra
 
		0xffffffff, // invalid for ships
 
		0xffffffff  // invalid for aircrafts
 
	},
 
};
 

	
 
/**
 
 * 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.
 
 * @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());
 
	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.*/
 
static bool IsVehicleRefitable(const Vehicle *v)
 
{
 
	if (!v->IsStoppedInDepot()) return false;
 
@@ -2126,13 +2146,13 @@ public:
 
				if (_ctrl_pressed) {
 
					/* Scroll to current order destination */
 
					TileIndex tile = v->current_order.GetLocation(v);
 
					if (tile != INVALID_TILE) ScrollMainWindowToTile(tile);
 
				} else {
 
					/* Start/Stop */
 
					StartStopVehicle(v);
 
					StartStopVehicle(v, false);
 
				}
 
				break;
 
			case VVW_WIDGET_CENTER_MAIN_VIEH: {// center main view
 
				const Window *mainwindow = FindWindowById(WC_MAIN_WINDOW, 0);
 
				/* code to allow the main window to 'follow' the vehicle if the ctrl key is pressed */
 
				if (_ctrl_pressed && mainwindow->viewport->zoom == ZOOM_LVL_NORMAL) {
src/vehicle_gui.h
Show inline comments
 
@@ -105,11 +105,11 @@ static inline WindowClass GetWindowClass
 
		case VEH_AIRCRAFT: return WC_AIRCRAFT_LIST;
 
	}
 
}
 

	
 
/* Unified window procedure */
 
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);
 

	
 
#endif /* VEHICLE_GUI_H */
src/viewport.cpp
Show inline comments
 
@@ -1808,13 +1808,20 @@ bool HandleViewportClicked(const ViewPor
 
	if (CheckClickOnSign(vp, x, y)) return true;
 
	CheckClickOnLandscape(vp, x, y);
 

	
 
	v = CheckClickOnVehicle(vp, x, y);
 
	if (v != NULL) {
 
		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 CheckClickOnLandscape(vp, x, y);
 
}
 

	
 
Vehicle *CheckMouseOverVehicle()
0 comments (0 inline, 0 general)