Avoid the need for per-settings control classes

This commit is contained in:
Dean Herbert 2021-07-08 16:56:16 +09:00
parent a6e94dd491
commit bd7c334588
7 changed files with 17 additions and 18 deletions

View File

@ -18,6 +18,8 @@ namespace osu.Game.Rulesets.Catch.Mods
Precision = 0.1f,
MinValue = 1,
MaxValue = 10,
ExtendedMaxValue = 11,
ReadFromDifficulty = diff => diff.CircleSize,
};
[SettingSource("Approach Rate", "Override a beatmap's set AR.", LAST_SETTING_ORDER + 1)]
@ -26,6 +28,8 @@ namespace osu.Game.Rulesets.Catch.Mods
Precision = 0.1f,
MinValue = 1,
MaxValue = 10,
ExtendedMaxValue = 11,
ReadFromDifficulty = diff => diff.ApproachRate,
};
[SettingSource("Spicy Patterns", "Adjust the patterns as if Hard Rock is enabled.")]

View File

@ -17,15 +17,17 @@ namespace osu.Game.Rulesets.Osu.Mods
MinValue = 0,
MaxValue = 10,
ExtendedMaxValue = 11,
ReadFromDifficulty = diff => diff.CircleSize,
};
[SettingSource("Approach Rate", "Override a beatmap's set AR.", LAST_SETTING_ORDER + 1, SettingControlType = typeof(ApproachRateSettingsControl))]
[SettingSource("Approach Rate", "Override a beatmap's set AR.", LAST_SETTING_ORDER + 1, SettingControlType = typeof(DifficultyAdjustSettingsControl))]
public DifficultyBindable ApproachRate { get; } = new DifficultyBindable
{
Precision = 0.1f,
MinValue = 0,
MaxValue = 10,
ExtendedMaxValue = 11,
ReadFromDifficulty = diff => diff.ApproachRate,
};
public OsuModDifficultyAdjust()

View File

@ -16,6 +16,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
Precision = 0.05f,
MinValue = 0.25f,
MaxValue = 4,
ReadFromDifficulty = _ => 1,
};
public override string SettingDescription

View File

@ -1,12 +0,0 @@
// 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.Game.Beatmaps;
namespace osu.Game.Rulesets.Mods
{
public class ApproachRateSettingsControl : DifficultyAdjustSettingsControl
{
protected override float UpdateFromDifficulty(BeatmapDifficulty difficulty) => difficulty.ApproachRate;
}
}

View File

@ -11,7 +11,6 @@ using osu.Game.Overlays.Settings;
namespace osu.Game.Rulesets.Mods
{
// TODO: make abstract once we finish making each implementation.
public class DifficultyAdjustSettingsControl : SettingsItem<float?>
{
[Resolved]
@ -69,14 +68,11 @@ namespace osu.Game.Rulesets.Mods
if (Current.Value == null)
{
isInternalChange = true;
CurrentNumber.Value = UpdateFromDifficulty(difficulty);
CurrentNumber.Value = difficultyBindable.ReadFromDifficulty(difficulty);
isInternalChange = false;
}
}
// TODO: make abstract
protected virtual float UpdateFromDifficulty(BeatmapDifficulty difficulty) => 0;
private class ControlDrawable : CompositeDrawable, IHasCurrentValue<float?>
{
private readonly BindableWithCurrent<float?> current = new BindableWithCurrent<float?>();

View File

@ -3,6 +3,7 @@
using System;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
namespace osu.Game.Rulesets.Mods
{
@ -23,6 +24,11 @@ namespace osu.Game.Rulesets.Mods
MaxValue = 10,
};
/// <summary>
/// A function that can extract the current value of this setting from a beatmap difficulty for display purposes.
/// </summary>
public Func<BeatmapDifficulty, float> ReadFromDifficulty;
public float Precision
{
set => CurrentNumber.Precision = value;

View File

@ -39,6 +39,7 @@ namespace osu.Game.Rulesets.Mods
MinValue = 0,
MaxValue = 10,
ExtendedMaxValue = 11,
ReadFromDifficulty = diff => diff.DrainRate,
};
[SettingSource("Accuracy", "Override a beatmap's set OD.", LAST_SETTING_ORDER, SettingControlType = typeof(DifficultyAdjustSettingsControl))]
@ -48,6 +49,7 @@ namespace osu.Game.Rulesets.Mods
MinValue = 0,
MaxValue = 10,
ExtendedMaxValue = 11,
ReadFromDifficulty = diff => diff.OverallDifficulty,
};
[SettingSource("Extended Limits", "Adjust difficulty beyond sane limits.")]