Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "Difficulty Adjust" mod's extended AR selection to go below zero #24736

Merged
merged 7 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 38 additions & 2 deletions osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Objects;

namespace osu.Game.Rulesets.Osu.Mods
{
public class OsuModDifficultyAdjust : ModDifficultyAdjust
public partial class OsuModDifficultyAdjust : ModDifficultyAdjust
{
[SettingSource("Circle Size", "Override a beatmap's set CS.", FIRST_SETTING_ORDER - 1, SettingControlType = typeof(DifficultyAdjustSettingsControl))]
public DifficultyBindable CircleSize { get; } = new DifficultyBindable
Expand All @@ -20,12 +26,13 @@ public class OsuModDifficultyAdjust : ModDifficultyAdjust
ReadCurrentFromDifficulty = diff => diff.CircleSize,
};

[SettingSource("Approach Rate", "Override a beatmap's set AR.", LAST_SETTING_ORDER + 1, SettingControlType = typeof(DifficultyAdjustSettingsControl))]
[SettingSource("Approach Rate", "Override a beatmap's set AR.", LAST_SETTING_ORDER + 1, SettingControlType = typeof(ApproachRateSettingsControl))]
public DifficultyBindable ApproachRate { get; } = new DifficultyBindable
{
Precision = 0.1f,
MinValue = 0,
MaxValue = 10,
ExtendedMinValue = -10,
ExtendedMaxValue = 11,
ReadCurrentFromDifficulty = diff => diff.ApproachRate,
};
Expand Down Expand Up @@ -53,5 +60,34 @@ protected override void ApplySettings(BeatmapDifficulty difficulty)
if (CircleSize.Value != null) difficulty.CircleSize = CircleSize.Value.Value;
if (ApproachRate.Value != null) difficulty.ApproachRate = ApproachRate.Value.Value;
}

private partial class ApproachRateSettingsControl : DifficultyAdjustSettingsControl
{
protected override RoundedSliderBar<float> CreateSlider(BindableNumber<float> current) =>
new ApproachRateSlider
{
RelativeSizeAxes = Axes.X,
Current = current,
KeyboardStep = 0.1f,
};

/// <summary>
/// A slider bar with more detailed approach rate info for its given value
/// </summary>
public partial class ApproachRateSlider : RoundedSliderBar<float>
{
public override LocalisableString TooltipText =>
(Current as BindableNumber<float>)?.MinValue < 0
? $"{base.TooltipText} ({getPreemptTime(Current.Value):0} ms)"
: base.TooltipText;

private double getPreemptTime(float approachRate)
{
var hitCircle = new HitCircle();
hitCircle.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { ApproachRate = approachRate });
return hitCircle.TimePreempt;
}
}
}
}
}
18 changes: 10 additions & 8 deletions osu.Game/Rulesets/Mods/DifficultyAdjustSettingsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ public partial class DifficultyAdjustSettingsControl : SettingsItem<float?>
/// </remarks>
private readonly BindableNumber<float> sliderDisplayCurrent = new BindableNumber<float>();

protected override Drawable CreateControl() => new SliderControl(sliderDisplayCurrent);
protected sealed override Drawable CreateControl() => new SliderControl(sliderDisplayCurrent, CreateSlider);

protected virtual RoundedSliderBar<float> CreateSlider(BindableNumber<float> current) => new RoundedSliderBar<float>
{
RelativeSizeAxes = Axes.X,
Current = current,
KeyboardStep = 0.1f,
};

/// <summary>
/// Guards against beatmap values displayed on slider bars being transferred to user override.
Expand Down Expand Up @@ -100,16 +107,11 @@ private partial class SliderControl : CompositeDrawable, IHasCurrentValue<float?
set => current.Current = value;
}

public SliderControl(BindableNumber<float> currentNumber)
public SliderControl(BindableNumber<float> currentNumber, Func<BindableNumber<float>, RoundedSliderBar<float>> createSlider)
{
InternalChildren = new Drawable[]
{
new RoundedSliderBar<float>
{
RelativeSizeAxes = Axes.X,
Current = currentNumber,
KeyboardStep = 0.1f,
}
createSlider(currentNumber)
};

AutoSizeAxes = Axes.Y;
Expand Down
37 changes: 32 additions & 5 deletions osu.Game/Rulesets/Mods/DifficultyBindable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,18 @@ public float Precision
set => CurrentNumber.Precision = value;
}

private float minValue;

public float MinValue
{
set => CurrentNumber.MinValue = value;
set
{
if (value == minValue)
return;

minValue = value;
updateExtents();
}
}

private float maxValue;
Expand All @@ -49,7 +58,24 @@ public float MaxValue
return;

maxValue = value;
updateMaxValue();
updateExtents();
}
}

private float? extendedMinValue;

/// <summary>
/// The minimum value to be used when extended limits are applied.
/// </summary>
public float? ExtendedMinValue
{
set
{
if (value == extendedMinValue)
return;

extendedMinValue = value;
updateExtents();
}
}

Expand All @@ -66,7 +92,7 @@ public float MaxValue
return;

extendedMaxValue = value;
updateMaxValue();
updateExtents();
}
}

Expand All @@ -78,7 +104,7 @@ public DifficultyBindable()
public DifficultyBindable(float? defaultValue = null)
: base(defaultValue)
{
ExtendedLimits.BindValueChanged(_ => updateMaxValue());
ExtendedLimits.BindValueChanged(_ => updateExtents());
}

public override float? Value
Expand All @@ -94,8 +120,9 @@ public DifficultyBindable(float? defaultValue = null)
}
}

private void updateMaxValue()
private void updateExtents()
{
CurrentNumber.MinValue = ExtendedLimits.Value && extendedMinValue != null ? extendedMinValue.Value : minValue;
CurrentNumber.MaxValue = ExtendedLimits.Value && extendedMaxValue != null ? extendedMaxValue.Value : maxValue;
}

Expand Down