1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 19:57:24 +08:00
osu-lazer/osu.Game/Screens/Select/FooterButtonMods.cs

90 lines
2.9 KiB
C#
Raw Normal View History

2019-05-08 17:43:15 +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 osu.Framework.Bindables;
using osu.Framework.Graphics;
2019-04-14 07:22:31 +08:00
using osu.Game.Screens.Play.HUD;
using osu.Game.Rulesets.Mods;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
2019-07-17 13:46:25 +08:00
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
using osuTK.Graphics;
using osu.Game.Input.Bindings;
namespace osu.Game.Screens.Select
{
public class FooterButtonMods : FooterButton, IHasCurrentValue<IReadOnlyList<Mod>>
{
2019-07-17 13:46:25 +08:00
public Bindable<IReadOnlyList<Mod>> Current
{
2019-07-17 13:46:25 +08:00
get => modDisplay.Current;
set => modDisplay.Current = value;
}
protected readonly OsuSpriteText MultiplierText;
private readonly ModDisplay modDisplay;
private Color4 lowMultiplierColour;
private Color4 highMultiplierColour;
2019-04-14 07:55:15 +08:00
2019-07-17 13:46:25 +08:00
public FooterButtonMods()
{
ButtonContentContainer.Add(modDisplay = new ModDisplay
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
DisplayUnrankedText = false,
Scale = new Vector2(0.8f),
ExpansionMode = ExpansionMode.AlwaysContracted,
});
ButtonContentContainer.Add(MultiplierText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(weight: FontWeight.Bold),
});
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
SelectedColour = colours.Yellow;
DeselectedColour = SelectedColour.Opacity(0.5f);
lowMultiplierColour = colours.Red;
highMultiplierColour = colours.Green;
Text = @"mods";
Hotkey = GlobalAction.ToggleModSelection;
}
protected override void LoadComplete()
{
base.LoadComplete();
Current.BindValueChanged(_ => updateMultiplierText(), true);
}
private void updateMultiplierText()
{
2019-12-18 20:30:57 +08:00
double multiplier = Current.Value?.Aggregate(1.0, (current, mod) => current * mod.ScoreMultiplier) ?? 1;
MultiplierText.Text = multiplier.Equals(1.0) ? string.Empty : $"{multiplier:N2}x";
if (multiplier > 1.0)
MultiplierText.FadeColour(highMultiplierColour, 200);
else if (multiplier < 1.0)
MultiplierText.FadeColour(lowMultiplierColour, 200);
else
MultiplierText.FadeColour(Color4.White, 200);
if (Current.Value?.Count > 0)
modDisplay.FadeIn();
else
modDisplay.FadeOut();
}
}
}