From 773e6a29119e02df9d4cf3434df113f30fcb0385 Mon Sep 17 00:00:00 2001 From: Jorolf Date: Mon, 17 Apr 2017 17:04:48 +0200 Subject: [PATCH] moved tooltip stuff to Tooltip instead of MenuCursor --- osu.Game/Graphics/Cursor/MenuCursor.cs | 63 ++++---------------------- osu.Game/Graphics/Cursor/Tooltip.cs | 34 +++++++++++++- 2 files changed, 42 insertions(+), 55 deletions(-) diff --git a/osu.Game/Graphics/Cursor/MenuCursor.cs b/osu.Game/Graphics/Cursor/MenuCursor.cs index 255fa2ca99..6f208219ae 100644 --- a/osu.Game/Graphics/Cursor/MenuCursor.cs +++ b/osu.Game/Graphics/Cursor/MenuCursor.cs @@ -12,8 +12,6 @@ using osu.Framework.Input; using osu.Game.Configuration; using System; using osu.Framework.Graphics.Textures; -using osu.Framework.Threading; -using System.Linq; namespace osu.Game.Graphics.Cursor { @@ -21,44 +19,16 @@ namespace osu.Game.Graphics.Cursor { protected override Drawable CreateCursor() => new Cursor(); - [BackgroundDependencyLoader] - private void load(OsuGameBase game) - { - this.game = game; - } - private bool dragging; + private Tooltip tooltip; - private ScheduledDelegate show; - private OsuGameBase game; - private IHasOverhangingTooltip overhang; + public MenuCursor() + { + Add(tooltip = new Tooltip()); + } protected override bool OnMouseMove(InputState state) { - Tooltip tooltip = ((Cursor)ActiveCursor).Tooltip; - if (overhang?.Overhanging ?? false) - tooltip.TooltipText = overhang.Tooltip; - else if (state.Mouse.Position != state.Mouse.LastPosition) - { - show?.Cancel(); - tooltip.TooltipText = string.Empty; - IHasTooltip hasTooltip = null; - if (game.InternalChildren.OfType().Any(child => (hasTooltip = searchTooltip(child as IContainerEnumerable)) != null)) - { - IHasDelayedTooltip delayedTooltip = hasTooltip as IHasDelayedTooltip; - overhang = hasTooltip as IHasOverhangingTooltip; - show = Scheduler.AddDelayed(delegate - { - tooltip.TooltipText = hasTooltip.Tooltip; - }, delayedTooltip?.Delay ?? 250); - } - } - else if(overhang != null) - { - overhang = null; - tooltip.TooltipText = string.Empty; - } - if (dragging) { Vector2 offset = state.Mouse.Position - state.Mouse.PositionMouseDown ?? state.Mouse.Delta; @@ -73,21 +43,12 @@ namespace osu.Game.Graphics.Cursor ActiveCursor.RotateTo(degrees, 600, EasingTypes.OutQuint); } + tooltip.Position = new Vector2(state.Mouse.Position.X,ActiveCursor.BoundingBox.Bottom); + tooltip.UpdateTooltip(state); + return base.OnMouseMove(state); } - private IHasTooltip searchTooltip(IContainerEnumerable children) - { - Drawable next = children.InternalChildren.OrderBy(drawable => drawable.Depth).FirstOrDefault(drawable => drawable.Hovering && !(drawable is CursorContainer)); - - IHasTooltip tooltipText = next as IHasTooltip; - if (tooltipText != null) return tooltipText; - - if (next is IContainer) - return searchTooltip(next as IContainerEnumerable); - return null; - } - protected override bool OnDragStart(InputState state) { dragging = true; @@ -140,14 +101,13 @@ namespace osu.Game.Graphics.Cursor public class Cursor : Container { private Container cursorContainer; - public Tooltip Tooltip; private Bindable cursorScale; public Sprite AdditiveLayer; public Cursor() { - Size = new Vector2(42); + AutoSizeAxes = Axes.Both; } [BackgroundDependencyLoader] @@ -175,15 +135,10 @@ namespace osu.Game.Graphics.Cursor }, } }, - Tooltip = new Tooltip - { - Alpha = 0, - }, }; cursorScale = config.GetBindable(OsuConfig.MenuCursorSize); cursorScale.ValueChanged += newScale => cursorContainer.Scale = new Vector2((float)newScale); - cursorScale.ValueChanged += newScale => Tooltip.Y = cursorContainer.Height * (float)newScale; cursorScale.TriggerChange(); } } diff --git a/osu.Game/Graphics/Cursor/Tooltip.cs b/osu.Game/Graphics/Cursor/Tooltip.cs index 5cde7464f0..5960e83763 100644 --- a/osu.Game/Graphics/Cursor/Tooltip.cs +++ b/osu.Game/Graphics/Cursor/Tooltip.cs @@ -8,7 +8,10 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; +using osu.Framework.Input; +using osu.Framework.Threading; using osu.Game.Graphics.Sprites; +using System.Linq; namespace osu.Game.Graphics.Cursor { @@ -17,6 +20,10 @@ namespace osu.Game.Graphics.Cursor private readonly Box tooltipBackground; private readonly OsuSpriteText text; + private ScheduledDelegate show; + private UserInputManager input; + private IHasOverhangingTooltip overhang; + public string TooltipText { get { @@ -65,9 +72,34 @@ namespace osu.Game.Graphics.Cursor } [BackgroundDependencyLoader] - private void load(OsuColour colour) + private void load(OsuColour colour, UserInputManager input) { + this.input = input; tooltipBackground.Colour = colour.Gray3; } + + public void UpdateTooltip(InputState state) + { + Scheduler.Update(); + if (overhang?.Overhanging ?? false) + TooltipText = overhang.Tooltip; + else if (state.Mouse.Position != state.Mouse.LastPosition) + { + show?.Cancel(); + TooltipText = string.Empty; + IHasTooltip hasTooltip = input.HoveredDrawables.OfType().FirstOrDefault(); + if (hasTooltip != null) + { + IHasDelayedTooltip delayedTooltip = hasTooltip as IHasDelayedTooltip; + overhang = hasTooltip as IHasOverhangingTooltip; + show = Scheduler.AddDelayed(() => TooltipText = hasTooltip.Tooltip, delayedTooltip?.Delay ?? 250); + } + } + else if (overhang != null) + { + overhang = null; + TooltipText = string.Empty; + } + } } }