From 7e0c45de6dfb736d749f3606b8c33eded764c432 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 28 Jan 2020 15:08:02 +0900 Subject: [PATCH] Allow selecting composition tools using 1-4 keys --- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index c413d25f09..82e0905bd8 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -9,6 +9,7 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input; +using osu.Framework.Input.Events; using osu.Framework.Logging; using osu.Framework.Threading; using osu.Framework.Timing; @@ -25,6 +26,7 @@ using osu.Game.Screens.Edit.Components.RadioButtons; using osu.Game.Screens.Edit.Compose; using osu.Game.Screens.Edit.Compose.Components; using osuTK; +using Key = osuTK.Input.Key; namespace osu.Game.Rulesets.Edit { @@ -58,6 +60,8 @@ namespace osu.Game.Rulesets.Edit private InputManager inputManager; + private RadioButtonCollection toolboxCollection; + protected HitObjectComposer(Ruleset ruleset) { Ruleset = ruleset; @@ -100,7 +104,6 @@ namespace osu.Game.Rulesets.Edit layerContainers.Add(layerBelowRuleset); layerContainers.Add(layerAboveRuleset); - RadioButtonCollection toolboxCollection; InternalChild = new GridContainer { RelativeSizeAxes = Axes.Both, @@ -147,6 +150,22 @@ namespace osu.Game.Rulesets.Edit blueprintContainer.SelectionChanged += selectionChanged; } + protected override bool OnKeyDown(KeyDownEvent e) + { + if (e.Key >= Key.Number1 && e.Key <= Key.Number9) + { + var item = toolboxCollection.Items.Skip(e.Key - Key.Number1).FirstOrDefault(); + + if (item != null) + { + item.Select(); + return true; + } + } + + return base.OnKeyDown(e); + } + protected override void LoadComplete() { base.LoadComplete();