1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 22:37:26 +08:00

Make "double ternary button" specific to samples

We can generalise *when* there is the need to generalise. So far the
generalisation only looked like *obfuscation*.
This commit is contained in:
Bartłomiej Dach 2024-08-19 11:07:34 +02:00
parent 55e9bb6a5d
commit 32821be046
No known key found for this signature in database
2 changed files with 44 additions and 56 deletions

View File

@ -270,7 +270,7 @@ namespace osu.Game.Rulesets.Edit
TernaryStates = CreateTernaryButtons().ToArray(); TernaryStates = CreateTernaryButtons().ToArray();
togglesCollection.AddRange(TernaryStates.Select(b => new DrawableTernaryButton(b))); togglesCollection.AddRange(TernaryStates.Select(b => new DrawableTernaryButton(b)));
sampleBankTogglesCollection.AddRange(BlueprintContainer.SampleBankTernaryStates.Zip(BlueprintContainer.SampleAdditionBankTernaryStates).Select(b => new DoubleDrawableTernaryButton(b.First, b.Second))); sampleBankTogglesCollection.AddRange(BlueprintContainer.SampleBankTernaryStates.Zip(BlueprintContainer.SampleAdditionBankTernaryStates).Select(b => new SampleBankTernaryButton(b.First, b.Second)));
setSelectTool(); setSelectTool();
@ -421,41 +421,29 @@ namespace osu.Game.Rulesets.Edit
if (checkRightToggleFromKey(e.Key, out int rightIndex)) if (checkRightToggleFromKey(e.Key, out int rightIndex))
{ {
if (e.ShiftPressed || e.AltPressed) if (e.ShiftPressed || e.AltPressed)
{
if (sampleBankTogglesCollection.ElementAtOrDefault(rightIndex) is SampleBankTernaryButton sampleBankTernaryButton)
{ {
if (e.ShiftPressed) if (e.ShiftPressed)
attemptToggle(rightIndex, sampleBankTogglesCollection); sampleBankTernaryButton.NormalButton.Toggle();
if (e.AltPressed) if (e.AltPressed)
attemptToggle(rightIndex, sampleBankTogglesCollection, true); sampleBankTernaryButton.AdditionsButton.Toggle();
return true;
}
} }
else else
attemptToggle(rightIndex, togglesCollection);
}
return handled || base.OnKeyDown(e);
void attemptToggle(int index, FillFlowContainer collection, bool second = false)
{ {
var item = collection.ElementAtOrDefault(index); if (togglesCollection.ElementAtOrDefault(rightIndex) is DrawableTernaryButton button)
switch (item)
{ {
case DrawableTernaryButton button:
button.Button.Toggle(); button.Button.Toggle();
handled = true; return true;
break; }
}
}
case DoubleDrawableTernaryButton doubleButton: return base.OnKeyDown(e);
{
if (second)
doubleButton.Button2.Toggle();
else
doubleButton.Button1.Toggle();
handled = true;
break;
}
}
}
} }
private bool checkLeftToggleFromKey(Key key, out int index) private bool checkLeftToggleFromKey(Key key, out int index)

View File

@ -9,15 +9,15 @@ using osu.Game.Rulesets.Edit;
namespace osu.Game.Screens.Edit.Components.TernaryButtons namespace osu.Game.Screens.Edit.Components.TernaryButtons
{ {
public partial class DoubleDrawableTernaryButton : CompositeDrawable public partial class SampleBankTernaryButton : CompositeDrawable
{ {
public readonly TernaryButton Button1; public readonly TernaryButton NormalButton;
public readonly TernaryButton Button2; public readonly TernaryButton AdditionsButton;
public DoubleDrawableTernaryButton(TernaryButton button1, TernaryButton button2) public SampleBankTernaryButton(TernaryButton normalButton, TernaryButton additionsButton)
{ {
Button1 = button1; NormalButton = normalButton;
Button2 = button2; AdditionsButton = additionsButton;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -36,7 +36,7 @@ namespace osu.Game.Screens.Edit.Components.TernaryButtons
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Width = 0.5f, Width = 0.5f,
Padding = new MarginPadding { Right = 1 }, Padding = new MarginPadding { Right = 1 },
Child = new InlineDrawableTernaryButton(Button1), Child = new InlineDrawableTernaryButton(NormalButton),
}, },
new Container new Container
{ {
@ -46,13 +46,12 @@ namespace osu.Game.Screens.Edit.Components.TernaryButtons
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Width = 0.5f, Width = 0.5f,
Padding = new MarginPadding { Left = 1 }, Padding = new MarginPadding { Left = 1 },
Child = new InlineDrawableTernaryButton(Button2), Child = new InlineDrawableTernaryButton(AdditionsButton),
}, },
}; };
} }
}
public partial class InlineDrawableTernaryButton : DrawableTernaryButton private partial class InlineDrawableTernaryButton : DrawableTernaryButton
{ {
public InlineDrawableTernaryButton(TernaryButton button) public InlineDrawableTernaryButton(TernaryButton button)
: base(button) : base(button)
@ -75,4 +74,5 @@ namespace osu.Game.Screens.Edit.Components.TernaryButtons
X = 31f X = 31f
}; };
} }
}
} }