mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 11:33:22 +08:00
Merge pull request #23722 from peppy/beat-divisor-better-defaults
Improve usability of beat divisor control
This commit is contained in:
commit
3597698544
@ -1,8 +1,6 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
@ -23,8 +21,8 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
{
|
||||
public partial class TestSceneBeatDivisorControl : OsuManualInputManagerTestScene
|
||||
{
|
||||
private BeatDivisorControl beatDivisorControl;
|
||||
private BindableBeatDivisor bindableBeatDivisor;
|
||||
private BeatDivisorControl beatDivisorControl = null!;
|
||||
private BindableBeatDivisor bindableBeatDivisor = null!;
|
||||
|
||||
private SliderBar<int> tickSliderBar => beatDivisorControl.ChildrenOfType<SliderBar<int>>().Single();
|
||||
private Triangle tickMarkerHead => tickSliderBar.ChildrenOfType<Triangle>().Single();
|
||||
@ -169,9 +167,11 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
|
||||
switchPresets(1);
|
||||
assertPreset(BeatDivisorType.Triplets);
|
||||
assertBeatSnap(6);
|
||||
|
||||
switchPresets(1);
|
||||
assertPreset(BeatDivisorType.Common);
|
||||
assertBeatSnap(4);
|
||||
|
||||
switchPresets(-1);
|
||||
assertPreset(BeatDivisorType.Triplets);
|
||||
@ -187,6 +187,7 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
|
||||
setDivisorViaInput(15);
|
||||
assertPreset(BeatDivisorType.Custom, 15);
|
||||
assertBeatSnap(15);
|
||||
|
||||
switchBeatSnap(-1);
|
||||
assertBeatSnap(5);
|
||||
@ -196,12 +197,14 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
|
||||
setDivisorViaInput(5);
|
||||
assertPreset(BeatDivisorType.Custom, 15);
|
||||
assertBeatSnap(5);
|
||||
|
||||
switchPresets(1);
|
||||
assertPreset(BeatDivisorType.Common);
|
||||
|
||||
switchPresets(-1);
|
||||
assertPreset(BeatDivisorType.Triplets);
|
||||
assertPreset(BeatDivisorType.Custom, 15);
|
||||
assertBeatSnap(15);
|
||||
}
|
||||
|
||||
private void switchBeatSnap(int direction) => AddRepeatStep($"move snap {(direction > 0 ? "forward" : "backward")}", () =>
|
||||
@ -225,7 +228,7 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
|
||||
private void assertPreset(BeatDivisorType type, int? maxDivisor = null)
|
||||
{
|
||||
AddAssert($"preset is {type}", () => bindableBeatDivisor.ValidDivisors.Value.Type == type);
|
||||
AddAssert($"preset is {type}", () => bindableBeatDivisor.ValidDivisors.Value.Type, () => Is.EqualTo(type));
|
||||
|
||||
if (type == BeatDivisorType.Custom)
|
||||
{
|
||||
@ -243,7 +246,7 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
BeatDivisorControl.CustomDivisorPopover popover = null;
|
||||
BeatDivisorControl.CustomDivisorPopover? popover = null;
|
||||
AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType<BeatDivisorControl.CustomDivisorPopover>().SingleOrDefault()) != null && popover.IsLoaded);
|
||||
AddStep($"set divisor to {divisor}", () =>
|
||||
{
|
||||
|
@ -1,8 +1,6 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
@ -33,6 +31,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
public partial class BeatDivisorControl : CompositeDrawable, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
private int? lastCustomDivisor;
|
||||
|
||||
private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor();
|
||||
|
||||
public BeatDivisorControl(BindableBeatDivisor beatDivisor)
|
||||
@ -186,29 +186,46 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
beatDivisor.ValidDivisors.BindValueChanged(valid =>
|
||||
{
|
||||
if (valid.NewValue.Type == BeatDivisorType.Custom)
|
||||
lastCustomDivisor = valid.NewValue.Presets.Last();
|
||||
}, true);
|
||||
}
|
||||
|
||||
private void cycleDivisorType(int direction)
|
||||
{
|
||||
Debug.Assert(Math.Abs(direction) == 1);
|
||||
int nextDivisorType = (int)beatDivisor.ValidDivisors.Value.Type + direction;
|
||||
if (nextDivisorType > (int)BeatDivisorType.Triplets)
|
||||
nextDivisorType = (int)BeatDivisorType.Common;
|
||||
else if (nextDivisorType < (int)BeatDivisorType.Common)
|
||||
nextDivisorType = (int)BeatDivisorType.Triplets;
|
||||
int totalTypes = Enum.GetValues<BeatDivisorType>().Length;
|
||||
BeatDivisorType currentType = beatDivisor.ValidDivisors.Value.Type;
|
||||
|
||||
switch ((BeatDivisorType)nextDivisorType)
|
||||
Debug.Assert(Math.Abs(direction) == 1);
|
||||
|
||||
cycleOnce();
|
||||
|
||||
if (lastCustomDivisor == null && currentType == BeatDivisorType.Custom)
|
||||
cycleOnce();
|
||||
|
||||
switch (currentType)
|
||||
{
|
||||
case BeatDivisorType.Common:
|
||||
beatDivisor.ValidDivisors.Value = BeatDivisorPresetCollection.COMMON;
|
||||
beatDivisor.SetArbitraryDivisor(4);
|
||||
break;
|
||||
|
||||
case BeatDivisorType.Triplets:
|
||||
beatDivisor.ValidDivisors.Value = BeatDivisorPresetCollection.TRIPLETS;
|
||||
beatDivisor.SetArbitraryDivisor(6);
|
||||
break;
|
||||
|
||||
case BeatDivisorType.Custom:
|
||||
beatDivisor.ValidDivisors.Value = BeatDivisorPresetCollection.Custom(beatDivisor.ValidDivisors.Value.Presets.Max());
|
||||
Debug.Assert(lastCustomDivisor != null);
|
||||
beatDivisor.SetArbitraryDivisor(lastCustomDivisor.Value);
|
||||
break;
|
||||
}
|
||||
|
||||
void cycleOnce() => currentType = (BeatDivisorType)(((int)currentType + totalTypes + direction) % totalTypes);
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
@ -326,12 +343,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
base.LoadComplete();
|
||||
BeatDivisor.BindValueChanged(_ => updateState(), true);
|
||||
divisorTextBox.OnCommit += (_, _) => setPresets();
|
||||
divisorTextBox.OnCommit += (_, _) => setPresetsFromTextBoxEntry();
|
||||
|
||||
Schedule(() => GetContainingInputManager().ChangeFocus(divisorTextBox));
|
||||
}
|
||||
|
||||
private void setPresets()
|
||||
private void setPresetsFromTextBoxEntry()
|
||||
{
|
||||
if (!int.TryParse(divisorTextBox.Text, out int divisor) || divisor < 1 || divisor > 64)
|
||||
{
|
||||
@ -394,10 +411,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
private partial class TickSliderBar : SliderBar<int>
|
||||
{
|
||||
private Marker marker;
|
||||
private Marker marker = null!;
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
private OsuColour colours { get; set; } = null!;
|
||||
|
||||
private readonly BindableBeatDivisor beatDivisor;
|
||||
|
||||
@ -539,7 +556,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
private partial class Marker : CompositeDrawable
|
||||
{
|
||||
[Resolved]
|
||||
private OverlayColourProvider colourProvider { get; set; }
|
||||
private OverlayColourProvider colourProvider { get; set; } = null!;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
|
@ -82,7 +82,7 @@ namespace osu.Game.Screens.Edit
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding { Right = 5 },
|
||||
},
|
||||
new BeatDivisorControl(beatDivisor) { RelativeSizeAxes = Axes.Both }
|
||||
new BeatDivisorControl(this.beatDivisor) { RelativeSizeAxes = Axes.Both }
|
||||
},
|
||||
},
|
||||
RowDimensions = new[]
|
||||
|
Loading…
Reference in New Issue
Block a user