Remove non-smoke key bindings on "Relax" mod instead

This commit is contained in:
Salman Ahmed 2022-10-09 17:14:16 +03:00
parent c89a55043e
commit 2d4f390372
4 changed files with 27 additions and 11 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

@ -3,7 +3,6 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
@ -11,6 +10,7 @@
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
@ -60,16 +60,30 @@ protected override bool HandleMouseTouchStateChange(TouchStateChangeEvent e)
private class OsuKeyBindingContainer : RulesetKeyBindingContainer
{
public bool AllowUserPresses = true;
private bool allowUserPresses = true;
private static readonly OsuAction[] all_actions = (OsuAction[])Enum.GetValues(typeof(OsuAction));
protected override IEnumerable<OsuAction> BlockedActions => !AllowUserPresses ? all_actions.Where(a => a != OsuAction.Smoke) : Enumerable.Empty<OsuAction>();
public bool AllowUserPresses
{
get => allowUserPresses;
set
{
allowUserPresses = value;
ReloadMappings();
}
}
public OsuKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
: base(ruleset, variant, unique)
{
}
protected override void ReloadMappings(IQueryable<RealmKeyBinding> realmKeyBindings)
{
base.ReloadMappings(realmKeyBindings);
if (!AllowUserPresses)
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();
}