1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 23:27:24 +08:00
osu-lazer/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs

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

181 lines
5.9 KiB
C#
Raw Normal View History

// 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.
#nullable disable
using System.Text;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Skinning.Components
{
[UsedImplicitly]
public class BeatmapInfoDrawable : Container, ISkinnableDrawable
{
public bool UsesFixedAnchor { get; set; }
[SettingSource("Tracked Beatmap Info", "Which part of the BeatmapInformation should be tracked")]
public Bindable<BeatmapInfo> Type { get; } = new Bindable<BeatmapInfo>(BeatmapInfo.StarRating);
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; }
private readonly OsuSpriteText text;
public BeatmapInfoDrawable()
{
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
text = new OsuSpriteText
{
Text = "BeatInfoDrawable",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Default.With(size: 40)
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Type.BindValueChanged(update, true);
}
private void update(ValueChangedEvent<BeatmapInfo> type)
{
switch (type.NewValue)
{
case BeatmapInfo.CircleSize:
beatmap.BindValueChanged(bm =>
{
text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.CircleSize.ToString("F2");
}, true);
break;
case BeatmapInfo.HPDrain:
beatmap.BindValueChanged(bm =>
{
text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.DrainRate.ToString("F2");
}, true);
break;
case BeatmapInfo.Accuracy:
beatmap.BindValueChanged(bm =>
{
text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.OverallDifficulty.ToString("F2");
}, true);
break;
case BeatmapInfo.ApproachRate:
beatmap.BindValueChanged(bm =>
{
text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.ApproachRate.ToString("F2");
}, true);
break;
case BeatmapInfo.StarRating:
beatmap.BindValueChanged(bm =>
{
text.Current.Value = bm.NewValue.BeatmapInfo.StarRating.ToString("F2");
}, true);
break;
case BeatmapInfo.Song:
beatmap.BindValueChanged(bm =>
{
text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Title;
}, true);
break;
case BeatmapInfo.Artist:
beatmap.BindValueChanged(bm =>
{
text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Artist;
}, true);
break;
case BeatmapInfo.Difficulty:
beatmap.BindValueChanged(bm =>
{
text.Current.Value = bm.NewValue.BeatmapInfo.DifficultyName;
}, true);
break;
case BeatmapInfo.Mapper:
beatmap.BindValueChanged(bm =>
{
text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Author.Username;
}, true);
break;
case BeatmapInfo.Length:
beatmap.BindValueChanged(bm =>
{
const long ms_to_s = 1000;
double length = bm.NewValue.BeatmapInfo.Length;
double rawS = length / ms_to_s;
double rawM = rawS / 60;
double rawH = rawM / 60;
double rawD = rawH / 24;
long s = (long)rawS % 60;
long m = (long)rawM % 60;
long h = (long)rawH % 24;
long d = (long)rawD;
StringBuilder builder = new StringBuilder();
if (d != 0)
{
builder.Append(d.ToString("D2"));
builder.Append(":");
}
if (h != 0 || d != 0)
{
builder.Append(h.ToString("D2"));
builder.Append(":");
}
builder.Append(m.ToString("D2"));
builder.Append(":");
builder.Append(s.ToString("D2"));
text.Current.Value = builder.ToString();
}, true);
break;
case BeatmapInfo.BPM:
beatmap.BindValueChanged(bm =>
{
text.Current.Value = bm.NewValue.BeatmapInfo.BPM.ToString("F2");
}, true);
break;
}
}
}
public enum BeatmapInfo
{
CircleSize,
HPDrain,
Accuracy,
ApproachRate,
StarRating,
Song,
Artist,
Difficulty,
Mapper,
Length,
BPM,
}
}