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]
|
|
|
|
protected IGameplayClock GameplayClock { get; private set; } = null!;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colour)
|
|
|
|
{
|
|
|
|
Colour = colour.BlueLighter;
|
|
|
|
Current.Value = DisplayedCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
//We dont 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)
|
|
|
|
{
|
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, fixedWidth: true),
|
|
|
|
Text = @"BPM",
|
|
|
|
Padding = new MarginPadding { Bottom = 1.5f }, // align baseline better
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2022-12-05 19:29:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
}
|
|
|
|
}
|