Initial implementation of new flow (only working for approach rate)

This commit is contained in:
Dean Herbert 2021-07-08 15:53:49 +09:00
parent fcee69ffe6
commit c4313d6e96
5 changed files with 195 additions and 4 deletions

View File

@ -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<float?> CircleSize { get; } = new Bindable<float?>
{
/*
@ -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<float?> ApproachRate { get; } = new Bindable<float?>
{
/*

View File

@ -0,0 +1,74 @@
// 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 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,
}
}
}));
}
}
}

View File

@ -0,0 +1,20 @@
// 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
{
public ApproachRateSettingsControl()
{
CurrentNumber.Precision = 0.1f;
CurrentNumber.MinValue = 0;
CurrentNumber.MaxValue = 10;
}
protected override float UpdateFromDifficulty(BeatmapDifficulty difficulty) => difficulty.ApproachRate;
}
}

View File

@ -0,0 +1,97 @@
// 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.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<float?>
{
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; }
protected readonly BindableNumber<float> CurrentNumber = new BindableNumber<float>
{
// 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<float?>
{
private readonly BindableWithCurrent<float?> current = new BindableWithCurrent<float?>();
public Bindable<float?> Current
{
get => current.Current;
set => current.Current = value;
}
public ControlDrawable(BindableNumber<float> currentNumber)
{
InternalChildren = new Drawable[]
{
new SettingsSlider<float>
{
ShowsDefaultIndicator = false,
Current = currentNumber,
}
};
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
}
}
}
}

View File

@ -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<float?> DrainRate { get; } = new Bindable<float?>
{
/*
@ -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<float?> OverallDifficulty { get; } = new Bindable<float?>
{
/*