From c4313d6e96b687befbbc9462c4320c3185e24dbf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 8 Jul 2021 15:53:49 +0900 Subject: [PATCH] Initial implementation of new flow (only working for approach rate) --- .../Mods/OsuModDifficultyAdjust.cs | 4 +- .../TestSceneModDifficultyAdjustSettings.cs | 74 ++++++++++++++ .../Mods/ApproachRateSettingsControl.cs | 20 ++++ .../Mods/DifficultyAdjustSettingsControl.cs | 97 +++++++++++++++++++ osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs | 4 +- 5 files changed, 195 insertions(+), 4 deletions(-) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneModDifficultyAdjustSettings.cs create mode 100644 osu.Game/Rulesets/Mods/ApproachRateSettingsControl.cs create mode 100644 osu.Game/Rulesets/Mods/DifficultyAdjustSettingsControl.cs diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs b/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs index 54e30c56a3..82c4a6fd56 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs @@ -11,7 +11,7 @@ namespace osu.Game.Rulesets.Osu.Mods { public class OsuModDifficultyAdjust : ModDifficultyAdjust { - [SettingSource("Circle Size", "Override a beatmap's set CS.", FIRST_SETTING_ORDER - 1)] + [SettingSource("Circle Size", "Override a beatmap's set CS.", FIRST_SETTING_ORDER - 1, SettingControlType = typeof(DifficultyAdjustSettingsControl))] public Bindable CircleSize { get; } = new Bindable { /* @@ -21,7 +21,7 @@ namespace osu.Game.Rulesets.Osu.Mods */ }; - [SettingSource("Approach Rate", "Override a beatmap's set AR.", LAST_SETTING_ORDER + 1)] + [SettingSource("Approach Rate", "Override a beatmap's set AR.", LAST_SETTING_ORDER + 1, SettingControlType = typeof(ApproachRateSettingsControl))] public Bindable ApproachRate { get; } = new Bindable { /* diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModDifficultyAdjustSettings.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModDifficultyAdjustSettings.cs new file mode 100644 index 0000000000..b1ad92273c --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModDifficultyAdjustSettings.cs @@ -0,0 +1,74 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Testing; +using osu.Game.Beatmaps; +using osu.Game.Configuration; +using osu.Game.Rulesets.Osu.Mods; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneModDifficultyAdjustSettings : OsuManualInputManagerTestScene + { + [SetUpSteps] + public void SetUpSteps() + { + AddStep("create difficulty adjust", () => + { + var modDifficultyAdjust = new OsuModDifficultyAdjust(); + + Child = new Container + { + Size = new Vector2(300), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Children = new Drawable[] + { + new Box + { + Colour = Color4.Black, + RelativeSizeAxes = Axes.Both, + }, + new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + ChildrenEnumerable = modDifficultyAdjust.CreateSettingsControls(), + }, + } + }; + }); + + setBeatmapWithDifficultyParameters(5); + setBeatmapWithDifficultyParameters(8); + } + + [Test] + public void TestBasic() + { + } + + private void setBeatmapWithDifficultyParameters(float value) + { + AddStep($"set beatmap with all {value}", () => Beatmap.Value = CreateWorkingBeatmap(new Beatmap() + { + BeatmapInfo = new BeatmapInfo + { + BaseDifficulty = new BeatmapDifficulty + { + OverallDifficulty = value, + CircleSize = value, + DrainRate = value, + ApproachRate = value, + } + } + })); + } + } +} diff --git a/osu.Game/Rulesets/Mods/ApproachRateSettingsControl.cs b/osu.Game/Rulesets/Mods/ApproachRateSettingsControl.cs new file mode 100644 index 0000000000..15a94cb271 --- /dev/null +++ b/osu.Game/Rulesets/Mods/ApproachRateSettingsControl.cs @@ -0,0 +1,20 @@ +// Copyright (c) ppy Pty Ltd . 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 + { + public ApproachRateSettingsControl() + { + CurrentNumber.Precision = 0.1f; + + CurrentNumber.MinValue = 0; + CurrentNumber.MaxValue = 10; + } + + protected override float UpdateFromDifficulty(BeatmapDifficulty difficulty) => difficulty.ApproachRate; + } +} diff --git a/osu.Game/Rulesets/Mods/DifficultyAdjustSettingsControl.cs b/osu.Game/Rulesets/Mods/DifficultyAdjustSettingsControl.cs new file mode 100644 index 0000000000..2b437370ea --- /dev/null +++ b/osu.Game/Rulesets/Mods/DifficultyAdjustSettingsControl.cs @@ -0,0 +1,97 @@ +// Copyright (c) ppy Pty Ltd . 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 +{ + // TODO: make abstract once we finish making each implementation. + public class DifficultyAdjustSettingsControl : SettingsItem + { + [Resolved] + private IBindable beatmap { get; set; } + + protected readonly BindableNumber CurrentNumber = new BindableNumber + { + // TODO: these need to be pulled out of the main bindable. + MinValue = 0, + MaxValue = 10, + }; + + protected override Drawable CreateControl() => new ControlDrawable(CurrentNumber); + + private bool isInternalChange; + + protected override void LoadComplete() + { + base.LoadComplete(); + + beatmap.BindValueChanged(b => + { + updateFromDifficulty(); + }, true); + + Current.BindValueChanged(current => + { + if (current.NewValue == null) + updateFromDifficulty(); + }); + + CurrentNumber.BindValueChanged(number => + { + if (!isInternalChange) + Current.Value = number.NewValue; + }); + } + + private void updateFromDifficulty() + { + var difficulty = beatmap.Value.BeatmapInfo.BaseDifficulty; + + if (difficulty == null) + return; + + if (Current.Value == null) + { + isInternalChange = true; + CurrentNumber.Value = UpdateFromDifficulty(difficulty); + isInternalChange = false; + } + } + + // TODO: make abstract + protected virtual float UpdateFromDifficulty(BeatmapDifficulty difficulty) => 0; + + private class ControlDrawable : CompositeDrawable, IHasCurrentValue + { + private readonly BindableWithCurrent current = new BindableWithCurrent(); + + public Bindable Current + { + get => current.Current; + set => current.Current = value; + } + + public ControlDrawable(BindableNumber currentNumber) + { + InternalChildren = new Drawable[] + { + new SettingsSlider + { + ShowsDefaultIndicator = false, + Current = currentNumber, + } + }; + + AutoSizeAxes = Axes.Y; + RelativeSizeAxes = Axes.X; + } + } + } +} diff --git a/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs b/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs index e98bd14720..4b68d9cc3f 100644 --- a/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs +++ b/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs @@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Mods protected const int LAST_SETTING_ORDER = 2; - [SettingSource("HP Drain", "Override a beatmap's set HP.", FIRST_SETTING_ORDER)] + [SettingSource("HP Drain", "Override a beatmap's set HP.", FIRST_SETTING_ORDER, SettingControlType = typeof(DifficultyAdjustSettingsControl))] public Bindable DrainRate { get; } = new Bindable { /* @@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Mods */ }; - [SettingSource("Accuracy", "Override a beatmap's set OD.", LAST_SETTING_ORDER)] + [SettingSource("Accuracy", "Override a beatmap's set OD.", LAST_SETTING_ORDER, SettingControlType = typeof(DifficultyAdjustSettingsControl))] public Bindable OverallDifficulty { get; } = new Bindable { /*