1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02:55 +08:00

Fix sliderbar not working correctly with TransferValueOnCommit = true

This commit is contained in:
smoogipoo 2019-01-08 16:07:54 +09:00
parent 7bb4a06122
commit 8692be9de3
4 changed files with 45 additions and 52 deletions

View File

@ -8,7 +8,6 @@ using osuTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
@ -33,38 +32,7 @@ namespace osu.Game.Graphics.UserInterface
private readonly Box leftBox; private readonly Box leftBox;
private readonly Box rightBox; private readonly Box rightBox;
public virtual string TooltipText public virtual string TooltipText { get; private set; }
{
get
{
var bindableDouble = CurrentNumber as BindableNumber<double>;
var bindableFloat = CurrentNumber as BindableNumber<float>;
var floatValue = bindableDouble?.Value ?? bindableFloat?.Value;
var floatPrecision = bindableDouble?.Precision ?? bindableFloat?.Precision;
if (floatValue != null)
{
var floatMinValue = bindableDouble?.MinValue ?? bindableFloat.MinValue;
var floatMaxValue = bindableDouble?.MaxValue ?? bindableFloat.MaxValue;
if (floatMaxValue == 1 && (floatMinValue == 0 || floatMinValue == -1))
return floatValue.Value.ToString("P0");
var decimalPrecision = normalise((decimal)floatPrecision, max_decimal_digits);
// Find the number of significant digits (we could have less than 5 after normalize())
var significantDigits = findPrecision(decimalPrecision);
return floatValue.Value.ToString($"N{significantDigits}");
}
var bindableInt = CurrentNumber as BindableNumber<int>;
if (bindableInt != null)
return bindableInt.Value.ToString("N0");
return Current.Value.ToString(CultureInfo.InvariantCulture);
}
}
private Color4 accentColour; private Color4 accentColour;
public Color4 AccentColour public Color4 AccentColour
@ -136,21 +104,34 @@ namespace osu.Game.Graphics.UserInterface
base.OnHoverLost(e); base.OnHoverLost(e);
} }
protected override void OnUserChange() protected override bool OnMouseDown(MouseDownEvent e)
{ {
base.OnUserChange(); Nub.Current.Value = true;
playSample(); return base.OnMouseDown(e);
} }
private void playSample() protected override bool OnMouseUp(MouseUpEvent e)
{
Nub.Current.Value = false;
return base.OnMouseUp(e);
}
protected override void OnUserChange(T value)
{
base.OnUserChange(value);
playSample(value);
updateTooltipText(value);
}
private void playSample(T value)
{ {
if (Clock == null || Clock.CurrentTime - lastSampleTime <= 50) if (Clock == null || Clock.CurrentTime - lastSampleTime <= 50)
return; return;
if (Current.Value.Equals(lastSampleValue)) if (value.Equals(lastSampleValue))
return; return;
lastSampleValue = Current.Value; lastSampleValue = value;
lastSampleTime = Clock.CurrentTime; lastSampleTime = Clock.CurrentTime;
sample.Frequency.Value = 1 + NormalizedValue * 0.2f; sample.Frequency.Value = 1 + NormalizedValue * 0.2f;
@ -163,16 +144,28 @@ namespace osu.Game.Graphics.UserInterface
sample.Play(); sample.Play();
} }
protected override bool OnMouseDown(MouseDownEvent e) private void updateTooltipText(T value)
{ {
Nub.Current.Value = true; if (CurrentNumber.IsInteger)
return base.OnMouseDown(e); TooltipText = ((int)Convert.ChangeType(value, typeof(int))).ToString("N0");
} else
{
double floatValue = (double)Convert.ChangeType(value, typeof(double));
double floatMinValue = (double)Convert.ChangeType(CurrentNumber.MinValue, typeof(double));
double floatMaxValue = (double)Convert.ChangeType(CurrentNumber.MaxValue, typeof(double));
protected override bool OnMouseUp(MouseUpEvent e) if (floatMaxValue == 1 && floatMinValue >= -1)
{ TooltipText = floatValue.ToString("P0");
Nub.Current.Value = false; else
return base.OnMouseUp(e); {
var decimalPrecision = normalise((decimal)Convert.ChangeType(CurrentNumber.Precision, typeof(decimal)), max_decimal_digits);
// Find the number of significant digits (we could have less than 5 after normalize())
var significantDigits = findPrecision(decimalPrecision);
TooltipText = floatValue.ToString($"N{significantDigits}");
}
}
} }
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()

View File

@ -62,6 +62,6 @@ namespace osu.Game.Graphics.UserInterface
fill.Width = value * UsableWidth; fill.Width = value * UsableWidth;
} }
protected override void OnUserChange() => OnSeek?.Invoke(Current); protected override void OnUserChange(double value) => OnSeek?.Invoke(Current);
} }
} }

View File

@ -238,11 +238,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
{ {
case Key.Right: case Key.Right:
beatDivisor.Next(); beatDivisor.Next();
OnUserChange(); OnUserChange(Current);
return true; return true;
case Key.Left: case Key.Left:
beatDivisor.Previous(); beatDivisor.Previous();
OnUserChange(); OnUserChange(Current);
return true; return true;
default: default:
return false; return false;
@ -279,7 +279,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
var xPosition = (ToLocalSpace(screenSpaceMousePosition).X - RangePadding) / UsableWidth; var xPosition = (ToLocalSpace(screenSpaceMousePosition).X - RangePadding) / UsableWidth;
CurrentNumber.Value = availableDivisors.OrderBy(d => Math.Abs(getMappedPosition(d) - xPosition)).First(); CurrentNumber.Value = availableDivisors.OrderBy(d => Math.Abs(getMappedPosition(d) - xPosition)).First();
OnUserChange(); OnUserChange(Current);
} }
private float getMappedPosition(float divisor) => (float)Math.Pow((divisor - 1) / (availableDivisors.Last() - 1), 0.90f); private float getMappedPosition(float divisor) => (float)Math.Pow((divisor - 1) / (availableDivisors.Last() - 1), 0.90f);

View File

@ -112,6 +112,6 @@ namespace osu.Game.Screens.Play
handleBase.X = xFill; handleBase.X = xFill;
} }
protected override void OnUserChange() => OnSeek?.Invoke(Current); protected override void OnUserChange(double value) => OnSeek?.Invoke(Current);
} }
} }