From 94fe52245e3890f5f00ea46baf902b9ee6c6a874 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sun, 2 Jul 2023 13:10:04 +0100 Subject: [PATCH] Refactor UI code structuring 109 changed files :D --- Bloxstrap/App.xaml.cs | 6 +- Bloxstrap/Bootstrapper.cs | 1 - Bloxstrap/Extensions/BootstrapperStyleEx.cs | 18 +----- Bloxstrap/UI/Controls.cs | 31 ++++++++-- .../Bootstrapper/Base}/BaseFunctions.cs | 2 +- .../Bootstrapper/Base/WinFormsDialogBase.cs} | 8 +-- .../Bootstrapper}/ByfronDialog.xaml | 2 +- .../Bootstrapper}/ByfronDialog.xaml.cs | 13 ++-- .../Bootstrapper}/FluentDialog.xaml | 4 +- .../Bootstrapper}/FluentDialog.xaml.cs | 22 +++---- .../LegacyDialog2009.Designer.cs | 2 +- .../Bootstrapper}/LegacyDialog2009.cs | 6 +- .../Bootstrapper}/LegacyDialog2009.resx | 0 .../LegacyDialog2011.Designer.cs | 2 +- .../Bootstrapper}/LegacyDialog2011.cs | 5 +- .../Bootstrapper}/LegacyDialog2011.resx | 0 .../Bootstrapper}/ProgressDialog.Designer.cs | 2 +- .../Bootstrapper}/ProgressDialog.cs | 5 +- .../Bootstrapper}/ProgressDialog.resx | 0 .../Bootstrapper}/VistaDialog.Designer.cs | 2 +- .../Bootstrapper}/VistaDialog.cs | 5 +- .../Bootstrapper}/VistaDialog.resx | 0 .../UI/{ => Elements}/ExceptionDialog.xaml | 0 .../UI/{ => Elements}/ExceptionDialog.xaml.cs | 0 .../FluentMessageBox.xaml | 0 .../FluentMessageBox.xaml.cs | 18 +----- .../Views => Elements/Menu}/MainWindow.xaml | 4 +- .../Menu}/MainWindow.xaml.cs | 4 +- .../Menu}/Pages/AboutPage.xaml | 4 +- .../Menu}/Pages/AboutPage.xaml.cs | 4 +- .../Menu}/Pages/AppearancePage.xaml | 3 +- .../Menu}/Pages/AppearancePage.xaml.cs | 4 +- .../Menu}/Pages/BehaviourPage.xaml | 2 +- .../Menu}/Pages/BehaviourPage.xaml.cs | 4 +- .../Menu}/Pages/FastFlagsPage.xaml | 4 +- .../Menu}/Pages/FastFlagsPage.xaml.cs | 4 +- .../Menu}/Pages/InstallationPage.xaml | 4 +- .../Menu}/Pages/InstallationPage.xaml.cs | 4 +- .../Menu}/Pages/IntegrationsPage.xaml | 2 +- .../Menu}/Pages/IntegrationsPage.xaml.cs | 4 +- .../Menu}/Pages/ModsPage.xaml | 4 +- .../Menu}/Pages/ModsPage.xaml.cs | 4 +- .../IBootstrapperDialog.cs | 2 +- Bloxstrap/UI/MessageBox/NativeMessageBox.cs | 15 ----- Bloxstrap/{ => UI}/Utility/Rendering.cs | 2 +- Bloxstrap/{ => UI}/Utility/WindowScaling.cs | 62 +++++++++---------- .../BootstrapperDialogViewModel.cs} | 11 ++-- .../Bootstrapper}/ByfronDialogViewModel.cs | 7 ++- .../{Menu => }/ViewModels/GlobalViewModel.cs | 2 +- .../Menu}/AboutViewModel.cs | 4 +- .../Menu}/AppearanceViewModel.cs | 5 +- .../Menu}/BehaviourViewModel.cs | 2 +- .../Menu}/FastFlagsViewModel.cs | 2 +- .../Menu}/InstallationViewModel.cs | 2 +- .../Menu}/IntegrationsViewModel.cs | 2 +- .../Menu}/MainWindowViewModel.cs | 14 ++--- .../Menu}/ModsViewModel.cs | 2 +- 57 files changed, 165 insertions(+), 182 deletions(-) rename Bloxstrap/UI/{BootstrapperDialogs => Elements/Bootstrapper/Base}/BaseFunctions.cs (87%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms/DialogBase.cs => Elements/Bootstrapper/Base/WinFormsDialogBase.cs} (93%) rename Bloxstrap/UI/{BootstrapperDialogs/WPF/Views => Elements/Bootstrapper}/ByfronDialog.xaml (98%) rename Bloxstrap/UI/{BootstrapperDialogs/WPF/Views => Elements/Bootstrapper}/ByfronDialog.xaml.cs (89%) rename Bloxstrap/UI/{BootstrapperDialogs/WPF/Views => Elements/Bootstrapper}/FluentDialog.xaml (87%) rename Bloxstrap/UI/{BootstrapperDialogs/WPF/Views => Elements/Bootstrapper}/FluentDialog.xaml.cs (81%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/LegacyDialog2009.Designer.cs (98%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/LegacyDialog2009.cs (87%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/LegacyDialog2009.resx (100%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/LegacyDialog2011.Designer.cs (98%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/LegacyDialog2011.cs (88%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/LegacyDialog2011.resx (100%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/ProgressDialog.Designer.cs (99%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/ProgressDialog.cs (93%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/ProgressDialog.resx (100%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/VistaDialog.Designer.cs (96%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/VistaDialog.cs (96%) rename Bloxstrap/UI/{BootstrapperDialogs/WinForms => Elements/Bootstrapper}/VistaDialog.resx (100%) rename Bloxstrap/UI/{ => Elements}/ExceptionDialog.xaml (100%) rename Bloxstrap/UI/{ => Elements}/ExceptionDialog.xaml.cs (100%) rename Bloxstrap/UI/{MessageBox => Elements}/FluentMessageBox.xaml (100%) rename Bloxstrap/UI/{MessageBox => Elements}/FluentMessageBox.xaml.cs (86%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/MainWindow.xaml (96%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/MainWindow.xaml.cs (95%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/AboutPage.xaml (99%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/AboutPage.xaml.cs (76%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/AppearancePage.xaml (97%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/AppearancePage.xaml.cs (78%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/BehaviourPage.xaml (96%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/BehaviourPage.xaml.cs (77%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/FastFlagsPage.xaml (98%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/FastFlagsPage.xaml.cs (85%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/InstallationPage.xaml (98%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/InstallationPage.xaml.cs (92%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/IntegrationsPage.xaml (98%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/IntegrationsPage.xaml.cs (90%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/ModsPage.xaml (98%) rename Bloxstrap/UI/{Menu/Views => Elements/Menu}/Pages/ModsPage.xaml.cs (87%) rename Bloxstrap/UI/{BootstrapperDialogs => }/IBootstrapperDialog.cs (91%) delete mode 100644 Bloxstrap/UI/MessageBox/NativeMessageBox.cs rename Bloxstrap/{ => UI}/Utility/Rendering.cs (95%) rename Bloxstrap/{ => UI}/Utility/WindowScaling.cs (94%) rename Bloxstrap/UI/{BootstrapperDialogs/WPF/ViewModels/FluentDialogViewModel.cs => ViewModels/Bootstrapper/BootstrapperDialogViewModel.cs} (73%) rename Bloxstrap/UI/{BootstrapperDialogs/WPF/ViewModels => ViewModels/Bootstrapper}/ByfronDialogViewModel.cs (84%) rename Bloxstrap/UI/{Menu => }/ViewModels/GlobalViewModel.cs (92%) rename Bloxstrap/UI/{Menu/ViewModels => ViewModels/Menu}/AboutViewModel.cs (87%) rename Bloxstrap/UI/{Menu/ViewModels => ViewModels/Menu}/AppearanceViewModel.cs (97%) rename Bloxstrap/UI/{Menu/ViewModels => ViewModels/Menu}/BehaviourViewModel.cs (90%) rename Bloxstrap/UI/{Menu/ViewModels => ViewModels/Menu}/FastFlagsViewModel.cs (99%) rename Bloxstrap/UI/{Menu/ViewModels => ViewModels/Menu}/InstallationViewModel.cs (99%) rename Bloxstrap/UI/{Menu/ViewModels => ViewModels/Menu}/IntegrationsViewModel.cs (98%) rename Bloxstrap/UI/{Menu/ViewModels => ViewModels/Menu}/MainWindowViewModel.cs (90%) rename Bloxstrap/UI/{Menu/ViewModels => ViewModels/Menu}/ModsViewModel.cs (97%) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 065c2203..d1f13ff0 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -17,8 +17,6 @@ using Bloxstrap.Models; using Bloxstrap.Models.Attributes; using Bloxstrap.UI; -using Bloxstrap.UI.BootstrapperDialogs; -using Bloxstrap.UI.MessageBox; using Bloxstrap.Utility; namespace Bloxstrap @@ -105,6 +103,7 @@ void GlobalExceptionHandler(object sender, DispatcherUnhandledExceptionEventArgs void FinalizeExceptionHandling(Exception exception) { +#pragma warning disable 162 #if DEBUG throw exception; #endif @@ -113,6 +112,7 @@ void FinalizeExceptionHandling(Exception exception) Controls.ShowExceptionDialog(exception); Terminate(Bootstrapper.ERROR_INSTALL_FAILURE); +#pragma warning restore 162 } protected override void OnStartup(StartupEventArgs e) @@ -248,7 +248,7 @@ protected override void OnStartup(StartupEventArgs e) else { if (Process.GetProcessesByName(ProjectName).Length > 1 && !IsQuiet) - FluentMessageBox.Show( + Controls.ShowMessageBox( $"{ProjectName} is currently running, likely as a background Roblox process. Please note that not all your changes will immediately apply until you close all currently open Roblox instances.", MessageBoxImage.Information ); diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 33d2fabd..2b75af00 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -18,7 +18,6 @@ using Bloxstrap.Models; using Bloxstrap.Tools; using Bloxstrap.UI; -using Bloxstrap.UI.BootstrapperDialogs; namespace Bloxstrap { diff --git a/Bloxstrap/Extensions/BootstrapperStyleEx.cs b/Bloxstrap/Extensions/BootstrapperStyleEx.cs index fa555785..bb837d88 100644 --- a/Bloxstrap/Extensions/BootstrapperStyleEx.cs +++ b/Bloxstrap/Extensions/BootstrapperStyleEx.cs @@ -1,24 +1,10 @@ using Bloxstrap.Enums; -using Bloxstrap.UI.BootstrapperDialogs; -using Bloxstrap.UI.BootstrapperDialogs.WinForms; -using Bloxstrap.UI.BootstrapperDialogs.WPF.Views; +using Bloxstrap.UI; namespace Bloxstrap.Extensions { static class BootstrapperStyleEx { - public static IBootstrapperDialog GetNew(this BootstrapperStyle bootstrapperStyle) - { - return bootstrapperStyle switch - { - BootstrapperStyle.VistaDialog => new VistaDialog(), - BootstrapperStyle.LegacyDialog2009 => new LegacyDialog2009(), - BootstrapperStyle.LegacyDialog2011 => new LegacyDialog2011(), - BootstrapperStyle.ProgressDialog => new ProgressDialog(), - BootstrapperStyle.FluentDialog => new FluentDialog(), - BootstrapperStyle.ByfronDialog => new ByfronDialog(), - _ => new FluentDialog() - }; - } + public static IBootstrapperDialog GetNew(this BootstrapperStyle bootstrapperStyle) => Controls.GetBootstrapperDialog(bootstrapperStyle); } } diff --git a/Bloxstrap/UI/Controls.cs b/Bloxstrap/UI/Controls.cs index ad4ab765..22a6a61c 100644 --- a/Bloxstrap/UI/Controls.cs +++ b/Bloxstrap/UI/Controls.cs @@ -1,9 +1,10 @@ using System; -using System.Drawing; using System.Windows; using Bloxstrap.Enums; -using Bloxstrap.UI.Menu.Views; +using Bloxstrap.Extensions; +using Bloxstrap.UI.Elements.Bootstrapper; +using Bloxstrap.UI.Menu; using Bloxstrap.UI.MessageBox; namespace Bloxstrap.UI @@ -14,14 +15,22 @@ static class Controls public static MessageBoxResult ShowMessageBox(string message, MessageBoxImage icon = MessageBoxImage.None, MessageBoxButton buttons = MessageBoxButton.OK, MessageBoxResult defaultResult = MessageBoxResult.None) { + if (App.IsQuiet) + return defaultResult; + switch (App.Settings.Prop.BootstrapperStyle) { case BootstrapperStyle.FluentDialog: case BootstrapperStyle.ByfronDialog: - return FluentMessageBox.Show(message, icon, buttons, defaultResult); + return Application.Current.Dispatcher.Invoke(new Func(() => + { + var messagebox = new FluentMessageBox(message, icon, buttons); + messagebox.ShowDialog(); + return messagebox.Result; + })); default: - return NativeMessageBox.Show(message, icon, buttons, defaultResult); + return System.Windows.MessageBox.Show(message, App.ProjectName, buttons, icon); } } @@ -32,5 +41,19 @@ public static void ShowExceptionDialog(Exception exception) new ExceptionDialog(exception).ShowDialog(); }); } + + public static IBootstrapperDialog GetBootstrapperDialog(BootstrapperStyle style) + { + return style switch + { + BootstrapperStyle.VistaDialog => new VistaDialog(), + BootstrapperStyle.LegacyDialog2009 => new LegacyDialog2009(), + BootstrapperStyle.LegacyDialog2011 => new LegacyDialog2011(), + BootstrapperStyle.ProgressDialog => new ProgressDialog(), + BootstrapperStyle.FluentDialog => new FluentDialog(), + BootstrapperStyle.ByfronDialog => new ByfronDialog(), + _ => new FluentDialog() + }; + } } } diff --git a/Bloxstrap/UI/BootstrapperDialogs/BaseFunctions.cs b/Bloxstrap/UI/Elements/Bootstrapper/Base/BaseFunctions.cs similarity index 87% rename from Bloxstrap/UI/BootstrapperDialogs/BaseFunctions.cs rename to Bloxstrap/UI/Elements/Bootstrapper/Base/BaseFunctions.cs index 3a89637b..c3e3c087 100644 --- a/Bloxstrap/UI/BootstrapperDialogs/BaseFunctions.cs +++ b/Bloxstrap/UI/Elements/Bootstrapper/Base/BaseFunctions.cs @@ -1,7 +1,7 @@ using System; using System.Windows; -namespace Bloxstrap.UI.BootstrapperDialogs +namespace Bloxstrap.UI.Elements.Bootstrapper.Base { static class BaseFunctions { diff --git a/Bloxstrap/UI/BootstrapperDialogs/WinForms/DialogBase.cs b/Bloxstrap/UI/Elements/Bootstrapper/Base/WinFormsDialogBase.cs similarity index 93% rename from Bloxstrap/UI/BootstrapperDialogs/WinForms/DialogBase.cs rename to Bloxstrap/UI/Elements/Bootstrapper/Base/WinFormsDialogBase.cs index 253062c3..4627a0be 100644 --- a/Bloxstrap/UI/BootstrapperDialogs/WinForms/DialogBase.cs +++ b/Bloxstrap/UI/Elements/Bootstrapper/Base/WinFormsDialogBase.cs @@ -2,13 +2,13 @@ using System.Windows.Forms; using Bloxstrap.Extensions; -using Bloxstrap.Utility; +using Bloxstrap.UI.Utility; -namespace Bloxstrap.UI.BootstrapperDialogs.WinForms +namespace Bloxstrap.UI.Elements.Bootstrapper.Base { - public class DialogBase : Form, IBootstrapperDialog + public class WinFormsDialogBase : Form, IBootstrapperDialog { - public Bootstrapper? Bootstrapper { get; set; } + public Bloxstrap.Bootstrapper? Bootstrapper { get; set; } #region UI Elements protected virtual string _message { get; set; } = "Please wait..."; diff --git a/Bloxstrap/UI/BootstrapperDialogs/WPF/Views/ByfronDialog.xaml b/Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml similarity index 98% rename from Bloxstrap/UI/BootstrapperDialogs/WPF/Views/ByfronDialog.xaml rename to Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml index ca5b62e0..b2b93870 100644 --- a/Bloxstrap/UI/BootstrapperDialogs/WPF/Views/ByfronDialog.xaml +++ b/Bloxstrap/UI/Elements/Bootstrapper/ByfronDialog.xaml @@ -1,4 +1,4 @@ - /// Interaction logic for ByfronDialog.xaml @@ -17,7 +18,7 @@ public partial class ByfronDialog : IBootstrapperDialog { private readonly ByfronDialogViewModel _viewModel; - public Bootstrapper? Bootstrapper { get; set; } + public Bloxstrap.Bootstrapper? Bootstrapper { get; set; } #region UI Elements public string Message @@ -52,10 +53,12 @@ public int ProgressValue public bool CancelEnabled { - get => _viewModel.CancelButtonVisibility == Visibility.Visible; + get => _viewModel.CancelEnabled; set { - _viewModel.CancelButtonVisibility = (value ? Visibility.Visible : Visibility.Collapsed); + _viewModel.CancelEnabled = value; + + _viewModel.OnPropertyChanged(nameof(_viewModel.CancelEnabled)); _viewModel.OnPropertyChanged(nameof(_viewModel.CancelButtonVisibility)); _viewModel.OnPropertyChanged(nameof(_viewModel.VersionTextVisibility)); diff --git a/Bloxstrap/UI/BootstrapperDialogs/WPF/Views/FluentDialog.xaml b/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml similarity index 87% rename from Bloxstrap/UI/BootstrapperDialogs/WPF/Views/FluentDialog.xaml rename to Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml index 0de1cce5..5916c073 100644 --- a/Bloxstrap/UI/BootstrapperDialogs/WPF/Views/FluentDialog.xaml +++ b/Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml @@ -1,4 +1,4 @@ - -