From 83e3c487a9fde33a59103b32a5ae84c8a4679938 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Fri, 13 Sep 2024 00:28:57 +0100 Subject: [PATCH] Persistence of settings window size/position (#2319) should be good enough imo --- Bloxstrap/LaunchHandler.cs | 4 ++- Bloxstrap/Models/State.cs | 2 ++ Bloxstrap/Models/WindowState.cs | 13 +++++++ .../UI/Elements/Settings/MainWindow.xaml.cs | 34 +++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 Bloxstrap/Models/WindowState.cs diff --git a/Bloxstrap/LaunchHandler.cs b/Bloxstrap/LaunchHandler.cs index 28b4e2be..891a7edd 100644 --- a/Bloxstrap/LaunchHandler.cs +++ b/Bloxstrap/LaunchHandler.cs @@ -140,7 +140,9 @@ public static void LaunchSettings() if (interlock.IsAcquired) { bool showAlreadyRunningWarning = Process.GetProcessesByName(App.ProjectName).Length > 1; - new UI.Elements.Settings.MainWindow(showAlreadyRunningWarning).Show(); + + var window = new UI.Elements.Settings.MainWindow(showAlreadyRunningWarning); + window.Show(); } else { diff --git a/Bloxstrap/Models/State.cs b/Bloxstrap/Models/State.cs index 45e2ef44..edaf426e 100644 --- a/Bloxstrap/Models/State.cs +++ b/Bloxstrap/Models/State.cs @@ -10,6 +10,8 @@ public class State public AppState Studio { get; set; } = new(); + public WindowState SettingsWindow { get; set; } = new(); + public List ModManifest { get; set; } = new(); } } diff --git a/Bloxstrap/Models/WindowState.cs b/Bloxstrap/Models/WindowState.cs new file mode 100644 index 00000000..efc808d7 --- /dev/null +++ b/Bloxstrap/Models/WindowState.cs @@ -0,0 +1,13 @@ +namespace Bloxstrap.Models +{ + public class WindowState + { + public double Width { get; set; } + + public double Height { get; set; } + + public double Left { get; set; } + + public double Top { get; set; } + } +} diff --git a/Bloxstrap/UI/Elements/Settings/MainWindow.xaml.cs b/Bloxstrap/UI/Elements/Settings/MainWindow.xaml.cs index 59bd1db3..df176581 100644 --- a/Bloxstrap/UI/Elements/Settings/MainWindow.xaml.cs +++ b/Bloxstrap/UI/Elements/Settings/MainWindow.xaml.cs @@ -14,6 +14,8 @@ namespace Bloxstrap.UI.Elements.Settings /// public partial class MainWindow : INavigationWindow { + private Models.WindowState _state => App.State.Prop.SettingsWindow; + public MainWindow(bool showAlreadyRunningWarning) { var viewModel = new MainWindowViewModel(); @@ -33,6 +35,30 @@ public MainWindow(bool showAlreadyRunningWarning) if (showAlreadyRunningWarning) ShowAlreadyRunningSnackbar(); + + LoadState(); + } + + public void LoadState() + { + if (_state.Left > SystemParameters.VirtualScreenWidth) + _state.Left = 0; + + if (_state.Top > SystemParameters.VirtualScreenHeight) + _state.Top = 0; + + if (_state.Width > 0) + this.Width = _state.Width; + + if (_state.Height > 0) + this.Height = _state.Height; + + if (_state.Left > 0 && _state.Top > 0) + { + this.WindowStartupLocation = WindowStartupLocation.Manual; + this.Left = _state.Left; + this.Top = _state.Top; + } } private async void ShowAlreadyRunningSnackbar() @@ -66,6 +92,14 @@ private void WpfUiWindow_Closing(object sender, CancelEventArgs e) if (result != MessageBoxResult.Yes) e.Cancel = true; } + + _state.Width = this.Width; + _state.Height = this.Height; + + _state.Top = this.Top; + _state.Left = this.Left; + + App.State.Save(); if (!e.Cancel) App.Terminate();