2019-05-08 17:43:15 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-04-10 21:53:13 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2019-04-10 21:53:13 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
2019-04-14 07:22:31 +08:00
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
2019-04-10 21:53:13 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using System.Collections.Generic;
|
2022-02-17 12:26:12 +08:00
|
|
|
|
using System.Linq;
|
2022-07-18 12:38:56 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2019-05-08 18:03:26 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2019-07-17 13:46:25 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2022-07-18 12:38:56 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2019-05-08 18:03:26 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2022-02-17 12:26:12 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2019-04-10 21:53:13 +08:00
|
|
|
|
using osuTK;
|
2022-02-17 12:26:12 +08:00
|
|
|
|
using osuTK.Graphics;
|
2020-06-04 11:25:05 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2019-04-10 21:53:13 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class FooterButtonMods : FooterButton, IHasCurrentValue<IReadOnlyList<Mod>>
|
2019-04-10 21:53:13 +08:00
|
|
|
|
{
|
2019-07-17 13:46:25 +08:00
|
|
|
|
public Bindable<IReadOnlyList<Mod>> Current
|
2019-04-10 21:53:13 +08:00
|
|
|
|
{
|
2019-07-17 13:46:25 +08:00
|
|
|
|
get => modDisplay.Current;
|
|
|
|
|
set => modDisplay.Current = value;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 12:26:12 +08:00
|
|
|
|
protected readonly OsuSpriteText MultiplierText;
|
2020-04-06 05:57:44 +08:00
|
|
|
|
private readonly ModDisplay modDisplay;
|
2022-02-17 12:26:12 +08:00
|
|
|
|
private Color4 lowMultiplierColour;
|
|
|
|
|
private Color4 highMultiplierColour;
|
2019-04-14 07:55:15 +08:00
|
|
|
|
|
2019-07-17 13:46:25 +08:00
|
|
|
|
public FooterButtonMods()
|
|
|
|
|
{
|
2020-04-06 05:57:44 +08:00
|
|
|
|
ButtonContentContainer.Add(modDisplay = new ModDisplay
|
2019-04-10 21:53:13 +08:00
|
|
|
|
{
|
2019-12-31 06:58:49 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2020-04-06 05:57:44 +08:00
|
|
|
|
Scale = new Vector2(0.8f),
|
|
|
|
|
ExpansionMode = ExpansionMode.AlwaysContracted,
|
2019-12-31 06:58:49 +08:00
|
|
|
|
});
|
2022-02-17 12:26:12 +08:00
|
|
|
|
ButtonContentContainer.Add(MultiplierText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold),
|
|
|
|
|
});
|
2019-04-10 21:53:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-08 18:03:26 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
SelectedColour = colours.Yellow;
|
|
|
|
|
DeselectedColour = SelectedColour.Opacity(0.5f);
|
2022-02-17 12:26:12 +08:00
|
|
|
|
lowMultiplierColour = colours.Red;
|
|
|
|
|
highMultiplierColour = colours.Green;
|
2019-05-08 18:03:26 +08:00
|
|
|
|
Text = @"mods";
|
2020-06-04 11:25:05 +08:00
|
|
|
|
Hotkey = GlobalAction.ToggleModSelection;
|
2019-05-08 18:03:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-18 12:38:56 +08:00
|
|
|
|
[CanBeNull]
|
|
|
|
|
private ModSettingChangeTracker modSettingChangeTracker;
|
|
|
|
|
|
2019-12-18 20:08:38 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2022-07-18 12:38:56 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
2022-07-18 12:38:56 +08:00
|
|
|
|
}, true);
|
2019-12-18 20:08:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-13 18:18:38 +08:00
|
|
|
|
private void updateMultiplierText() => Schedule(() =>
|
2019-11-28 13:01:40 +08:00
|
|
|
|
{
|
2022-02-17 12:26:12 +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);
|
|
|
|
|
|
2019-12-31 19:21:55 +08:00
|
|
|
|
if (Current.Value?.Count > 0)
|
2020-01-30 10:00:14 +08:00
|
|
|
|
modDisplay.FadeIn();
|
2019-12-31 19:21:55 +08:00
|
|
|
|
else
|
2020-01-30 10:00:14 +08:00
|
|
|
|
modDisplay.FadeOut();
|
2022-07-13 18:18:38 +08:00
|
|
|
|
});
|
2019-04-10 21:53:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|