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 16:39:59 +08:00
|
|
|
/// <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>();
|
2021-07-08 14:53:49 +08:00
|
|
|
|
2021-07-08 19:37:38 +08:00
|
|
|
protected override Drawable CreateControl() => new SliderControl(displayNumber);
|
2021-07-08 14:53:49 +08:00
|
|
|
|
|
|
|
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;
|
2021-07-08 16:39:59 +08:00
|
|
|
|
|
|
|
// this bind is used to transfer bounds/precision only.
|
|
|
|
displayNumber.BindTo(difficultyBindable.CurrentNumber);
|
|
|
|
|
2021-07-08 15:40:32 +08:00
|
|
|
base.Current = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-08 14:53:49 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2021-07-08 16:39:59 +08:00
|
|
|
beatmap.BindValueChanged(b => updateFromDifficulty(), true);
|
2021-07-08 14:53:49 +08:00
|
|
|
|
|
|
|
Current.BindValueChanged(current =>
|
|
|
|
{
|
2021-07-08 16:39:59 +08:00
|
|
|
// the user override has changed; transfer the correct value to the visual display.
|
2021-07-08 14:53:49 +08:00
|
|
|
if (current.NewValue == null)
|
|
|
|
updateFromDifficulty();
|
2021-07-08 16:39:59 +08:00
|
|
|
else
|
|
|
|
displayNumber.Value = current.NewValue.Value;
|
2021-07-08 14:53:49 +08:00
|
|
|
});
|
|
|
|
|
2021-07-08 16:39:59 +08:00
|
|
|
displayNumber.BindValueChanged(number =>
|
2021-07-08 14:53:49 +08:00
|
|
|
{
|
|
|
|
if (!isInternalChange)
|
|
|
|
Current.Value = number.NewValue;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateFromDifficulty()
|
|
|
|
{
|
|
|
|
var difficulty = beatmap.Value.BeatmapInfo.BaseDifficulty;
|
|
|
|
|
|
|
|
if (difficulty == null)
|
|
|
|
return;
|
|
|
|
|
2021-07-09 12:26:00 +08:00
|
|
|
if (Current.Value == null && difficultyBindable.ReadCurrentFromDifficulty != null)
|
2021-07-08 14:53:49 +08:00
|
|
|
{
|
2021-07-08 16:39:59 +08:00
|
|
|
// ensure the beatmap's value is not transferred as a user override.
|
2021-07-08 14:53:49 +08:00
|
|
|
isInternalChange = true;
|
2021-07-09 12:24:26 +08:00
|
|
|
displayNumber.Value = difficultyBindable.ReadCurrentFromDifficulty(difficulty);
|
2021-07-08 14:53:49 +08:00
|
|
|
isInternalChange = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-08 19:37:38 +08:00
|
|
|
private class SliderControl : CompositeDrawable, IHasCurrentValue<float?>
|
2021-07-08 14:53:49 +08:00
|
|
|
{
|
|
|
|
private readonly BindableWithCurrent<float?> current = new BindableWithCurrent<float?>();
|
|
|
|
|
2021-07-08 16:39:59 +08:00
|
|
|
// Mainly just for fulfilling the interface requirements.
|
|
|
|
// The actual update flow is done via the provided number.
|
2021-07-08 19:37:38 +08:00
|
|
|
// Of note, this is used for the "reset to default" flow.
|
2021-07-08 14:53:49 +08:00
|
|
|
public Bindable<float?> Current
|
|
|
|
{
|
|
|
|
get => current.Current;
|
|
|
|
set => current.Current = value;
|
|
|
|
}
|
|
|
|
|
2021-07-08 19:37:38 +08:00
|
|
|
public SliderControl(BindableNumber<float> currentNumber)
|
2021-07-08 14:53:49 +08:00
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new SettingsSlider<float>
|
|
|
|
{
|
|
|
|
ShowsDefaultIndicator = false,
|
|
|
|
Current = currentNumber,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|