1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 20:47:26 +08:00
osu-lazer/osu.Game/Overlays/BeatmapSet/BasicStats.cs

172 lines
6.0 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.
2018-04-13 17:19:50 +08:00
using System;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
2018-04-13 17:19:50 +08:00
using osu.Game.Beatmaps;
using osu.Game.Extensions;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2021-08-08 16:25:51 +08:00
using osu.Game.Resources.Localisation.Web;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.BeatmapSet
{
public class BasicStats : Container
{
private readonly Statistic length, bpm, circleCount, sliderCount;
private BeatmapSetInfo beatmapSet;
2018-04-13 17:19:50 +08:00
public BeatmapSetInfo BeatmapSet
{
get => beatmapSet;
2018-04-13 17:19:50 +08:00
set
{
if (value == beatmapSet) return;
2019-02-28 12:31:40 +08:00
2018-04-13 17:19:50 +08:00
beatmapSet = value;
updateDisplay();
2018-04-13 17:19:50 +08:00
}
}
private BeatmapInfo beatmap;
2018-04-13 17:19:50 +08:00
public BeatmapInfo Beatmap
{
get => beatmap;
2018-04-13 17:19:50 +08:00
set
{
if (value == beatmap) return;
2019-02-28 12:31:40 +08:00
2018-04-13 17:19:50 +08:00
beatmap = value;
updateDisplay();
}
}
private void updateDisplay()
{
2021-08-08 16:25:51 +08:00
bpm.Value = BeatmapSet?.OnlineInfo?.BPM.ToLocalisableString(@"0.##") ?? (LocalisableString)"-";
if (beatmap == null)
{
length.Value = string.Empty;
circleCount.Value = string.Empty;
sliderCount.Value = string.Empty;
}
else
{
2021-08-08 16:25:51 +08:00
length.TooltipText = BeatmapsetsStrings.ShowStatsTotalLength(TimeSpan.FromMilliseconds(beatmap.Length).ToFormattedDuration());
length.Value = TimeSpan.FromMilliseconds(beatmap.Length).ToFormattedDuration();
2021-08-08 16:25:51 +08:00
2021-08-16 18:46:41 +08:00
circleCount.Value = beatmap.OnlineInfo.CircleCount.ToLocalisableString(@"N0");
sliderCount.Value = beatmap.OnlineInfo.SliderCount.ToLocalisableString(@"N0");
2018-04-13 17:19:50 +08:00
}
}
public BasicStats()
{
Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal,
Children = new[]
{
2021-08-16 20:50:00 +08:00
length = new Statistic(BeatmapStatisticsIconType.Length, BeatmapsetsStrings.ShowStatsTotalLength(string.Empty)) { Width = 0.25f },
bpm = new Statistic(BeatmapStatisticsIconType.Bpm, BeatmapsetsStrings.ShowStatsBpm) { Width = 0.25f },
circleCount = new Statistic(BeatmapStatisticsIconType.Circles, BeatmapsetsStrings.ShowStatsCountCircles) { Width = 0.25f },
sliderCount = new Statistic(BeatmapStatisticsIconType.Sliders, BeatmapsetsStrings.ShowStatsCountSliders) { Width = 0.25f },
2018-04-13 17:19:50 +08:00
},
};
}
[BackgroundDependencyLoader]
private void load()
{
updateDisplay();
}
2018-04-13 17:19:50 +08:00
private class Statistic : Container, IHasTooltip
{
private readonly OsuSpriteText value;
2021-08-08 16:25:51 +08:00
public LocalisableString TooltipText { get; set; }
public LocalisableString Value
2018-04-13 17:19:50 +08:00
{
get => value.Text;
set => this.value.Text = value;
2018-04-13 17:19:50 +08:00
}
2021-08-16 20:50:08 +08:00
public Statistic(BeatmapStatisticsIconType icon, LocalisableString name)
2018-04-13 17:19:50 +08:00
{
2019-11-12 17:45:42 +08:00
TooltipText = name;
2018-04-13 17:19:50 +08:00
RelativeSizeAxes = Axes.X;
Height = 24f;
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
{
new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
{
new SpriteIcon
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
2019-04-02 18:55:24 +08:00
Icon = FontAwesome.Solid.Square,
Size = new Vector2(12),
2018-04-13 17:19:50 +08:00
Rotation = 45,
Colour = Color4Extensions.FromHex(@"441288"),
2018-04-13 17:19:50 +08:00
},
new SpriteIcon
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
Icon = FontAwesome.Regular.Circle,
Size = new Vector2(10),
Rotation = 0,
Colour = Color4Extensions.FromHex(@"f7dd55"),
},
new BeatmapStatisticIcon(icon)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
Size = new Vector2(10),
Colour = Color4Extensions.FromHex(@"f7dd55"),
2018-04-13 17:19:50 +08:00
Scale = new Vector2(0.8f),
},
value = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Left = 10 },
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
2018-04-13 17:19:50 +08:00
},
},
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colour)
{
value.Colour = colour.Yellow;
}
}
}
}