mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 15:22:55 +08:00
Add component for game-wide touch detection
This commit is contained in:
parent
68efb3c110
commit
980c900f43
@ -12,6 +12,7 @@ using osu.Framework.Extensions;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -835,6 +836,27 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
AddAssert("exit dialog is shown", () => Game.Dependencies.Get<IDialogOverlay>().CurrentDialog is ConfirmExitDialog);
|
AddAssert("exit dialog is shown", () => Game.Dependencies.Get<IDialogOverlay>().CurrentDialog is ConfirmExitDialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestTouchScreenDetection()
|
||||||
|
{
|
||||||
|
AddStep("touch logo", () =>
|
||||||
|
{
|
||||||
|
var button = Game.ChildrenOfType<OsuLogo>().Single();
|
||||||
|
var touch = new Touch(TouchSource.Touch1, button.ScreenSpaceDrawQuad.Centre);
|
||||||
|
InputManager.BeginTouch(touch);
|
||||||
|
InputManager.EndTouch(touch);
|
||||||
|
});
|
||||||
|
AddAssert("touch screen detected active", () => Game.Dependencies.Get<SessionStatics>().Get<bool>(Static.TouchInputActive), () => Is.True);
|
||||||
|
|
||||||
|
AddStep("click settings button", () =>
|
||||||
|
{
|
||||||
|
var button = Game.ChildrenOfType<MainMenuButton>().Last();
|
||||||
|
InputManager.MoveMouseTo(button);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddAssert("touch screen detected inactive", () => Game.Dependencies.Get<SessionStatics>().Get<bool>(Static.TouchInputActive), () => Is.False);
|
||||||
|
}
|
||||||
|
|
||||||
private Func<Player> playToResults()
|
private Func<Player> playToResults()
|
||||||
{
|
{
|
||||||
var player = playToCompletion();
|
var player = playToCompletion();
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Input;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Mods;
|
using osu.Game.Overlays.Mods;
|
||||||
@ -24,6 +25,7 @@ namespace osu.Game.Configuration
|
|||||||
SetDefault(Static.LastHoverSoundPlaybackTime, (double?)null);
|
SetDefault(Static.LastHoverSoundPlaybackTime, (double?)null);
|
||||||
SetDefault(Static.LastModSelectPanelSamplePlaybackTime, (double?)null);
|
SetDefault(Static.LastModSelectPanelSamplePlaybackTime, (double?)null);
|
||||||
SetDefault<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null);
|
SetDefault<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null);
|
||||||
|
SetDefault(Static.TouchInputActive, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -63,6 +65,12 @@ namespace osu.Game.Configuration
|
|||||||
/// The last playback time in milliseconds of an on/off sample (from <see cref="ModSelectPanel"/>).
|
/// The last playback time in milliseconds of an on/off sample (from <see cref="ModSelectPanel"/>).
|
||||||
/// Used to debounce <see cref="ModSelectPanel"/> on/off sounds game-wide to avoid volume saturation, especially in activating mod presets with many mods.
|
/// Used to debounce <see cref="ModSelectPanel"/> on/off sounds game-wide to avoid volume saturation, especially in activating mod presets with many mods.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
LastModSelectPanelSamplePlaybackTime
|
LastModSelectPanelSamplePlaybackTime,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the last positional input received was a touch input.
|
||||||
|
/// Used in touchscreen detection scenarios (<see cref="TouchInputInterceptor"/>).
|
||||||
|
/// </summary>
|
||||||
|
TouchInputActive,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
osu.Game/Input/TouchInputInterceptor.cs
Normal file
41
osu.Game/Input/TouchInputInterceptor.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Framework.Input.StateChanges;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Input
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Intercepts all positional input events and sets the appropriate <see cref="Static.TouchInputActive"/> value
|
||||||
|
/// for consumption by particular game screens.
|
||||||
|
/// </summary>
|
||||||
|
public partial class TouchInputInterceptor : Component
|
||||||
|
{
|
||||||
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private SessionStatics statics { get; set; } = null!;
|
||||||
|
|
||||||
|
protected override bool Handle(UIEvent e)
|
||||||
|
{
|
||||||
|
switch (e)
|
||||||
|
{
|
||||||
|
case MouseEvent:
|
||||||
|
if (e.CurrentState.Mouse.LastSource is not ISourcedFromTouch)
|
||||||
|
statics.SetValue(Static.TouchInputActive, false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TouchEvent:
|
||||||
|
statics.SetValue(Static.TouchInputActive, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -407,6 +407,8 @@ namespace osu.Game
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
base.Content.Add(new TouchInputInterceptor());
|
||||||
|
|
||||||
KeyBindingStore = new RealmKeyBindingStore(realm, keyCombinationProvider);
|
KeyBindingStore = new RealmKeyBindingStore(realm, keyCombinationProvider);
|
||||||
KeyBindingStore.Register(globalBindings, RulesetStore.AvailableRulesets);
|
KeyBindingStore.Register(globalBindings, RulesetStore.AvailableRulesets);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user