Add ability to use Shift+Number to set current beat divisor in editor

This commit is contained in:
Dean Herbert 2022-10-24 15:20:15 +09:00
parent d0e6bda9ef
commit 1d5df15027
2 changed files with 32 additions and 11 deletions

View File

@ -25,6 +25,26 @@ namespace osu.Game.Screens.Edit
BindValueChanged(_ => ensureValidDivisor());
}
/// <summary>
/// Set a divisor, updating the valid divisor range appropriately.
/// </summary>
/// <param name="divisor">The intended divisor.</param>
public void SetArbitraryDivisor(int divisor)
{
// If the current valid divisor range doesn't contain the proposed value, attempt to find one which does.
if (!ValidDivisors.Value.Presets.Contains(divisor))
{
if (BeatDivisorPresetCollection.COMMON.Presets.Contains(divisor))
ValidDivisors.Value = BeatDivisorPresetCollection.COMMON;
else if (BeatDivisorPresetCollection.TRIPLETS.Presets.Contains(divisor))
ValidDivisors.Value = BeatDivisorPresetCollection.TRIPLETS;
else
ValidDivisors.Value = BeatDivisorPresetCollection.Custom(divisor);
}
Value = divisor;
}
private void updateBindableProperties()
{
ensureValidDivisor();

View File

@ -209,6 +209,17 @@ namespace osu.Game.Screens.Edit.Compose.Components
}
}
protected override bool OnKeyDown(KeyDownEvent e)
{
if (e.ShiftPressed && e.Key >= Key.Number1 && e.Key <= Key.Number9)
{
beatDivisor.SetArbitraryDivisor(e.Key - Key.Number0);
return true;
}
return base.OnKeyDown(e);
}
internal class DivisorDisplay : OsuAnimatedButton, IHasPopover
{
public BindableBeatDivisor BeatDivisor { get; } = new BindableBeatDivisor();
@ -306,17 +317,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
return;
}
if (!BeatDivisor.ValidDivisors.Value.Presets.Contains(divisor))
{
if (BeatDivisorPresetCollection.COMMON.Presets.Contains(divisor))
BeatDivisor.ValidDivisors.Value = BeatDivisorPresetCollection.COMMON;
else if (BeatDivisorPresetCollection.TRIPLETS.Presets.Contains(divisor))
BeatDivisor.ValidDivisors.Value = BeatDivisorPresetCollection.TRIPLETS;
else
BeatDivisor.ValidDivisors.Value = BeatDivisorPresetCollection.Custom(divisor);
}
BeatDivisor.Value = divisor;
BeatDivisor.SetArbitraryDivisor(divisor);
this.HidePopover();
}