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

Merge pull request #24736 from isakvik/negative-ar-adjustment

Allow "Difficulty Adjust" mod's extended AR selection to go below zero
This commit is contained in:
Dean Herbert 2023-09-07 17:17:59 +09:00 committed by GitHub
commit b1a9f50065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 15 deletions

View File

@ -2,13 +2,19 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq; using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Objects;
namespace osu.Game.Rulesets.Osu.Mods 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))] [SettingSource("Circle Size", "Override a beatmap's set CS.", FIRST_SETTING_ORDER - 1, SettingControlType = typeof(DifficultyAdjustSettingsControl))]
public DifficultyBindable CircleSize { get; } = new DifficultyBindable public DifficultyBindable CircleSize { get; } = new DifficultyBindable
@ -20,12 +26,13 @@ namespace osu.Game.Rulesets.Osu.Mods
ReadCurrentFromDifficulty = diff => diff.CircleSize, 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 public DifficultyBindable ApproachRate { get; } = new DifficultyBindable
{ {
Precision = 0.1f, Precision = 0.1f,
MinValue = 0, MinValue = 0,
MaxValue = 10, MaxValue = 10,
ExtendedMinValue = -10,
ExtendedMaxValue = 11, ExtendedMaxValue = 11,
ReadCurrentFromDifficulty = diff => diff.ApproachRate, ReadCurrentFromDifficulty = diff => diff.ApproachRate,
}; };
@ -53,5 +60,34 @@ namespace osu.Game.Rulesets.Osu.Mods
if (CircleSize.Value != null) difficulty.CircleSize = CircleSize.Value.Value; if (CircleSize.Value != null) difficulty.CircleSize = CircleSize.Value.Value;
if (ApproachRate.Value != null) difficulty.ApproachRate = ApproachRate.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;
}
}
}
} }
} }

View File

@ -29,7 +29,14 @@ namespace osu.Game.Rulesets.Mods
/// </remarks> /// </remarks>
private readonly BindableNumber<float> sliderDisplayCurrent = new BindableNumber<float>(); 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> /// <summary>
/// Guards against beatmap values displayed on slider bars being transferred to user override. /// Guards against beatmap values displayed on slider bars being transferred to user override.
@ -100,16 +107,11 @@ namespace osu.Game.Rulesets.Mods
set => current.Current = value; set => current.Current = value;
} }
public SliderControl(BindableNumber<float> currentNumber) public SliderControl(BindableNumber<float> currentNumber, Func<BindableNumber<float>, RoundedSliderBar<float>> createSlider)
{ {
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
new RoundedSliderBar<float> createSlider(currentNumber)
{
RelativeSizeAxes = Axes.X,
Current = currentNumber,
KeyboardStep = 0.1f,
}
}; };
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;

View File

@ -34,9 +34,18 @@ namespace osu.Game.Rulesets.Mods
set => CurrentNumber.Precision = value; set => CurrentNumber.Precision = value;
} }
private float minValue;
public float MinValue public float MinValue
{ {
set => CurrentNumber.MinValue = value; set
{
if (value == minValue)
return;
minValue = value;
updateExtents();
}
} }
private float maxValue; private float maxValue;
@ -49,7 +58,24 @@ namespace osu.Game.Rulesets.Mods
return; return;
maxValue = value; 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();
} }
} }
@ -66,7 +92,7 @@ namespace osu.Game.Rulesets.Mods
return; return;
extendedMaxValue = value; extendedMaxValue = value;
updateMaxValue(); updateExtents();
} }
} }
@ -78,7 +104,7 @@ namespace osu.Game.Rulesets.Mods
public DifficultyBindable(float? defaultValue = null) public DifficultyBindable(float? defaultValue = null)
: base(defaultValue) : base(defaultValue)
{ {
ExtendedLimits.BindValueChanged(_ => updateMaxValue()); ExtendedLimits.BindValueChanged(_ => updateExtents());
} }
public override float? Value public override float? Value
@ -94,8 +120,9 @@ namespace osu.Game.Rulesets.Mods
} }
} }
private void updateMaxValue() private void updateExtents()
{ {
CurrentNumber.MinValue = ExtendedLimits.Value && extendedMinValue != null ? extendedMinValue.Value : minValue;
CurrentNumber.MaxValue = ExtendedLimits.Value && extendedMaxValue != null ? extendedMaxValue.Value : maxValue; CurrentNumber.MaxValue = ExtendedLimits.Value && extendedMaxValue != null ? extendedMaxValue.Value : maxValue;
} }