1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 05:32:54 +08:00

Inline local control

This commit is contained in:
Dean Herbert 2023-09-07 14:20:19 +09:00
parent d2a6235135
commit e05d7d5f8d
3 changed files with 39 additions and 45 deletions

View File

@ -1,14 +1,18 @@
// 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 System;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.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))]
public DifficultyBindable CircleSize { get; } = new DifficultyBindable
@ -20,7 +24,7 @@ namespace osu.Game.Rulesets.Osu.Mods
ReadCurrentFromDifficulty = diff => diff.CircleSize,
};
[SettingSource("Approach Rate", "Override a beatmap's set AR.", LAST_SETTING_ORDER + 1, SettingControlType = typeof(ApproachRateDifficultyAdjustSettingsControl))]
[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,
@ -54,5 +58,31 @@ namespace osu.Game.Rulesets.Osu.Mods
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 Drawable CreateControl() => new SliderControl(SliderDisplayCurrent,
new ApproachRateSlider
{
RelativeSizeAxes = Axes.X,
Current = SliderDisplayCurrent,
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 =>
$"{base.TooltipText} ({millisecondsFromApproachRate(Current.Value, 1.0f)} ms)";
private double millisecondsFromApproachRate(float value, float clockRate)
{
return Math.Round(1800 - Math.Min(value, 5) * 120 - (value >= 5 ? (value - 5) * 150 : 0) / clockRate);
}
}
}
}
}

View File

@ -1,36 +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 System;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Rulesets.Mods
{
public partial class ApproachRateDifficultyAdjustSettingsControl : DifficultyAdjustSettingsControl
{
protected override Drawable CreateControl() => new SliderControl(sliderDisplayCurrent,
new ApproachRateSlider
{
RelativeSizeAxes = Axes.X,
Current = sliderDisplayCurrent,
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 =>
$"{base.TooltipText} ({millisecondsFromApproachRate(Current.Value, 1.0f)} ms)";
private double millisecondsFromApproachRate(float value, float clockRate)
{
return Math.Round(1800 - Math.Min(value, 5) * 120 - (value >= 5 ? (value - 5) * 150 : 0) / clockRate);
}
}
}
}

View File

@ -27,13 +27,13 @@ namespace osu.Game.Rulesets.Mods
/// When the mod is overriding a default, this will match the value of <see cref="Current"/>.
/// When there is no override (ie. <see cref="Current"/> is null), this value will match the beatmap provided default via <see cref="updateCurrentFromSlider"/>.
/// </remarks>
protected readonly BindableNumber<float> sliderDisplayCurrent = new BindableNumber<float>();
protected readonly BindableNumber<float> SliderDisplayCurrent = new BindableNumber<float>();
protected override Drawable CreateControl() => new SliderControl(sliderDisplayCurrent,
protected override Drawable CreateControl() => new SliderControl(SliderDisplayCurrent,
new RoundedSliderBar<float>
{
RelativeSizeAxes = Axes.X,
Current = sliderDisplayCurrent,
Current = SliderDisplayCurrent,
KeyboardStep = 0.1f,
}
);
@ -53,7 +53,7 @@ namespace osu.Game.Rulesets.Mods
// Intercept and extract the internal number bindable from DifficultyBindable.
// This will provide bounds and precision specifications for the slider bar.
difficultyBindable = (DifficultyBindable)value.GetBoundCopy();
sliderDisplayCurrent.BindTo(difficultyBindable.CurrentNumber);
SliderDisplayCurrent.BindTo(difficultyBindable.CurrentNumber);
base.Current = difficultyBindable;
}
@ -66,7 +66,7 @@ namespace osu.Game.Rulesets.Mods
Current.BindValueChanged(_ => updateCurrentFromSlider());
beatmap.BindValueChanged(_ => updateCurrentFromSlider(), true);
sliderDisplayCurrent.BindValueChanged(number =>
SliderDisplayCurrent.BindValueChanged(number =>
{
// this handles the transfer of the slider value to the main bindable.
// as such, should be skipped if the slider is being updated via updateFromDifficulty().
@ -80,7 +80,7 @@ namespace osu.Game.Rulesets.Mods
if (Current.Value != null)
{
// a user override has been added or updated.
sliderDisplayCurrent.Value = Current.Value.Value;
SliderDisplayCurrent.Value = Current.Value.Value;
return;
}
@ -91,7 +91,7 @@ namespace osu.Game.Rulesets.Mods
return;
isInternalChange = true;
sliderDisplayCurrent.Value = difficultyBindable.ReadCurrentFromDifficulty(difficulty);
SliderDisplayCurrent.Value = difficultyBindable.ReadCurrentFromDifficulty(difficulty);
isInternalChange = false;
}