1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 12:27:26 +08:00
osu-lazer/osu.Game/Screens/Play/Break/BreakInfoLine.cs

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

82 lines
2.4 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
2019-04-21 12:04:15 +08:00
using System;
2017-09-23 21:42:18 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2019-04-21 12:04:15 +08:00
using osu.Framework.Extensions;
2017-09-23 21:42:18 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2021-07-24 04:37:08 +08:00
using osu.Framework.Localisation;
2017-09-23 21:42:18 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Utils;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Play.Break
2017-09-23 21:42:18 +08:00
{
public partial class BreakInfoLine<T> : Container
2017-09-23 21:42:18 +08:00
where T : struct
{
private const int margin = 2;
2018-04-13 17:19:50 +08:00
2017-09-23 21:42:18 +08:00
public Bindable<T> Current = new Bindable<T>();
2018-04-13 17:19:50 +08:00
private readonly LocalisableString name;
private OsuSpriteText valueText = null!;
2018-04-13 17:19:50 +08:00
2023-07-30 01:40:18 +08:00
public BreakInfoLine(LocalisableString name)
2017-09-23 21:42:18 +08:00
{
this.name = name;
2017-09-23 21:42:18 +08:00
AutoSizeAxes = Axes.Y;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2017-09-23 21:42:18 +08:00
Children = new Drawable[]
{
new OsuSpriteText
2017-09-23 21:42:18 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.CentreRight,
Text = name,
Font = OsuFont.GetFont(size: 17),
Margin = new MarginPadding { Right = margin },
Colour = colours.Yellow,
2017-09-23 21:42:18 +08:00
},
valueText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.CentreLeft,
2023-07-30 01:40:18 +08:00
Text = @"-",
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 17),
Margin = new MarginPadding { Left = margin },
Colour = colours.YellowLight,
2017-09-23 21:42:18 +08:00
}
};
Current.BindValueChanged(text => valueText.Text = Format(text.NewValue));
2017-09-23 21:42:18 +08:00
}
2018-04-13 17:19:50 +08:00
2021-07-24 04:37:08 +08:00
protected virtual LocalisableString Format(T count)
2019-04-21 12:04:15 +08:00
{
if (count is Enum countEnum)
return countEnum.GetDescription();
2023-07-30 01:39:50 +08:00
return count.ToString() ?? string.Empty;
2019-04-21 12:04:15 +08:00
}
2017-09-23 21:42:18 +08:00
}
2018-04-13 17:19:50 +08:00
public partial class PercentageBreakInfoLine : BreakInfoLine<double>
2017-09-23 21:42:18 +08:00
{
2023-07-30 01:40:18 +08:00
public PercentageBreakInfoLine(LocalisableString name)
: base(name)
2017-09-23 21:42:18 +08:00
{
}
2018-04-13 17:19:50 +08:00
2021-07-24 04:37:08 +08:00
protected override LocalisableString Format(double count) => count.FormatAccuracy();
2017-09-23 21:42:18 +08:00
}
}