2021-08-29 00:09:37 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2023-12-22 10:07:12 +08:00
|
|
|
using System;
|
2023-12-23 06:28:02 +08:00
|
|
|
using System.Linq;
|
2021-08-29 00:09:37 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2023-12-23 06:28:02 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2021-08-29 00:09:37 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables
|
|
|
|
{
|
2021-09-01 02:16:02 +08:00
|
|
|
internal partial class DifficultyIconTooltip : VisibilityContainer, ITooltip<DifficultyIconTooltipContent>
|
2021-08-29 00:09:37 +08:00
|
|
|
{
|
2022-04-22 14:56:03 +08:00
|
|
|
private OsuSpriteText difficultyName;
|
|
|
|
private StarRatingDisplay starRating;
|
2023-12-22 10:07:12 +08:00
|
|
|
private OsuSpriteText overallDifficulty;
|
|
|
|
private OsuSpriteText drainRate;
|
|
|
|
private OsuSpriteText circleSize;
|
|
|
|
private OsuSpriteText approachRate;
|
2023-12-23 06:28:02 +08:00
|
|
|
private OsuSpriteText bpm;
|
2023-12-22 10:07:12 +08:00
|
|
|
private OsuSpriteText maxCombo;
|
|
|
|
private OsuSpriteText length;
|
2021-08-29 00:09:37 +08:00
|
|
|
|
2024-01-17 22:07:17 +08:00
|
|
|
private FillFlowContainer difficultyFillFlowContainer;
|
|
|
|
private FillFlowContainer miscFillFlowContainer;
|
|
|
|
|
2022-04-22 14:56:03 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
2021-08-29 00:09:37 +08:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
Masking = true;
|
|
|
|
CornerRadius = 5;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-04-22 14:56:03 +08:00
|
|
|
new Box
|
2021-08-29 00:09:37 +08:00
|
|
|
{
|
2022-02-01 15:35:22 +08:00
|
|
|
Alpha = 0.9f,
|
2022-04-22 14:56:03 +08:00
|
|
|
Colour = colours.Gray3,
|
2021-08-29 00:09:37 +08:00
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
},
|
2023-12-22 10:07:12 +08:00
|
|
|
// Headers
|
2021-08-29 00:09:37 +08:00
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
AutoSizeDuration = 200,
|
|
|
|
AutoSizeEasing = Easing.OutQuint,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Padding = new MarginPadding(10),
|
2022-04-22 14:56:03 +08:00
|
|
|
Spacing = new Vector2(5),
|
2021-08-29 00:09:37 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
difficultyName = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
|
|
|
|
},
|
2022-04-22 14:56:03 +08:00
|
|
|
starRating = new StarRatingDisplay(default, StarRatingDisplaySize.Small)
|
2021-08-29 00:09:37 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2023-12-22 10:07:12 +08:00
|
|
|
},
|
|
|
|
// Difficulty stats
|
2024-01-17 22:07:17 +08:00
|
|
|
difficultyFillFlowContainer = new FillFlowContainer
|
2023-12-22 10:07:12 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2024-01-17 22:07:17 +08:00
|
|
|
Alpha = 0,
|
2023-12-22 10:07:12 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2023-12-23 06:28:02 +08:00
|
|
|
circleSize = new OsuSpriteText
|
2023-12-22 10:07:12 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
},
|
|
|
|
drainRate = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
},
|
2023-12-23 06:28:02 +08:00
|
|
|
approachRate = new OsuSpriteText
|
2023-12-22 10:07:12 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
},
|
2023-12-23 06:28:02 +08:00
|
|
|
overallDifficulty = new OsuSpriteText
|
2023-12-22 10:07:12 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Misc stats
|
2024-01-17 22:07:17 +08:00
|
|
|
miscFillFlowContainer = new FillFlowContainer
|
2023-12-22 10:07:12 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2024-01-17 22:07:17 +08:00
|
|
|
Alpha = 0,
|
2023-12-22 10:07:12 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
length = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
},
|
2023-12-23 06:28:02 +08:00
|
|
|
bpm = new OsuSpriteText
|
2023-12-22 10:07:12 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
},
|
|
|
|
maxCombo = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
},
|
|
|
|
}
|
2021-08-29 00:09:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-22 14:56:03 +08:00
|
|
|
private DifficultyIconTooltipContent displayedContent;
|
2021-08-29 00:09:37 +08:00
|
|
|
|
|
|
|
public void SetContent(DifficultyIconTooltipContent content)
|
|
|
|
{
|
2022-04-22 14:56:03 +08:00
|
|
|
if (displayedContent != null)
|
|
|
|
starRating.Current.UnbindFrom(displayedContent.Difficulty);
|
2021-08-29 00:09:37 +08:00
|
|
|
|
2022-04-22 14:56:03 +08:00
|
|
|
displayedContent = content;
|
2023-12-23 06:28:02 +08:00
|
|
|
|
|
|
|
// Header row
|
2022-04-22 14:56:03 +08:00
|
|
|
starRating.Current.BindTarget = displayedContent.Difficulty;
|
|
|
|
difficultyName.Text = displayedContent.BeatmapInfo.DifficultyName;
|
2023-12-22 10:07:12 +08:00
|
|
|
|
2024-01-17 22:07:17 +08:00
|
|
|
// Don't show difficulty stats if showTooltip is false
|
|
|
|
if (!displayedContent.ShowTooltip) return;
|
|
|
|
|
|
|
|
// Show the difficulty stats if showTooltip is true
|
|
|
|
difficultyFillFlowContainer.Show();
|
|
|
|
miscFillFlowContainer.Show();
|
|
|
|
|
2023-12-23 06:28:02 +08:00
|
|
|
double rate = 1;
|
|
|
|
|
|
|
|
if (displayedContent.Mods != null)
|
|
|
|
{
|
|
|
|
foreach (var mod in displayedContent.Mods.OfType<IApplicableToRate>())
|
|
|
|
rate = mod.ApplyToRate(0, rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
double bpmAdjusted = displayedContent.BeatmapInfo.BPM * rate;
|
|
|
|
|
|
|
|
BeatmapDifficulty originalDifficulty = new BeatmapDifficulty(displayedContent.BeatmapInfo.Difficulty);
|
|
|
|
|
|
|
|
if (displayedContent.Mods != null)
|
|
|
|
{
|
|
|
|
foreach (var mod in displayedContent.Mods.OfType<IApplicableToDifficulty>())
|
|
|
|
{
|
|
|
|
mod.ApplyToDifficulty(originalDifficulty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ruleset ruleset = displayedContent.Ruleset.CreateInstance();
|
|
|
|
BeatmapDifficulty adjustedDifficulty = ruleset.GetRateAdjustedDisplayDifficulty(originalDifficulty, rate);
|
|
|
|
|
2023-12-22 10:07:12 +08:00
|
|
|
// Difficulty row
|
2023-12-23 06:28:02 +08:00
|
|
|
circleSize.Text = "CS: " + adjustedDifficulty.CircleSize.ToString("0.##");
|
2024-01-15 04:47:50 +08:00
|
|
|
drainRate.Text = " HP: " + adjustedDifficulty.DrainRate.ToString("0.##");
|
|
|
|
approachRate.Text = " AR: " + adjustedDifficulty.ApproachRate.ToString("0.##");
|
|
|
|
overallDifficulty.Text = " OD: " + adjustedDifficulty.OverallDifficulty.ToString("0.##");
|
2023-12-22 10:07:12 +08:00
|
|
|
|
|
|
|
// Misc row
|
2023-12-23 06:28:02 +08:00
|
|
|
length.Text = "Length: " + TimeSpan.FromMilliseconds(displayedContent.BeatmapInfo.Length / rate).ToString("mm\\:ss");
|
2024-01-17 22:07:17 +08:00
|
|
|
bpm.Text = " BPM: " + Math.Round(bpmAdjusted, 0);
|
2024-01-15 04:47:50 +08:00
|
|
|
maxCombo.Text = " Max Combo: " + displayedContent.BeatmapInfo.TotalObjectCount;
|
2021-08-29 00:09:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Move(Vector2 pos) => Position = pos;
|
|
|
|
|
|
|
|
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
|
|
|
|
|
|
|
|
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
2021-09-01 02:16:02 +08:00
|
|
|
internal class DifficultyIconTooltipContent
|
2021-08-29 00:09:37 +08:00
|
|
|
{
|
2021-10-29 16:03:50 +08:00
|
|
|
public readonly IBeatmapInfo BeatmapInfo;
|
2021-08-29 00:09:37 +08:00
|
|
|
public readonly IBindable<StarDifficulty> Difficulty;
|
2023-12-23 06:28:02 +08:00
|
|
|
public readonly IRulesetInfo Ruleset;
|
|
|
|
public readonly Mod[] Mods;
|
2024-01-17 22:07:17 +08:00
|
|
|
public readonly bool ShowTooltip;
|
2021-08-29 00:09:37 +08:00
|
|
|
|
2024-01-17 22:07:17 +08:00
|
|
|
public DifficultyIconTooltipContent(IBeatmapInfo beatmapInfo, IBindable<StarDifficulty> difficulty, IRulesetInfo rulesetInfo, Mod[] mods, bool showTooltip = false)
|
2021-08-29 00:09:37 +08:00
|
|
|
{
|
2021-10-02 23:55:29 +08:00
|
|
|
BeatmapInfo = beatmapInfo;
|
2021-08-29 00:09:37 +08:00
|
|
|
Difficulty = difficulty;
|
2023-12-23 06:28:02 +08:00
|
|
|
Ruleset = rulesetInfo;
|
|
|
|
Mods = mods;
|
2024-01-17 22:07:17 +08:00
|
|
|
ShowTooltip = showTooltip;
|
2021-08-29 00:09:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|