osu/osu.Game.Rulesets.Osu/OsuInputManager.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
4.0 KiB
C#
Raw Normal View History

// 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.
2018-04-13 09:19:50 +00:00
2022-06-17 07:37:17 +00:00
#nullable disable
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using osu.Framework.Input;
2017-08-11 07:11:46 +00:00
using osu.Framework.Input.Bindings;
2018-10-02 03:02:47 +00:00
using osu.Framework.Input.Events;
using osu.Framework.Input.StateChanges.Events;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets.UI;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Rulesets.Osu
{
public class OsuInputManager : RulesetInputManager<OsuAction>
{
public IEnumerable<OsuAction> PressedActions => KeyBindingContainer.PressedActions;
2018-04-13 09:19:50 +00:00
2022-10-10 06:42:08 +00:00
/// <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
{
2022-10-10 06:42:08 +00:00
set => ((OsuKeyBindingContainer)KeyBindingContainer).AllowGameplayInputs = value;
2018-08-17 10:33:14 +00:00
}
2019-08-12 06:00:32 +00:00
/// <summary>
/// Whether the user's cursor movement events should be accepted.
/// Can be used to block only movement while still accepting button input.
/// </summary>
public bool AllowUserCursorMovement { get; set; } = true;
2020-03-23 08:33:02 +00:00
protected override KeyBindingContainer<OsuAction> CreateKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
2018-08-17 10:33:14 +00:00
=> new OsuKeyBindingContainer(ruleset, variant, unique);
public OsuInputManager(RulesetInfo ruleset)
: base(ruleset, 0, SimultaneousBindingMode.Unique)
{
}
protected override bool Handle(UIEvent e)
{
if ((e is MouseMoveEvent || e is TouchMoveEvent) && !AllowUserCursorMovement) return false;
return base.Handle(e);
}
protected override bool HandleMouseTouchStateChange(TouchStateChangeEvent e)
{
if (!AllowUserCursorMovement)
{
// Still allow for forwarding of the "touch" part, but replace the positional data with that of the mouse.
// Primarily relied upon by the "autopilot" osu! mod.
var touch = new Touch(e.Touch.Source, CurrentState.Mouse.Position);
e = new TouchStateChangeEvent(e.State, e.Input, touch, e.IsActive, null);
}
return base.HandleMouseTouchStateChange(e);
}
2018-08-17 10:33:14 +00:00
private class OsuKeyBindingContainer : RulesetKeyBindingContainer
{
2022-10-10 06:42:08 +00:00
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
{
2022-10-10 06:42:08 +00:00
get => allowGameplayInputs;
set
{
2022-10-10 06:42:08 +00:00
allowGameplayInputs = value;
ReloadMappings();
}
}
2018-08-17 10:33:14 +00:00
public OsuKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
: base(ruleset, variant, unique)
{
}
protected override void ReloadMappings(IQueryable<RealmKeyBinding> realmKeyBindings)
{
base.ReloadMappings(realmKeyBindings);
2022-10-10 06:42:08 +00:00
if (!AllowGameplayInputs)
KeyBindings = KeyBindings.Where(b => b.GetAction<OsuAction>() == OsuAction.Smoke).ToList();
}
}
}
2018-04-13 09:19:50 +00:00
public enum OsuAction
{
2018-09-15 14:30:11 +00:00
[Description("Left button")]
LeftButton,
2018-08-17 10:33:14 +00:00
2018-09-15 14:30:11 +00:00
[Description("Right button")]
2022-09-18 19:08:34 +00:00
RightButton,
[Description("Smoke")]
Smoke,
}
}