Initial support for multi-part (pseudo-articulated) ships

This commit is contained in:
Jonathan G Rennison
2023-03-14 00:16:31 +00:00
parent 5718730d68
commit 211fdd62b2
16 changed files with 216 additions and 58 deletions

View File

@@ -2823,9 +2823,9 @@ struct VehicleDetailsWindow : Window {
}
if (!gui_scope) return;
const Vehicle *v = Vehicle::Get(this->window_number);
if (v->type == VEH_ROAD) {
if (v->type == VEH_ROAD || v->type == VEH_SHIP) {
const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(WID_VD_MIDDLE_DETAILS);
uint aimed_height = this->GetRoadVehDetailsHeight(v);
uint aimed_height = this->GetRoadOrShipVehDetailsHeight(v);
/* If the number of articulated parts changes, the size of the window must change too. */
if (aimed_height != nwid_info->current_y) {
this->ReInit();
@@ -2839,16 +2839,17 @@ struct VehicleDetailsWindow : Window {
}
/**
* Gets the desired height for the road vehicle details panel.
* Gets the desired height for the road vehicle and ship details panel.
* @param v Road vehicle being shown.
* @return Desired height in pixels.
*/
uint GetRoadVehDetailsHeight(const Vehicle *v)
uint GetRoadOrShipVehDetailsHeight(const Vehicle *v)
{
uint desired_height;
if (v->HasArticulatedPart()) {
if (v->Next() != nullptr) {
/* An articulated RV has its text drawn under the sprite instead of after it, hence 15 pixels extra. */
desired_height = ScaleGUITrad(15) + 4 * FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal * 2;
desired_height = 4 * FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal * 2;
if (v->type == VEH_ROAD) desired_height += ScaleGUITrad(15);
/* Add space for the cargo amount for each part. */
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
if (u->cargo_cap != 0) desired_height += FONT_HEIGHT_NORMAL;
@@ -2948,11 +2949,8 @@ struct VehicleDetailsWindow : Window {
const Vehicle *v = Vehicle::Get(this->window_number);
switch (v->type) {
case VEH_ROAD:
size->height = this->GetRoadVehDetailsHeight(v) + padding.height;
break;
case VEH_SHIP:
size->height = 5 * FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal * 2 + padding.height;
size->height = this->GetRoadOrShipVehDetailsHeight(v) + padding.height;
break;
case VEH_AIRCRAFT:
@@ -3489,7 +3487,7 @@ static bool IsVehicleRefitable(const Vehicle *v)
do {
if (IsEngineRefittable(v->engine_type)) return true;
} while (v->IsGroundVehicle() && (v = v->Next()) != nullptr);
} while (v->IsArticulatedCallbackVehicleType() && (v = v->Next()) != nullptr);
return false;
}