1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 12:27:26 +08:00

Override OnMouseMove for cursor position fetching

This commit is contained in:
CloneWith 2024-10-04 16:42:48 +08:00
parent 5dd28d5352
commit 2d7fdaf892
No known key found for this signature in database
GPG Key ID: F4FC0D1E91D7FFD5

View File

@ -8,7 +8,6 @@ using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Framework.Utils;
@ -39,8 +38,6 @@ namespace osu.Game.Screens.Play.HUD
private float relativePositionX;
private InputManager? inputManager;
public LocalisableString TooltipText => $"{(relativePositionX > 0 ? (EndTime - StartTime) * relativePositionX / DrawWidth : relativePositionX > DrawWidth ? EndTime : 0).ToEditorFormattedString()}"
+ $" - {(relativePositionX > 0 ? Math.Round(relativePositionX / DrawWidth * 100, 2) : relativePositionX > DrawWidth ? 100 : 0)}%";
@ -85,7 +82,6 @@ namespace osu.Game.Screens.Play.HUD
private void load(OsuColour colours)
{
catchUpColour = colours.BlueDark;
inputManager = GetContainingInputManager();
}
protected override void LoadComplete()
@ -96,6 +92,16 @@ namespace osu.Game.Screens.Play.HUD
playfieldBar.TransformTo(nameof(playfieldBar.AccentColour), mainColour, 200, Easing.In);
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
base.OnMouseMove(e);
var cursorPosition = e.ScreenSpaceMousePosition;
relativePositionX = ToLocalSpace(cursorPosition).X;
return true;
}
protected override bool OnHover(HoverEvent e)
{
if (Interactive)
@ -114,18 +120,6 @@ namespace osu.Game.Screens.Play.HUD
{
base.Update();
if (inputManager != null)
{
// Update the cursor position in time
var cursorPosition = inputManager.CurrentState.Mouse.Position;
relativePositionX = ToLocalSpace(cursorPosition).X;
}
else
{
// If null (e.g. before the game starts), try getting the input manager again
inputManager = GetContainingInputManager();
}
playfieldBar.Length = (float)Interpolation.Lerp(playfieldBar.Length, Progress, Math.Clamp(Time.Elapsed / 40, 0, 1));
audioBar.Length = (float)Interpolation.Lerp(audioBar.Length, AudioProgress, Math.Clamp(Time.Elapsed / 40, 0, 1));