2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-06-26 01:10:04 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2024-08-02 12:16:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Cursor
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class OsuTooltipContainer : TooltipContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
protected override ITooltip CreateTooltip() => new OsuTooltip();
|
|
|
|
|
|
2019-02-28 12:31:40 +08:00
|
|
|
|
public OsuTooltipContainer(CursorContainer cursor)
|
|
|
|
|
: base(cursor)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 14:27:17 +08:00
|
|
|
|
protected override double AppearDelay => (1 - CurrentTooltip.Alpha) * base.AppearDelay; // reduce appear delay if the tooltip is already partly visible.
|
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class OsuTooltip : Tooltip
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2024-08-02 19:44:55 +08:00
|
|
|
|
private const float max_width = 500;
|
2024-08-02 12:16:50 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly Box background;
|
2024-08-02 12:16:50 +08:00
|
|
|
|
private readonly TextFlowContainer text;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private bool instantMovement = true;
|
|
|
|
|
|
2024-08-03 18:39:49 +08:00
|
|
|
|
private LocalisableString lastContent;
|
2024-08-02 12:16:50 +08:00
|
|
|
|
|
2024-08-03 18:39:49 +08:00
|
|
|
|
public override void SetContent(LocalisableString content)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2024-08-03 18:39:49 +08:00
|
|
|
|
if (content.Equals(lastContent))
|
2024-08-02 12:16:50 +08:00
|
|
|
|
return;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2024-08-03 18:39:49 +08:00
|
|
|
|
text.Text = content;
|
2019-08-19 09:46:28 +08:00
|
|
|
|
|
|
|
|
|
if (IsPresent)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeDuration = 250;
|
|
|
|
|
background.FlashColour(OsuColour.Gray(0.4f), 1000, Easing.OutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2019-08-19 09:46:28 +08:00
|
|
|
|
else
|
|
|
|
|
AutoSizeDuration = 0;
|
2024-08-02 12:16:50 +08:00
|
|
|
|
|
2024-08-03 18:39:49 +08:00
|
|
|
|
lastContent = content;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OsuTooltip()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeEasing = Easing.OutQuint;
|
|
|
|
|
|
|
|
|
|
CornerRadius = 5;
|
|
|
|
|
Masking = true;
|
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(40),
|
|
|
|
|
Radius = 5,
|
|
|
|
|
};
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0.9f,
|
|
|
|
|
},
|
2024-08-02 12:16:50 +08:00
|
|
|
|
text = new TextFlowContainer(f =>
|
|
|
|
|
{
|
|
|
|
|
f.Font = OsuFont.GetFont(weight: FontWeight.Regular);
|
|
|
|
|
})
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2024-08-02 12:16:50 +08:00
|
|
|
|
Margin = new MarginPadding(5),
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
MaximumSize = new Vector2(max_width, float.PositiveInfinity),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colour)
|
|
|
|
|
{
|
|
|
|
|
background.Colour = colour.Gray3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
instantMovement |= !IsPresent;
|
|
|
|
|
this.FadeIn(500, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut() => this.Delay(150).FadeOut(500, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
public override void Move(Vector2 pos)
|
|
|
|
|
{
|
|
|
|
|
if (instantMovement)
|
|
|
|
|
{
|
|
|
|
|
Position = pos;
|
|
|
|
|
instantMovement = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.MoveTo(pos, 200, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|