2021-07-08 14:53:49 +08:00
|
|
|
// 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 osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Overlays.Settings;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mods
|
|
|
|
{
|
|
|
|
public class DifficultyAdjustSettingsControl : SettingsItem<float?>
|
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private IBindable<WorkingBeatmap> beatmap { get; set; }
|
|
|
|
|
2021-07-08 15:40:32 +08:00
|
|
|
protected readonly BindableNumber<float> CurrentNumber = new BindableNumber<float>();
|
2021-07-08 14:53:49 +08:00
|
|
|
|
|
|
|
protected override Drawable CreateControl() => new ControlDrawable(CurrentNumber);
|
|
|
|
|
|
|
|
private bool isInternalChange;
|
|
|
|
|
2021-07-08 15:40:32 +08:00
|
|
|
private DifficultyBindable difficultyBindable;
|
|
|
|
|
|
|
|
public override Bindable<float?> Current
|
|
|
|
{
|
|
|
|
get => base.Current;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
// intercept and extract the DifficultyBindable.
|
|
|
|
difficultyBindable = (DifficultyBindable)value;
|
|
|
|
CurrentNumber.BindTo(difficultyBindable.CurrentNumber);
|
|
|
|
base.Current = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-08 14:53:49 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
beatmap.BindValueChanged(b =>
|
|
|
|
{
|
|
|
|
updateFromDifficulty();
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
Current.BindValueChanged(current =>
|
|
|
|
{
|
|
|
|
if (current.NewValue == null)
|
|
|
|
updateFromDifficulty();
|
|
|
|
});
|
|
|
|
|
|
|
|
CurrentNumber.BindValueChanged(number =>
|
|
|
|
{
|
|
|
|
if (!isInternalChange)
|
|
|
|
Current.Value = number.NewValue;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateFromDifficulty()
|
|
|
|
{
|
|
|
|
var difficulty = beatmap.Value.BeatmapInfo.BaseDifficulty;
|
|
|
|
|
|
|
|
if (difficulty == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Current.Value == null)
|
|
|
|
{
|
|
|
|
isInternalChange = true;
|
2021-07-08 15:56:16 +08:00
|
|
|
CurrentNumber.Value = difficultyBindable.ReadFromDifficulty(difficulty);
|
2021-07-08 14:53:49 +08:00
|
|
|
isInternalChange = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ControlDrawable : CompositeDrawable, IHasCurrentValue<float?>
|
|
|
|
{
|
|
|
|
private readonly BindableWithCurrent<float?> current = new BindableWithCurrent<float?>();
|
|
|
|
|
|
|
|
public Bindable<float?> Current
|
|
|
|
{
|
|
|
|
get => current.Current;
|
|
|
|
set => current.Current = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ControlDrawable(BindableNumber<float> currentNumber)
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new SettingsSlider<float>
|
|
|
|
{
|
|
|
|
ShowsDefaultIndicator = false,
|
|
|
|
Current = currentNumber,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|