mirror of
https://github.com/ppy/osu.git
synced 2025-01-21 11:22:55 +08:00
Remember the last used custom divisor when cycling divisor types
This commit is contained in:
parent
bcde2cbc73
commit
32207d4112
@ -29,6 +29,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
{
|
{
|
||||||
public partial class BeatDivisorControl : CompositeDrawable
|
public partial class BeatDivisorControl : CompositeDrawable
|
||||||
{
|
{
|
||||||
|
private int? lastCustomDivisor;
|
||||||
|
|
||||||
private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor();
|
private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor();
|
||||||
|
|
||||||
public BeatDivisorControl(BindableBeatDivisor beatDivisor)
|
public BeatDivisorControl(BindableBeatDivisor beatDivisor)
|
||||||
@ -182,16 +184,30 @@ 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)
|
private void cycleDivisorType(int direction)
|
||||||
{
|
{
|
||||||
Debug.Assert(Math.Abs(direction) == 1);
|
int totalTypes = Enum.GetValues<BeatDivisorType>().Length;
|
||||||
int nextDivisorType = (int)beatDivisor.ValidDivisors.Value.Type + direction;
|
BeatDivisorType currentType = beatDivisor.ValidDivisors.Value.Type;
|
||||||
if (nextDivisorType > (int)BeatDivisorType.Triplets)
|
|
||||||
nextDivisorType = (int)BeatDivisorType.Common;
|
|
||||||
else if (nextDivisorType < (int)BeatDivisorType.Common)
|
|
||||||
nextDivisorType = (int)BeatDivisorType.Triplets;
|
|
||||||
|
|
||||||
switch ((BeatDivisorType)nextDivisorType)
|
Debug.Assert(Math.Abs(direction) == 1);
|
||||||
|
|
||||||
|
cycleOnce();
|
||||||
|
|
||||||
|
if (lastCustomDivisor == null && currentType == BeatDivisorType.Custom)
|
||||||
|
cycleOnce();
|
||||||
|
|
||||||
|
switch (currentType)
|
||||||
{
|
{
|
||||||
case BeatDivisorType.Common:
|
case BeatDivisorType.Common:
|
||||||
beatDivisor.SetArbitraryDivisor(4);
|
beatDivisor.SetArbitraryDivisor(4);
|
||||||
@ -202,9 +218,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case BeatDivisorType.Custom:
|
case BeatDivisorType.Custom:
|
||||||
beatDivisor.ValidDivisors.Value = BeatDivisorPresetCollection.Custom(beatDivisor.ValidDivisors.Value.Presets.Max());
|
Debug.Assert(lastCustomDivisor != null);
|
||||||
|
beatDivisor.SetArbitraryDivisor(lastCustomDivisor.Value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cycleOnce() => currentType = (BeatDivisorType)(((int)currentType + totalTypes + direction) % totalTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnKeyDown(KeyDownEvent e)
|
protected override bool OnKeyDown(KeyDownEvent e)
|
||||||
@ -302,12 +321,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
BeatDivisor.BindValueChanged(_ => updateState(), true);
|
BeatDivisor.BindValueChanged(_ => updateState(), true);
|
||||||
divisorTextBox.OnCommit += (_, _) => setPresets();
|
divisorTextBox.OnCommit += (_, _) => setPresetsFromTextBoxEntry();
|
||||||
|
|
||||||
Schedule(() => GetContainingInputManager().ChangeFocus(divisorTextBox));
|
Schedule(() => GetContainingInputManager().ChangeFocus(divisorTextBox));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPresets()
|
private void setPresetsFromTextBoxEntry()
|
||||||
{
|
{
|
||||||
if (!int.TryParse(divisorTextBox.Text, out int divisor) || divisor < 1 || divisor > 64)
|
if (!int.TryParse(divisorTextBox.Text, out int divisor) || divisor < 1 || divisor > 64)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user