mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Restructure everything to fix free mod overlay issue
This commit is contained in:
@ -30,6 +30,13 @@ namespace osu.Game.Overlays.Mods.Input
|
||||
[Key.V] = new[] { typeof(ModAutoplay), typeof(ModCinema) }
|
||||
};
|
||||
|
||||
private readonly bool allowIncompatibleSelection;
|
||||
|
||||
public ClassicModHotkeyHandler(bool allowIncompatibleSelection)
|
||||
{
|
||||
this.allowIncompatibleSelection = allowIncompatibleSelection;
|
||||
}
|
||||
|
||||
public bool HandleHotkeyPressed(KeyDownEvent e, IEnumerable<ModState> availableMods)
|
||||
{
|
||||
if (!mod_type_lookup.TryGetValue(e.Key, out var typesToMatch))
|
||||
@ -46,8 +53,19 @@ namespace osu.Game.Overlays.Mods.Input
|
||||
return true;
|
||||
}
|
||||
|
||||
// we're assuming that only one mod from the group can be active at a time.
|
||||
// this is mostly ensured by `IncompatibleMods` definitions, but let's make sure just in case.
|
||||
if (allowIncompatibleSelection)
|
||||
{
|
||||
// easier path - multiple incompatible mods can be active at a time.
|
||||
// this is used in the free mod select overlay.
|
||||
// in this case, just toggle everything.
|
||||
bool anyActive = matchingMods.Any(mod => mod.Active.Value);
|
||||
foreach (var mod in matchingMods)
|
||||
mod.Active.Value = !anyActive;
|
||||
return true;
|
||||
}
|
||||
|
||||
// we now know there are multiple possible mods to handle, and only one of them can be active at a time.
|
||||
// let's make sure of this just in case.
|
||||
Debug.Assert(matchingMods.Count(modState => modState.Active.Value) <= 1);
|
||||
int currentSelectedIndex = Array.FindIndex(matchingMods, modState => modState.Active.Value);
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
// 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 osu.Game.Rulesets.Mods;
|
||||
|
||||
namespace osu.Game.Overlays.Mods.Input
|
||||
{
|
||||
/// <summary>
|
||||
/// Static factory class for <see cref="IModHotkeyHandler"/>s.
|
||||
/// </summary>
|
||||
public static class ModHotkeyHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an appropriate <see cref="IModHotkeyHandler"/> for the given <paramref name="modType"/>.
|
||||
/// </summary>
|
||||
public static IModHotkeyHandler Create(ModType modType, ModSelectHotkeyStyle style)
|
||||
{
|
||||
switch (modType)
|
||||
{
|
||||
case ModType.DifficultyReduction:
|
||||
case ModType.DifficultyIncrease:
|
||||
case ModType.Automation:
|
||||
return style == ModSelectHotkeyStyle.Sequential
|
||||
? (IModHotkeyHandler)SequentialModHotkeyHandler.Create(modType)
|
||||
: new ClassicModHotkeyHandler();
|
||||
|
||||
default:
|
||||
return new NoopModHotkeyHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -71,8 +71,7 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
protected virtual ModPanel CreateModPanel(ModState mod) => new ModPanel(mod);
|
||||
|
||||
private Bindable<ModSelectHotkeyStyle> hotkeyStyle = null!;
|
||||
private IModHotkeyHandler hotkeyHandler = null!;
|
||||
private readonly bool allowIncompatibleSelection;
|
||||
|
||||
private readonly TextFlowContainer headerText;
|
||||
private readonly Box headerBackground;
|
||||
@ -83,14 +82,18 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
private Colour4 accentColour;
|
||||
|
||||
private Bindable<ModSelectHotkeyStyle> hotkeyStyle = null!;
|
||||
private IModHotkeyHandler hotkeyHandler = null!;
|
||||
|
||||
private Task? latestLoadTask;
|
||||
internal bool ItemsLoaded => latestLoadTask == null;
|
||||
|
||||
private const float header_height = 42;
|
||||
|
||||
public ModColumn(ModType modType, bool allowBulkSelection)
|
||||
public ModColumn(ModType modType, bool allowIncompatibleSelection)
|
||||
{
|
||||
ModType = modType;
|
||||
this.allowIncompatibleSelection = allowIncompatibleSelection;
|
||||
|
||||
Width = 320;
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
@ -198,7 +201,7 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
createHeaderText();
|
||||
|
||||
if (allowBulkSelection)
|
||||
if (allowIncompatibleSelection)
|
||||
{
|
||||
controlContainer.Height = 35;
|
||||
controlContainer.Add(toggleAllCheckbox = new ToggleAllCheckbox(this)
|
||||
@ -253,7 +256,7 @@ namespace osu.Game.Overlays.Mods
|
||||
base.LoadComplete();
|
||||
|
||||
toggleAllCheckbox?.Current.BindValueChanged(_ => updateToggleAllText(), true);
|
||||
hotkeyStyle.BindValueChanged(val => hotkeyHandler = ModHotkeyHandler.Create(ModType, val.NewValue), true);
|
||||
hotkeyStyle.BindValueChanged(val => hotkeyHandler = CreateHotkeyHandler(val.NewValue), true);
|
||||
asyncLoadPanels();
|
||||
}
|
||||
|
||||
@ -427,6 +430,26 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
#region Keyboard selection support
|
||||
|
||||
/// <summary>
|
||||
/// Creates an appropriate <see cref="IModHotkeyHandler"/> for this column's <see cref="ModType"/> and
|
||||
/// the supplied <paramref name="hotkeyStyle"/>.
|
||||
/// </summary>
|
||||
protected virtual IModHotkeyHandler CreateHotkeyHandler(ModSelectHotkeyStyle hotkeyStyle)
|
||||
{
|
||||
switch (ModType)
|
||||
{
|
||||
case ModType.DifficultyReduction:
|
||||
case ModType.DifficultyIncrease:
|
||||
case ModType.Automation:
|
||||
return hotkeyStyle == ModSelectHotkeyStyle.Sequential
|
||||
? (IModHotkeyHandler)SequentialModHotkeyHandler.Create(ModType)
|
||||
: new ClassicModHotkeyHandler(allowIncompatibleSelection);
|
||||
|
||||
default:
|
||||
return new NoopModHotkeyHandler();
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
{
|
||||
if (e.ControlPressed || e.AltPressed || e.SuperPressed || e.Repeat)
|
||||
|
@ -40,8 +40,8 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
private class UserModColumn : ModColumn
|
||||
{
|
||||
public UserModColumn(ModType modType, bool allowBulkSelection)
|
||||
: base(modType, allowBulkSelection)
|
||||
public UserModColumn(ModType modType, bool allowIncompatibleSelection)
|
||||
: base(modType, allowIncompatibleSelection)
|
||||
{
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user