mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
moved tooltip stuff to Tooltip instead of MenuCursor
This commit is contained in:
@ -12,8 +12,6 @@ using osu.Framework.Input;
|
|||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Threading;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Cursor
|
namespace osu.Game.Graphics.Cursor
|
||||||
{
|
{
|
||||||
@ -21,44 +19,16 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
{
|
{
|
||||||
protected override Drawable CreateCursor() => new Cursor();
|
protected override Drawable CreateCursor() => new Cursor();
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OsuGameBase game)
|
|
||||||
{
|
|
||||||
this.game = game;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool dragging;
|
private bool dragging;
|
||||||
|
private Tooltip tooltip;
|
||||||
|
|
||||||
private ScheduledDelegate show;
|
public MenuCursor()
|
||||||
private OsuGameBase game;
|
{
|
||||||
private IHasOverhangingTooltip overhang;
|
Add(tooltip = new Tooltip());
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnMouseMove(InputState state)
|
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<IContainer>().Any(child => (hasTooltip = searchTooltip(child as IContainerEnumerable<Drawable>)) != 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)
|
if (dragging)
|
||||||
{
|
{
|
||||||
Vector2 offset = state.Mouse.Position - state.Mouse.PositionMouseDown ?? state.Mouse.Delta;
|
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);
|
ActiveCursor.RotateTo(degrees, 600, EasingTypes.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tooltip.Position = new Vector2(state.Mouse.Position.X,ActiveCursor.BoundingBox.Bottom);
|
||||||
|
tooltip.UpdateTooltip(state);
|
||||||
|
|
||||||
return base.OnMouseMove(state);
|
return base.OnMouseMove(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IHasTooltip searchTooltip(IContainerEnumerable<Drawable> 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<Drawable>);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnDragStart(InputState state)
|
protected override bool OnDragStart(InputState state)
|
||||||
{
|
{
|
||||||
dragging = true;
|
dragging = true;
|
||||||
@ -140,14 +101,13 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
public class Cursor : Container
|
public class Cursor : Container
|
||||||
{
|
{
|
||||||
private Container cursorContainer;
|
private Container cursorContainer;
|
||||||
public Tooltip Tooltip;
|
|
||||||
private Bindable<double> cursorScale;
|
private Bindable<double> cursorScale;
|
||||||
|
|
||||||
public Sprite AdditiveLayer;
|
public Sprite AdditiveLayer;
|
||||||
|
|
||||||
public Cursor()
|
public Cursor()
|
||||||
{
|
{
|
||||||
Size = new Vector2(42);
|
AutoSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -175,15 +135,10 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Tooltip = new Tooltip
|
|
||||||
{
|
|
||||||
Alpha = 0,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cursorScale = config.GetBindable<double>(OsuConfig.MenuCursorSize);
|
cursorScale = config.GetBindable<double>(OsuConfig.MenuCursorSize);
|
||||||
cursorScale.ValueChanged += newScale => cursorContainer.Scale = new Vector2((float)newScale);
|
cursorScale.ValueChanged += newScale => cursorContainer.Scale = new Vector2((float)newScale);
|
||||||
cursorScale.ValueChanged += newScale => Tooltip.Y = cursorContainer.Height * (float)newScale;
|
|
||||||
cursorScale.TriggerChange();
|
cursorScale.TriggerChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,10 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Input;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Cursor
|
namespace osu.Game.Graphics.Cursor
|
||||||
{
|
{
|
||||||
@ -17,6 +20,10 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
private readonly Box tooltipBackground;
|
private readonly Box tooltipBackground;
|
||||||
private readonly OsuSpriteText text;
|
private readonly OsuSpriteText text;
|
||||||
|
|
||||||
|
private ScheduledDelegate show;
|
||||||
|
private UserInputManager input;
|
||||||
|
private IHasOverhangingTooltip overhang;
|
||||||
|
|
||||||
public string TooltipText {
|
public string TooltipText {
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@ -65,9 +72,34 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colour)
|
private void load(OsuColour colour, UserInputManager input)
|
||||||
{
|
{
|
||||||
|
this.input = input;
|
||||||
tooltipBackground.Colour = colour.Gray3;
|
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<IHasTooltip>().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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user