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

move tooltip outside of the cursor

This commit is contained in:
Jorolf 2017-04-20 00:42:40 +02:00
parent e8aea3ccd2
commit ea67b41683
4 changed files with 30 additions and 28 deletions

View File

@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;

View File

@ -98,7 +98,7 @@ namespace osu.Game.Graphics.Cursor
public Cursor()
{
Size = new Vector2(42);
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]

View File

@ -26,32 +26,16 @@ namespace osu.Game.Graphics.Cursor
private ScheduledDelegate show;
private UserInputManager input;
private IHasDisappearingTooltip disappearingTooltip;
private IHasTooltip hasTooltip;
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)
{
this.cursor = cursor;
AlwaysPresent = true;
RelativeSizeAxes = Axes.Both;
Add(tooltip = new Tooltip());
}
[BackgroundDependencyLoader]
@ -62,9 +46,9 @@ namespace osu.Game.Graphics.Cursor
protected override void Update()
{
if (disappearingTooltip?.Disappear == false)
tooltip.TooltipText = disappearingTooltip.TooltipText;
else if (disappearingTooltip != null)
if (tooltip?.IsPresent == true)
tooltip.TooltipText = hasTooltip?.TooltipText;
else if (disappearingTooltip?.Disappear == true && show?.Completed == true)
{
disappearingTooltip = null;
tooltip.TooltipText = string.Empty;
@ -73,7 +57,23 @@ namespace osu.Game.Graphics.Cursor
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);
}
@ -87,13 +87,15 @@ namespace osu.Game.Graphics.Cursor
set
{
text.Text = value;
if (string.IsNullOrEmpty(value))
if (string.IsNullOrEmpty(value) && !Hovering)
Hide();
else
Show();
}
}
public override bool HandleInput => false;
public Tooltip()
{

View File

@ -144,9 +144,10 @@ namespace osu.Game
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 }
}
});
}