-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from stanriders/add-bpm
Add BPM to the beatmap card
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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 | ||
|
@@ -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) | ||
{ | ||
|
@@ -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) | ||
|
@@ -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; | ||
} | ||
} | ||
} |