Define DifficultyBindableWithCurrent and use in SliderControl

This commit is contained in:
Salman Ahmed
2021-08-25 07:40:41 +03:00
parent 6fcbf81995
commit 84637b59ef

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -91,7 +92,7 @@ namespace osu.Game.Rulesets.Mods
{ {
// This is required as SettingsItem relies heavily on this bindable for internal use. // This is required as SettingsItem relies heavily on this bindable for internal use.
// The actual update flow is done via the bindable provided in the constructor. // The actual update flow is done via the bindable provided in the constructor.
private readonly BindableWithCurrent<float?> current = new BindableWithCurrent<float?>(); private readonly DifficultyBindableWithCurrent current = new DifficultyBindableWithCurrent();
public Bindable<float?> Current public Bindable<float?> Current
{ {
@ -114,5 +115,30 @@ namespace osu.Game.Rulesets.Mods
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
} }
} }
private class DifficultyBindableWithCurrent : DifficultyBindable, IHasCurrentValue<float?>
{
private Bindable<float?> currentBound;
public Bindable<float?> Current
{
get => this;
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
if (currentBound != null) UnbindFrom(currentBound);
BindTo(currentBound = value);
}
}
public DifficultyBindableWithCurrent(float? defaultValue = default)
: base(defaultValue)
{
}
protected override Bindable<float?> CreateInstance() => new DifficultyBindableWithCurrent();
}
} }
} }