mirror of
https://github.com/ppy/osu.git
synced 2025-03-12 10:27:20 +08:00
move tooltip outside of the cursor
This commit is contained in:
parent
e8aea3ccd2
commit
ea67b41683
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
|
@ -98,7 +98,7 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
|
|
||||||
public Cursor()
|
public Cursor()
|
||||||
{
|
{
|
||||||
Size = new Vector2(42);
|
AutoSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
|
@ -26,32 +26,16 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
private ScheduledDelegate show;
|
private ScheduledDelegate show;
|
||||||
private UserInputManager input;
|
private UserInputManager input;
|
||||||
private IHasDisappearingTooltip disappearingTooltip;
|
private IHasDisappearingTooltip disappearingTooltip;
|
||||||
|
private IHasTooltip hasTooltip;
|
||||||
|
|
||||||
public const int DEFAULT_APPEAR_DELAY = 250;
|
public const int DEFAULT_APPEAR_DELAY = 250;
|
||||||
|
|
||||||
public IMouseState MouseState
|
|
||||||
{
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value.Position != value.LastPosition && disappearingTooltip?.Disappear != false)
|
|
||||||
{
|
|
||||||
show?.Cancel();
|
|
||||||
tooltip.TooltipText = string.Empty;
|
|
||||||
IHasTooltip hasTooltip = input.HoveredDrawables.OfType<IHasTooltip>().FirstOrDefault();
|
|
||||||
if (hasTooltip != null)
|
|
||||||
{
|
|
||||||
IHasTooltipWithCustomDelay delayedTooltip = hasTooltip as IHasTooltipWithCustomDelay;
|
|
||||||
disappearingTooltip = hasTooltip as IHasDisappearingTooltip;
|
|
||||||
show = Scheduler.AddDelayed(() => tooltip.TooltipText = hasTooltip.TooltipText, delayedTooltip?.TooltipDelay ?? DEFAULT_APPEAR_DELAY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TooltipContainer(CursorContainer cursor)
|
public TooltipContainer(CursorContainer cursor)
|
||||||
{
|
{
|
||||||
this.cursor = cursor;
|
this.cursor = cursor;
|
||||||
AlwaysPresent = true;
|
AlwaysPresent = true;
|
||||||
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
Add(tooltip = new Tooltip());
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -62,9 +46,9 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
if (disappearingTooltip?.Disappear == false)
|
if (tooltip?.IsPresent == true)
|
||||||
tooltip.TooltipText = disappearingTooltip.TooltipText;
|
tooltip.TooltipText = hasTooltip?.TooltipText;
|
||||||
else if (disappearingTooltip != null)
|
else if (disappearingTooltip?.Disappear == true && show?.Completed == true)
|
||||||
{
|
{
|
||||||
disappearingTooltip = null;
|
disappearingTooltip = null;
|
||||||
tooltip.TooltipText = string.Empty;
|
tooltip.TooltipText = string.Empty;
|
||||||
@ -73,7 +57,23 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
|
|
||||||
protected override bool OnMouseMove(InputState state)
|
protected override bool OnMouseMove(InputState state)
|
||||||
{
|
{
|
||||||
Position = new Vector2(state.Mouse.Position.X, Math.Min(cursor.ActiveCursor.BoundingBox.Bottom, state.Mouse.Position.Y + cursor.ActiveCursor.DrawHeight));
|
if (((hasTooltip as Drawable)?.Hovering != true && disappearingTooltip?.Disappear != false) || show?.Completed != true)
|
||||||
|
{
|
||||||
|
show?.Cancel();
|
||||||
|
tooltip.TooltipText = string.Empty;
|
||||||
|
hasTooltip = input.HoveredDrawables.OfType<IHasTooltip>().FirstOrDefault();
|
||||||
|
if (hasTooltip != null)
|
||||||
|
{
|
||||||
|
IHasTooltipWithCustomDelay delayedTooltip = hasTooltip as IHasTooltipWithCustomDelay;
|
||||||
|
disappearingTooltip = hasTooltip as IHasDisappearingTooltip;
|
||||||
|
show = Scheduler.AddDelayed(delegate
|
||||||
|
{
|
||||||
|
tooltip.TooltipText = hasTooltip.TooltipText;
|
||||||
|
tooltip.Position = new Vector2(state.Mouse.Position.X, Math.Min(cursor.ActiveCursor.BoundingBox.Bottom, state.Mouse.Position.Y + cursor.ActiveCursor.DrawHeight));
|
||||||
|
}, delayedTooltip?.TooltipDelay ?? DEFAULT_APPEAR_DELAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return base.OnMouseMove(state);
|
return base.OnMouseMove(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,13 +87,15 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
text.Text = value;
|
text.Text = value;
|
||||||
if (string.IsNullOrEmpty(value))
|
if (string.IsNullOrEmpty(value) && !Hovering)
|
||||||
Hide();
|
Hide();
|
||||||
else
|
else
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool HandleInput => false;
|
||||||
|
|
||||||
public Tooltip()
|
public Tooltip()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -144,9 +144,10 @@ namespace osu.Game
|
|||||||
|
|
||||||
AddInternal(ratioContainer = new RatioAdjust
|
AddInternal(ratioContainer = new RatioAdjust
|
||||||
{
|
{
|
||||||
Children = new[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
Cursor = new MenuCursor { Depth = float.MinValue }
|
Cursor = new MenuCursor { Depth = float.MinValue },
|
||||||
|
new TooltipContainer(Cursor) { Depth = float.MinValue }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user