Add logging & debug facility for touch input interceptor

This commit is contained in:
Bartłomiej Dach 2023-11-02 19:48:34 +01:00
parent c588f434e5
commit 4532d0ecdf
No known key found for this signature in database
1 changed files with 27 additions and 0 deletions

View File

@ -1,12 +1,16 @@
// 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 System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Framework.Input.StateChanges;
using osu.Framework.Logging;
using osu.Game.Configuration;
using osuTK;
using osuTK.Input;
namespace osu.Game.Input
{
@ -23,19 +27,42 @@ public partial class TouchInputInterceptor : Component
protected override bool Handle(UIEvent e)
{
bool touchInputWasActive = statics.Get<bool>(Static.TouchInputActive);
switch (e)
{
case MouseEvent:
if (e.CurrentState.Mouse.LastSource is not ISourcedFromTouch)
{
if (touchInputWasActive)
Logger.Log($@"Touch input deactivated due to received {e.GetType().ReadableName()}", LoggingTarget.Input);
statics.SetValue(Static.TouchInputActive, false);
}
break;
case TouchEvent:
if (!touchInputWasActive)
Logger.Log($@"Touch input activated due to received {e.GetType().ReadableName()}", LoggingTarget.Input);
statics.SetValue(Static.TouchInputActive, true);
break;
case KeyDownEvent keyDown:
if (keyDown.Key == Key.T && keyDown.ControlPressed && keyDown.ShiftPressed)
debugToggleTouchInputActive();
break;
}
return false;
}
[Conditional("TOUCH_INPUT_DEBUG")]
private void debugToggleTouchInputActive()
{
bool oldValue = statics.Get<bool>(Static.TouchInputActive);
bool newValue = !oldValue;
Logger.Log($@"Debug-toggling touch input to {(newValue ? @"active" : @"inactive")}", LoggingTarget.Input, LogLevel.Debug);
statics.SetValue(Static.TouchInputActive, newValue);
}
}
}