mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 19:12:54 +08:00
Use OnMouseMove instead of Update logic
This commit is contained in:
parent
babb7d5158
commit
7b770d03c5
@ -18,7 +18,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
{
|
{
|
||||||
public class QuitButton : FillFlowContainer
|
public class QuitButton : FillFlowContainer
|
||||||
{
|
{
|
||||||
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => button.ReceiveMouseInputAt(screenSpacePos);
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
|
||||||
|
|
||||||
private readonly Button button;
|
private readonly Button button;
|
||||||
|
|
||||||
@ -43,7 +43,11 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft
|
Origin = Anchor.CentreLeft
|
||||||
},
|
},
|
||||||
button = new Button()
|
button = new Button
|
||||||
|
{
|
||||||
|
HoverGained = () => text.FadeIn(500, Easing.OutQuint),
|
||||||
|
HoverLost = () => text.FadeOut(500, Easing.OutQuint)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
@ -54,28 +58,24 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnHover(InputState state)
|
private float positionalAdjust;
|
||||||
{
|
|
||||||
text.FadeIn(500, Easing.OutQuint);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnHoverLost(InputState state)
|
protected override bool OnMouseMove(InputState state)
|
||||||
{
|
{
|
||||||
text.FadeOut(500, Easing.OutQuint);
|
positionalAdjust = Vector2.Distance(state.Mouse.NativeState.Position, button.ScreenSpaceDrawQuad.Centre) / 200;
|
||||||
base.OnHoverLost(state);
|
return base.OnMouseMove(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
float adjust = Vector2.Distance(GetContainingInputManager().CurrentState.Mouse.NativeState.Position, button.ScreenSpaceDrawQuad.Centre) / 200;
|
if (text.Alpha > 0 || button.Progress.Value > 0 || button.IsHovered)
|
||||||
double elapsed = MathHelper.Clamp(Clock.ElapsedFrameTime, 0, 1000);
|
Alpha = 1;
|
||||||
|
else
|
||||||
bool stayVisible = text.Alpha > 0 || button.Progress.Value > 0 || IsHovered;
|
Alpha = Interpolation.ValueAt(
|
||||||
|
MathHelper.Clamp(Clock.ElapsedFrameTime, 0, 1000),
|
||||||
Alpha = stayVisible ? 1 : Interpolation.ValueAt(elapsed, Alpha, MathHelper.Clamp(1 - adjust, 0.04f, 1), 0, 200, Easing.OutQuint);
|
Alpha, MathHelper.Clamp(1 - positionalAdjust, 0.04f, 1), 0, 200, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Button : HoldToConfirmContainer
|
private class Button : HoldToConfirmContainer
|
||||||
@ -86,6 +86,9 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
|
|
||||||
protected override bool AllowMultipleFires => true;
|
protected override bool AllowMultipleFires => true;
|
||||||
|
|
||||||
|
public Action HoverGained;
|
||||||
|
public Action HoverLost;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
@ -163,6 +166,18 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool OnHover(InputState state)
|
||||||
|
{
|
||||||
|
HoverGained?.Invoke();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(InputState state)
|
||||||
|
{
|
||||||
|
HoverLost?.Invoke();
|
||||||
|
base.OnHoverLost(state);
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||||
{
|
{
|
||||||
if (!pendingAnimation && state.Mouse.Buttons.Count == 1)
|
if (!pendingAnimation && state.Mouse.Buttons.Count == 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user