From b63ba8fe2e93165c7a8bf5d02e176f780c3a8fd1 Mon Sep 17 00:00:00 2001 From: maj00r Date: Mon, 16 Nov 2026 00:09:36 +0100 Subject: [PATCH] feat(start): starting with unsaved settings asks first Edits on the settings page (or of the keys) not saved yet: the start asks whether to save them and start, start without them, or not start. Closing the question starts nothing. "Start without saving settings" from the menu asks nothing, as it says what it does. --- StarterNG/MainWindow.axaml.cs | 12 ++++++++++++ StarterNG/Views/MessageBox.cs | 29 +++++++++++++++++++++++++++++ StarterNG/Views/Settings.axaml.cs | 5 ++++- StarterNG/startercfg/lang/cz.xml | 3 +++ StarterNG/startercfg/lang/en.xml | 3 +++ StarterNG/startercfg/lang/hu.xml | 3 +++ StarterNG/startercfg/lang/pl.xml | 3 +++ StarterNG/startercfg/lang/ru.xml | 3 +++ 8 files changed, 60 insertions(+), 1 deletion(-) diff --git a/StarterNG/MainWindow.axaml.cs b/StarterNG/MainWindow.axaml.cs index db87da5..008905a 100644 --- a/StarterNG/MainWindow.axaml.cs +++ b/StarterNG/MainWindow.axaml.cs @@ -610,6 +610,18 @@ public partial class MainWindow : Window App.Loc["StartNoStaffTitle"], MessageBoxButtons.YesNo)) return; + // edits on the settings page not saved: said before they go to the simulator, or not + if (saveSettings && SettingsView.HasUnsavedChanges) + { + var save = await MessageBox.Choose(this, App.Loc["StartUnsavedMessage"], App.Loc["UnsavedChanges"], + App.Loc["StartUnsavedSave"], App.Loc["StartUnsavedWithout"]); + if (save is null) + return; + if (save == true) + SettingsView.Save(); + saveSettings = save == true; + } + LoadingScreen.Prepare(trainset?.Logo, Path.GetFileNameWithoutExtension(scenery.Path)); await FollowStartAsync(() => AppServices.Current.StartSimulation.Execute(freeFly, saveSettings)); diff --git a/StarterNG/Views/MessageBox.cs b/StarterNG/Views/MessageBox.cs index 30818b4..1067562 100644 --- a/StarterNG/Views/MessageBox.cs +++ b/StarterNG/Views/MessageBox.cs @@ -42,6 +42,35 @@ public static class MessageBox return yes; } + /// + /// A question with two answers and a way back: true for the first, false for the second, null when cancelled + /// or the window is closed - closing it never picks one of the answers. + /// + public static async Task Choose(Window owner, string message, string title, string firstText, + string secondText) + { + var win = FixedDialog(title, 460); + + bool? answer = null; + var first = DialogButton(firstText, "Accent", 80, () => { answer = true; win.Close(); }); + var second = DialogButton(secondText, "Flat", 80, () => { answer = false; win.Close(); }); + var cancel = DialogButton(App.Loc["Cancel"], "Flat", 80, () => win.Close()); + + win.Content = new StackPanel + { + Margin = new Avalonia.Thickness(16), + Spacing = 16, + Children = + { + new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap }, + ButtonRow(first, second, cancel) + } + }; + + await win.ShowDialog(owner); + return answer; + } + /// /// A notice with one action besides closing it, and a box to stop it coming /// back, which counts however the window is closed. diff --git a/StarterNG/Views/Settings.axaml.cs b/StarterNG/Views/Settings.axaml.cs index d2d74d3..176c839 100644 --- a/StarterNG/Views/Settings.axaml.cs +++ b/StarterNG/Views/Settings.axaml.cs @@ -1482,9 +1482,12 @@ public partial class Settings : UserControl, ISettingsCapture UpdateSaveState(); } + /// Edits on the page, or of the keys, not saved yet: what "Niezapisane zmiany" tells. + public bool HasUnsavedChanges => _dirty || KeyboardConfig.Instance.Dirty; + private void UpdateSaveState() { - bool dirty = _dirty || KeyboardConfig.Instance.Dirty; + bool dirty = HasUnsavedChanges; SaveButton.Classes.Set("Accent", dirty); SaveStatus.Text = dirty ? App.Loc["UnsavedChanges"] : string.Empty; } diff --git a/StarterNG/startercfg/lang/cz.xml b/StarterNG/startercfg/lang/cz.xml index 8177d3d..7fdd310 100644 --- a/StarterNG/startercfg/lang/cz.xml +++ b/StarterNG/startercfg/lang/cz.xml @@ -632,6 +632,9 @@ Připojit soupravu ze skladu Přidat soupravy ze souboru... Spustit bez uložení nastavení + Nastavení obsahuje neuložené změny. Simulátor se s nimi spustí, jen pokud budou uloženy. + Uložit a spustit + Spustit bez uložení Další způsoby spuštění Spustit bez vozidla Editor scenérie diff --git a/StarterNG/startercfg/lang/en.xml b/StarterNG/startercfg/lang/en.xml index 2e37b91..17fa374 100644 --- a/StarterNG/startercfg/lang/en.xml +++ b/StarterNG/startercfg/lang/en.xml @@ -658,6 +658,9 @@ Append warehouse consist Add consists from file... Start without saving settings + The settings have unsaved changes. The simulator starts with them only if they are saved. + Save and start + Start without saving More ways to start Start with no vehicle Scenery editor diff --git a/StarterNG/startercfg/lang/hu.xml b/StarterNG/startercfg/lang/hu.xml index b77a00d..8223491 100644 --- a/StarterNG/startercfg/lang/hu.xml +++ b/StarterNG/startercfg/lang/hu.xml @@ -632,6 +632,9 @@ Raktári szerelvény hozzáfűzése Szerelvények hozzáadása fájlból... Indítás a beállítások mentése nélkül + A beállításokban nem mentett módosítások vannak. A szimulátor csak akkor indul velük, ha mentve lesznek. + Mentés és indítás + Indítás mentés nélkül További indítási módok Indítás jármű nélkül Pályaszerkesztő diff --git a/StarterNG/startercfg/lang/pl.xml b/StarterNG/startercfg/lang/pl.xml index 37d3e05..2ad493a 100644 --- a/StarterNG/startercfg/lang/pl.xml +++ b/StarterNG/startercfg/lang/pl.xml @@ -658,6 +658,9 @@ Dołącz skład z magazynu Dodaj składy z pliku... Uruchom bez zapisu ustawień + Ustawienia mają niezapisane zmiany. Symulator uruchomi się z nimi tylko wtedy, gdy zostaną zapisane. + Zapisz i uruchom + Uruchom bez zapisu Inne sposoby uruchomienia Uruchom bez pojazdu Edytor scenerii diff --git a/StarterNG/startercfg/lang/ru.xml b/StarterNG/startercfg/lang/ru.xml index 669d65c..f16810a 100644 --- a/StarterNG/startercfg/lang/ru.xml +++ b/StarterNG/startercfg/lang/ru.xml @@ -632,6 +632,9 @@ Присоединить состав со склада Добавить составы из файла... Запустить без сохранения настроек + В настройках есть несохранённые изменения. Симулятор запустится с ними, только если их сохранить. + Сохранить и запустить + Запустить без сохранения Другие способы запуска Запустить без транспорта Редактор сценария