From 3e326a9234cb99d743f8ae80de42d85b4a43428c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 14 Oct 2020 15:21:28 +0900 Subject: [PATCH] Use bindable flow for event propagation --- osu.Game/Overlays/Mods/ModSelectOverlay.cs | 5 +++-- .../Overlays/Mods/ModSettingsContainer.cs | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index 2d8b4dba7c..31adf47456 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -289,8 +289,11 @@ namespace osu.Game.Overlays.Mods Width = 0.25f, Alpha = 0, X = -100, + SelectedMods = { BindTarget = SelectedMods }, } }; + + ((IBindable)CustomiseButton.Enabled).BindTo(ModSettingsContainer.HasSettingsForSelection); } [BackgroundDependencyLoader(true)] @@ -399,8 +402,6 @@ namespace osu.Game.Overlays.Mods section.SelectTypes(mods.NewValue.Select(m => m.GetType()).ToList()); updateMods(); - - CustomiseButton.Enabled.Value = ModSettingsContainer.UpdateModSettings(mods); } private void updateMods() diff --git a/osu.Game/Overlays/Mods/ModSettingsContainer.cs b/osu.Game/Overlays/Mods/ModSettingsContainer.cs index 0521bc35b8..b185b56ecd 100644 --- a/osu.Game/Overlays/Mods/ModSettingsContainer.cs +++ b/osu.Game/Overlays/Mods/ModSettingsContainer.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Bindables; @@ -18,6 +19,12 @@ namespace osu.Game.Overlays.Mods { public class ModSettingsContainer : Container { + public readonly IBindable> SelectedMods = new Bindable>(Array.Empty()); + + public IBindable HasSettingsForSelection => hasSettingsForSelection; + + private readonly Bindable hasSettingsForSelection = new Bindable(); + private readonly FillFlowContainer modSettingsContent; public ModSettingsContainer() @@ -45,8 +52,14 @@ namespace osu.Game.Overlays.Mods }; } - ///Bool indicating whether any settings are listed - public bool UpdateModSettings(ValueChangedEvent> mods) + protected override void LoadComplete() + { + base.LoadComplete(); + + SelectedMods.BindValueChanged(modsChanged, true); + } + + private void modsChanged(ValueChangedEvent> mods) { modSettingsContent.Clear(); @@ -62,7 +75,7 @@ namespace osu.Game.Overlays.Mods if (!hasSettings) Hide(); - return hasSettings; + hasSettingsForSelection.Value = hasSettings; } protected override bool OnMouseDown(MouseDownEvent e) => true;