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