Merge pull request #20665 from frenzibyte/fix-smoke-blocked-on-relax

Fix smoke being blocked with "Relax" mod enabled
This commit is contained in:
Dean Herbert 2022-10-10 16:36:03 +09:00 committed by GitHub
commit e57819d687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 14 deletions

View File

@ -3,9 +3,11 @@
#nullable disable
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Mania.Tests
@ -37,7 +39,7 @@ public LocalKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBi
{
}
protected override void ReloadMappings()
protected override void ReloadMappings(IQueryable<RealmKeyBinding> realmKeyBindings)
{
KeyBindings = DefaultKeyBindings;
}

View File

@ -20,7 +20,9 @@ namespace osu.Game.Rulesets.Osu.Mods
public class OsuModRelax : ModRelax, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>, IApplicableToPlayer
{
public override LocalisableString Description => @"You don't need to click. Give your clicking/tapping fingers a break from the heat of things.";
public override Type[] IncompatibleMods => base.IncompatibleMods.Concat(new[] { typeof(OsuModAutopilot), typeof(OsuModMagnetised), typeof(OsuModAlternate), typeof(OsuModSingleTap) }).ToArray();
public override Type[] IncompatibleMods =>
base.IncompatibleMods.Concat(new[] { typeof(OsuModAutopilot), typeof(OsuModMagnetised), typeof(OsuModAlternate), typeof(OsuModSingleTap) }).ToArray();
/// <summary>
/// How early before a hitobject's start time to trigger a hit.
@ -51,7 +53,7 @@ public void ApplyToPlayer(Player player)
return;
}
osuInputManager.AllowUserPresses = false;
osuInputManager.AllowGameplayInputs = false;
}
public void Update(Playfield playfield)

View File

@ -5,10 +5,12 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Input.StateChanges.Events;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu
@ -17,9 +19,16 @@ public class OsuInputManager : RulesetInputManager<OsuAction>
{
public IEnumerable<OsuAction> PressedActions => KeyBindingContainer.PressedActions;
public bool AllowUserPresses
/// <summary>
/// Whether gameplay input buttons should be allowed.
/// Defaults to <c>true</c>, generally used for mods like Relax which turn off main inputs.
/// </summary>
/// <remarks>
/// Of note, auxiliary inputs like the "smoke" key are left usable.
/// </remarks>
public bool AllowGameplayInputs
{
set => ((OsuKeyBindingContainer)KeyBindingContainer).AllowUserPresses = value;
set => ((OsuKeyBindingContainer)KeyBindingContainer).AllowGameplayInputs = value;
}
/// <summary>
@ -58,18 +67,36 @@ protected override bool HandleMouseTouchStateChange(TouchStateChangeEvent e)
private class OsuKeyBindingContainer : RulesetKeyBindingContainer
{
public bool AllowUserPresses = true;
private bool allowGameplayInputs = true;
/// <summary>
/// Whether gameplay input buttons should be allowed.
/// Defaults to <c>true</c>, generally used for mods like Relax which turn off main inputs.
/// </summary>
/// <remarks>
/// Of note, auxiliary inputs like the "smoke" key are left usable.
/// </remarks>
public bool AllowGameplayInputs
{
get => allowGameplayInputs;
set
{
allowGameplayInputs = value;
ReloadMappings();
}
}
public OsuKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
: base(ruleset, variant, unique)
{
}
protected override bool Handle(UIEvent e)
protected override void ReloadMappings(IQueryable<RealmKeyBinding> realmKeyBindings)
{
if (!AllowUserPresses) return false;
base.ReloadMappings(realmKeyBindings);
return base.Handle(e);
if (!AllowGameplayInputs)
KeyBindings = KeyBindings.Where(b => b.GetAction<OsuAction>() == OsuAction.Smoke).ToList();
}
}
}

View File

@ -55,13 +55,13 @@ protected override void LoadComplete()
{
// The first fire of this is a bit redundant as this is being called in base.LoadComplete,
// but this is safest in case the subscription is restored after a context recycle.
reloadMappings(sender.AsQueryable());
ReloadMappings(sender.AsQueryable());
});
base.LoadComplete();
}
protected override void ReloadMappings() => reloadMappings(queryRealmKeyBindings(realm.Realm));
protected sealed override void ReloadMappings() => ReloadMappings(queryRealmKeyBindings(realm.Realm));
private IQueryable<RealmKeyBinding> queryRealmKeyBindings(Realm realm)
{
@ -70,7 +70,7 @@ private IQueryable<RealmKeyBinding> queryRealmKeyBindings(Realm realm)
.Where(b => b.RulesetName == rulesetName && b.Variant == variant);
}
private void reloadMappings(IQueryable<RealmKeyBinding> realmKeyBindings)
protected virtual void ReloadMappings(IQueryable<RealmKeyBinding> realmKeyBindings)
{
var defaults = DefaultKeyBindings.ToList();

View File

@ -230,9 +230,9 @@ public RulesetKeyBindingContainer(RulesetInfo ruleset, int variant, Simultaneous
{
}
protected override void ReloadMappings()
protected override void ReloadMappings(IQueryable<RealmKeyBinding> realmKeyBindings)
{
base.ReloadMappings();
base.ReloadMappings(realmKeyBindings);
KeyBindings = KeyBindings.Where(b => RealmKeyBindingStore.CheckValidForGameplay(b.KeyCombination)).ToList();
}