From 4a1401a33df7c3b489c6c0db05b68f6f1fe31079 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Thu, 28 Nov 2024 02:37:27 -0500 Subject: [PATCH] Rewrite bindable flow to make more sense --- .../Edit/Setup/FormBeatmapFileSelector.cs | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/osu.Game/Screens/Edit/Setup/FormBeatmapFileSelector.cs b/osu.Game/Screens/Edit/Setup/FormBeatmapFileSelector.cs index 6af78f24f8..3e5f0f4306 100644 --- a/osu.Game/Screens/Edit/Setup/FormBeatmapFileSelector.cs +++ b/osu.Game/Screens/Edit/Setup/FormBeatmapFileSelector.cs @@ -40,13 +40,7 @@ namespace osu.Game.Screens.Edit.Setup protected override FileChooserPopover CreatePopover(string[] handledExtensions, Bindable current, string? chooserPath) { var popover = new BeatmapFileChooserPopover(handledExtensions, current, chooserPath, beatmapHasMultipleDifficulties); - - popover.ApplyToAllDifficulties.ValueChanged += v => - { - Debug.Assert(v.NewValue != null); - ApplyToAllDifficulties.Value = v.NewValue.Value; - }; - + popover.ApplyToAllDifficulties.BindTo(ApplyToAllDifficulties); return popover; } @@ -54,7 +48,7 @@ namespace osu.Game.Screens.Edit.Setup { private readonly bool beatmapHasMultipleDifficulties; - public readonly Bindable ApplyToAllDifficulties = new Bindable(); + public readonly Bindable ApplyToAllDifficulties = new Bindable(true); private Container selectApplicationScopeContainer = null!; @@ -115,7 +109,11 @@ namespace osu.Game.Screens.Edit.Setup Origin = Anchor.Centre, Width = 300f, Text = "Apply to all difficulties", - Action = () => ApplyToAllDifficulties.Value = true, + Action = () => + { + ApplyToAllDifficulties.Value = true; + updateFileSelection(); + }, BackgroundColour = colours.Red2, }, new RoundedButton @@ -124,7 +122,11 @@ namespace osu.Game.Screens.Edit.Setup Origin = Anchor.Centre, Width = 300f, Text = "Only apply to this difficulty", - Action = () => ApplyToAllDifficulties.Value = false, + Action = () => + { + ApplyToAllDifficulties.Value = false; + updateFileSelection(); + }, }, } } @@ -134,12 +136,6 @@ namespace osu.Game.Screens.Edit.Setup }); } - protected override void LoadComplete() - { - base.LoadComplete(); - ApplyToAllDifficulties.ValueChanged += onChangeScopeSelected; - } - protected override void OnFileSelected(FileInfo file) { if (beatmapHasMultipleDifficulties) @@ -148,11 +144,8 @@ namespace osu.Game.Screens.Edit.Setup base.OnFileSelected(file); } - private void onChangeScopeSelected(ValueChangedEvent c) + private void updateFileSelection() { - if (c.NewValue == null) - return; - Debug.Assert(FileSelector.CurrentFile.Value != null); base.OnFileSelected(FileSelector.CurrentFile.Value); }