1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 15:57:24 +08:00

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 #nullable disable
using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Mania.Tests namespace osu.Game.Rulesets.Mania.Tests
@ -37,7 +39,7 @@ namespace osu.Game.Rulesets.Mania.Tests
{ {
} }
protected override void ReloadMappings() protected override void ReloadMappings(IQueryable<RealmKeyBinding> realmKeyBindings)
{ {
KeyBindings = DefaultKeyBindings; KeyBindings = DefaultKeyBindings;
} }

View File

@ -20,7 +20,9 @@ namespace osu.Game.Rulesets.Osu.Mods
public class OsuModRelax : ModRelax, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>, IApplicableToPlayer 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 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> /// <summary>
/// How early before a hitobject's start time to trigger a hit. /// How early before a hitobject's start time to trigger a hit.
@ -51,7 +53,7 @@ namespace osu.Game.Rulesets.Osu.Mods
return; return;
} }
osuInputManager.AllowUserPresses = false; osuInputManager.AllowGameplayInputs = false;
} }
public void Update(Playfield playfield) public void Update(Playfield playfield)

View File

@ -5,10 +5,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Input.StateChanges.Events; using osu.Framework.Input.StateChanges.Events;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu namespace osu.Game.Rulesets.Osu
@ -17,9 +19,16 @@ namespace osu.Game.Rulesets.Osu
{ {
public IEnumerable<OsuAction> PressedActions => KeyBindingContainer.PressedActions; 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> /// <summary>
@ -58,18 +67,36 @@ namespace osu.Game.Rulesets.Osu
private class OsuKeyBindingContainer : RulesetKeyBindingContainer 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) public OsuKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
: base(ruleset, variant, 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 @@ namespace osu.Game.Input.Bindings
{ {
// The first fire of this is a bit redundant as this is being called in base.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. // but this is safest in case the subscription is restored after a context recycle.
reloadMappings(sender.AsQueryable()); ReloadMappings(sender.AsQueryable());
}); });
base.LoadComplete(); 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) private IQueryable<RealmKeyBinding> queryRealmKeyBindings(Realm realm)
{ {
@ -70,7 +70,7 @@ namespace osu.Game.Input.Bindings
.Where(b => b.RulesetName == rulesetName && b.Variant == variant); .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(); var defaults = DefaultKeyBindings.ToList();

View File

@ -230,9 +230,9 @@ namespace osu.Game.Rulesets.UI
{ {
} }
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(); KeyBindings = KeyBindings.Where(b => RealmKeyBindingStore.CheckValidForGameplay(b.KeyCombination)).ToList();
} }