1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 10:27:35 +08:00
osu-lazer/osu.Game/Overlays/Mods/ModEffectPreviewPanel.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

239 lines
10 KiB
C#
Raw Normal View History

2023-08-29 04:16:33 +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.
2023-09-09 01:32:55 +08:00
using System.Collections.Generic;
using System.Linq;
2023-08-29 04:16:33 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2023-09-03 07:09:01 +08:00
using osu.Framework.Extensions.LocalisationExtensions;
2023-08-29 04:16:33 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2023-09-03 07:09:01 +08:00
using osu.Framework.Graphics.Colour;
2023-08-29 04:16:33 +08:00
using osu.Framework.Graphics.Shapes;
2023-09-03 07:09:01 +08:00
using osu.Framework.Localisation;
2023-08-29 04:16:33 +08:00
using osu.Game.Beatmaps;
2023-09-03 07:09:01 +08:00
using osu.Game.Beatmaps.Drawables;
2023-08-29 04:16:33 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
2023-09-09 01:32:55 +08:00
using osu.Game.Rulesets.Mods;
2023-08-29 04:16:33 +08:00
using osuTK;
using osuTK.Graphics;
2023-09-09 01:32:55 +08:00
using System.Threading;
2023-08-29 04:16:33 +08:00
namespace osu.Game.Overlays.Mods
{
2023-09-09 01:32:55 +08:00
public partial class ModEffectPreviewPanel : CompositeDrawable
2023-08-29 04:16:33 +08:00
{
2023-09-11 14:26:05 +08:00
private Container content = null!;
private Container innerContent = null!;
2023-09-03 07:09:01 +08:00
2023-09-11 14:26:05 +08:00
private Box background = null!;
private Box innerBackground = null!;
2023-09-03 07:09:01 +08:00
2023-09-11 14:26:05 +08:00
private StarRatingDisplay starRatingDisplay = null!;
private BPMDisplay bpmDisplay = null!;
2023-09-03 07:09:01 +08:00
2023-09-11 14:26:05 +08:00
private VerticalAttributeDisplay circleSizeDisplay = null!;
private VerticalAttributeDisplay drainRateDisplay = null!;
private VerticalAttributeDisplay approachRateDisplay = null!;
private VerticalAttributeDisplay overallDifficultyDisplay = null!;
2023-08-29 04:16:33 +08:00
2023-09-09 01:32:55 +08:00
public const float HEIGHT = 50; // as ModSelectOverlay footer buttons
private const float transition_duration = 250;
2023-09-11 14:26:05 +08:00
private IBeatmapInfo? beatmapInfo;
2023-09-09 01:32:55 +08:00
2023-09-11 14:26:05 +08:00
public IBeatmapInfo? BeatmapInfo
2023-09-09 01:32:55 +08:00
{
get => beatmapInfo;
set
{
if (value == beatmapInfo) return;
beatmapInfo = value;
updateStarDifficultyBind();
UpdateValues();
}
}
[Resolved]
private Bindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
2023-08-29 04:16:33 +08:00
[Resolved]
2023-09-09 01:32:55 +08:00
private OverlayColourProvider colourProvider { get; set; } = null!;
2023-08-29 04:16:33 +08:00
[Resolved]
2023-09-09 01:32:55 +08:00
private BeatmapDifficultyCache difficultyCache { get; set; } = null!;
2023-08-29 04:16:33 +08:00
2023-09-11 14:26:05 +08:00
private CancellationTokenSource? cancellationSource;
2023-09-09 01:32:55 +08:00
private IBindable<StarDifficulty?> starDifficulty = null!;
2023-09-11 14:26:05 +08:00
[BackgroundDependencyLoader]
private void load()
2023-09-03 07:09:01 +08:00
{
// values as ModSelectOverlay footer buttons
const float shear = ShearedOverlayContainer.SHEAR;
const float corner_radius = 7;
const float border_thickness = 2;
2023-08-29 04:16:33 +08:00
2023-09-03 19:51:53 +08:00
AutoSizeAxes = Axes.Both;
2023-09-03 07:09:01 +08:00
InternalChild = content = new InputBlockingContainer
{
Origin = Anchor.BottomRight,
Anchor = Anchor.BottomRight,
AutoSizeAxes = Axes.X,
2023-09-09 01:32:55 +08:00
Height = HEIGHT,
2023-09-03 07:09:01 +08:00
Shear = new Vector2(shear, 0),
CornerRadius = corner_radius,
BorderThickness = border_thickness,
Masking = true,
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both
},
new FillFlowContainer // divide inner and outer content
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
innerContent = new Container
{
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
BorderThickness = border_thickness,
CornerRadius = corner_radius,
Masking = true,
Children = new Drawable[]
{
innerBackground = new Box
{
RelativeSizeAxes = Axes.Both
},
new FillFlowContainer // actual inner content
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.X,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Horizontal = 15 },
Children = new Drawable[]
{
new Container // wrap to reserve space for StarRatingDisplay
{
Width = 70, // can be up to 70px on extra high SR
Child = starRatingDisplay = new StarRatingDisplay(default, animated: true)
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Shear = new Vector2(-shear, 0),
}
},
new Container // wrap to reserve space for BPM
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Width = 70,
Child = bpmDisplay = new BPMDisplay
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Shear = new Vector2(-shear, 0),
}
}
}
}
}
},
new FillFlowContainer<VerticalAttributeDisplay> // outer content
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal,
Children = new[]
{
circleSizeDisplay = new VerticalAttributeDisplay("CS", "0.#"),
drainRateDisplay = new VerticalAttributeDisplay("HP", "0.#"),
approachRateDisplay = new VerticalAttributeDisplay("AR", "0.##"),
overallDifficultyDisplay = new VerticalAttributeDisplay("OD", "0.##"),
2023-09-03 07:09:01 +08:00
}
}
}
}
}
};
}
2023-09-11 14:26:05 +08:00
2023-08-29 04:16:33 +08:00
protected override void LoadComplete()
{
2023-09-03 07:09:01 +08:00
background.Colour = colourProvider.Background4;
innerBackground.Colour = colourProvider.Background3;
2023-09-11 14:26:05 +08:00
Color4 glowColour = colourProvider.Background1;
2023-08-29 04:16:33 +08:00
2023-09-11 14:26:05 +08:00
content.BorderColour = ColourInfo.GradientVertical(background.Colour, glowColour);
innerContent.BorderColour = ColourInfo.GradientVertical(innerBackground.Colour, glowColour);
2023-09-09 01:32:55 +08:00
updateStarDifficultyBind();
2023-08-29 04:16:33 +08:00
}
2023-09-11 14:26:05 +08:00
2023-09-09 01:32:55 +08:00
private void updateStarDifficultyBind()
{
2023-09-11 14:26:05 +08:00
if (beatmapInfo == null)
return;
cancellationSource?.Cancel();
2023-09-09 01:32:55 +08:00
starDifficulty = difficultyCache.GetBindableDifficulty(beatmapInfo, (cancellationSource = new CancellationTokenSource()).Token);
starDifficulty.BindValueChanged(s =>
{
starRatingDisplay.Current.Value = s.NewValue ?? default;
2023-08-29 04:16:33 +08:00
2023-09-09 01:32:55 +08:00
if (!starRatingDisplay.IsPresent)
starRatingDisplay.FinishTransforms(true);
starRatingDisplay.FadeIn(transition_duration);
});
}
2023-09-11 14:26:05 +08:00
2023-09-03 07:09:01 +08:00
public void UpdateValues()
2023-08-29 04:16:33 +08:00
{
2023-09-11 14:26:05 +08:00
if (beatmapInfo == null)
return;
2023-09-09 01:32:55 +08:00
double rate = 1;
foreach (var mod in mods.Value.OfType<IApplicableToRate>())
rate = mod.ApplyToRate(0, rate);
bpmDisplay.Current.Value = beatmapInfo.BPM * rate;
2023-09-03 07:09:01 +08:00
2023-09-11 14:26:05 +08:00
BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(beatmapInfo.Difficulty);
2023-09-09 01:32:55 +08:00
foreach (var mod in mods.Value.OfType<IApplicableToDifficulty>())
mod.ApplyToDifficulty(adjustedDifficulty);
2023-09-03 07:09:01 +08:00
2023-09-09 01:32:55 +08:00
circleSizeDisplay.Current.Value = adjustedDifficulty.CircleSize;
drainRateDisplay.Current.Value = adjustedDifficulty.DrainRate;
approachRateDisplay.Current.Value = adjustedDifficulty.ApproachRate;
overallDifficultyDisplay.Current.Value = adjustedDifficulty.OverallDifficulty;
2023-09-03 07:09:01 +08:00
}
private partial class BPMDisplay : RollingCounter<double>
{
protected override double RollingDuration => 500;
protected override LocalisableString FormatCount(double count) => count.ToLocalisableString("0 BPM");
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText
{
Font = OsuFont.Default.With(size: 20, weight: FontWeight.SemiBold)
};
2023-08-29 04:16:33 +08:00
}
}
}