Depot: per-vehicle wagon number, model path, activation after removal

The number editor was pinned to the unit's first car, so every vehicle in a
multiple unit shared one number. Removing a vehicle only moved the highlight,
leaving the starting vehicle and the panels on the deleted one. Drops the tab
strip around the single configuration panel and shortens the consist row when
the thumbnails are small.
This commit is contained in:
maj00r
2026-09-04 23:04:09 +02:00
parent 88fa5a2978
commit c072898e4f
5 changed files with 41 additions and 13 deletions

View File

@@ -10,7 +10,7 @@
x:Class="StarterNG.Views.Depot">
<!-- TabIndex follows the workflow - pick a consist, browse, build the train,
then the editors - not the column order the grid happens to have. -->
<Grid Margin="0" ColumnSpacing="3" RowSpacing="3">
<Grid Name="depotGrid" Margin="0" ColumnSpacing="3" RowSpacing="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="270" MinWidth="220" />
<ColumnDefinition />
@@ -23,7 +23,7 @@
cap fits the seven lines of the texture tab. -->
<Grid.RowDefinitions>
<RowDefinition Height="*" MinHeight="150" />
<RowDefinition Height="1.57*" MinHeight="120" MaxHeight="207" />
<RowDefinition Height="1.57*" MinHeight="120" MaxHeight="240" />
<RowDefinition Height="Auto" MinHeight="140" MaxHeight="230" />
</Grid.RowDefinitions>
@@ -127,7 +127,8 @@
<!-- The configuration is the one panel here that is actually edited, so it
gets a column of its own spanning both rows - from the top edge down to
the consist - instead of a third of one squeezed row. -->
the consist. No tab strip: it was a single tab naming the only thing
the column could hold. -->
<Border Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" TabIndex="6"
Background="{StaticResource CarbonPanelBg}"
BorderBrush="{StaticResource CarbonBorderLight}"
@@ -138,13 +139,9 @@
HorizontalContentAlignment="Center"
Click="RemoveVehicleButton_OnClick"
Content="{Binding [RemoveVehicle], Source={x:Static starterNg:App.Loc}}" />
<TabControl>
<TabItem Header="{Binding [Configuration], Source={x:Static starterNg:App.Loc}}">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel Name="loadsPanel" Margin="4" Grid.IsSharedSizeScope="True" />
</ScrollViewer>
</TabItem>
</TabControl>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel Name="loadsPanel" Margin="4" Grid.IsSharedSizeScope="True" />
</ScrollViewer>
</DockPanel>
</Border>

View File

@@ -147,6 +147,19 @@ public partial class Depot : UserControl
private void VehicleListBox_OnPointerPressed(object? sender, PointerPressedEventArgs e) =>
_drag.VehicleListPressed(sender, e);
/// <summary>
/// Floor of the consist row with the small thumbnails, one thumbnail height
/// below the roomy one.
/// </summary>
private const double SmallConsistRowHeight = 106;
private const double LargeConsistRowHeight = 140;
private void SyncConsistRowHeight() =>
depotGrid.RowDefinitions[2].MinHeight = AppServices.Current.Settings.LargeThumbnails
? LargeConsistRowHeight
: SmallConsistRowHeight;
private Dynamic NewVehicle(VehicleTexture texture) =>
_consist.MakeDynamic(texture, _listScenery ?? AppServices.Current.State.CurrentScenery);
@@ -177,6 +190,7 @@ public partial class Depot : UserControl
private void RebuildConsist()
{
SyncConsistRowHeight();
consistStack.Children.Clear();
_cards.Forget();
_drag.Reset();
@@ -192,6 +206,13 @@ public partial class Depot : UserControl
}
emptyHint.IsVisible = _consist.Count == 0;
// A selection the consist moved on its own - after a removal, say - is only
// highlighted; activating it runs what a click would have run.
if (_consist.Selected is { } moved &&
(_consist.SelectedCar is null || !moved.Cars.Contains(_consist.SelectedCar)))
_cards.Activate(moved);
_details.Refresh();
UpdateTrainStats();
WriteBackToScenery();

View File

@@ -445,6 +445,7 @@ public sealed class VehicleBrowser
}
Reading(App.Loc["TextureInfo"], Consist.Base(texture.Skinfile));
Reading(App.Loc["Model"], texture.Directory + texture.Model);
if (texture.Meta is { } meta)
{

View File

@@ -234,6 +234,13 @@ public sealed class VehicleCards
/// Selects an item without going through a redraw. <paramref name="car"/> picks the
/// active member of a multi-vehicle unit; null keeps the current one when possible.
/// </summary>
/// <summary>
/// Gives an item the selection a click would give it. Removing a vehicle only
/// moves the highlight, which left the starting vehicle, the detail panels and
/// the browser pointing at what was deleted.
/// </summary>
public void Activate(ConsistItem item) => Select(item, null);
private void Select(ConsistItem item, Dynamic? car)
{
var target = car ?? (ReferenceEquals(_consist.Selected, item)

View File

@@ -304,19 +304,21 @@ public sealed class VehicleDetails
if (IsPassengerVehicle(item))
{
var lead = item.Cars[0];
// The number rides in each vehicle's own name, so it belongs to the
// member the user picked inside the unit, not to its first car.
var numbered = _consist.ActiveCar(item);
var numBox = new NumericUpDown
{
FontSize = 12,
Minimum = 0,
Maximum = 99999,
Increment = 1,
Value = Consist.GetWagonNumber(lead),
Value = Consist.GetWagonNumber(numbered),
FormatString = "0"
};
numBox.ValueChanged += (_, _) =>
{
_consist.SetWagonNumber(lead, (int)(numBox.Value ?? 0));
_consist.SetWagonNumber(numbered, (int)(numBox.Value ?? 0));
_redraw();
};
rows.Children.Add(Row(App.Loc["WagonNumber"], numBox));