mirror of
https://github.com/ppy/osu
synced 2024-12-14 10:57:41 +00:00
Merge pull request #14487 from frenzibyte/alternative-difficulty-bindable
Fix unbind exception in `DifficultyBindable` due to different bindable type bindings
This commit is contained in:
commit
aacca006e4
@ -1,6 +1,7 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
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.
|
||||
// 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
|
||||
{
|
||||
@ -114,5 +115,30 @@ namespace osu.Game.Rulesets.Mods
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user