mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 16:12:54 +08:00
Move shared logic to LatencySampleComponent
and implement key support for circle gameplay
This commit is contained in:
parent
7f4a54096f
commit
2f1c331f65
@ -8,13 +8,14 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Framework.Input.States;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Overlays.Settings;
|
using osu.Game.Overlays.Settings;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
|
using osu.Game.Screens.Utility.SampleComponents;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -141,7 +142,7 @@ namespace osu.Game.Screens.Utility
|
|||||||
unstableRate.Text = $"{hitEvents.CalculateUnstableRate():N1}";
|
unstableRate.Text = $"{hitEvents.CalculateUnstableRate():N1}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SampleHitCircle : CompositeDrawable
|
public class SampleHitCircle : LatencySampleComponent
|
||||||
{
|
{
|
||||||
public HitEvent? HitEvent;
|
public HitEvent? HitEvent;
|
||||||
|
|
||||||
@ -198,6 +199,8 @@ namespace osu.Game.Screens.Utility
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool OnHover(HoverEvent e) => true;
|
||||||
|
|
||||||
protected override bool OnMouseDown(MouseDownEvent e)
|
protected override bool OnMouseDown(MouseDownEvent e)
|
||||||
{
|
{
|
||||||
if (HitEvent != null)
|
if (HitEvent != null)
|
||||||
@ -206,6 +209,37 @@ namespace osu.Game.Screens.Utility
|
|||||||
if (Math.Abs(Clock.CurrentTime - HitTime) > 200)
|
if (Math.Abs(Clock.CurrentTime - HitTime) > 200)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
attemptHit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnKeyDown(KeyDownEvent e)
|
||||||
|
{
|
||||||
|
if (!IsActive.Value)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (IsHovered)
|
||||||
|
attemptHit();
|
||||||
|
return base.OnKeyDown(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateAtLimitedRate(InputState inputState)
|
||||||
|
{
|
||||||
|
if (HitEvent == null)
|
||||||
|
{
|
||||||
|
approach.Scale = new Vector2(1 + (float)MathHelper.Clamp((HitTime - Clock.CurrentTime) / approach_rate_milliseconds.Value, 0, 100));
|
||||||
|
Alpha = (float)MathHelper.Clamp((Clock.CurrentTime - HitTime + 600) / 400, 0, 1);
|
||||||
|
|
||||||
|
if (Clock.CurrentTime > HitTime + 200)
|
||||||
|
Expire();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void attemptHit() => Schedule(() =>
|
||||||
|
{
|
||||||
|
if (HitEvent != null)
|
||||||
|
return;
|
||||||
|
|
||||||
approach.Expire();
|
approach.Expire();
|
||||||
|
|
||||||
circle
|
circle
|
||||||
@ -220,23 +254,7 @@ namespace osu.Game.Screens.Utility
|
|||||||
Hit?.Invoke(HitEvent.Value);
|
Hit?.Invoke(HitEvent.Value);
|
||||||
|
|
||||||
this.Delay(200).Expire();
|
this.Delay(200).Expire();
|
||||||
|
});
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
|
||||||
{
|
|
||||||
base.Update();
|
|
||||||
|
|
||||||
if (HitEvent == null)
|
|
||||||
{
|
|
||||||
approach.Scale = new Vector2(1 + (float)MathHelper.Clamp((HitTime - Clock.CurrentTime) / approach_rate_milliseconds.Value, 0, 100));
|
|
||||||
Alpha = (float)MathHelper.Clamp((Clock.CurrentTime - HitTime + 600) / 400, 0, 1);
|
|
||||||
|
|
||||||
if (Clock.CurrentTime > HitTime + 200)
|
|
||||||
Expire();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ using osuTK.Input;
|
|||||||
|
|
||||||
namespace osu.Game.Screens.Utility
|
namespace osu.Game.Screens.Utility
|
||||||
{
|
{
|
||||||
|
[Cached]
|
||||||
public class LatencyArea : CompositeDrawable
|
public class LatencyArea : CompositeDrawable
|
||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved]
|
||||||
@ -82,11 +83,11 @@ namespace osu.Game.Screens.Utility
|
|||||||
case LatencyVisualMode.Simple:
|
case LatencyVisualMode.Simple:
|
||||||
visualContent.Children = new Drawable[]
|
visualContent.Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new LatencyMovableBox(IsActiveArea)
|
new LatencyMovableBox
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
new LatencyCursorContainer(IsActiveArea)
|
new LatencyCursorContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
@ -100,7 +101,7 @@ namespace osu.Game.Screens.Utility
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
new LatencyCursorContainer(IsActiveArea)
|
new LatencyCursorContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
@ -114,7 +115,7 @@ namespace osu.Game.Screens.Utility
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
new LatencyCursorContainer(IsActiveArea)
|
new LatencyCursorContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
|
@ -3,31 +3,25 @@
|
|||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Input;
|
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Framework.Input.States;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Utility.SampleComponents
|
namespace osu.Game.Screens.Utility.SampleComponents
|
||||||
{
|
{
|
||||||
public class LatencyCursorContainer : CompositeDrawable
|
public class LatencyCursorContainer : LatencySampleComponent
|
||||||
{
|
{
|
||||||
private Circle cursor = null!;
|
private Circle cursor = null!;
|
||||||
private InputManager inputManager = null!;
|
|
||||||
|
|
||||||
private readonly BindableBool isActive;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OverlayColourProvider overlayColourProvider { get; set; } = null!;
|
private OverlayColourProvider overlayColourProvider { get; set; } = null!;
|
||||||
|
|
||||||
public LatencyCursorContainer(BindableBool isActive)
|
public LatencyCursorContainer()
|
||||||
{
|
{
|
||||||
this.isActive = isActive;
|
|
||||||
Masking = true;
|
Masking = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,27 +35,23 @@ namespace osu.Game.Screens.Utility.SampleComponents
|
|||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Colour = overlayColourProvider.Colour2,
|
Colour = overlayColourProvider.Colour2,
|
||||||
};
|
};
|
||||||
|
|
||||||
inputManager = GetContainingInputManager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e) => false;
|
protected override bool OnHover(HoverEvent e) => false;
|
||||||
|
|
||||||
protected override void Update()
|
protected override void UpdateAtLimitedRate(InputState inputState)
|
||||||
{
|
{
|
||||||
cursor.Colour = inputManager.CurrentState.Mouse.IsPressed(MouseButton.Left) ? overlayColourProvider.Content1 : overlayColourProvider.Colour2;
|
cursor.Colour = inputState.Mouse.IsPressed(MouseButton.Left) ? overlayColourProvider.Content1 : overlayColourProvider.Colour2;
|
||||||
|
|
||||||
if (isActive.Value)
|
if (IsActive.Value)
|
||||||
{
|
{
|
||||||
cursor.Position = ToLocalSpace(inputManager.CurrentState.Mouse.Position);
|
cursor.Position = ToLocalSpace(inputState.Mouse.Position);
|
||||||
cursor.Alpha = 1;
|
cursor.Alpha = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cursor.Alpha = 0;
|
cursor.Alpha = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
base.Update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,47 +2,31 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Input;
|
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Overlays;
|
using osu.Framework.Input.States;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Utility.SampleComponents
|
namespace osu.Game.Screens.Utility.SampleComponents
|
||||||
{
|
{
|
||||||
public class LatencyMovableBox : CompositeDrawable
|
public class LatencyMovableBox : LatencySampleComponent
|
||||||
{
|
{
|
||||||
private Box box = null!;
|
private Box box = null!;
|
||||||
private InputManager inputManager = null!;
|
|
||||||
|
|
||||||
private readonly BindableBool isActive;
|
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private OverlayColourProvider overlayColourProvider { get; set; } = null!;
|
|
||||||
|
|
||||||
public LatencyMovableBox(BindableBool isActive)
|
|
||||||
{
|
|
||||||
this.isActive = isActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
inputManager = GetContainingInputManager();
|
|
||||||
|
|
||||||
InternalChild = box = new Box
|
InternalChild = box = new Box
|
||||||
{
|
{
|
||||||
Size = new Vector2(40),
|
Size = new Vector2(40),
|
||||||
RelativePositionAxes = Axes.Both,
|
RelativePositionAxes = Axes.Both,
|
||||||
Position = new Vector2(0.5f),
|
Position = new Vector2(0.5f),
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Colour = overlayColourProvider.Colour1,
|
Colour = OverlayColourProvider.Colour1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,14 +34,12 @@ namespace osu.Game.Screens.Utility.SampleComponents
|
|||||||
|
|
||||||
private double? lastFrameTime;
|
private double? lastFrameTime;
|
||||||
|
|
||||||
protected override void Update()
|
protected override void UpdateAtLimitedRate(InputState inputState)
|
||||||
{
|
{
|
||||||
base.Update();
|
if (!IsActive.Value)
|
||||||
|
|
||||||
if (!isActive.Value)
|
|
||||||
{
|
{
|
||||||
lastFrameTime = null;
|
lastFrameTime = null;
|
||||||
box.Colour = overlayColourProvider.Colour1;
|
box.Colour = OverlayColourProvider.Colour1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,9 +47,9 @@ namespace osu.Game.Screens.Utility.SampleComponents
|
|||||||
{
|
{
|
||||||
float movementAmount = (float)(Clock.CurrentTime - lastFrameTime) / 400;
|
float movementAmount = (float)(Clock.CurrentTime - lastFrameTime) / 400;
|
||||||
|
|
||||||
var buttons = inputManager.CurrentState.Keyboard.Keys;
|
var buttons = inputState.Keyboard.Keys;
|
||||||
|
|
||||||
box.Colour = buttons.HasAnyButtonPressed ? overlayColourProvider.Content1 : overlayColourProvider.Colour1;
|
box.Colour = buttons.HasAnyButtonPressed ? OverlayColourProvider.Content1 : OverlayColourProvider.Colour1;
|
||||||
|
|
||||||
foreach (var key in buttons)
|
foreach (var key in buttons)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Input;
|
||||||
|
using osu.Framework.Input.States;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.Utility.SampleComponents
|
||||||
|
{
|
||||||
|
public abstract class LatencySampleComponent : CompositeDrawable
|
||||||
|
{
|
||||||
|
protected readonly BindableBool IsActive = new BindableBool();
|
||||||
|
|
||||||
|
private InputManager inputManager = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private LatencyArea latencyArea { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
protected OverlayColourProvider OverlayColourProvider { get; private set; } = null!;
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
inputManager = GetContainingInputManager();
|
||||||
|
IsActive.BindTo(latencyArea.IsActiveArea);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected sealed override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
UpdateAtLimitedRate(inputManager.CurrentState);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void UpdateAtLimitedRate(InputState inputState);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user