diff --git a/osu.Game.Tests/Visual/Playlists/TestSceneFooterButtonFreeModsV2.cs b/osu.Game.Tests/Visual/Playlists/TestSceneFooterButtonFreeModsV2.cs index 7eb82d5fd1..222b9a80f8 100644 --- a/osu.Game.Tests/Visual/Playlists/TestSceneFooterButtonFreeModsV2.cs +++ b/osu.Game.Tests/Visual/Playlists/TestSceneFooterButtonFreeModsV2.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Linq; +using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Overlays; @@ -16,20 +17,36 @@ namespace osu.Game.Tests.Visual.Playlists [Cached] private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine); + private readonly FooterButtonFreeModsV2 button; + public TestSceneFooterButtonFreeModsV2() { ModSelectOverlay modSelectOverlay; Add(modSelectOverlay = new TestModSelectOverlay()); - - FooterButtonFreeModsV2 button; Add(button = new FooterButtonFreeModsV2(modSelectOverlay) { Anchor = Anchor.Centre, Origin = Anchor.CentreLeft, X = -100, }); + } - button.FreeMods.Value = new OsuRuleset().CreateAllMods().ToArray(); + [Test] + public void TestAllMods() + { + AddStep("all mods", () => button.FreeMods.Value = new OsuRuleset().CreateAllMods().ToArray()); + } + + [Test] + public void TestNoMods() + { + AddStep("no mods", () => button.FreeMods.Value = []); + } + + [Test] + public void TestFreestyle() + { + AddToggleStep("toggle freestyle", v => button.Freestyle.Value = v); } private partial class TestModSelectOverlay : UserModSelectOverlay diff --git a/osu.Game/Screens/OnlinePlay/FooterButtonFreeModsV2.cs b/osu.Game/Screens/OnlinePlay/FooterButtonFreeModsV2.cs index 37755cd326..d9cb0acb4f 100644 --- a/osu.Game/Screens/OnlinePlay/FooterButtonFreeModsV2.cs +++ b/osu.Game/Screens/OnlinePlay/FooterButtonFreeModsV2.cs @@ -27,8 +27,8 @@ namespace osu.Game.Screens.OnlinePlay { private const float bar_height = 30f; - public readonly Bindable> FreeMods = new Bindable>(); - public readonly IBindable Freestyle = new Bindable(); + public readonly Bindable> FreeMods = new Bindable>([]); + public readonly Bindable Freestyle = new Bindable(); public new Action Action { @@ -104,7 +104,11 @@ namespace osu.Game.Screens.OnlinePlay Current = { BindTarget = FreeMods }, ExpansionMode = ExpansionMode.AlwaysContracted, }, - overflowModCountDisplay = new ModCountText { Mods = { BindTarget = FreeMods }, }, + overflowModCountDisplay = new ModCountText + { + Mods = { BindTarget = FreeMods }, + Freestyle = { BindTarget = Freestyle } + }, } }, } @@ -135,6 +139,7 @@ namespace osu.Game.Screens.OnlinePlay private partial class ModCountText : CompositeDrawable { public readonly Bindable> Mods = new Bindable>(); + public readonly Bindable Freestyle = new Bindable(); private OsuSpriteText text = null!; @@ -164,7 +169,18 @@ namespace osu.Game.Screens.OnlinePlay } }; - Mods.BindValueChanged(v => text.Text = ModSelectOverlayStrings.Mods(v.NewValue.Count).ToUpper(), true); + Mods.BindValueChanged(_ => updateText()); + Freestyle.BindValueChanged(_ => updateText()); + + updateText(); + } + + private void updateText() + { + if (Freestyle.Value) + text.Text = "ALL MODS"; + else + text.Text = ModSelectOverlayStrings.Mods(Mods.Value.Count).ToUpper(); } } } diff --git a/osu.Game/Screens/OnlinePlay/FooterButtonFreestyleV2.cs b/osu.Game/Screens/OnlinePlay/FooterButtonFreestyleV2.cs index 5381c64cc4..6d39ee92e7 100644 --- a/osu.Game/Screens/OnlinePlay/FooterButtonFreestyleV2.cs +++ b/osu.Game/Screens/OnlinePlay/FooterButtonFreestyleV2.cs @@ -14,6 +14,7 @@ using osu.Game.Graphics.Sprites; using osu.Game.Overlays; using osu.Game.Screens.Footer; using osuTK; +using osuTK.Graphics; namespace osu.Game.Screens.OnlinePlay { @@ -34,6 +35,9 @@ namespace osu.Game.Screens.OnlinePlay [Resolved] private OverlayColourProvider colourProvider { get; set; } = null!; + private Drawable statusBackground = null!; + private OsuSpriteText statusText = null!; + public FooterButtonFreestyleV2() { // Overwrite any external behaviour as we delegate the main toggle action to a sub-button. @@ -66,56 +70,44 @@ namespace osu.Game.Screens.OnlinePlay Colour = Colour4.Black.Opacity(0.25f), Offset = new Vector2(0, 2), }, - Children = new Drawable[] + Children = new[] { - new Box + statusBackground = new Box { Colour = colourProvider.Background3, RelativeSizeAxes = Axes.Both, }, - new StatusText { Freestyle = { BindTarget = Freestyle } } + statusText = new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.Torus.With(size: 14f, weight: FontWeight.Bold), + Shear = -OsuGame.SHEAR, + }, } }, }); } - private partial class StatusText : CompositeDrawable + protected override void LoadComplete() { - public readonly Bindable Freestyle = new Bindable(); + base.LoadComplete(); - private OsuSpriteText text = null!; - - [Resolved] - private OverlayColourProvider colourProvider { get; set; } = null!; - - protected override void LoadComplete() + Freestyle.BindValueChanged(v => { - base.LoadComplete(); - - RelativeSizeAxes = Axes.Both; - - InternalChildren = new Drawable[] + if (v.NewValue) { - new Box - { - Colour = colourProvider.Background3, - Alpha = 0.8f, - RelativeSizeAxes = Axes.Both, - }, - text = new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Font = OsuFont.Torus.With(size: 14f, weight: FontWeight.Bold), - Shear = -OsuGame.SHEAR, - } - }; - - Freestyle.BindValueChanged(v => + statusBackground.Colour = colours.Yellow; + statusText.Text = "ON"; + statusText.Colour = Color4.Black; + } + else { - text.Text = v.NewValue ? "ON" : "OFF"; - }, true); - } + statusBackground.Colour = colourProvider.Background3; + statusText.Text = "OFF"; + statusText.Colour = Color4.White; + } + }, true); } } }