mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 00:42:55 +08:00
Merge pull request #21519 from mk56-spn/variable_BPM_counter
Add dynamic BPM counter to SkinEditor
This commit is contained in:
commit
3210586eb6
BIN
osu.Game.Tests/Resources/Archives/modified-default-20221205.osk
Normal file
BIN
osu.Game.Tests/Resources/Archives/modified-default-20221205.osk
Normal file
Binary file not shown.
@ -42,7 +42,9 @@ namespace osu.Game.Tests.Skins
|
|||||||
// Covers longest combo counter
|
// Covers longest combo counter
|
||||||
"Archives/modified-default-20221012.osk",
|
"Archives/modified-default-20221012.osk",
|
||||||
// Covers TextElement and BeatmapInfoDrawable
|
// Covers TextElement and BeatmapInfoDrawable
|
||||||
"Archives/modified-default-20221102.osk"
|
"Archives/modified-default-20221102.osk",
|
||||||
|
// Covers BPM counter.
|
||||||
|
"Archives/modified-default-20221205.osk"
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
98
osu.Game/Screens/Play/HUD/BPMCounter.cs
Normal file
98
osu.Game/Screens/Play/HUD/BPMCounter.cs
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.Play.HUD
|
||||||
|
{
|
||||||
|
public partial class BPMCounter : RollingCounter<double>, ISkinnableDrawable
|
||||||
|
{
|
||||||
|
protected override double RollingDuration => 750;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IGameplayClock gameplayClock { get; set; } = null!;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colour)
|
||||||
|
{
|
||||||
|
Colour = colour.BlueLighter;
|
||||||
|
Current.Value = DisplayedCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
//We don't want it going to 0 when we pause. so we block the updates
|
||||||
|
if (gameplayClock.IsPaused.Value) return;
|
||||||
|
|
||||||
|
// We want to check Rate every update to cover windup/down
|
||||||
|
Current.Value = beatmap.Value.Beatmap.ControlPointInfo.TimingPointAt(gameplayClock.CurrentTime).BPM * gameplayClock.Rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override OsuSpriteText CreateSpriteText()
|
||||||
|
=> base.CreateSpriteText().With(s => s.Font = s.Font.With(size: 20f, fixedWidth: true));
|
||||||
|
|
||||||
|
protected override LocalisableString FormatCount(double count)
|
||||||
|
{
|
||||||
|
return $@"{count:0}";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IHasText CreateText() => new TextComponent();
|
||||||
|
|
||||||
|
private partial class TextComponent : CompositeDrawable, IHasText
|
||||||
|
{
|
||||||
|
public LocalisableString Text
|
||||||
|
{
|
||||||
|
get => text.Text;
|
||||||
|
set => text.Text = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly OsuSpriteText text;
|
||||||
|
|
||||||
|
public TextComponent()
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
InternalChild = new FillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Spacing = new Vector2(2),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
text = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Origin = Anchor.BottomLeft,
|
||||||
|
Font = OsuFont.Numeric.With(size: 16, fixedWidth: true)
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Origin = Anchor.BottomLeft,
|
||||||
|
Font = OsuFont.Numeric.With(size: 8),
|
||||||
|
Text = @"BPM",
|
||||||
|
Padding = new MarginPadding { Bottom = 2f }, // align baseline better
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UsesFixedAnchor { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user