1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 21:02:55 +08:00
osu-lazer/osu.Game/Screens/Select/FooterButtonMods.cs

107 lines
3.4 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.
2022-06-17 15:37:17 +08:00
#nullable disable
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 JetBrains.Annotations;
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.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
using osuTK.Graphics;
using osu.Game.Input.Bindings;
namespace osu.Game.Screens.Select
{
2022-11-24 13:32:20 +08:00
public partial 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,
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;
}
[CanBeNull]
private ModSettingChangeTracker modSettingChangeTracker;
protected override void LoadComplete()
{
base.LoadComplete();
Current.BindValueChanged(mods =>
{
modSettingChangeTracker?.Dispose();
updateMultiplierText();
2022-07-18 15:09:14 +08:00
if (mods.NewValue != null)
{
modSettingChangeTracker = new ModSettingChangeTracker(mods.NewValue);
modSettingChangeTracker.SettingChanged += _ => updateMultiplierText();
}
}, true);
}
private void updateMultiplierText() => Schedule(() =>
{
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();
});
}
}