2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
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;
|
2020-02-08 07:11:19 +08:00
|
|
|
|
using osu.Game.Utils;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-03 23:50:41 +08:00
|
|
|
|
namespace osu.Game.Screens.Play.Break
|
2017-09-23 21:42:18 +08:00
|
|
|
|
{
|
2022-11-24 13:32:20 +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
|
|
|
|
|
2017-09-23 21:42:18 +08:00
|
|
|
|
private readonly OsuSpriteText text;
|
|
|
|
|
private readonly OsuSpriteText valueText;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-23 21:42:18 +08:00
|
|
|
|
private readonly string prefix;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-01-28 12:53:48 +08:00
|
|
|
|
public BreakInfoLine(LocalisableString name, string prefix = @"")
|
2017-09-23 21:42:18 +08:00
|
|
|
|
{
|
|
|
|
|
this.prefix = prefix;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-23 21:42:18 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
text = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Text = name,
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 17),
|
2017-09-23 21:42:18 +08:00
|
|
|
|
Margin = new MarginPadding { Right = margin }
|
|
|
|
|
},
|
|
|
|
|
valueText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Text = prefix + @"-",
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 17),
|
2017-09-23 21:42:18 +08:00
|
|
|
|
Margin = new MarginPadding { Left = margin }
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-23 21:42:18 +08:00
|
|
|
|
Current.ValueChanged += currentValueChanged;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
private void currentValueChanged(ValueChangedEvent<T> e)
|
2017-09-23 21:42:18 +08:00
|
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
|
string newText = prefix + Format(e.NewValue);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-24 00:59:34 +08:00
|
|
|
|
if (valueText.Text == newText)
|
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-24 00:59:34 +08:00
|
|
|
|
valueText.Text = newText;
|
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();
|
|
|
|
|
|
|
|
|
|
return count.ToString();
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-23 21:42:18 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
text.Colour = colours.Yellow;
|
|
|
|
|
valueText.Colour = colours.YellowLight;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class PercentageBreakInfoLine : BreakInfoLine<double>
|
2017-09-23 21:42:18 +08:00
|
|
|
|
{
|
2022-01-28 12:53:48 +08:00
|
|
|
|
public PercentageBreakInfoLine(LocalisableString name, string prefix = "")
|
2019-02-28 12:31:40 +08:00
|
|
|
|
: base(name, prefix)
|
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
|
|
|
|
}
|
|
|
|
|
}
|