2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2017-12-06 14:03:31 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-08-14 11:19:25 +00:00
|
|
|
|
using System.ComponentModel;
|
2022-10-09 12:28:12 +00:00
|
|
|
|
using System.Linq;
|
2023-01-16 10:35:55 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
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;
|
2022-10-09 14:14:16 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2023-01-23 08:07:27 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2023-01-16 10:35:55 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2017-08-21 03:31:21 +00:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2023-01-23 08:07:27 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-08-10 09:28:43 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Osu
|
|
|
|
|
{
|
2017-08-21 03:31:21 +00:00
|
|
|
|
public partial class OsuInputManager : RulesetInputManager<OsuAction>
|
2017-08-10 09:28:43 +00:00
|
|
|
|
{
|
2017-12-06 14:03:31 +00:00
|
|
|
|
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
|
2017-08-10 09:28:43 +00:00
|
|
|
|
{
|
2023-01-17 06:01:01 +00:00
|
|
|
|
get => ((OsuKeyBindingContainer)KeyBindingContainer).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>
|
2019-05-10 16:12:32 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2023-01-23 08:07:27 +00:00
|
|
|
|
public bool CheckScreenSpaceActionPressJudgeable(Vector2 screenSpacePosition) =>
|
2023-01-25 06:03:47 +00:00
|
|
|
|
// This is a very naive but simple approach.
|
|
|
|
|
//
|
|
|
|
|
// Based on user feedback of more nuanced scenarios (where touch doesn't behave as expected),
|
|
|
|
|
// this can be expanded to a more complex implementation, but I'd still want to keep it as simple as we can.
|
2023-01-23 08:07:27 +00:00
|
|
|
|
NonPositionalInputQueue.OfType<DrawableHitCircle.HitReceptor>().Any(c => c.ReceivePositionalInputAt(screenSpacePosition));
|
|
|
|
|
|
2018-08-17 10:33:14 +00:00
|
|
|
|
public OsuInputManager(RulesetInfo ruleset)
|
|
|
|
|
: base(ruleset, 0, SimultaneousBindingMode.Unique)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 10:35:55 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
Add(new OsuTouchInputMapper(this) { RelativeSizeAxes = Axes.Both });
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 16:12:32 +00:00
|
|
|
|
protected override bool Handle(UIEvent e)
|
|
|
|
|
{
|
2021-12-10 14:13:13 +00:00
|
|
|
|
if ((e is MouseMoveEvent || e is TouchMoveEvent) && !AllowUserCursorMovement) return false;
|
2019-05-10 16:12:32 +00:00
|
|
|
|
|
|
|
|
|
return base.Handle(e);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-17 10:33:14 +00:00
|
|
|
|
private partial 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-09 14:14:16 +00:00
|
|
|
|
{
|
2022-10-10 06:42:08 +00:00
|
|
|
|
get => allowGameplayInputs;
|
2022-10-09 14:14:16 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2022-10-10 06:42:08 +00:00
|
|
|
|
allowGameplayInputs = value;
|
2022-10-09 14:14:16 +00:00
|
|
|
|
ReloadMappings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-09 12:28:12 +00:00
|
|
|
|
|
2018-08-17 10:33:14 +00:00
|
|
|
|
public OsuKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
|
|
|
|
|
: base(ruleset, variant, unique)
|
|
|
|
|
{
|
|
|
|
|
}
|
2022-10-09 14:14:16 +00:00
|
|
|
|
|
|
|
|
|
protected override void ReloadMappings(IQueryable<RealmKeyBinding> realmKeyBindings)
|
|
|
|
|
{
|
|
|
|
|
base.ReloadMappings(realmKeyBindings);
|
|
|
|
|
|
2022-10-10 06:42:08 +00:00
|
|
|
|
if (!AllowGameplayInputs)
|
2022-10-09 14:14:16 +00:00
|
|
|
|
KeyBindings = KeyBindings.Where(b => b.GetAction<OsuAction>() == OsuAction.Smoke).ToList();
|
|
|
|
|
}
|
2017-08-10 09:28:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-08-10 09:28:43 +00:00
|
|
|
|
public enum OsuAction
|
|
|
|
|
{
|
2018-09-15 14:30:11 +00:00
|
|
|
|
[Description("Left button")]
|
2017-08-10 09:28:43 +00:00
|
|
|
|
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,
|
2017-08-10 09:28:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|