2022-06-10 07:22:34 +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.
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
2022-06-10 10:33:01 +00:00
|
|
|
using osu.Framework.Input.States;
|
2022-06-10 07:22:34 +00:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Utility.SampleComponents
|
|
|
|
{
|
2022-06-10 10:33:01 +00:00
|
|
|
public partial class LatencyMovableBox : LatencySampleComponent
|
2022-06-10 07:22:34 +00:00
|
|
|
{
|
|
|
|
private Box box = null!;
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
InternalChild = box = new Box
|
|
|
|
{
|
|
|
|
Size = new Vector2(40),
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
Position = new Vector2(0.5f),
|
|
|
|
Origin = Anchor.Centre,
|
2022-06-10 10:33:01 +00:00
|
|
|
Colour = OverlayColourProvider.Colour1,
|
2022-06-10 07:22:34 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e) => false;
|
|
|
|
|
|
|
|
private double? lastFrameTime;
|
|
|
|
|
2022-06-10 10:33:01 +00:00
|
|
|
protected override void UpdateAtLimitedRate(InputState inputState)
|
2022-06-10 07:22:34 +00:00
|
|
|
{
|
2022-06-10 10:33:01 +00:00
|
|
|
if (!IsActive.Value)
|
2022-06-10 07:22:34 +00:00
|
|
|
{
|
|
|
|
lastFrameTime = null;
|
2022-06-10 10:33:01 +00:00
|
|
|
box.Colour = OverlayColourProvider.Colour1;
|
2022-06-10 07:22:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastFrameTime != null)
|
|
|
|
{
|
|
|
|
float movementAmount = (float)(Clock.CurrentTime - lastFrameTime) / 400;
|
|
|
|
|
2022-06-10 10:33:01 +00:00
|
|
|
var buttons = inputState.Keyboard.Keys;
|
2022-06-10 07:22:34 +00:00
|
|
|
|
2022-06-10 10:33:01 +00:00
|
|
|
box.Colour = buttons.HasAnyButtonPressed ? OverlayColourProvider.Content1 : OverlayColourProvider.Colour1;
|
2022-06-10 07:22:34 +00:00
|
|
|
|
|
|
|
foreach (var key in buttons)
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case Key.F:
|
|
|
|
case Key.Up:
|
|
|
|
box.Y = MathHelper.Clamp(box.Y - movementAmount, 0.1f, 0.9f);
|
|
|
|
break;
|
|
|
|
|
2022-06-10 11:08:53 +00:00
|
|
|
case Key.J:
|
2022-06-10 07:22:34 +00:00
|
|
|
case Key.Down:
|
|
|
|
box.Y = MathHelper.Clamp(box.Y + movementAmount, 0.1f, 0.9f);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.Z:
|
|
|
|
case Key.Left:
|
|
|
|
box.X = MathHelper.Clamp(box.X - movementAmount, 0.1f, 0.9f);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.X:
|
|
|
|
case Key.Right:
|
|
|
|
box.X = MathHelper.Clamp(box.X + movementAmount, 0.1f, 0.9f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastFrameTime = Clock.CurrentTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|