Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to toggle all free mods quickly at multiplayer song select #24294

Merged
merged 4 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public override void SetUpSteps()
AddUntilStep("wait for present", () => songSelect.IsCurrentScreen() && songSelect.BeatmapSetsLoaded);
}

[Test]
public void TestSelectFreeMods()
{
AddStep("set some freemods", () => songSelect.FreeMods.Value = new OsuRuleset().GetModsFor(ModType.Fun).ToArray());
AddStep("set all freemods", () => songSelect.FreeMods.Value = new OsuRuleset().CreateAllMods().ToArray());
AddStep("set no freemods", () => songSelect.FreeMods.Value = Array.Empty<Mod>());
}

[Test]
public void TestBeatmapConfirmed()
{
Expand Down
10 changes: 5 additions & 5 deletions osu.Game/Overlays/Mods/ModSelectOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected virtual IEnumerable<ShearedButton> CreateFooterButtons()

private readonly Bindable<Dictionary<ModType, IReadOnlyList<Mod>>> globalAvailableMods = new Bindable<Dictionary<ModType, IReadOnlyList<Mod>>>();

private IEnumerable<ModState> allAvailableMods => AvailableMods.Value.SelectMany(pair => pair.Value);
public IEnumerable<ModState> AllAvailableMods => AvailableMods.Value.SelectMany(pair => pair.Value);

private readonly BindableBool customisationVisible = new BindableBool();

Expand Down Expand Up @@ -382,7 +382,7 @@ private void createLocalMods()

private void filterMods()
{
foreach (var modState in allAvailableMods)
foreach (var modState in AllAvailableMods)
modState.ValidForSelection.Value = modState.Mod.HasImplementation && IsValidMod.Invoke(modState.Mod);
}

Expand All @@ -407,7 +407,7 @@ private void updateCustomisation()
bool anyCustomisableModActive = false;
bool anyModPendingConfiguration = false;

foreach (var modState in allAvailableMods)
foreach (var modState in AllAvailableMods)
{
anyCustomisableModActive |= modState.Active.Value && modState.Mod.GetSettingsSourceProperties().Any();
anyModPendingConfiguration |= modState.PendingConfiguration;
Expand Down Expand Up @@ -464,7 +464,7 @@ private void updateFromExternalSelection()

var newSelection = new List<Mod>();

foreach (var modState in allAvailableMods)
foreach (var modState in AllAvailableMods)
{
var matchingSelectedMod = SelectedMods.Value.SingleOrDefault(selected => selected.GetType() == modState.Mod.GetType());

Expand All @@ -491,7 +491,7 @@ private void updateFromInternalSelection()
if (externalSelectionUpdateInProgress)
return;

var candidateSelection = allAvailableMods.Where(modState => modState.Active.Value)
var candidateSelection = AllAvailableMods.Where(modState => modState.Active.Value)
.Select(modState => modState.Mod)
.ToArray();

Expand Down
109 changes: 91 additions & 18 deletions osu.Game/Screens/OnlinePlay/FooterButtonFreeMods.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,82 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Select;
using osuTK;

namespace osu.Game.Screens.OnlinePlay
{
public partial class FooterButtonFreeMods : FooterButton, IHasCurrentValue<IReadOnlyList<Mod>>
{
public Bindable<IReadOnlyList<Mod>> Current
public Bindable<IReadOnlyList<Mod>> Current { get; set; } = new BindableWithCurrent<IReadOnlyList<Mod>>();

private OsuSpriteText count = null!;

private Circle circle = null!;

private readonly FreeModSelectOverlay freeModSelectOverlay;

public FooterButtonFreeMods(FreeModSelectOverlay freeModSelectOverlay)
{
get => modDisplay.Current;
set => modDisplay.Current = value;
this.freeModSelectOverlay = freeModSelectOverlay;
}

private readonly ModDisplay modDisplay;
[Resolved]
private OsuColour colours { get; set; } = null!;

public FooterButtonFreeMods()
[BackgroundDependencyLoader]
private void load()
{
ButtonContentContainer.Add(modDisplay = new ModDisplay
ButtonContentContainer.AddRange(new[]
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.8f),
ExpansionMode = ExpansionMode.AlwaysContracted,
new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
circle = new Circle
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = colours.YellowDark,
RelativeSizeAxes = Axes.Both,
},
count = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Padding = new MarginPadding(5),
UseFullGlyphHeight = false,
}
}
},
new IconButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.8f),
Icon = FontAwesome.Solid.Bars,
Action = () => freeModSelectOverlay.ToggleVisibility()
}
});
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
SelectedColour = colours.Yellow;
DeselectedColour = SelectedColour.Opacity(0.5f);
Text = @"freemods";
Expand All @@ -49,14 +87,49 @@ protected override void LoadComplete()
base.LoadComplete();

Current.BindValueChanged(_ => updateModDisplay(), true);

// Overwrite any external behaviour as we delegate the main toggle action to a sub-button.
Action = toggleAllFreeMods;
}

/// <summary>
/// Immediately toggle all free mods on/off.
/// </summary>
private void toggleAllFreeMods()
{
var availableMods = allAvailableAndValidMods.ToArray();

Current.Value = Current.Value.Count == availableMods.Length
? Array.Empty<Mod>()
: availableMods;
}

private void updateModDisplay()
{
if (Current.Value?.Count > 0)
modDisplay.FadeIn();
int current = Current.Value.Count;

if (current == allAvailableAndValidMods.Count())
{
count.Text = "all";
count.FadeColour(colours.Gray2, 200, Easing.OutQuint);
circle.FadeColour(colours.Yellow, 200, Easing.OutQuint);
}
else if (current > 0)
{
count.Text = $"{current} mods";
count.FadeColour(colours.Gray2, 200, Easing.OutQuint);
circle.FadeColour(colours.YellowDark, 200, Easing.OutQuint);
}
else
modDisplay.FadeOut();
{
count.Text = "off";
count.FadeColour(colours.GrayF, 200, Easing.OutQuint);
circle.FadeColour(colours.Gray4, 200, Easing.OutQuint);
}
}

private IEnumerable<Mod> allAvailableAndValidMods => freeModSelectOverlay.AllAvailableMods
.Where(state => state.ValidForSelection.Value)
.Select(state => state.Mod);
}
}
9 changes: 6 additions & 3 deletions osu.Game/Screens/OnlinePlay/OnlinePlaySongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,12 @@ public override bool OnExiting(ScreenExitEvent e)

protected override IEnumerable<(FooterButton, OverlayContainer?)> CreateFooterButtons()
{
var buttons = base.CreateFooterButtons().ToList();
buttons.Insert(buttons.FindIndex(b => b.Item1 is FooterButtonMods) + 1, (new FooterButtonFreeMods { Current = FreeMods }, freeModSelectOverlay));
return buttons;
var baseButtons = base.CreateFooterButtons().ToList();
var freeModsButton = new FooterButtonFreeMods(freeModSelectOverlay) { Current = FreeMods };

baseButtons.Insert(baseButtons.FindIndex(b => b.Item1 is FooterButtonMods) + 1, (freeModsButton, freeModSelectOverlay));

return baseButtons;
}

/// <summary>
Expand Down