2023-06-23 00:37:25 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2021-02-01 17:08:49 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2023-07-19 18:08:32 +08:00
|
|
|
|
using System;
|
2021-02-01 17:08:49 +08:00
|
|
|
|
using System.Collections.Generic;
|
2023-07-19 18:08:32 +08:00
|
|
|
|
using System.Linq;
|
2021-02-01 17:08:49 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
2023-07-19 18:08:32 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-02-01 17:08:49 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Graphics;
|
2023-07-19 18:08:32 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-02-01 17:08:49 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osu.Game.Screens.Select;
|
|
|
|
|
using osuTK;
|
|
|
|
|
|
2021-02-02 20:46:22 +08:00
|
|
|
|
namespace osu.Game.Screens.OnlinePlay
|
2021-02-01 17:08:49 +08:00
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class FooterButtonFreeMods : FooterButton, IHasCurrentValue<IReadOnlyList<Mod>>
|
2021-02-01 17:08:49 +08:00
|
|
|
|
{
|
2023-07-19 18:08:32 +08:00
|
|
|
|
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)
|
2021-02-01 17:08:49 +08:00
|
|
|
|
{
|
2023-07-19 18:08:32 +08:00
|
|
|
|
this.freeModSelectOverlay = freeModSelectOverlay;
|
2021-02-01 17:08:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-19 18:08:32 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
2021-02-01 17:08:49 +08:00
|
|
|
|
|
2023-07-19 18:08:32 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2021-02-01 17:08:49 +08:00
|
|
|
|
{
|
2023-07-19 18:08:32 +08:00
|
|
|
|
ButtonContentContainer.AddRange(new[]
|
2021-02-01 17:08:49 +08:00
|
|
|
|
{
|
2023-07-19 18:08:32 +08:00
|
|
|
|
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()
|
|
|
|
|
}
|
2021-02-01 17:08:49 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
SelectedColour = colours.Yellow;
|
|
|
|
|
DeselectedColour = SelectedColour.Opacity(0.5f);
|
|
|
|
|
Text = @"freemods";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
Current.BindValueChanged(_ => updateModDisplay(), true);
|
2023-07-19 18:08:32 +08:00
|
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
{
|
2023-07-20 11:58:13 +08:00
|
|
|
|
var availableMods = allAvailableAndValidMods.ToArray();
|
2023-07-19 18:08:32 +08:00
|
|
|
|
|
|
|
|
|
Current.Value = Current.Value.Count == availableMods.Length
|
|
|
|
|
? Array.Empty<Mod>()
|
|
|
|
|
: availableMods;
|
2021-02-01 17:08:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateModDisplay()
|
|
|
|
|
{
|
2023-07-19 18:08:32 +08:00
|
|
|
|
int current = Current.Value.Count;
|
|
|
|
|
|
2023-07-20 11:58:13 +08:00
|
|
|
|
if (current == allAvailableAndValidMods.Count())
|
2023-07-19 18:08:32 +08:00
|
|
|
|
{
|
|
|
|
|
count.Text = "all";
|
|
|
|
|
circle.FadeColour(colours.Yellow, 200, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
else if (current > 0)
|
|
|
|
|
{
|
|
|
|
|
count.Text = $"{current} mods";
|
|
|
|
|
circle.FadeColour(colours.YellowDark, 200, Easing.OutQuint);
|
|
|
|
|
}
|
2021-02-01 17:08:49 +08:00
|
|
|
|
else
|
2023-07-19 18:08:32 +08:00
|
|
|
|
{
|
|
|
|
|
count.Text = "off";
|
|
|
|
|
circle.FadeColour(colours.Gray4, 200, Easing.OutQuint);
|
|
|
|
|
}
|
2021-02-01 17:08:49 +08:00
|
|
|
|
}
|
2023-07-20 11:58:13 +08:00
|
|
|
|
|
|
|
|
|
private IEnumerable<Mod> allAvailableAndValidMods => freeModSelectOverlay.AllAvailableMods
|
|
|
|
|
.Where(state => state.ValidForSelection.Value)
|
|
|
|
|
.Select(state => state.Mod);
|
2021-02-01 17:08:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|