Encapsulate mod hotkey selection logic in strategy pattern

This commit is contained in:
Bartłomiej Dach
2022-06-21 12:49:01 +02:00
parent b7b7de115f
commit 73124d2b1f
9 changed files with 145 additions and 31 deletions

View File

@ -21,7 +21,6 @@ using osu.Game.Localisation;
using osu.Game.Rulesets.Mods;
using osu.Game.Utils;
using osuTK;
using osuTK.Input;
namespace osu.Game.Overlays.Mods
{
@ -68,7 +67,7 @@ namespace osu.Game.Overlays.Mods
/// </summary>
protected virtual bool AllowCustomisation => true;
protected virtual ModColumn CreateModColumn(ModType modType, Key[]? toggleKeys = null) => new ModColumn(modType, false, toggleKeys);
protected virtual ModColumn CreateModColumn(ModType modType) => new ModColumn(modType, false);
protected virtual IReadOnlyList<Mod> ComputeNewModsFromSelection(IReadOnlyList<Mod> oldSelection, IReadOnlyList<Mod> newSelection) => newSelection;
@ -160,9 +159,9 @@ namespace osu.Game.Overlays.Mods
Padding = new MarginPadding { Bottom = 10 },
Children = new[]
{
createModColumnContent(ModType.DifficultyReduction, new[] { Key.Q, Key.W, Key.E, Key.R, Key.T, Key.Y, Key.U, Key.I, Key.O, Key.P }),
createModColumnContent(ModType.DifficultyIncrease, new[] { Key.A, Key.S, Key.D, Key.F, Key.G, Key.H, Key.J, Key.K, Key.L }),
createModColumnContent(ModType.Automation, new[] { Key.Z, Key.X, Key.C, Key.V, Key.B, Key.N, Key.M }),
createModColumnContent(ModType.DifficultyReduction),
createModColumnContent(ModType.DifficultyIncrease),
createModColumnContent(ModType.Automation),
createModColumnContent(ModType.Conversion),
createModColumnContent(ModType.Fun)
}
@ -264,9 +263,9 @@ namespace osu.Game.Overlays.Mods
column.DeselectAll();
}
private ColumnDimContainer createModColumnContent(ModType modType, Key[]? toggleKeys = null)
private ColumnDimContainer createModColumnContent(ModType modType)
{
var column = CreateModColumn(modType, toggleKeys).With(column =>
var column = CreateModColumn(modType).With(column =>
{
// spacing applied here rather than via `columnFlow.Spacing` to avoid uneven gaps when some of the columns are hidden.
column.Margin = new MarginPadding { Right = 10 };