Set up flow for switching between hotkey styles

This commit is contained in:
Bartłomiej Dach
2022-06-21 13:10:22 +02:00
parent 5abd8a07d2
commit 658f5341c7
4 changed files with 35 additions and 6 deletions

View File

@ -9,9 +9,11 @@ using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Mods; using osu.Game.Overlays.Mods;
using osu.Game.Overlays.Mods.Input;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Utils; using osu.Game.Utils;
@ -25,6 +27,9 @@ namespace osu.Game.Tests.Visual.UserInterface
[Cached] [Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green); private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
[Resolved]
private OsuConfigManager configManager { get; set; } = null!;
[TestCase(ModType.DifficultyReduction)] [TestCase(ModType.DifficultyReduction)]
[TestCase(ModType.DifficultyIncrease)] [TestCase(ModType.DifficultyIncrease)]
[TestCase(ModType.Conversion)] [TestCase(ModType.Conversion)]
@ -132,8 +137,10 @@ namespace osu.Game.Tests.Visual.UserInterface
} }
[Test] [Test]
public void TestKeyboardSelection() public void TestSequentialKeyboardSelection()
{ {
AddStep("set sequential hotkey mode", () => configManager.SetValue(OsuSetting.ModSelectHotkeyStyle, ModSelectHotkeyStyle.Sequential));
ModColumn column = null!; ModColumn column = null!;
AddStep("create content", () => Child = new Container AddStep("create content", () => Child = new Container
{ {

View File

@ -0,0 +1,16 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osuTK.Input;
namespace osu.Game.Overlays.Mods.Input
{
/// <summary>
/// Uses bindings from stable 1:1.
/// </summary>
public class ClassicModHotkeyHandler : IModHotkeyHandler
{
public bool HandleHotkeyPressed(Key hotkey, IEnumerable<ModState> availableMods) => false; // TODO
}
}

View File

@ -13,14 +13,16 @@ namespace osu.Game.Overlays.Mods.Input
/// <summary> /// <summary>
/// Creates an appropriate <see cref="IModHotkeyHandler"/> for the given <paramref name="modType"/>. /// Creates an appropriate <see cref="IModHotkeyHandler"/> for the given <paramref name="modType"/>.
/// </summary> /// </summary>
public static IModHotkeyHandler Create(ModType modType) public static IModHotkeyHandler Create(ModType modType, ModSelectHotkeyStyle style)
{ {
switch (modType) switch (modType)
{ {
case ModType.DifficultyReduction: case ModType.DifficultyReduction:
case ModType.DifficultyIncrease: case ModType.DifficultyIncrease:
case ModType.Automation: case ModType.Automation:
return SequentialModHotkeyHandler.Create(modType); return style == ModSelectHotkeyStyle.Sequential
? (IModHotkeyHandler)SequentialModHotkeyHandler.Create(modType)
: new ClassicModHotkeyHandler();
default: default:
return new NoopModHotkeyHandler(); return new NoopModHotkeyHandler();

View File

@ -17,6 +17,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Configuration;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -70,7 +71,8 @@ namespace osu.Game.Overlays.Mods
protected virtual ModPanel CreateModPanel(ModState mod) => new ModPanel(mod); protected virtual ModPanel CreateModPanel(ModState mod) => new ModPanel(mod);
private readonly IModHotkeyHandler hotkeyHandler; private Bindable<ModSelectHotkeyStyle> hotkeyStyle = null!;
private IModHotkeyHandler hotkeyHandler = null!;
private readonly TextFlowContainer headerText; private readonly TextFlowContainer headerText;
private readonly Box headerBackground; private readonly Box headerBackground;
@ -89,7 +91,6 @@ namespace osu.Game.Overlays.Mods
public ModColumn(ModType modType, bool allowBulkSelection) public ModColumn(ModType modType, bool allowBulkSelection)
{ {
ModType = modType; ModType = modType;
hotkeyHandler = ModHotkeyHandler.Create(modType);
Width = 320; Width = 320;
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
@ -231,7 +232,7 @@ namespace osu.Game.Overlays.Mods
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider, OsuColour colours) private void load(OverlayColourProvider colourProvider, OsuColour colours, OsuConfigManager configManager)
{ {
headerBackground.Colour = accentColour = colours.ForModType(ModType); headerBackground.Colour = accentColour = colours.ForModType(ModType);
@ -243,6 +244,8 @@ namespace osu.Game.Overlays.Mods
contentContainer.BorderColour = ColourInfo.GradientVertical(colourProvider.Background4, colourProvider.Background3); contentContainer.BorderColour = ColourInfo.GradientVertical(colourProvider.Background4, colourProvider.Background3);
contentBackground.Colour = colourProvider.Background4; contentBackground.Colour = colourProvider.Background4;
hotkeyStyle = configManager.GetBindable<ModSelectHotkeyStyle>(OsuSetting.ModSelectHotkeyStyle);
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -250,6 +253,7 @@ namespace osu.Game.Overlays.Mods
base.LoadComplete(); base.LoadComplete();
toggleAllCheckbox?.Current.BindValueChanged(_ => updateToggleAllText(), true); toggleAllCheckbox?.Current.BindValueChanged(_ => updateToggleAllText(), true);
hotkeyStyle.BindValueChanged(val => hotkeyHandler = ModHotkeyHandler.Create(ModType, val.NewValue), true);
asyncLoadPanels(); asyncLoadPanels();
} }