mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 06:52:53 +08:00
Merge pull request #7779 from Malox10/hoverable-timestamps
Add tooltips with precise dates to beatmap set overlay
This commit is contained in:
commit
4fb4c03956
@ -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,72 @@ 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)
|
||||||
|
{
|
||||||
|
background.Colour = colours.GreySeafoamDarker;
|
||||||
|
timeText.Colour = colours.BlueLighter;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = $"{date:d MMMM yyyy} ";
|
||||||
|
timeText.Text = $"{date:hh:mm:ss \"UTC\"z}";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Move(Vector2 pos) => Position = pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -50,7 +51,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
fields.Children = new Drawable[]
|
fields.Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Field("mapped by", BeatmapSet.Metadata.Author.Username, OsuFont.GetFont(weight: FontWeight.Regular, italics: true)),
|
new Field("mapped by", BeatmapSet.Metadata.Author.Username, OsuFont.GetFont(weight: FontWeight.Regular, italics: true)),
|
||||||
new Field("submitted on", online.Submitted.ToString(@"MMMM d, yyyy"), OsuFont.GetFont(weight: FontWeight.Bold))
|
new Field("submitted", online.Submitted, OsuFont.GetFont(weight: FontWeight.Bold))
|
||||||
{
|
{
|
||||||
Margin = new MarginPadding { Top = 5 },
|
Margin = new MarginPadding { Top = 5 },
|
||||||
},
|
},
|
||||||
@ -58,11 +59,11 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
|
|
||||||
if (online.Ranked.HasValue)
|
if (online.Ranked.HasValue)
|
||||||
{
|
{
|
||||||
fields.Add(new Field("ranked on", online.Ranked.Value.ToString(@"MMMM d, yyyy"), OsuFont.GetFont(weight: FontWeight.Bold)));
|
fields.Add(new Field("ranked", online.Ranked.Value, OsuFont.GetFont(weight: FontWeight.Bold)));
|
||||||
}
|
}
|
||||||
else if (online.LastUpdated.HasValue)
|
else if (online.LastUpdated.HasValue)
|
||||||
{
|
{
|
||||||
fields.Add(new Field("last updated on", online.LastUpdated.Value.ToString(@"MMMM d, yyyy"), OsuFont.GetFont(weight: FontWeight.Bold)));
|
fields.Add(new Field("last updated", online.LastUpdated.Value, OsuFont.GetFont(weight: FontWeight.Bold)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +127,25 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Field(string first, DateTimeOffset second, FontUsage secondFont)
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
Direction = FillDirection.Horizontal;
|
||||||
|
|
||||||
|
Children = new[]
|
||||||
|
{
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Text = $"{first} ",
|
||||||
|
Font = OsuFont.GetFont(size: 13)
|
||||||
|
},
|
||||||
|
new DrawableDate(second)
|
||||||
|
{
|
||||||
|
Font = secondFont.With(size: 13)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -12,7 +13,6 @@ using osu.Game.Graphics.Sprites;
|
|||||||
using osu.Game.Online.Leaderboards;
|
using osu.Game.Online.Leaderboards;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Users.Drawables;
|
using osu.Game.Users.Drawables;
|
||||||
using osu.Game.Utils;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
private readonly UpdateableRank rank;
|
private readonly UpdateableRank rank;
|
||||||
private readonly UpdateableAvatar avatar;
|
private readonly UpdateableAvatar avatar;
|
||||||
private readonly LinkFlowContainer usernameText;
|
private readonly LinkFlowContainer usernameText;
|
||||||
private readonly SpriteText date;
|
private readonly DrawableDate achievedOn;
|
||||||
private readonly UpdateableFlag flag;
|
private readonly UpdateableFlag flag;
|
||||||
|
|
||||||
public TopScoreUserSection()
|
public TopScoreUserSection()
|
||||||
@ -92,11 +92,24 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
date = new OsuSpriteText
|
new FillFlowContainer
|
||||||
{
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Font = OsuFont.GetFont(size: 10)
|
Children = new[]
|
||||||
|
{
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Text = "achieved ",
|
||||||
|
Font = OsuFont.GetFont(size: 10, weight: FontWeight.Bold)
|
||||||
|
},
|
||||||
|
achievedOn = new DrawableDate(DateTimeOffset.MinValue)
|
||||||
|
{
|
||||||
|
Font = OsuFont.GetFont(size: 10, weight: FontWeight.Bold)
|
||||||
|
},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
flag = new UpdateableFlag
|
flag = new UpdateableFlag
|
||||||
{
|
{
|
||||||
@ -126,7 +139,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
{
|
{
|
||||||
avatar.User = value.User;
|
avatar.User = value.User;
|
||||||
flag.Country = value.User.Country;
|
flag.Country = value.User.Country;
|
||||||
date.Text = $@"achieved {HumanizerUtils.Humanize(value.Date)}";
|
achievedOn.Date = value.Date;
|
||||||
|
|
||||||
usernameText.Clear();
|
usernameText.Clear();
|
||||||
usernameText.AddUserLink(value.User);
|
usernameText.AddUserLink(value.User);
|
||||||
|
Loading…
Reference in New Issue
Block a user