2023-09-13 09:51:31 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2022-02-20 14:48:33 +00:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2023-09-13 09:51:31 +00:00
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2023-09-13 10:57:48 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-09-14 04:57:56 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2023-09-13 09:51:31 +00:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2022-02-20 15:02:46 +00:00
|
|
|
using osu.Framework.Localisation;
|
2023-09-13 09:51:31 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-05-07 08:48:15 +00:00
|
|
|
using osu.Game.Localisation;
|
2023-09-13 09:51:31 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2023-12-31 02:18:07 +00:00
|
|
|
using osu.Game.Utils;
|
2023-09-13 09:51:31 +00:00
|
|
|
using osuTK;
|
2022-02-20 14:48:33 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
2023-09-13 09:51:31 +00:00
|
|
|
/// <summary>
|
2023-09-13 09:55:17 +00:00
|
|
|
/// On the mod select overlay, this provides a local updating view of the aggregate score multiplier coming from mods.
|
2023-09-13 09:51:31 +00:00
|
|
|
/// </summary>
|
2023-09-13 11:00:06 +00:00
|
|
|
public partial class ScoreMultiplierDisplay : ModFooterInformationDisplay, IHasCurrentValue<double>
|
2022-02-20 14:48:33 +00:00
|
|
|
{
|
2023-09-13 09:51:31 +00:00
|
|
|
public const float HEIGHT = 42;
|
|
|
|
|
|
|
|
public Bindable<double> Current
|
|
|
|
{
|
|
|
|
get => current.Current;
|
|
|
|
set => current.Current = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly BindableWithCurrent<double> current = new BindableWithCurrent<double>();
|
|
|
|
|
2023-09-13 10:33:39 +00:00
|
|
|
private const float transition_duration = 200;
|
|
|
|
|
|
|
|
private RollingCounter<double> counter = null!;
|
|
|
|
|
2023-09-14 04:57:56 +00:00
|
|
|
private Box flashLayer = null!;
|
2023-09-13 09:51:31 +00:00
|
|
|
|
|
|
|
[Resolved]
|
2023-09-14 04:57:56 +00:00
|
|
|
private OsuColour colours { get; set; } = null!;
|
2023-09-13 09:51:31 +00:00
|
|
|
|
2023-09-13 11:00:06 +00:00
|
|
|
public ScoreMultiplierDisplay()
|
2022-02-20 14:48:33 +00:00
|
|
|
{
|
2022-08-29 19:48:45 +00:00
|
|
|
Current.Default = 1d;
|
|
|
|
Current.Value = 1d;
|
2023-09-13 09:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2023-09-14 04:57:56 +00:00
|
|
|
// You would think that we could add this to `Content`, but borders don't mix well
|
|
|
|
// with additive blending children elements.
|
|
|
|
AddInternal(new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Shear = new Vector2(ShearedOverlayContainer.SHEAR, 0),
|
|
|
|
CornerRadius = ShearedButton.CORNER_RADIUS,
|
|
|
|
Masking = true,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
flashLayer = new Box
|
|
|
|
{
|
|
|
|
Alpha = 0,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-09-13 10:33:39 +00:00
|
|
|
LeftContent.AddRange(new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
|
2023-09-13 11:00:06 +00:00
|
|
|
Text = ModSelectOverlayStrings.ScoreMultiplier,
|
2023-09-13 10:33:39 +00:00
|
|
|
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
|
|
|
|
}
|
|
|
|
});
|
2023-09-13 09:51:31 +00:00
|
|
|
|
2023-09-13 10:57:48 +00:00
|
|
|
RightContent.Add(new Container
|
2023-09-13 10:33:39 +00:00
|
|
|
{
|
|
|
|
Width = 40,
|
2023-09-13 10:57:48 +00:00
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Margin = new MarginPadding(10),
|
2023-09-13 10:33:39 +00:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2023-09-13 10:57:48 +00:00
|
|
|
Child = counter = new EffectCounter
|
|
|
|
{
|
|
|
|
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Current = { BindTarget = Current }
|
|
|
|
}
|
2023-09-13 10:33:39 +00:00
|
|
|
});
|
2022-02-20 14:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
2023-09-13 10:33:39 +00:00
|
|
|
base.LoadComplete();
|
|
|
|
|
2023-09-13 09:51:31 +00:00
|
|
|
Current.BindValueChanged(e =>
|
|
|
|
{
|
2023-12-31 02:18:07 +00:00
|
|
|
if (e.NewValue > Current.Default)
|
2023-09-13 10:57:48 +00:00
|
|
|
{
|
|
|
|
MainBackground
|
|
|
|
.FadeColour(colours.ForModType(ModType.DifficultyIncrease), transition_duration, Easing.OutQuint);
|
2023-09-14 04:57:56 +00:00
|
|
|
counter.FadeColour(ColourProvider.Background5, transition_duration, Easing.OutQuint);
|
2023-09-13 10:57:48 +00:00
|
|
|
}
|
2023-12-31 02:18:07 +00:00
|
|
|
else if (e.NewValue < Current.Default)
|
2023-09-13 10:57:48 +00:00
|
|
|
{
|
|
|
|
MainBackground
|
|
|
|
.FadeColour(colours.ForModType(ModType.DifficultyReduction), transition_duration, Easing.OutQuint);
|
2023-09-14 04:57:56 +00:00
|
|
|
counter.FadeColour(ColourProvider.Background5, transition_duration, Easing.OutQuint);
|
2023-09-13 10:57:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-14 04:57:56 +00:00
|
|
|
MainBackground.FadeColour(ColourProvider.Background4, transition_duration, Easing.OutQuint);
|
2023-09-13 10:57:48 +00:00
|
|
|
counter.FadeColour(Colour4.White, transition_duration, Easing.OutQuint);
|
|
|
|
}
|
2023-09-13 09:51:31 +00:00
|
|
|
|
2023-09-14 04:57:56 +00:00
|
|
|
flashLayer
|
|
|
|
.FadeOutFromOne()
|
|
|
|
.FadeTo(0.15f, 60, Easing.OutQuint)
|
|
|
|
.Then().FadeOut(500, Easing.OutQuint);
|
2023-09-13 09:51:31 +00:00
|
|
|
|
2023-09-13 10:57:48 +00:00
|
|
|
const float move_amount = 4;
|
|
|
|
if (e.NewValue > e.OldValue)
|
|
|
|
counter.MoveToY(Math.Max(-move_amount * 2, counter.Y - move_amount)).Then().MoveToY(0, transition_duration * 2, Easing.OutQuint);
|
|
|
|
else
|
|
|
|
counter.MoveToY(Math.Min(move_amount * 2, counter.Y + move_amount)).Then().MoveToY(0, transition_duration * 2, Easing.OutQuint);
|
|
|
|
}, true);
|
2023-09-13 09:51:31 +00:00
|
|
|
|
2023-09-13 10:57:48 +00:00
|
|
|
// required to prevent the counter initially rolling up from 0 to 1
|
|
|
|
// due to `Current.Value` having a nonstandard default value of 1.
|
|
|
|
counter.SetCountWithoutRolling(Current.Value);
|
2023-09-13 09:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private partial class EffectCounter : RollingCounter<double>
|
|
|
|
{
|
2024-01-17 09:18:53 +00:00
|
|
|
protected override double RollingDuration => 250;
|
2023-09-13 09:51:31 +00:00
|
|
|
|
2023-12-31 02:18:07 +00:00
|
|
|
protected override LocalisableString FormatCount(double count) => ModUtils.FormatScoreMultiplier(count);
|
2023-09-13 09:51:31 +00:00
|
|
|
|
|
|
|
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText
|
|
|
|
{
|
2023-09-13 10:33:39 +00:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2023-09-13 09:51:31 +00:00
|
|
|
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
|
|
|
|
};
|
|
|
|
}
|
2022-02-20 14:48:33 +00:00
|
|
|
}
|
|
|
|
}
|