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