2023-09-13 17:51:31 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2022-02-20 22:48:33 +08:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2023-09-13 17:51:31 +08:00
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2023-09-13 18:57:48 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2024-01-31 22:50:43 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2023-09-14 12:57:56 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-02-20 23:02:46 +08:00
|
|
|
using osu.Framework.Localisation;
|
2023-09-13 17:51:31 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-05-07 16:48:15 +08:00
|
|
|
using osu.Game.Localisation;
|
2023-09-13 17:51:31 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2023-12-31 10:18:07 +08:00
|
|
|
using osu.Game.Utils;
|
2023-09-13 17:51:31 +08:00
|
|
|
using osuTK;
|
2022-02-20 22:48:33 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
2023-09-13 17:51:31 +08:00
|
|
|
/// <summary>
|
2023-09-13 17:55:17 +08:00
|
|
|
/// On the mod select overlay, this provides a local updating view of the aggregate score multiplier coming from mods.
|
2023-09-13 17:51:31 +08:00
|
|
|
/// </summary>
|
2024-01-31 22:50:43 +08:00
|
|
|
public partial class RankingInformationDisplay : ModFooterInformationDisplay
|
2022-02-20 22:48:33 +08:00
|
|
|
{
|
2023-09-13 17:51:31 +08:00
|
|
|
public const float HEIGHT = 42;
|
|
|
|
|
2024-01-31 22:50:43 +08:00
|
|
|
public Bindable<double> ModMultiplier = new BindableDouble(1);
|
|
|
|
|
|
|
|
public Bindable<bool> Ranked { get; } = new BindableBool(true);
|
2023-09-13 17:51:31 +08:00
|
|
|
|
|
|
|
private readonly BindableWithCurrent<double> current = new BindableWithCurrent<double>();
|
|
|
|
|
2023-09-13 18:33:39 +08:00
|
|
|
private const float transition_duration = 200;
|
|
|
|
|
|
|
|
private RollingCounter<double> counter = null!;
|
|
|
|
|
2023-09-14 12:57:56 +08:00
|
|
|
private Box flashLayer = null!;
|
2024-01-31 22:50:43 +08:00
|
|
|
private TextWithTooltip rankedText = null!;
|
2023-09-13 17:51:31 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2023-09-14 12:57:56 +08:00
|
|
|
private OsuColour colours { get; set; } = null!;
|
2023-09-13 17:51:31 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2023-09-14 12:57:56 +08: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,
|
2024-05-16 12:27:54 +08:00
|
|
|
Shear = new Vector2(OsuGame.SHEAR, 0),
|
2023-09-14 12:57:56 +08:00
|
|
|
CornerRadius = ShearedButton.CORNER_RADIUS,
|
|
|
|
Masking = true,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
flashLayer = new Box
|
|
|
|
{
|
|
|
|
Alpha = 0,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-09-13 18:33:39 +08:00
|
|
|
LeftContent.AddRange(new Drawable[]
|
|
|
|
{
|
2024-01-31 22:50:43 +08:00
|
|
|
new Container
|
2023-09-13 18:33:39 +08:00
|
|
|
{
|
2024-01-31 22:50:43 +08:00
|
|
|
Width = 50,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Margin = new MarginPadding(10),
|
2023-09-13 18:33:39 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2024-01-31 22:50:43 +08:00
|
|
|
Child = rankedText = new TextWithTooltip
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2024-05-16 12:27:54 +08:00
|
|
|
Shear = new Vector2(-OsuGame.SHEAR, 0),
|
2024-01-31 22:50:43 +08:00
|
|
|
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
|
|
|
|
}
|
2023-09-13 18:33:39 +08:00
|
|
|
}
|
|
|
|
});
|
2023-09-13 17:51:31 +08:00
|
|
|
|
2023-09-13 18:57:48 +08:00
|
|
|
RightContent.Add(new Container
|
2023-09-13 18:33:39 +08:00
|
|
|
{
|
|
|
|
Width = 40,
|
2023-09-13 18:57:48 +08:00
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Margin = new MarginPadding(10),
|
2023-09-13 18:33:39 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2023-09-13 18:57:48 +08:00
|
|
|
Child = counter = new EffectCounter
|
|
|
|
{
|
2024-05-16 12:27:54 +08:00
|
|
|
Shear = new Vector2(-OsuGame.SHEAR, 0),
|
2023-09-13 18:57:48 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2024-01-31 22:50:43 +08:00
|
|
|
Current = { BindTarget = ModMultiplier }
|
2023-09-13 18:57:48 +08:00
|
|
|
}
|
2023-09-13 18:33:39 +08:00
|
|
|
});
|
2022-02-20 22:48:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
2023-09-13 18:33:39 +08:00
|
|
|
base.LoadComplete();
|
|
|
|
|
2024-01-31 22:50:43 +08:00
|
|
|
ModMultiplier.BindValueChanged(e =>
|
2023-09-13 17:51:31 +08:00
|
|
|
{
|
2024-01-31 22:50:43 +08:00
|
|
|
if (e.NewValue > ModMultiplier.Default)
|
2023-09-13 18:57:48 +08:00
|
|
|
{
|
2024-01-31 22:50:43 +08:00
|
|
|
counter.FadeColour(colours.ForModType(ModType.DifficultyIncrease), transition_duration, Easing.OutQuint);
|
2023-09-13 18:57:48 +08:00
|
|
|
}
|
2024-01-31 22:50:43 +08:00
|
|
|
else if (e.NewValue < ModMultiplier.Default)
|
2023-09-13 18:57:48 +08:00
|
|
|
{
|
2024-01-31 22:50:43 +08:00
|
|
|
counter.FadeColour(colours.ForModType(ModType.DifficultyReduction), transition_duration, Easing.OutQuint);
|
2023-09-13 18:57:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
counter.FadeColour(Colour4.White, transition_duration, Easing.OutQuint);
|
|
|
|
}
|
2023-09-13 17:51:31 +08:00
|
|
|
|
2024-01-31 22:50:43 +08:00
|
|
|
flash();
|
2023-09-13 17:51:31 +08:00
|
|
|
|
2023-09-13 18:57:48 +08: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 17:51:31 +08:00
|
|
|
|
2023-09-13 18:57:48 +08:00
|
|
|
// required to prevent the counter initially rolling up from 0 to 1
|
|
|
|
// due to `Current.Value` having a nonstandard default value of 1.
|
2024-01-31 22:50:43 +08:00
|
|
|
counter.SetCountWithoutRolling(ModMultiplier.Value);
|
|
|
|
|
|
|
|
Ranked.BindValueChanged(e =>
|
|
|
|
{
|
|
|
|
flash();
|
|
|
|
|
|
|
|
if (e.NewValue)
|
|
|
|
{
|
|
|
|
rankedText.Text = ModSelectOverlayStrings.Ranked;
|
|
|
|
rankedText.TooltipText = ModSelectOverlayStrings.RankedExplanation;
|
|
|
|
rankedText.FadeColour(Colour4.White, transition_duration, Easing.OutQuint);
|
|
|
|
FrontBackground.FadeColour(ColourProvider.Background3, transition_duration, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rankedText.Text = ModSelectOverlayStrings.Unranked;
|
|
|
|
rankedText.TooltipText = ModSelectOverlayStrings.UnrankedExplanation;
|
|
|
|
rankedText.FadeColour(ColourProvider.Background5, transition_duration, Easing.OutQuint);
|
|
|
|
FrontBackground.FadeColour(colours.Orange1, transition_duration, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void flash()
|
|
|
|
{
|
|
|
|
flashLayer
|
|
|
|
.FadeOutFromOne()
|
|
|
|
.FadeTo(0.15f, 60, Easing.OutQuint)
|
|
|
|
.Then().FadeOut(500, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
|
|
|
private partial class TextWithTooltip : OsuSpriteText, IHasTooltip
|
|
|
|
{
|
|
|
|
public LocalisableString TooltipText { get; set; }
|
2023-09-13 17:51:31 +08:00
|
|
|
}
|
|
|
|
|
2024-01-31 22:50:43 +08:00
|
|
|
private partial class EffectCounter : RollingCounter<double>, IHasTooltip
|
2023-09-13 17:51:31 +08:00
|
|
|
{
|
2024-01-17 17:18:53 +08:00
|
|
|
protected override double RollingDuration => 250;
|
2023-09-13 17:51:31 +08:00
|
|
|
|
2023-12-31 10:18:07 +08:00
|
|
|
protected override LocalisableString FormatCount(double count) => ModUtils.FormatScoreMultiplier(count);
|
2023-09-13 17:51:31 +08:00
|
|
|
|
|
|
|
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText
|
|
|
|
{
|
2023-09-13 18:33:39 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2023-09-13 17:51:31 +08:00
|
|
|
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
|
|
|
|
};
|
2024-01-31 22:50:43 +08:00
|
|
|
|
|
|
|
public LocalisableString TooltipText => ModSelectOverlayStrings.ScoreMultiplier;
|
2023-09-13 17:51:31 +08:00
|
|
|
}
|
2022-02-20 22:48:33 +08:00
|
|
|
}
|
|
|
|
}
|