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.
This commit is contained in:
maj00r
2026-11-16 00:09:36 +01:00
parent 76693c1494
commit b63ba8fe2e
8 changed files with 60 additions and 1 deletions

View File

@@ -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));

View File

@@ -42,6 +42,35 @@ public static class MessageBox
return yes;
}
/// <summary>
/// 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.
/// </summary>
public static async Task<bool?> 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;
}
/// <summary>
/// A notice with one action besides closing it, and a box to stop it coming
/// back, which counts however the window is closed.

View File

@@ -1482,9 +1482,12 @@ public partial class Settings : UserControl, ISettingsCapture
UpdateSaveState();
}
/// <summary>Edits on the page, or of the keys, not saved yet: what "Niezapisane zmiany" tells.</summary>
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;
}

View File

@@ -632,6 +632,9 @@
<String key="WarehouseAppend">Připojit soupravu ze skladu</String>
<String key="WarehouseImportFile">Přidat soupravy ze souboru...</String>
<String key="StartWithoutSaving">Spustit bez uložení nastavení</String>
<String key="StartUnsavedMessage">Nastavení obsahuje neuložené změny. Simulátor se s nimi spustí, jen pokud budou uloženy.</String>
<String key="StartUnsavedSave">Uložit a spustit</String>
<String key="StartUnsavedWithout">Spustit bez uložení</String>
<String key="StartMore">Další způsoby spuštění</String>
<String key="StartFreeFly">Spustit bez vozidla</String>
<String key="StartEditorShort">Editor scenérie</String>

View File

@@ -658,6 +658,9 @@
<String key="WarehouseAppend">Append warehouse consist</String>
<String key="WarehouseImportFile">Add consists from file...</String>
<String key="StartWithoutSaving">Start without saving settings</String>
<String key="StartUnsavedMessage">The settings have unsaved changes. The simulator starts with them only if they are saved.</String>
<String key="StartUnsavedSave">Save and start</String>
<String key="StartUnsavedWithout">Start without saving</String>
<String key="StartMore">More ways to start</String>
<String key="StartFreeFly">Start with no vehicle</String>
<String key="StartEditorShort">Scenery editor</String>

View File

@@ -632,6 +632,9 @@
<String key="WarehouseAppend">Raktári szerelvény hozzáfűzése</String>
<String key="WarehouseImportFile">Szerelvények hozzáadása fájlból...</String>
<String key="StartWithoutSaving">Indítás a beállítások mentése nélkül</String>
<String key="StartUnsavedMessage">A beállításokban nem mentett módosítások vannak. A szimulátor csak akkor indul velük, ha mentve lesznek.</String>
<String key="StartUnsavedSave">Mentés és indítás</String>
<String key="StartUnsavedWithout">Indítás mentés nélkül</String>
<String key="StartMore">További indítási módok</String>
<String key="StartFreeFly">Indítás jármű nélkül</String>
<String key="StartEditorShort">Pályaszerkesztő</String>

View File

@@ -658,6 +658,9 @@
<String key="WarehouseAppend">Dołącz skład z magazynu</String>
<String key="WarehouseImportFile">Dodaj składy z pliku...</String>
<String key="StartWithoutSaving">Uruchom bez zapisu ustawień</String>
<String key="StartUnsavedMessage">Ustawienia mają niezapisane zmiany. Symulator uruchomi się z nimi tylko wtedy, gdy zostaną zapisane.</String>
<String key="StartUnsavedSave">Zapisz i uruchom</String>
<String key="StartUnsavedWithout">Uruchom bez zapisu</String>
<String key="StartMore">Inne sposoby uruchomienia</String>
<String key="StartFreeFly">Uruchom bez pojazdu</String>
<String key="StartEditorShort">Edytor scenerii</String>

View File

@@ -632,6 +632,9 @@
<String key="WarehouseAppend">Присоединить состав со склада</String>
<String key="WarehouseImportFile">Добавить составы из файла...</String>
<String key="StartWithoutSaving">Запустить без сохранения настроек</String>
<String key="StartUnsavedMessage">В настройках есть несохранённые изменения. Симулятор запустится с ними, только если их сохранить.</String>
<String key="StartUnsavedSave">Сохранить и запустить</String>
<String key="StartUnsavedWithout">Запустить без сохранения</String>
<String key="StartMore">Другие способы запуска</String>
<String key="StartFreeFly">Запустить без транспорта</String>
<String key="StartEditorShort">Редактор сценария</String>