1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 06:47:24 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/FooterButtonFreeMods.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

133 lines
4.5 KiB
C#
Raw Normal View History

2021-02-01 17:08:49 +08:00
// 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;
2021-02-01 17:08:49 +08:00
using System.Collections.Generic;
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;
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;
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
{
public partial class FooterButtonFreeMods : FooterButton, IHasCurrentValue<IReadOnlyList<Mod>>
{
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
{
this.freeModSelectOverlay = freeModSelectOverlay;
2021-02-01 17:08:49 +08:00
}
[Resolved]
private OsuColour colours { get; set; } = null!;
2021-02-01 17:08:49 +08:00
[BackgroundDependencyLoader]
private void load()
2021-02-01 17:08:49 +08:00
{
ButtonContentContainer.AddRange(new[]
2021-02-01 17:08:49 +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);
// 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;
2021-02-01 17:08:49 +08:00
}
private void updateModDisplay()
{
int current = Current.Value.Count;
if (current == allAvailableAndValidMods.Count())
{
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
{
count.Text = "off";
circle.FadeColour(colours.Gray4, 200, Easing.OutQuint);
}
2021-02-01 17:08:49 +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
}
}