1
0
Fork 0
mirror of https://github.com/ppy/osu-tools.git synced 2025-06-08 07:17:01 +09:00

Merge pull request #255 from stanriders/add-beatmap-stats

Add beatmap stats tooltip, fix bpm not updating on mod settings changes
This commit is contained in:
James Wilson 2025-04-03 16:25:38 +01:00 committed by GitHub
commit 4f77fb61df
Signed by: github
GPG key ID: B5690EEEBB952194
2 changed files with 162 additions and 3 deletions

View file

@ -2,21 +2,26 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq;
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.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Events;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Utils;
using osuTK;
@ -24,7 +29,7 @@ using PerformanceCalculatorGUI.Components.TextBoxes;
namespace PerformanceCalculatorGUI.Components
{
public partial class BeatmapCard : OsuClickableContainer
public partial class BeatmapCard : OsuClickableContainer, IHasCustomTooltip<ProcessorWorkingBeatmap>
{
private readonly ProcessorWorkingBeatmap beatmap;
@ -40,6 +45,10 @@ namespace PerformanceCalculatorGUI.Components
[Resolved]
private Bindable<IReadOnlyList<Mod>> mods { get; set; }
public ITooltip<ProcessorWorkingBeatmap> GetCustomTooltip() => new BeatmapCardTooltip(colourProvider);
public ProcessorWorkingBeatmap TooltipContent { get; }
private ModSettingChangeTracker modSettingChangeTracker;
private OsuSpriteText bpmText = null!;
public BeatmapCard(ProcessorWorkingBeatmap beatmap)
@ -49,6 +58,7 @@ namespace PerformanceCalculatorGUI.Components
RelativeSizeAxes = Axes.X;
Height = 40;
CornerRadius = ExtendedLabelledTextBox.CORNER_RADIUS;
TooltipContent = beatmap;
}
[BackgroundDependencyLoader]
@ -115,7 +125,13 @@ namespace PerformanceCalculatorGUI.Components
Action = () => { host.OpenUrlExternally($"https://osu.ppy.sh/beatmaps/{beatmap.BeatmapInfo.OnlineID}"); };
mods.BindValueChanged(_ => updateBpm());
mods.BindValueChanged(_ =>
{
modSettingChangeTracker?.Dispose();
modSettingChangeTracker = new ModSettingChangeTracker(mods.Value);
modSettingChangeTracker.SettingChanged += _ => updateBpm();
updateBpm();
}, true);
updateBpm();
}
@ -146,5 +162,146 @@ namespace PerformanceCalculatorGUI.Components
bpmText.Text = labelText;
}
public partial class BeatmapCardTooltip : VisibilityContainer, ITooltip<ProcessorWorkingBeatmap>
{
public BeatmapCardTooltip(OverlayColourProvider colourProvider)
{
this.colourProvider = colourProvider;
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 8;
}
protected override void PopIn() => this.FadeIn(150, Easing.OutQuint);
protected override void PopOut() => this.Delay(150).FadeOut(500, Easing.OutQuint);
public void Move(Vector2 pos) => Position = pos;
private ProcessorWorkingBeatmap beatmap;
private VerticalAttributeDisplay keyCountDisplay = null!;
private VerticalAttributeDisplay circleSizeDisplay = null!;
private VerticalAttributeDisplay drainRateDisplay = null!;
private VerticalAttributeDisplay approachRateDisplay = null!;
private VerticalAttributeDisplay overallDifficultyDisplay = null!;
[Resolved]
private Bindable<IReadOnlyList<Mod>> mods { get; set; }
private readonly OverlayColourProvider colourProvider;
private ModSettingChangeTracker modSettingChangeTracker;
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
mods.BindValueChanged(_ =>
{
modSettingChangeTracker?.Dispose();
modSettingChangeTracker = new ModSettingChangeTracker(mods.Value);
modSettingChangeTracker.SettingChanged += _ => updateValues();
updateValues();
}, true);
ruleset.BindValueChanged(_ => updateValues());
}
protected override bool OnMouseDown(MouseDownEvent e) => true;
protected override bool OnClick(ClickEvent e) => true;
private void updateValues() => Scheduler.AddOnce(() =>
{
if (beatmap?.BeatmapInfo == null)
return;
double rate = ModUtils.CalculateRateWithMods(mods.Value);
BeatmapDifficulty originalDifficulty = new BeatmapDifficulty(beatmap.BeatmapInfo.Difficulty);
BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(originalDifficulty);
foreach (var mod in mods.Value.OfType<IApplicableToDifficulty>())
mod.ApplyToDifficulty(adjustedDifficulty);
Ruleset rulesetInstance = ruleset.Value.CreateInstance();
adjustedDifficulty = rulesetInstance.GetRateAdjustedDisplayDifficulty(adjustedDifficulty, rate);
if (ruleset.Value.OnlineID >= 0)
{
if (ruleset.Value.ShortName is "osu" or "fruits")
{
circleSizeDisplay.Show();
circleSizeDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(originalDifficulty.CircleSize, adjustedDifficulty.CircleSize);
circleSizeDisplay.Current.Value = adjustedDifficulty.CircleSize;
approachRateDisplay.Show();
approachRateDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(originalDifficulty.ApproachRate, adjustedDifficulty.ApproachRate);
approachRateDisplay.Current.Value = adjustedDifficulty.ApproachRate;
}
else
{
circleSizeDisplay.Hide();
approachRateDisplay.Hide();
}
if (ruleset.Value.ShortName == "mania")
{
ILegacyRuleset legacyRuleset = (ILegacyRuleset)ruleset.Value.CreateInstance();
int keyCount = legacyRuleset.GetKeyCount(beatmap.BeatmapInfo, mods.Value);
int keyCountOriginal = legacyRuleset.GetKeyCount(beatmap.BeatmapInfo, []);
keyCountDisplay.Show();
keyCountDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(keyCountOriginal, keyCount);
keyCountDisplay.Current.Value = keyCount;
}
else
{
keyCountDisplay.Hide();
}
}
drainRateDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(originalDifficulty.DrainRate, adjustedDifficulty.DrainRate);
overallDifficultyDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(originalDifficulty.OverallDifficulty, adjustedDifficulty.OverallDifficulty);
drainRateDisplay.Current.Value = adjustedDifficulty.DrainRate;
overallDifficultyDisplay.Current.Value = adjustedDifficulty.OverallDifficulty;
});
public void SetContent(ProcessorWorkingBeatmap content)
{
if (content == beatmap && Children.Any())
return;
beatmap = content;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background6
},
new FillFlowContainer
{
Padding = new MarginPadding(8),
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
keyCountDisplay = new VerticalAttributeDisplay("Keys") { AutoSizeAxes = Axes.Both, Alpha = 0 },
circleSizeDisplay = new VerticalAttributeDisplay("CS") { AutoSizeAxes = Axes.Both, Alpha = 0 },
drainRateDisplay = new VerticalAttributeDisplay("HP") { AutoSizeAxes = Axes.Both },
overallDifficultyDisplay = new VerticalAttributeDisplay("OD") { AutoSizeAxes = Axes.Both },
approachRateDisplay = new VerticalAttributeDisplay("AR") { AutoSizeAxes = Axes.Both, Alpha = 0 },
}
}
};
}
}
}
}

View file

@ -582,6 +582,7 @@ namespace PerformanceCalculatorGUI.Screens
// recreate calculators to update DHOs
createCalculators();
modSettingChangeTracker?.Dispose();
modSettingChangeTracker = new ModSettingChangeTracker(mods.NewValue);
modSettingChangeTracker.SettingChanged += m =>
{
@ -592,7 +593,7 @@ namespace PerformanceCalculatorGUI.Screens
updateMissesTextboxes();
calculateDifficulty();
calculatePerformance();
}, 100);
}, 300);
};
calculateDifficulty();
@ -647,6 +648,7 @@ namespace PerformanceCalculatorGUI.Screens
resetCalculations();
}
beatmapTitle.Clear();
beatmapTitle.Add(new BeatmapCard(working));
loadBackground();