1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 16:12:54 +08:00

Add more comments and xmldoc

This commit is contained in:
Dean Herbert 2021-07-08 17:39:59 +09:00
parent 533db01cc0
commit 52ea62e3b2

View File

@ -16,9 +16,13 @@ namespace osu.Game.Rulesets.Mods
[Resolved] [Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } private IBindable<WorkingBeatmap> beatmap { get; set; }
protected readonly BindableNumber<float> CurrentNumber = new BindableNumber<float>(); /// <summary>
/// Used to track the display value on the setting slider.
/// This can either be a user override or the beatmap default (when <see cref="Current"/> is null).
/// </summary>
private readonly BindableNumber<float> displayNumber = new BindableNumber<float>();
protected override Drawable CreateControl() => new ControlDrawable(CurrentNumber); protected override Drawable CreateControl() => new ControlDrawable(displayNumber);
private bool isInternalChange; private bool isInternalChange;
@ -31,7 +35,10 @@ namespace osu.Game.Rulesets.Mods
{ {
// intercept and extract the DifficultyBindable. // intercept and extract the DifficultyBindable.
difficultyBindable = (DifficultyBindable)value; difficultyBindable = (DifficultyBindable)value;
CurrentNumber.BindTo(difficultyBindable.CurrentNumber);
// this bind is used to transfer bounds/precision only.
displayNumber.BindTo(difficultyBindable.CurrentNumber);
base.Current = value; base.Current = value;
} }
} }
@ -40,18 +47,18 @@ namespace osu.Game.Rulesets.Mods
{ {
base.LoadComplete(); base.LoadComplete();
beatmap.BindValueChanged(b => beatmap.BindValueChanged(b => updateFromDifficulty(), true);
{
updateFromDifficulty();
}, true);
Current.BindValueChanged(current => Current.BindValueChanged(current =>
{ {
// the user override has changed; transfer the correct value to the visual display.
if (current.NewValue == null) if (current.NewValue == null)
updateFromDifficulty(); updateFromDifficulty();
else
displayNumber.Value = current.NewValue.Value;
}); });
CurrentNumber.BindValueChanged(number => displayNumber.BindValueChanged(number =>
{ {
if (!isInternalChange) if (!isInternalChange)
Current.Value = number.NewValue; Current.Value = number.NewValue;
@ -67,8 +74,9 @@ namespace osu.Game.Rulesets.Mods
if (Current.Value == null) if (Current.Value == null)
{ {
// ensure the beatmap's value is not transferred as a user override.
isInternalChange = true; isInternalChange = true;
CurrentNumber.Value = difficultyBindable.ReadFromDifficulty(difficulty); displayNumber.Value = difficultyBindable.ReadFromDifficulty(difficulty);
isInternalChange = false; isInternalChange = false;
} }
} }
@ -77,6 +85,8 @@ namespace osu.Game.Rulesets.Mods
{ {
private readonly BindableWithCurrent<float?> current = new BindableWithCurrent<float?>(); private readonly BindableWithCurrent<float?> current = new BindableWithCurrent<float?>();
// Mainly just for fulfilling the interface requirements.
// The actual update flow is done via the provided number.
public Bindable<float?> Current public Bindable<float?> Current
{ {
get => current.Current; get => current.Current;