mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Remove unnecessary interfaces and simplify tooltip logic.
This commit is contained in:
@ -31,11 +31,8 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
Spacing = new Vector2(0,10),
|
Spacing = new Vector2(0,10),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new TooltipTextContainer("Text with some tooltip"),
|
new TooltipTextContainer("text with a tooltip"),
|
||||||
new TooltipTextContainer("and another one with a custom delay")
|
new TooltipTextContainer("more text with another tooltip"),
|
||||||
{
|
|
||||||
TooltipDelay = 1000,
|
|
||||||
},
|
|
||||||
new TooltipTextbox
|
new TooltipTextbox
|
||||||
{
|
{
|
||||||
Text = "a box with a tooltip",
|
Text = "a box with a tooltip",
|
||||||
@ -56,14 +53,12 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TooltipTextContainer : Container, IHasTooltipWithCustomDelay
|
private class TooltipTextContainer : Container, IHasTooltip
|
||||||
{
|
{
|
||||||
private readonly OsuSpriteText text;
|
private readonly OsuSpriteText text;
|
||||||
|
|
||||||
public string TooltipText => text.Text;
|
public string TooltipText => text.Text;
|
||||||
|
|
||||||
public int TooltipDelay { get; set; } = TooltipContainer.DEFAULT_APPEAR_DELAY;
|
|
||||||
|
|
||||||
public TooltipTextContainer(string tooltipText)
|
public TooltipTextContainer(string tooltipText)
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
@ -82,7 +77,7 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
public string TooltipText => Text;
|
public string TooltipText => Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TooltipSlider : OsuSliderBar<int>, IHasDisappearingTooltip
|
private class TooltipSlider : OsuSliderBar<int>, IHasTooltip
|
||||||
{
|
{
|
||||||
public string TooltipText => Current.Value.ToString();
|
public string TooltipText => Current.Value.ToString();
|
||||||
|
|
||||||
|
@ -12,26 +12,4 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
string TooltipText { get; }
|
string TooltipText { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tooltip with custom appear time
|
|
||||||
/// </summary>
|
|
||||||
public interface IHasTooltipWithCustomDelay : IHasTooltip
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Time until the tooltip appears (in milliseconds)
|
|
||||||
/// </summary>
|
|
||||||
int TooltipDelay { get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tooltip which can decide when to disappear
|
|
||||||
/// </summary>
|
|
||||||
public interface IHasDisappearingTooltip : IHasTooltip
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Should the tooltip disappear?
|
|
||||||
/// </summary>
|
|
||||||
bool Disappear { get; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,55 +23,68 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
private readonly CursorContainer cursor;
|
private readonly CursorContainer cursor;
|
||||||
private readonly Tooltip tooltip;
|
private readonly Tooltip tooltip;
|
||||||
|
|
||||||
private ScheduledDelegate show;
|
private ScheduledDelegate findTooltipTask;
|
||||||
private UserInputManager input;
|
private UserInputManager inputManager;
|
||||||
private IHasDisappearingTooltip disappearingTooltip;
|
|
||||||
private IHasTooltip hasTooltip;
|
|
||||||
|
|
||||||
public const int DEFAULT_APPEAR_DELAY = 250;
|
private const int default_appear_delay = 250;
|
||||||
|
|
||||||
|
private IHasTooltip currentlyDisplayed;
|
||||||
|
|
||||||
|
private IMouseState lastState;
|
||||||
|
|
||||||
public TooltipContainer(CursorContainer cursor)
|
public TooltipContainer(CursorContainer cursor)
|
||||||
{
|
{
|
||||||
this.cursor = cursor;
|
this.cursor = cursor;
|
||||||
AlwaysPresent = true;
|
AlwaysPresent = true;
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
Add(tooltip = new Tooltip());
|
Add(tooltip = new Tooltip { Alpha = 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colour, UserInputManager input)
|
private void load(OsuColour colour, UserInputManager input)
|
||||||
{
|
{
|
||||||
this.input = input;
|
this.inputManager = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
if (tooltip?.IsPresent == true)
|
if (tooltip.IsPresent && lastState != null)
|
||||||
tooltip.TooltipText = hasTooltip?.TooltipText;
|
|
||||||
else if (disappearingTooltip?.Disappear == true && show?.Completed == true)
|
|
||||||
{
|
{
|
||||||
disappearingTooltip = null;
|
if (currentlyDisplayed != null)
|
||||||
tooltip.TooltipText = string.Empty;
|
tooltip.TooltipText = currentlyDisplayed.TooltipText;
|
||||||
|
|
||||||
|
//update the position of the displayed tooltip.
|
||||||
|
tooltip.Position = new Vector2(
|
||||||
|
lastState.Position.X,
|
||||||
|
Math.Min(cursor.ActiveCursor.BoundingBox.Bottom, lastState.Position.Y + cursor.ActiveCursor.DrawHeight));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnMouseMove(InputState state)
|
protected override bool OnMouseMove(InputState state)
|
||||||
{
|
{
|
||||||
if (((hasTooltip as Drawable)?.Hovering != true && disappearingTooltip?.Disappear != false) || show?.Completed != true)
|
lastState = state.Mouse;
|
||||||
|
|
||||||
|
if (currentlyDisplayed?.Hovering != true)
|
||||||
{
|
{
|
||||||
show?.Cancel();
|
if (currentlyDisplayed != null)
|
||||||
tooltip.TooltipText = string.Empty;
|
|
||||||
hasTooltip = input.HoveredDrawables.OfType<IHasTooltip>().FirstOrDefault();
|
|
||||||
if (hasTooltip != null)
|
|
||||||
{
|
{
|
||||||
IHasTooltipWithCustomDelay delayedTooltip = hasTooltip as IHasTooltipWithCustomDelay;
|
tooltip.Delay(100);
|
||||||
disappearingTooltip = hasTooltip as IHasDisappearingTooltip;
|
tooltip.FadeOut(500, EasingTypes.OutQuint);
|
||||||
show = Scheduler.AddDelayed(delegate
|
currentlyDisplayed = null;
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findTooltipTask?.Cancel();
|
||||||
|
findTooltipTask = Scheduler.AddDelayed(delegate
|
||||||
|
{
|
||||||
|
var tooltipTarget = inputManager.HoveredDrawables.OfType<IHasTooltip>().FirstOrDefault();
|
||||||
|
|
||||||
|
if (tooltipTarget == null) return;
|
||||||
|
|
||||||
|
tooltip.TooltipText = tooltipTarget.TooltipText;
|
||||||
|
tooltip.FadeIn(500, EasingTypes.OutQuint);
|
||||||
|
|
||||||
|
currentlyDisplayed = tooltipTarget;
|
||||||
|
}, (1 - tooltip.Alpha) * default_appear_delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.OnMouseMove(state);
|
return base.OnMouseMove(state);
|
||||||
@ -87,10 +100,6 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
text.Text = value;
|
text.Text = value;
|
||||||
if (string.IsNullOrEmpty(value) && !Hovering)
|
|
||||||
Hide();
|
|
||||||
else
|
|
||||||
Show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +125,7 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
},
|
},
|
||||||
text = new OsuSpriteText
|
text = new OsuSpriteText
|
||||||
{
|
{
|
||||||
Padding = new MarginPadding(3),
|
Padding = new MarginPadding(5),
|
||||||
Font = @"Exo2.0-Regular",
|
Font = @"Exo2.0-Regular",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user