1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 06:57:25 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/BPMCounter.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
3.2 KiB
C#
Raw Normal View History

2022-12-05 19:29:23 +08:00
// 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;
2022-12-06 22:08:21 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
2022-12-05 19:29:23 +08:00
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;
2022-12-06 22:08:21 +08:00
using osuTK;
2022-12-05 19:29:23 +08:00
namespace osu.Game.Screens.Play.HUD
{
public partial class BPMCounter : RollingCounter<double>, ISkinnableDrawable
{
2022-12-06 00:08:00 +08:00
protected override double RollingDuration => 750;
2022-12-05 19:29:23 +08:00
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
[Resolved]
2023-01-10 17:15:08 +08:00
private IGameplayClock gameplayClock { get; set; } = null!;
2022-12-05 19:29:23 +08:00
[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
2023-01-10 17:15:08 +08:00
if (gameplayClock.IsPaused.Value) return;
2022-12-05 19:29:23 +08:00
// We want to check Rate every update to cover windup/down
2023-01-10 17:15:08 +08:00
Current.Value = beatmap.Value.Beatmap.ControlPointInfo.TimingPointAt(gameplayClock.CurrentTime).BPM * gameplayClock.Rate;
2022-12-05 19:29:23 +08:00
}
protected override OsuSpriteText CreateSpriteText()
=> base.CreateSpriteText().With(s => s.Font = s.Font.With(size: 20f, fixedWidth: true));
protected override LocalisableString FormatCount(double count)
{
2022-12-06 22:08:21 +08:00
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),
2022-12-06 22:08:21 +08:00
Text = @"BPM",
Padding = new MarginPadding { Bottom = 2f }, // align baseline better
2022-12-06 22:08:21 +08:00
}
}
};
}
2022-12-05 19:29:23 +08:00
}
public bool UsesFixedAnchor { get; set; }
}
}