1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00
osu-lazer/osu.Game.Rulesets.Osu/OsuInputManager.cs

69 lines
2.1 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 17:19:50 +08:00
using System.Collections.Generic;
using System.ComponentModel;
using osu.Framework.Input.Bindings;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu
{
public class OsuInputManager : RulesetInputManager<OsuAction>
{
public IEnumerable<OsuAction> PressedActions => KeyBindingContainer.PressedActions;
2018-08-17 18:33:14 +08:00
public bool AllowUserPresses
2018-04-13 17:19:50 +08:00
{
2018-08-17 18:33:14 +08:00
set => ((OsuKeyBindingContainer)KeyBindingContainer).AllowUserPresses = value;
}
2019-08-12 14:00:32 +08: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 16:33:02 +08:00
protected override KeyBindingContainer<OsuAction> CreateKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
2018-08-17 18:33:14 +08:00
=> new OsuKeyBindingContainer(ruleset, variant, unique);
public OsuInputManager(RulesetInfo ruleset)
: base(ruleset, 0, SimultaneousBindingMode.Unique)
{
}
protected override bool Handle(UIEvent e)
{
2019-05-11 00:46:13 +08:00
if (e is MouseMoveEvent && !AllowUserCursorMovement) return false;
return base.Handle(e);
}
2018-08-17 18:33:14 +08:00
private class OsuKeyBindingContainer : RulesetKeyBindingContainer
{
public bool AllowUserPresses = true;
public OsuKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
: base(ruleset, variant, unique)
{
}
protected override bool Handle(UIEvent e)
{
if (!AllowUserPresses) return false;
2019-02-28 12:31:40 +08:00
return base.Handle(e);
}
2018-04-13 17:19:50 +08:00
}
}
public enum OsuAction
{
2018-09-15 22:30:11 +08:00
[Description("Left button")]
2018-04-13 17:19:50 +08:00
LeftButton,
2018-08-17 18:33:14 +08:00
2018-09-15 22:30:11 +08:00
[Description("Right button")]
2018-04-13 17:19:50 +08:00
RightButton
}
}