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

Tidy up GlobalActionContainer a bit

This commit is contained in:
Dean Herbert 2023-10-13 13:47:51 +09:00
parent c2e92cbb70
commit 9289c47cd4
No known key found for this signature in database

View File

@ -14,6 +14,8 @@ namespace osu.Game.Input.Bindings
{
public partial class GlobalActionContainer : DatabasedKeyBindingContainer<GlobalAction>, IHandleGlobalKeyboardInput, IKeyBindingHandler<GlobalAction>
{
protected override bool Prioritised => true;
private readonly IKeyBindingHandler<GlobalAction>? handler;
public GlobalActionContainer(OsuGameBase? game)
@ -23,22 +25,62 @@ namespace osu.Game.Input.Bindings
handler = h;
}
protected override bool Prioritised => true;
// IMPORTANT: Take care when changing order of the items in the enumerable.
// It is used to decide the order of precedence, with the earlier items having higher precedence.
public override IEnumerable<IKeyBinding> DefaultKeyBindings => GlobalKeyBindings
.Concat(EditorKeyBindings)
.Concat(InGameKeyBindings)
.Concat(ReplayKeyBindings)
.Concat(SongSelectKeyBindings)
.Concat(AudioControlKeyBindings)
/// <summary>
/// All default key bindings across all categories, ordered with highest priority first.
/// </summary>
/// <remarks>
/// IMPORTANT: Take care when changing order of the items in the enumerable.
/// It is used to decide the order of precedence, with the earlier items having higher precedence.
/// </remarks>
public override IEnumerable<IKeyBinding> DefaultKeyBindings => globalKeyBindings
.Concat(editorKeyBindings)
.Concat(inGameKeyBindings)
.Concat(replayKeyBindings)
.Concat(songSelectKeyBindings)
.Concat(audioControlKeyBindings)
// Overlay bindings may conflict with more local cases like the editor so they are checked last.
// It has generally been agreed on that local screens like the editor should have priority,
// based on such usages potentially requiring a lot more key bindings that may be "shared" with global ones.
.Concat(OverlayKeyBindings);
.Concat(overlayKeyBindings);
public static IEnumerable<KeyBinding> GlobalKeyBindings => new[]
public static IEnumerable<KeyBinding> GetDefaultBindingsFor(GlobalActionCategory category)
{
switch (category)
{
case GlobalActionCategory.General:
return globalKeyBindings;
case GlobalActionCategory.Editor:
return editorKeyBindings;
case GlobalActionCategory.InGame:
return inGameKeyBindings;
case GlobalActionCategory.Replay:
return replayKeyBindings;
case GlobalActionCategory.SongSelect:
return songSelectKeyBindings;
case GlobalActionCategory.AudioControl:
return audioControlKeyBindings;
case GlobalActionCategory.Overlays:
return overlayKeyBindings;
default:
throw new ArgumentOutOfRangeException(nameof(category), category, $"Unexpected {nameof(GlobalActionCategory)}");
}
}
public static IEnumerable<GlobalAction> GetGlobalActionsFor(GlobalActionCategory category)
=> GetDefaultBindingsFor(category).Select(binding => binding.Action).Cast<GlobalAction>().Distinct();
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e) => handler?.OnPressed(e) == true;
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) => handler?.OnReleased(e);
private static IEnumerable<KeyBinding> globalKeyBindings => new[]
{
new KeyBinding(InputKey.Up, GlobalAction.SelectPrevious),
new KeyBinding(InputKey.Down, GlobalAction.SelectNext),
@ -68,7 +110,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.F12, GlobalAction.TakeScreenshot),
};
public static IEnumerable<KeyBinding> OverlayKeyBindings => new[]
private static IEnumerable<KeyBinding> overlayKeyBindings => new[]
{
new KeyBinding(InputKey.F8, GlobalAction.ToggleChat),
new KeyBinding(InputKey.F6, GlobalAction.ToggleNowPlaying),
@ -78,7 +120,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(new[] { InputKey.Control, InputKey.N }, GlobalAction.ToggleNotifications),
};
public static IEnumerable<KeyBinding> EditorKeyBindings => new[]
private static IEnumerable<KeyBinding> editorKeyBindings => new[]
{
new KeyBinding(new[] { InputKey.F1 }, GlobalAction.EditorComposeMode),
new KeyBinding(new[] { InputKey.F2 }, GlobalAction.EditorDesignMode),
@ -102,7 +144,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(new[] { InputKey.Control, InputKey.R }, GlobalAction.EditorToggleRotateControl),
};
public static IEnumerable<KeyBinding> InGameKeyBindings => new[]
private static IEnumerable<KeyBinding> inGameKeyBindings => new[]
{
new KeyBinding(InputKey.Space, GlobalAction.SkipCutscene),
new KeyBinding(InputKey.ExtraMouseButton2, GlobalAction.SkipCutscene),
@ -119,7 +161,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.F2, GlobalAction.ExportReplay),
};
public static IEnumerable<KeyBinding> ReplayKeyBindings => new[]
private static IEnumerable<KeyBinding> replayKeyBindings => new[]
{
new KeyBinding(InputKey.Space, GlobalAction.TogglePauseReplay),
new KeyBinding(InputKey.MouseMiddle, GlobalAction.TogglePauseReplay),
@ -128,7 +170,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(new[] { InputKey.Control, InputKey.H }, GlobalAction.ToggleReplaySettings),
};
public static IEnumerable<KeyBinding> SongSelectKeyBindings => new[]
private static IEnumerable<KeyBinding> songSelectKeyBindings => new[]
{
new KeyBinding(InputKey.F1, GlobalAction.ToggleModSelection),
new KeyBinding(InputKey.F2, GlobalAction.SelectNextRandom),
@ -137,7 +179,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.BackSpace, GlobalAction.DeselectAllMods),
};
public static IEnumerable<KeyBinding> AudioControlKeyBindings => new[]
private static IEnumerable<KeyBinding> audioControlKeyBindings => new[]
{
new KeyBinding(new[] { InputKey.Alt, InputKey.Up }, GlobalAction.IncreaseVolume),
new KeyBinding(new[] { InputKey.Alt, InputKey.Down }, GlobalAction.DecreaseVolume),
@ -154,43 +196,6 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.PlayPause, GlobalAction.MusicPlay),
new KeyBinding(InputKey.F3, GlobalAction.MusicPlay)
};
public static IEnumerable<KeyBinding> GetDefaultBindingsFor(GlobalActionCategory category)
{
switch (category)
{
case GlobalActionCategory.General:
return GlobalKeyBindings;
case GlobalActionCategory.Editor:
return EditorKeyBindings;
case GlobalActionCategory.InGame:
return InGameKeyBindings;
case GlobalActionCategory.Replay:
return ReplayKeyBindings;
case GlobalActionCategory.SongSelect:
return SongSelectKeyBindings;
case GlobalActionCategory.AudioControl:
return AudioControlKeyBindings;
case GlobalActionCategory.Overlays:
return OverlayKeyBindings;
default:
throw new ArgumentOutOfRangeException(nameof(category), category, $"Unexpected {nameof(GlobalActionCategory)}");
}
}
public static IEnumerable<GlobalAction> GetGlobalActionsFor(GlobalActionCategory category)
=> GetDefaultBindingsFor(category).Select(binding => binding.Action).Cast<GlobalAction>().Distinct();
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e) => handler?.OnPressed(e) == true;
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) => handler?.OnReleased(e);
}
public enum GlobalAction