2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2017-06-03 12:50:35 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-04-02 05:51:28 +00:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2017-06-20 05:54:23 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-06-25 17:10:04 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2017-06-03 12:50:35 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-06-03 12:50:35 +00:00
|
|
|
|
namespace osu.Game.Graphics.Cursor
|
|
|
|
|
{
|
|
|
|
|
public partial class OsuTooltipContainer : TooltipContainer
|
|
|
|
|
{
|
2017-07-07 05:59:17 +00:00
|
|
|
|
protected override ITooltip CreateTooltip() => new OsuTooltip();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-02-28 04:31:40 +00:00
|
|
|
|
public OsuTooltipContainer(CursorContainer cursor)
|
|
|
|
|
: base(cursor)
|
2017-06-03 12:50:35 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-12 06:27:17 +00:00
|
|
|
|
protected override double AppearDelay => (1 - CurrentTooltip.Alpha) * base.AppearDelay; // reduce appear delay if the tooltip is already partly visible.
|
|
|
|
|
|
2017-06-03 12:50:35 +00:00
|
|
|
|
public partial class OsuTooltip : Tooltip
|
|
|
|
|
{
|
|
|
|
|
private readonly Box background;
|
|
|
|
|
private readonly OsuSpriteText text;
|
2017-06-05 11:52:46 +00:00
|
|
|
|
private bool instantMovement = true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-08-30 07:04:54 +00:00
|
|
|
|
public override void SetContent(LocalisableString contentString)
|
2017-06-03 12:50:35 +00:00
|
|
|
|
{
|
2021-08-30 07:04:54 +00:00
|
|
|
|
if (contentString == text.Text) return;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2019-08-19 01:46:28 +00:00
|
|
|
|
text.Text = contentString;
|
|
|
|
|
|
|
|
|
|
if (IsPresent)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeDuration = 250;
|
|
|
|
|
background.FlashColour(OsuColour.Gray(0.4f), 1000, Easing.OutQuint);
|
2017-06-03 12:50:35 +00:00
|
|
|
|
}
|
2019-08-19 01:46:28 +00:00
|
|
|
|
else
|
|
|
|
|
AutoSizeDuration = 0;
|
2017-06-03 12:50:35 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-06-03 12:50:35 +00:00
|
|
|
|
public OsuTooltip()
|
|
|
|
|
{
|
2017-07-22 18:50:25 +00:00
|
|
|
|
AutoSizeEasing = Easing.OutQuint;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-06-03 12:50:35 +00:00
|
|
|
|
CornerRadius = 5;
|
|
|
|
|
Masking = true;
|
2017-06-12 03:48:47 +00:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2017-06-03 12:50:35 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
2019-02-20 07:52:36 +00:00
|
|
|
|
Padding = new MarginPadding(5),
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Regular)
|
2017-06-03 12:50:35 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-06-03 12:50:35 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colour)
|
|
|
|
|
{
|
|
|
|
|
background.Colour = colour.Gray3;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-06-03 12:50:35 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
2017-06-05 11:52:46 +00:00
|
|
|
|
instantMovement |= !IsPresent;
|
2017-07-22 18:50:25 +00:00
|
|
|
|
this.FadeIn(500, Easing.OutQuint);
|
2017-06-03 12:50:35 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-07-22 18:50:25 +00:00
|
|
|
|
protected override void PopOut() => this.Delay(150).FadeOut(500, Easing.OutQuint);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-06-05 10:59:29 +00:00
|
|
|
|
public override void Move(Vector2 pos)
|
|
|
|
|
{
|
2017-06-05 11:52:46 +00:00
|
|
|
|
if (instantMovement)
|
2017-06-05 10:59:29 +00:00
|
|
|
|
{
|
|
|
|
|
Position = pos;
|
2017-06-05 11:52:46 +00:00
|
|
|
|
instantMovement = false;
|
2017-06-05 10:59:29 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-22 18:50:25 +00:00
|
|
|
|
this.MoveTo(pos, 200, Easing.OutQuint);
|
2017-06-05 10:59:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-03 12:50:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|