mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 13:32:54 +08:00
update osu to use the framework's TooltipContainer
This commit is contained in:
parent
900e3ce3e2
commit
a43890ffb4
@ -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
|
||||
{
|
||||
|
97
osu.Game/Graphics/Cursor/OsuTooltipContainer.cs
Normal file
97
osu.Game/Graphics/Cursor/OsuTooltipContainer.cs
Normal file
@ -0,0 +1,97 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,157 +0,0 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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<IHasTooltip>().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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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
|
||||
{
|
||||
/// <summary>
|
||||
/// Tooltip that shows when hovering the drawable
|
||||
/// </summary>
|
||||
string TooltipText { get; }
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
|
@ -158,7 +158,7 @@ namespace osu.Game
|
||||
Children = new Drawable[]
|
||||
{
|
||||
Cursor = new MenuCursor(),
|
||||
new TooltipContainer(Cursor) { Depth = -1 },
|
||||
new OsuTooltipContainer(Cursor) { Depth = -1 },
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -105,7 +105,6 @@
|
||||
<Compile Include="Graphics\Cursor\CursorTrail.cs" />
|
||||
<Compile Include="Graphics\Cursor\GameplayCursor.cs" />
|
||||
<Compile Include="Graphics\IHasAccentColour.cs" />
|
||||
<Compile Include="Graphics\IHasTooltip.cs" />
|
||||
<Compile Include="Graphics\Sprites\OsuSpriteText.cs" />
|
||||
<Compile Include="Graphics\Transforms\TransformAccent.cs" />
|
||||
<Compile Include="Graphics\UserInterface\BackButton.cs" />
|
||||
@ -118,7 +117,7 @@
|
||||
<Compile Include="Graphics\UserInterface\OsuTextBox.cs" />
|
||||
<Compile Include="Graphics\UserInterface\SimpleComboCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\TwoLayerButton.cs" />
|
||||
<Compile Include="Graphics\Cursor\TooltipContainer.cs" />
|
||||
<Compile Include="Graphics\Cursor\OsuTooltipContainer.cs" />
|
||||
<Compile Include="Input\Handlers\ReplayInputHandler.cs" />
|
||||
<Compile Include="IO\Legacy\ILegacySerializable.cs" />
|
||||
<Compile Include="IO\Legacy\SerializationReader.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user