Keep the crew when a vehicle is swapped in the depot

The crew was copied to the card but not to the new cars, which are what is
shown and exported, so a swapped locomotive came out unstaffed. Swapping now
moves the crew over and otherwise staffs the vehicle as adding would.
This commit is contained in:
maj00r
2026-10-04 13:31:53 +02:00
parent 76f104798c
commit 04f6a4cc8d
3 changed files with 160 additions and 26 deletions

View File

@@ -573,10 +573,9 @@ public partial class Depot : UserControl
{
Cars = unit.Select(NewVehicle).ToList(),
Grouped = unit.Count > 1,
Driver = _consist.Selected.Driver,
Flipped = _consist.Selected.Flipped
};
_consist[i] = item;
_consist.Replace(i, item);
_consist.Selected = item;
_consist.AutoConnectAll();
RebuildConsist();
@@ -607,36 +606,13 @@ public partial class Depot : UserControl
};
at = Math.Clamp(at, 0, _consist.Count);
MatchOccupancy(item, at);
_consist.Staff(item, at);
_consist.Insert(at, item);
_consist.Selected = item;
_consist.AutoConnectAll();
RebuildConsist();
}
private void MatchOccupancy(ConsistItem item, int position)
{
item.Driver = eDriverType.Nobody;
var lead = item.Cars.FirstOrDefault();
if (lead is null) return;
foreach (var car in item.Cars)
car.DriverType = eDriverType.Nobody;
var tex = _db.TextureForSkin(lead.SkinFile);
string? cat = tex != null ? VehicleInfo.CategoryOf(tex) : null;
if (!VehicleInfo.IsPoweredCategory(cat))
return;
bool staffed = _consist.Any(i =>
i.Driver is eDriverType.Headdriver or eDriverType.Reardriver);
if (position == 0 || !staffed)
{
item.Driver = eDriverType.Headdriver;
lead.DriverType = eDriverType.Headdriver;
}
}
private async void TextureBaseButton_OnClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
if (TopLevel.GetTopLevel(this) is not Window owner) return;