2019-01-24 16:43:03 +08:00
|
|
|
|
// 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
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-12-06 22:03:31 +08:00
|
|
|
|
using System.Collections.Generic;
|
2017-08-14 19:19:25 +08:00
|
|
|
|
using System.ComponentModel;
|
2022-10-09 20:28:12 +08:00
|
|
|
|
using System.Linq;
|
2021-12-16 18:57:24 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-08-11 15:11:46 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-12-10 18:14:33 +08:00
|
|
|
|
using osu.Framework.Input.StateChanges.Events;
|
2022-10-09 22:14:16 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2017-08-21 11:31:21 +08:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-10 17:28:43 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Osu
|
|
|
|
|
{
|
2017-08-21 11:31:21 +08:00
|
|
|
|
public class OsuInputManager : RulesetInputManager<OsuAction>
|
2017-08-10 17:28:43 +08:00
|
|
|
|
{
|
2017-12-06 22:03:31 +08:00
|
|
|
|
public IEnumerable<OsuAction> PressedActions => KeyBindingContainer.PressedActions;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-17 18:33:14 +08:00
|
|
|
|
public bool AllowUserPresses
|
2017-08-10 17:28:43 +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>
|
2019-05-11 00:12:32 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-11 00:12:32 +08:00
|
|
|
|
protected override bool Handle(UIEvent e)
|
|
|
|
|
{
|
2021-12-10 22:13:13 +08:00
|
|
|
|
if ((e is MouseMoveEvent || e is TouchMoveEvent) && !AllowUserCursorMovement) return false;
|
2019-05-11 00:12:32 +08:00
|
|
|
|
|
|
|
|
|
return base.Handle(e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 18:14:33 +08:00
|
|
|
|
protected override bool HandleMouseTouchStateChange(TouchStateChangeEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (!AllowUserCursorMovement)
|
|
|
|
|
{
|
2021-12-16 18:57:24 +08:00
|
|
|
|
// 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);
|
2021-12-10 18:14:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.HandleMouseTouchStateChange(e);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-17 18:33:14 +08:00
|
|
|
|
private class OsuKeyBindingContainer : RulesetKeyBindingContainer
|
|
|
|
|
{
|
2022-10-09 22:14:16 +08:00
|
|
|
|
private bool allowUserPresses = true;
|
2018-08-17 18:33:14 +08:00
|
|
|
|
|
2022-10-09 22:14:16 +08:00
|
|
|
|
public bool AllowUserPresses
|
|
|
|
|
{
|
|
|
|
|
get => allowUserPresses;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
allowUserPresses = value;
|
|
|
|
|
ReloadMappings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-09 20:28:12 +08:00
|
|
|
|
|
2018-08-17 18:33:14 +08:00
|
|
|
|
public OsuKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
|
|
|
|
|
: base(ruleset, variant, unique)
|
|
|
|
|
{
|
|
|
|
|
}
|
2022-10-09 22:14:16 +08:00
|
|
|
|
|
|
|
|
|
protected override void ReloadMappings(IQueryable<RealmKeyBinding> realmKeyBindings)
|
|
|
|
|
{
|
|
|
|
|
base.ReloadMappings(realmKeyBindings);
|
|
|
|
|
|
|
|
|
|
if (!AllowUserPresses)
|
|
|
|
|
KeyBindings = KeyBindings.Where(b => b.GetAction<OsuAction>() == OsuAction.Smoke).ToList();
|
|
|
|
|
}
|
2017-08-10 17:28:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-10 17:28:43 +08:00
|
|
|
|
public enum OsuAction
|
|
|
|
|
{
|
2018-09-15 22:30:11 +08:00
|
|
|
|
[Description("Left button")]
|
2017-08-10 17:28:43 +08:00
|
|
|
|
LeftButton,
|
2018-08-17 18:33:14 +08:00
|
|
|
|
|
2018-09-15 22:30:11 +08:00
|
|
|
|
[Description("Right button")]
|
2022-09-19 03:08:34 +08:00
|
|
|
|
RightButton,
|
|
|
|
|
|
|
|
|
|
[Description("Smoke")]
|
|
|
|
|
Smoke,
|
2017-08-10 17:28:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|