diff --git a/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs b/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs index c536672314..bc3a48fcab 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseTooltip.cs @@ -9,6 +9,7 @@ using osu.Game.Graphics.UserInterface; using osu.Framework.Configuration; using OpenTK; using osu.Game.Graphics; +using osu.Framework.Graphics.Cursor; namespace osu.Desktop.VisualTests.Tests { diff --git a/osu.Game/Graphics/Cursor/OsuTooltipContainer.cs b/osu.Game/Graphics/Cursor/OsuTooltipContainer.cs new file mode 100644 index 0000000000..902e92e880 --- /dev/null +++ b/osu.Game/Graphics/Cursor/OsuTooltipContainer.cs @@ -0,0 +1,97 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Allocation; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; +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 +{ + public class OsuTooltipContainer : TooltipContainer + { + protected override Tooltip CreateTooltip() => new OsuTooltip(); + + public OsuTooltipContainer(CursorContainer cursor) : base(cursor) + { + } + + public class OsuTooltip : Tooltip + { + private readonly Box background; + private readonly OsuSpriteText text; + + public override string TooltipText + { + set + { + if (value == text.Text) return; + + text.Text = value; + if (Alpha > 0) + { + AutoSizeDuration = 250; + background.FlashColour(OsuColour.Gray(0.4f), 1000, EasingTypes.OutQuint); + } + else + AutoSizeDuration = 0; + } + } + + private const float text_size = 16; + + public OsuTooltip() + { + AutoSizeEasing = EasingTypes.OutQuint; + + CornerRadius = 5; + Masking = true; + EdgeEffect = new EdgeEffect + { + Type = EdgeEffectType.Shadow, + Colour = Color4.Black.Opacity(40), + Radius = 5, + }; + Children = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0.9f, + }, + text = new OsuSpriteText + { + TextSize = text_size, + Padding = new MarginPadding(5), + Font = @"Exo2.0-Regular", + } + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colour) + { + background.Colour = colour.Gray3; + } + + protected override void PopIn() + { + FadeIn(500, EasingTypes.OutQuint); + } + + protected override void PopOut() + { + using (BeginDelayedSequence(150)) + FadeOut(500, EasingTypes.OutQuint); + } + } + } +} diff --git a/osu.Game/Graphics/Cursor/TooltipContainer.cs b/osu.Game/Graphics/Cursor/TooltipContainer.cs deleted file mode 100644 index c5b8382816..0000000000 --- a/osu.Game/Graphics/Cursor/TooltipContainer.cs +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using OpenTK; -using OpenTK.Graphics; -using osu.Framework.Allocation; -using osu.Framework.Extensions.Color4Extensions; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Cursor; -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 -{ - public class TooltipContainer : Container - { - private readonly CursorContainer cursor; - private readonly Tooltip tooltip; - - private ScheduledDelegate findTooltipTask; - private UserInputManager inputManager; - - private const int default_appear_delay = 220; - - private IHasTooltip currentlyDisplayed; - - public TooltipContainer(CursorContainer cursor) - { - this.cursor = cursor; - AlwaysPresent = true; - RelativeSizeAxes = Axes.Both; - Add(tooltip = new Tooltip { Alpha = 0 }); - } - - [BackgroundDependencyLoader] - private void load(UserInputManager input) - { - inputManager = input; - } - - protected override void Update() - { - if (tooltip.IsPresent) - { - if (currentlyDisplayed != null) - tooltip.TooltipText = currentlyDisplayed.TooltipText; - - //update the position of the displayed tooltip. - tooltip.Position = ToLocalSpace(cursor.ActiveCursor.ScreenSpaceDrawQuad.Centre) + new Vector2(10); - } - } - - protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) - { - updateTooltipState(state); - return base.OnMouseUp(state, args); - } - - protected override bool OnMouseMove(InputState state) - { - updateTooltipState(state); - return base.OnMouseMove(state); - } - - private void updateTooltipState(InputState state) - { - if (currentlyDisplayed?.Hovering != true) - { - if (currentlyDisplayed != null && !state.Mouse.HasMainButtonPressed) - { - tooltip.Delay(150); - tooltip.FadeOut(500, EasingTypes.OutQuint); - currentlyDisplayed = null; - } - - findTooltipTask?.Cancel(); - findTooltipTask = Scheduler.AddDelayed(delegate - { - var tooltipTarget = inputManager.HoveredDrawables.OfType().FirstOrDefault(); - - if (tooltipTarget == null) return; - - tooltip.TooltipText = tooltipTarget.TooltipText; - tooltip.FadeIn(500, EasingTypes.OutQuint); - - currentlyDisplayed = tooltipTarget; - }, (1 - tooltip.Alpha) * default_appear_delay); - } - } - - public class Tooltip : Container - { - private readonly Box background; - private readonly OsuSpriteText text; - - public string TooltipText - { - set - { - if (value == text.Text) return; - - text.Text = value; - if (Alpha > 0) - { - AutoSizeDuration = 250; - background.FlashColour(OsuColour.Gray(0.4f), 1000, EasingTypes.OutQuint); - } - else - AutoSizeDuration = 0; - } - } - - public override bool HandleInput => false; - - private const float text_size = 16; - - public Tooltip() - { - AutoSizeEasing = EasingTypes.OutQuint; - AutoSizeAxes = Axes.Both; - - CornerRadius = 5; - Masking = true; - EdgeEffect = new EdgeEffect - { - Type = EdgeEffectType.Shadow, - Colour = Color4.Black.Opacity(40), - Radius = 5, - }; - Children = new Drawable[] - { - background = new Box - { - RelativeSizeAxes = Axes.Both, - Alpha = 0.9f, - }, - text = new OsuSpriteText - { - TextSize = text_size, - Padding = new MarginPadding(5), - Font = @"Exo2.0-Regular", - } - }; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colour) - { - background.Colour = colour.Gray3; - } - } - } -} diff --git a/osu.Game/Graphics/IHasTooltip.cs b/osu.Game/Graphics/IHasTooltip.cs deleted file mode 100644 index dd51d68c41..0000000000 --- a/osu.Game/Graphics/IHasTooltip.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework.Graphics; - -namespace osu.Game.Graphics -{ - public interface IHasTooltip : IDrawable - { - /// - /// Tooltip that shows when hovering the drawable - /// - string TooltipText { get; } - } -} diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index 6cf7b2dfa5..c8be085b51 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -11,6 +11,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; +using osu.Framework.Graphics.Cursor; namespace osu.Game.Graphics.UserInterface { diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 2c39a82245..b228b6485a 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -158,7 +158,7 @@ namespace osu.Game Children = new Drawable[] { Cursor = new MenuCursor(), - new TooltipContainer(Cursor) { Depth = -1 }, + new OsuTooltipContainer(Cursor) { Depth = -1 }, } }, } diff --git a/osu.Game/Overlays/Mods/ModButton.cs b/osu.Game/Overlays/Mods/ModButton.cs index f7df67b66d..dd135e43ef 100644 --- a/osu.Game/Overlays/Mods/ModButton.cs +++ b/osu.Game/Overlays/Mods/ModButton.cs @@ -16,7 +16,7 @@ using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.UI; using System; using System.Linq; -using osu.Game.Graphics; +using osu.Framework.Graphics.Cursor; namespace osu.Game.Overlays.Mods { diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index b58e2f8c41..6b3b4d01ba 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -105,7 +105,6 @@ - @@ -118,7 +117,7 @@ - +