add a function to OsuSliderBar to manually set the tooltip text

This commit is contained in:
Jorolf
2017-04-20 14:52:06 +02:00
parent 1d2f19b5a2
commit 02249dcd67
6 changed files with 35 additions and 8 deletions

View File

@ -10,6 +10,8 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input; using osu.Framework.Input;
using System;
using System.Globalization;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
@ -23,16 +25,20 @@ namespace osu.Game.Graphics.UserInterface
private readonly Box leftBox; private readonly Box leftBox;
private readonly Box rightBox; private readonly Box rightBox;
public Func<T, string> TooltipTextFunc { get; set; }
public string TooltipText public string TooltipText
{ {
get get
{ {
if (TooltipTextFunc != null) return TooltipTextFunc(Current);
var bindableDouble = CurrentNumber as BindableNumber<double>; var bindableDouble = CurrentNumber as BindableNumber<double>;
if (bindableDouble != null) if (bindableDouble != null)
{ {
if (bindableDouble.MaxValue == 1 && bindableDouble.MinValue == 0) if (bindableDouble.MaxValue == 1 && (bindableDouble.MinValue == 0 || bindableDouble.MinValue == -1))
return bindableDouble.Value.ToString(@"P0"); return bindableDouble.Value.ToString(@"P0");
return bindableDouble.Value.ToString(@"n1"); return bindableDouble.Value.ToString(@"n1", CultureInfo.InvariantCulture);
} }
var bindableInt = CurrentNumber as BindableNumber<int>; var bindableInt = CurrentNumber as BindableNumber<int>;

View File

@ -6,15 +6,15 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using System;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
public class OptionSlider<T> : FillFlowContainer where T : struct public class OptionSlider<T> : FillFlowContainer where T : struct
{ {
private readonly SliderBar<T> slider; private readonly OsuSliderBar<T> slider;
private readonly SpriteText text; private readonly SpriteText text;
public string LabelText public string LabelText
@ -38,6 +38,18 @@ namespace osu.Game.Overlays.Options
} }
} }
public Func<T,string> TooltipText
{
get
{
return slider.TooltipTextFunc;
}
set
{
slider.TooltipTextFunc = value;
}
}
public OptionSlider() public OptionSlider()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;

View File

@ -22,6 +22,7 @@ namespace osu.Game.Overlays.Options.Sections.Audio
{ {
LabelText = "Audio Offset", LabelText = "Audio Offset",
Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.AudioOffset) Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.AudioOffset)
TooltipText = value => value.ToString(@"0ms")
}, },
new OsuButton new OsuButton
{ {

View File

@ -5,6 +5,7 @@ using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Configuration; using osu.Game.Configuration;
using System.Globalization;
namespace osu.Game.Overlays.Options.Sections.Gameplay namespace osu.Game.Overlays.Options.Sections.Gameplay
{ {
@ -20,12 +21,14 @@ namespace osu.Game.Overlays.Options.Sections.Gameplay
new OptionSlider<double> new OptionSlider<double>
{ {
LabelText = "Display beatmaps from", LabelText = "Display beatmaps from",
Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.DisplayStarsMinimum) Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.DisplayStarsMinimum),
TooltipText = value => value.ToString(@"0.## stars", CultureInfo.InvariantCulture)
}, },
new OptionSlider<double> new OptionSlider<double>
{ {
LabelText = "up to", LabelText = "up to",
Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.DisplayStarsMaximum) Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.DisplayStarsMaximum),
TooltipText = value => value.ToString(@"0.## stars", CultureInfo.InvariantCulture)
}, },
}; };
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Globalization;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -22,6 +23,7 @@ namespace osu.Game.Overlays.Options.Sections.Input
{ {
LabelText = "Sensitivity", LabelText = "Sensitivity",
Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.MouseSpeed), Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.MouseSpeed),
TooltipText = value => value.ToString(@"0.##x", CultureInfo.InvariantCulture)
}, },
new OsuCheckbox new OsuCheckbox
{ {

View File

@ -8,6 +8,7 @@ using osu.Game.Configuration;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using OpenTK; using OpenTK;
using System.Globalization;
namespace osu.Game.Overlays.Options.Sections namespace osu.Game.Overlays.Options.Sections
{ {
@ -62,12 +63,14 @@ namespace osu.Game.Overlays.Options.Sections
new OptionSlider<double> new OptionSlider<double>
{ {
LabelText = "Menu cursor size", LabelText = "Menu cursor size",
Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.MenuCursorSize) Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.MenuCursorSize),
TooltipText = value => value.ToString(@"0.##x", CultureInfo.InvariantCulture)
}, },
new OptionSlider<double> new OptionSlider<double>
{ {
LabelText = "Gameplay cursor size", LabelText = "Gameplay cursor size",
Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.GameplayCursorSize) Bindable = (BindableDouble)config.GetBindable<double>(OsuConfig.GameplayCursorSize),
TooltipText = value => value.ToString(@"0.##x", CultureInfo.InvariantCulture)
}, },
new OsuCheckbox new OsuCheckbox
{ {