2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2019-04-21 04:04:15 +00:00
|
|
|
|
using System;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-04-21 04:04:15 +00:00
|
|
|
|
using osu.Framework.Extensions;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-02-07 23:11:19 +00:00
|
|
|
|
using osu.Game.Utils;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.Break
|
|
|
|
|
{
|
|
|
|
|
public class BreakInfoLine<T> : Container
|
|
|
|
|
where T : struct
|
|
|
|
|
{
|
|
|
|
|
private const int margin = 2;
|
|
|
|
|
|
|
|
|
|
public Bindable<T> Current = new Bindable<T>();
|
|
|
|
|
|
|
|
|
|
private readonly OsuSpriteText text;
|
|
|
|
|
private readonly OsuSpriteText valueText;
|
|
|
|
|
|
|
|
|
|
private readonly string prefix;
|
|
|
|
|
|
|
|
|
|
public BreakInfoLine(string name, string prefix = @"")
|
|
|
|
|
{
|
|
|
|
|
this.prefix = prefix;
|
|
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
text = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Text = name,
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 17),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Margin = new MarginPadding { Right = margin }
|
|
|
|
|
},
|
|
|
|
|
valueText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Text = prefix + @"-",
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 17),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Margin = new MarginPadding { Left = margin }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Current.ValueChanged += currentValueChanged;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
private void currentValueChanged(ValueChangedEvent<T> e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-02-21 09:56:34 +00:00
|
|
|
|
var newText = prefix + Format(e.NewValue);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
if (valueText.Text == newText)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
valueText.Text = newText;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-21 04:04:15 +00:00
|
|
|
|
protected virtual string Format(T count)
|
|
|
|
|
{
|
|
|
|
|
if (count is Enum countEnum)
|
|
|
|
|
return countEnum.GetDescription();
|
|
|
|
|
|
|
|
|
|
return count.ToString();
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
text.Colour = colours.Yellow;
|
|
|
|
|
valueText.Colour = colours.YellowLight;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PercentageBreakInfoLine : BreakInfoLine<double>
|
|
|
|
|
{
|
2019-02-28 04:31:40 +00:00
|
|
|
|
public PercentageBreakInfoLine(string name, string prefix = "")
|
|
|
|
|
: base(name, prefix)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 23:11:19 +00:00
|
|
|
|
protected override string Format(double count) => count.FormatAccuracy();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|