Skip to content

Commit

Permalink
Merge pull request #236 from stanriders/add-bpm
Browse files Browse the repository at this point in the history
Add BPM to the beatmap card
  • Loading branch information
smoogipoo authored Dec 6, 2024
2 parents 790f6a2 + 1380389 commit 5239181
Showing 1 changed file with 52 additions and 0 deletions.
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;
}
}
}

0 comments on commit 5239181

Please sign in to comment.