1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 15:22:55 +08:00

implement custom tooltip for DrawableDate

This commit is contained in:
Maximilian Junges 2020-02-11 14:21:12 +01:00
parent ed8cb1d6bf
commit 6278338448

View File

@ -4,13 +4,16 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Utils; using osu.Game.Utils;
using osuTK;
namespace osu.Game.Graphics namespace osu.Game.Graphics
{ {
public class DrawableDate : OsuSpriteText, IHasTooltip public class DrawableDate : OsuSpriteText, IHasCustomTooltip
{ {
private DateTimeOffset date; private DateTimeOffset date;
@ -75,6 +78,74 @@ namespace osu.Game.Graphics
private void updateTime() => Text = Format(); private void updateTime() => Text = Format();
public virtual string TooltipText => string.Format($"{Date:MMMM d, yyyy h:mm tt \"UTC\"z}"); public ITooltip GetCustomTooltip() => new DateTooltip();
public object TooltipContent => Date;
private class DateTooltip : VisibilityContainer, ITooltip
{
private readonly OsuSpriteText dateText, timeText;
private readonly Box background;
public DateTooltip()
{
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 5;
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Padding = new MarginPadding(10),
Children = new Drawable[]
{
dateText = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
},
timeText = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
}
}
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
// Temporary colour since it's currently impossible to change it without bugs (see https://github.com/ppy/osu-framework/issues/3231)
// If above is fixed, this should use OverlayColourProvider
background.Colour = colours.Gray1;
timeText.Colour = colours.GreyCyanLighter;
}
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
public bool SetContent(object content)
{
if (!(content is DateTimeOffset date))
return false;
dateText.Text = string.Format($"{date:d MMMM yyyy}") + " ";
timeText.Text = string.Format($"{date:hh:mm:ss \"UTC\"z}");
return true;
}
public void Move(Vector2 pos) => Position = pos;
}
} }
} }