Merge branch 'template_train_replacement-sx' into jgrpp
# Conflicts: # src/window.cpp
This commit is contained in:
@@ -3186,35 +3186,74 @@ void CcBuildPrimaryVehicle(const CommandCost &result, TileIndex tile, uint32 p1,
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of a vehicle (including all parts of the consist) in pixels.
|
||||
* Get the width of a vehicle (part) in pixels.
|
||||
* @param v Vehicle to get the width for.
|
||||
* @return Width of the vehicle.
|
||||
*/
|
||||
int GetVehicleWidth(Vehicle *v, EngineImageType image_type)
|
||||
int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type)
|
||||
{
|
||||
int vehicle_width = 0;
|
||||
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN:
|
||||
for (const Train *u = Train::From(v); u != NULL; u = u->Next()) {
|
||||
vehicle_width += u->GetDisplayImageWidth();
|
||||
}
|
||||
break;
|
||||
return Train::From(v)->GetDisplayImageWidth();
|
||||
|
||||
case VEH_ROAD:
|
||||
for (const RoadVehicle *u = RoadVehicle::From(v); u != NULL; u = u->Next()) {
|
||||
vehicle_width += u->GetDisplayImageWidth();
|
||||
}
|
||||
break;
|
||||
return RoadVehicle::From(v)->GetDisplayImageWidth();
|
||||
|
||||
default:
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
SpriteID sprite = v->GetImage(rtl ? DIR_E : DIR_W, image_type);
|
||||
const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
|
||||
vehicle_width = UnScaleGUI(real_sprite->width);
|
||||
return UnScaleGUI(real_sprite->width);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
/**
|
||||
* Get the width of a vehicle (including all parts of the consist) in pixels.
|
||||
* @param v Vehicle to get the width for.
|
||||
* @return Width of the vehicle.
|
||||
*/
|
||||
int GetVehicleWidth(const Vehicle *v, EngineImageType image_type)
|
||||
{
|
||||
if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
|
||||
int vehicle_width = 0;
|
||||
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
|
||||
vehicle_width += GetSingleVehicleWidth(u, image_type);
|
||||
}
|
||||
return vehicle_width;
|
||||
} else {
|
||||
return GetSingleVehicleWidth(v, image_type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the mouse cursor to look like a vehicle.
|
||||
* @param v Vehicle
|
||||
* @param image_type Type of vehicle image to use.
|
||||
*/
|
||||
void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type)
|
||||
{
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
|
||||
_cursor.sprite_count = 0;
|
||||
int total_width = 0;
|
||||
for (; v != NULL; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : NULL) {
|
||||
if (_cursor.sprite_count == lengthof(_cursor.sprite_seq)) break;
|
||||
if (total_width >= 2 * (int)VEHICLEINFO_FULL_VEHICLE_WIDTH) break;
|
||||
|
||||
_cursor.sprite_seq[_cursor.sprite_count].sprite = v->GetImage(rtl ? DIR_E : DIR_W, image_type);
|
||||
_cursor.sprite_seq[_cursor.sprite_count].pal = GetVehiclePalette(v);
|
||||
_cursor.sprite_pos[_cursor.sprite_count].x = rtl ? -total_width : total_width;
|
||||
_cursor.sprite_pos[_cursor.sprite_count].y = 0;
|
||||
|
||||
total_width += GetSingleVehicleWidth(v, image_type);
|
||||
_cursor.sprite_count++;
|
||||
}
|
||||
|
||||
return vehicle_width;
|
||||
int offs = ((int)VEHICLEINFO_FULL_VEHICLE_WIDTH - total_width) / 2;
|
||||
if (rtl) offs = -offs;
|
||||
for (uint i = 0; i < _cursor.sprite_count; ++i) {
|
||||
_cursor.sprite_pos[i].x += offs;
|
||||
}
|
||||
|
||||
UpdateCursorSize();
|
||||
}
|
||||
|
Reference in New Issue
Block a user