Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BPM to the beatmap card #236

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions PerformanceCalculatorGUI/Components/BeatmapCard.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
Expand All @@ -15,6 +17,9 @@
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Rulesets.Mods;
using osu.Game.Utils;
using osuTK;
using PerformanceCalculatorGUI.Components.TextBoxes;

namespace PerformanceCalculatorGUI.Components
Expand All @@ -32,6 +37,11 @@ public partial class BeatmapCard : OsuClickableContainer
[Resolved]
private LargeTextureStore textures { get; set; }

[Resolved]
private Bindable<IReadOnlyList<Mod>> mods { get; set; }

private OsuSpriteText bpmText = null!;

public BeatmapCard(ProcessorWorkingBeatmap beatmap)
: base(HoverSampleSet.Button)
{
Expand Down Expand Up @@ -77,10 +87,37 @@ private void load(GameHost host)
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
Text = $"[{beatmap.BeatmapInfo.Ruleset.Name}] {beatmap.Metadata.GetDisplayTitle()} [{beatmap.BeatmapInfo.DifficultyName}]",
Margin = new MarginPadding(10)
},
new FillFlowContainer
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding(10),
Children = new Drawable[]
{
new BeatmapStatisticIcon(BeatmapStatisticsIconType.Bpm)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(16)
},
bpmText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 14)
}
}
}
});

Action = () => { host.OpenUrlExternally($"https://osu.ppy.sh/beatmaps/{beatmap.BeatmapInfo.OnlineID}"); };

mods.BindValueChanged(_ => updateBpm());

updateBpm();
}

protected override bool OnHover(HoverEvent e)
Expand All @@ -94,5 +131,20 @@ protected override void OnHoverLost(HoverLostEvent e)
BorderThickness = 0;
base.OnHoverLost(e);
}

private void updateBpm()
{
double rate = ModUtils.CalculateRateWithMods(mods.Value);

int bpmMax = FormatUtils.RoundBPM(beatmap.Beatmap.ControlPointInfo.BPMMaximum, rate);
int bpmMin = FormatUtils.RoundBPM(beatmap.Beatmap.ControlPointInfo.BPMMinimum, rate);
int mostCommonBPM = FormatUtils.RoundBPM(60000 / beatmap.Beatmap.GetMostCommonBeatLength(), rate);

string labelText = bpmMin == bpmMax
? $"{bpmMin}"
: $"{bpmMin}-{bpmMax} (mostly {mostCommonBPM})";

bpmText.Text = labelText;
}
}
}
Loading