From a9f4a09cf5e7400f179bfa9a522c2d25a552f83c Mon Sep 17 00:00:00 2001 From: maj00r Date: Sun, 4 Oct 2026 14:03:52 +0200 Subject: [PATCH] Add a vehicle several times from the browser's menu The count is asked for in a flyout; the copies go in one after another, each staffed as a single add would be, with one redraw. --- StarterNG/Views/Depot.axaml.cs | 40 +++++++++++++-------- StarterNG/Views/Depot/VehicleBrowser.cs | 47 +++++++++++++++++++++++-- StarterNG/startercfg/lang/cz.xml | 2 ++ StarterNG/startercfg/lang/en.xml | 2 ++ StarterNG/startercfg/lang/hu.xml | 2 ++ StarterNG/startercfg/lang/pl.xml | 2 ++ StarterNG/startercfg/lang/ru.xml | 2 ++ 7 files changed, 80 insertions(+), 17 deletions(-) diff --git a/StarterNG/Views/Depot.axaml.cs b/StarterNG/Views/Depot.axaml.cs index b5ded2f..b061ee8 100644 --- a/StarterNG/Views/Depot.axaml.cs +++ b/StarterNG/Views/Depot.axaml.cs @@ -71,7 +71,10 @@ public partial class Depot : UserControl _browser = new VehicleBrowser(categoryCombo, classCombo, vehicleListBox, searchBox, hideArchivalCheck, miniPreview, addVehicleButton, _db, _minis, - () => TextureBaseButton_OnClick(null, null!)); + () => TextureBaseButton_OnClick(null, null!)) + { + AddMany = (texture, count) => AddTexture(texture, count) + }; _drag = new ConsistDragging(consistStack, consistScroll, consistOverlay, consistDropTarget, vehicleListBox, miniPreviewPanel, @@ -580,7 +583,7 @@ public partial class Depot : UserControl RebuildConsist(); } - private void AddTexture(VehicleTexture texture) + private void AddTexture(VehicleTexture texture, int count = 1) { int at = _consist.Count; if (_consist.Selected != null) @@ -588,26 +591,33 @@ public partial class Depot : UserControl int si = _consist.IndexOf(_consist.Selected); if (si >= 0) at = si + 1; } - InsertTextureAt(texture, at); + InsertTexturesAt(texture, at, count); } - private void InsertTextureAt(VehicleTexture texture, int at) + private void InsertTextureAt(VehicleTexture texture, int at) => InsertTexturesAt(texture, at, 1); + + /// The vehicle count times in a row from at - each staffed as added - and one redraw. + private void InsertTexturesAt(VehicleTexture texture, int at, int count) { var set = _db.ResolveSet(texture); var unit = set ?? new List { texture }; - var item = new ConsistItem - { - Cars = unit.Select(NewVehicle).ToList(), - Grouped = unit.Count > 1, - Driver = eDriverType.Nobody, - Flipped = false - }; - at = Math.Clamp(at, 0, _consist.Count); - _consist.Staff(item, at); - _consist.Insert(at, item); - _consist.Selected = item; + for (int n = 0; n < count; n++, at++) + { + var item = new ConsistItem + { + Cars = unit.Select(NewVehicle).ToList(), + Grouped = unit.Count > 1, + Driver = eDriverType.Nobody, + Flipped = false + }; + + _consist.Staff(item, at); + _consist.Insert(at, item); + _consist.Selected = item; + } + _consist.AutoConnectAll(); RebuildConsist(); } diff --git a/StarterNG/Views/Depot/VehicleBrowser.cs b/StarterNG/Views/Depot/VehicleBrowser.cs index 96210d9..6a3930b 100644 --- a/StarterNG/Views/Depot/VehicleBrowser.cs +++ b/StarterNG/Views/Depot/VehicleBrowser.cs @@ -51,6 +51,11 @@ public sealed class VehicleBrowser public Action? TextureSelected { get; set; } + /// Adds the vehicle to the consist the given number of times. + public Action? AddMany { get; set; } + + private const int MaxAddMany = 100; + private bool _suppress; private bool _syncingCombos; @@ -358,6 +363,38 @@ public sealed class VehicleBrowser } } + private void ShowAddManyFlyout(Control anchor, VehicleTexture texture) + { + var count = new NumericUpDown + { + Minimum = 1, Maximum = MaxAddMany, Increment = 1, FormatString = "0", Value = 2, MinWidth = 120 + }; + var add = new Button { Content = App.Loc["AddVehicle"], HorizontalAlignment = HorizontalAlignment.Right }; + add.Classes.Add("Flat"); + add.Classes.Add("Accent"); + + var panel = new StackPanel { Spacing = 6, Margin = new Thickness(8), MinWidth = 160 }; + panel.Children.Add(new TextBlock { Text = App.Loc["AddManyCount"], FontWeight = FontWeight.Bold, FontSize = 12 }); + panel.Children.Add(count); + panel.Children.Add(add); + + var flyout = new Flyout { Content = panel, Placement = PlacementMode.Right }; + void Commit() + { + flyout.Hide(); + AddMany?.Invoke(texture, Math.Clamp((int)(count.Value ?? 1), 1, MaxAddMany)); + } + add.Click += (_, _) => Commit(); + count.KeyDown += (_, e) => + { + if (e.Key != Key.Enter) return; + e.Handled = true; + Commit(); + }; + flyout.ShowAt(anchor); + count.Focus(); + } + private void List_OnContextRequested(object? sender, ContextRequestedEventArgs e) { var hit = e.Source as Control; @@ -367,13 +404,19 @@ public sealed class VehicleBrowser if (hit is not ListBoxItem { Tag: VehicleTexture texture }) return; - BuildBrowserMenu(texture).Open(hit); + BuildBrowserMenu(texture, hit).Open(hit); e.Handled = true; } - private ContextMenu BuildBrowserMenu(VehicleTexture texture) + private ContextMenu BuildBrowserMenu(VehicleTexture texture, Control anchor) { var menu = new ContextMenu(); + + var addMany = new MenuItem { Header = App.Loc["AddMany"], IsEnabled = AddMany is not null }; + addMany.Click += (_, _) => ShowAddManyFlyout(anchor, texture); + menu.Items.Add(addMany); + menu.Items.Add(new Separator()); + var copy = new MenuItem { Header = App.Loc["CopyTextureName"] }; copy.Click += async (_, _) => { diff --git a/StarterNG/startercfg/lang/cz.xml b/StarterNG/startercfg/lang/cz.xml index 76324b1..ad89e46 100644 --- a/StarterNG/startercfg/lang/cz.xml +++ b/StarterNG/startercfg/lang/cz.xml @@ -281,6 +281,8 @@ Spojit toto vozidlo s následujícím do jedné jednotky Přetáhněte pro změnu pořadí Přidat + Přidat vícekrát… + Kolikrát vozidlo přidat Přidat toto vozidlo do soupravy Přidat celou jednotku do soupravy diff --git a/StarterNG/startercfg/lang/en.xml b/StarterNG/startercfg/lang/en.xml index dfa3c38..31e184b 100644 --- a/StarterNG/startercfg/lang/en.xml +++ b/StarterNG/startercfg/lang/en.xml @@ -281,6 +281,8 @@ Couple this vehicle with the next one into a single unit Drag to reorder Add + Add several… + How many times to add it Add this vehicle to the consist Add the whole unit to the consist diff --git a/StarterNG/startercfg/lang/hu.xml b/StarterNG/startercfg/lang/hu.xml index 1592ae3..8895e7c 100644 --- a/StarterNG/startercfg/lang/hu.xml +++ b/StarterNG/startercfg/lang/hu.xml @@ -281,6 +281,8 @@ A jármű összekapcsolása a következővel egy egységgé Húzza az átrendezéshez Hozzáadás + Hozzáadás többször… + Hányszor add hozzá a járművet Jármű hozzáadása a szerelvényhez A teljes egység hozzáadása a szerelvényhez diff --git a/StarterNG/startercfg/lang/pl.xml b/StarterNG/startercfg/lang/pl.xml index 6d7d9bf..4910aac 100644 --- a/StarterNG/startercfg/lang/pl.xml +++ b/StarterNG/startercfg/lang/pl.xml @@ -281,6 +281,8 @@ Połącz ten pojazd z następnym w jeden zespół Przeciągnij, aby zmienić kolejność Dodaj + Dodaj wiele… + Ile razy dodać pojazd Dodaj ten pojazd do składu Dodaj cały zespół do składu diff --git a/StarterNG/startercfg/lang/ru.xml b/StarterNG/startercfg/lang/ru.xml index a559f5d..d58d62d 100644 --- a/StarterNG/startercfg/lang/ru.xml +++ b/StarterNG/startercfg/lang/ru.xml @@ -281,6 +281,8 @@ Соединить этот вагон со следующим в один состав Перетащите для изменения порядка Добавить + Добавить несколько… + Сколько раз добавить единицу Добавить эту единицу в состав Добавить весь сцеп в состав