From e54cd90adc4cd1c4f3d8e6dddce0384aba8e69c5 Mon Sep 17 00:00:00 2001 From: GreemDev Date: Sun, 23 Nov 2025 17:28:48 -0600 Subject: [PATCH] combine SetupWizardPage and the builder type since the builder mutated an instance of the built type anyways --- .../Systems/SetupWizard/BaseSetupWizard.cs | 14 +--- .../SetupWizard/SetupWizardPage.Builder.cs | 66 +++++++++++++++ .../Systems/SetupWizard/SetupWizardPage.cs | 16 ++-- .../SetupWizard/SetupWizardPageBuilder.cs | 80 ------------------- .../SetupWizard/SetupWizardPageView.axaml | 4 +- .../UI/SetupWizard/RyujinxSetupWizard.cs | 9 ++- 6 files changed, 87 insertions(+), 102 deletions(-) create mode 100644 src/Ryujinx/Systems/SetupWizard/SetupWizardPage.Builder.cs delete mode 100644 src/Ryujinx/Systems/SetupWizard/SetupWizardPageBuilder.cs diff --git a/src/Ryujinx/Systems/SetupWizard/BaseSetupWizard.cs b/src/Ryujinx/Systems/SetupWizard/BaseSetupWizard.cs index 7da662207..93fb02a64 100644 --- a/src/Ryujinx/Systems/SetupWizard/BaseSetupWizard.cs +++ b/src/Ryujinx/Systems/SetupWizard/BaseSetupWizard.cs @@ -11,18 +11,10 @@ namespace Ryujinx.Ava.Systems.SetupWizard /// public abstract Task Start(); - protected ValueTask FirstPage() - { - SetupWizardPageBuilder builder = new(presenter, isFirstPage: true); + protected SetupWizardPage FirstPage() + => new(presenter, isFirstPage: true); - return builder - .WithTitle(LocaleKeys.SetupWizardFirstPageTitle) - .WithContent(LocaleKeys.SetupWizardFirstPageContent) - .WithActionContent(LocaleKeys.SetupWizardFirstPageAction) - .Show(); - } - - protected SetupWizardPageBuilder NextPage() + protected SetupWizardPage NextPage() => new(presenter); } } diff --git a/src/Ryujinx/Systems/SetupWizard/SetupWizardPage.Builder.cs b/src/Ryujinx/Systems/SetupWizard/SetupWizardPage.Builder.cs new file mode 100644 index 000000000..e12df291b --- /dev/null +++ b/src/Ryujinx/Systems/SetupWizard/SetupWizardPage.Builder.cs @@ -0,0 +1,66 @@ +using Avalonia; +using Avalonia.Controls; +using Ryujinx.Ava.Common.Locale; +using Ryujinx.Ava.UI.Controls; +using Ryujinx.Ava.UI.ViewModels; + +namespace Ryujinx.Ava.Systems.SetupWizard +{ + public partial class SetupWizardPage + { + public SetupWizardPage WithTitle(LocaleKeys title) => WithTitle(LocaleManager.Instance[title]); + + public SetupWizardPage WithTitle(string title) + { + Title = title; + return this; + } + + public SetupWizardPage WithContent(LocaleKeys content) => WithContent(LocaleManager.Instance[content]); + + public SetupWizardPage WithContent(object? content) + { + if (content is StyledElement { Parent: ContentControl parent }) + { + parent.Content = null; + } + + Content = content; + return this; + } + + public SetupWizardPage WithHelpContent(LocaleKeys content) => + WithHelpContent(LocaleManager.Instance[content]); + + public SetupWizardPage WithHelpContent(object? content) + { + HelpContent = content; + return this; + } + + public SetupWizardPage WithContent(object? context = null) where TControl : Control, new() + { + Content = new TControl { DataContext = context }; + + return this; + } + + public SetupWizardPage WithContent(out TViewModel boundViewModel) + where TControl : RyujinxControl, new() + where TViewModel : BaseModel, new() + { + boundViewModel = new(); + + return WithContent(boundViewModel); + } + + public SetupWizardPage WithActionContent(LocaleKeys content) => + WithActionContent(LocaleManager.Instance[content]); + + public SetupWizardPage WithActionContent(object? content) + { + ActionContent = content; + return this; + } + } +} diff --git a/src/Ryujinx/Systems/SetupWizard/SetupWizardPage.cs b/src/Ryujinx/Systems/SetupWizard/SetupWizardPage.cs index 5681ec90a..c96664fed 100644 --- a/src/Ryujinx/Systems/SetupWizard/SetupWizardPage.cs +++ b/src/Ryujinx/Systems/SetupWizard/SetupWizardPage.cs @@ -8,10 +8,10 @@ using System.Threading.Tasks; namespace Ryujinx.Ava.Systems.SetupWizard { - public partial class SetupWizardPage(bool isFirstPage = false) : BaseModel + public partial class SetupWizardPage(ContentPresenter contentPresenter, bool isFirstPage = false) : BaseModel { - protected bool? _result; - protected readonly CancellationTokenSource _cancellationTokenSource = new(); + private bool? _result; + private readonly CancellationTokenSource _cts = new(); public bool IsFirstPage { get; } = isFirstPage; @@ -30,23 +30,23 @@ namespace Ryujinx.Ava.Systems.SetupWizard private void MoveBack() { _result = false; - _cancellationTokenSource.Cancel(); + _cts.Cancel(); } [RelayCommand] private void MoveNext() { _result = true; - _cancellationTokenSource.Cancel(); + _cts.Cancel(); } - public async ValueTask Show(ContentPresenter presenter) + public async ValueTask Show() { - presenter.Content = new SetupWizardPageView { DataContext = this, }; + contentPresenter.Content = new SetupWizardPageView { ViewModel = this }; try { - await Task.Delay(-1, _cancellationTokenSource.Token); + await Task.Delay(-1, _cts.Token); } catch (TaskCanceledException) { diff --git a/src/Ryujinx/Systems/SetupWizard/SetupWizardPageBuilder.cs b/src/Ryujinx/Systems/SetupWizard/SetupWizardPageBuilder.cs deleted file mode 100644 index d87e31e0c..000000000 --- a/src/Ryujinx/Systems/SetupWizard/SetupWizardPageBuilder.cs +++ /dev/null @@ -1,80 +0,0 @@ -using Avalonia; -using Avalonia.Controls; -using Avalonia.Controls.Presenters; -using Ryujinx.Ava.Common.Locale; -using Ryujinx.Ava.UI.Controls; -using Ryujinx.Ava.UI.ViewModels; -using System.Threading.Tasks; - -namespace Ryujinx.Ava.Systems.SetupWizard -{ - public class SetupWizardPageBuilder(ContentPresenter presenter, bool isFirstPage = false) - { - private readonly SetupWizardPage _page = new(isFirstPage); - - public SetupWizardPage Build() - { - return _page; - } - - public SetupWizardPageBuilder WithTitle(LocaleKeys title) => WithTitle(LocaleManager.Instance[title]); - - public SetupWizardPageBuilder WithTitle(string title) - { - _page.Title = title; - return this; - } - - public SetupWizardPageBuilder WithContent(LocaleKeys content) => WithContent(LocaleManager.Instance[content]); - - public SetupWizardPageBuilder WithContent(object? content) - { - if (content is StyledElement { Parent: ContentControl parent }) - { - parent.Content = null; - } - - _page.Content = content; - return this; - } - - public SetupWizardPageBuilder WithHelpContent(LocaleKeys content) => - WithHelpContent(LocaleManager.Instance[content]); - - public SetupWizardPageBuilder WithHelpContent(object? content) - { - _page.HelpContent = content; - return this; - } - - public SetupWizardPageBuilder WithContent(object? context = null) where TControl : Control, new() - { - _page.Content = new TControl { DataContext = context }; - - return this; - } - - public SetupWizardPageBuilder WithContent(out TViewModel boundViewModel) - where TControl : RyujinxControl, new() - where TViewModel : BaseModel, new() - { - boundViewModel = new(); - - return WithContent(boundViewModel); - } - - public SetupWizardPageBuilder WithActionContent(LocaleKeys content) => - WithActionContent(LocaleManager.Instance[content]); - - public SetupWizardPageBuilder WithActionContent(object? content) - { - _page.ActionContent = content; - return this; - } - - public ValueTask Show() - { - return _page.Show(presenter); - } - } -} diff --git a/src/Ryujinx/Systems/SetupWizard/SetupWizardPageView.axaml b/src/Ryujinx/Systems/SetupWizard/SetupWizardPageView.axaml index 99eb4d071..9b451fa0d 100644 --- a/src/Ryujinx/Systems/SetupWizard/SetupWizardPageView.axaml +++ b/src/Ryujinx/Systems/SetupWizard/SetupWizardPageView.axaml @@ -27,7 +27,7 @@ - + @@ -53,7 +53,7 @@ Padding="6"> - +