mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Merge pull request #14591 from frenzibyte/simplify-user-graph-tooltips
Simplify user graph tooltips implementation
This commit is contained in:
@ -8,7 +8,6 @@ using Humanizer;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.LocalisationExtensions;
|
using osu.Framework.Extensions.LocalisationExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Localisation;
|
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Resources.Localisation.Web;
|
using osu.Game.Resources.Localisation.Web;
|
||||||
@ -61,40 +60,14 @@ namespace osu.Game.Overlays.Profile.Header.Components
|
|||||||
placeholder.FadeIn(FADE_DURATION, Easing.Out);
|
placeholder.FadeIn(FADE_DURATION, Easing.Out);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override object GetTooltipContent(int index, int rank)
|
protected override UserGraphTooltipContent GetTooltipContent(int index, int rank)
|
||||||
{
|
{
|
||||||
var days = ranked_days - index + 1;
|
var days = ranked_days - index + 1;
|
||||||
|
|
||||||
return new TooltipDisplayContent
|
return new UserGraphTooltipContent(
|
||||||
{
|
UsersStrings.ShowRankGlobalSimple,
|
||||||
Rank = rank.ToLocalisableString("\\##,##0"),
|
rank.ToLocalisableString("\\##,##0"),
|
||||||
Time = days == 0 ? "now" : $"{"day".ToQuantity(days)} ago"
|
days == 0 ? "now" : $"{"day".ToQuantity(days)} ago");
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override UserGraphTooltip GetTooltip() => new RankGraphTooltip();
|
|
||||||
|
|
||||||
private class RankGraphTooltip : UserGraphTooltip
|
|
||||||
{
|
|
||||||
public RankGraphTooltip()
|
|
||||||
: base(UsersStrings.ShowRankGlobalSimple)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SetContent(object content)
|
|
||||||
{
|
|
||||||
if (!(content is TooltipDisplayContent info))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Counter.Text = info.Rank;
|
|
||||||
BottomText.Text = info.Time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TooltipDisplayContent
|
|
||||||
{
|
|
||||||
public LocalisableString Rank;
|
|
||||||
public string Time;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,43 +28,10 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
|
|||||||
|
|
||||||
protected override float GetDataPointHeight(long playCount) => playCount;
|
protected override float GetDataPointHeight(long playCount) => playCount;
|
||||||
|
|
||||||
protected override UserGraphTooltip GetTooltip() => new HistoryGraphTooltip(tooltipCounterName);
|
protected override UserGraphTooltipContent GetTooltipContent(DateTime date, long playCount) =>
|
||||||
|
new UserGraphTooltipContent(
|
||||||
protected override object GetTooltipContent(DateTime date, long playCount)
|
tooltipCounterName,
|
||||||
{
|
playCount.ToLocalisableString("N0"),
|
||||||
return new TooltipDisplayContent
|
date.ToLocalisableString("MMMM yyyy"));
|
||||||
{
|
|
||||||
Name = tooltipCounterName,
|
|
||||||
Count = playCount.ToLocalisableString("N0"),
|
|
||||||
Date = date.ToLocalisableString("MMMM yyyy")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class HistoryGraphTooltip : UserGraphTooltip
|
|
||||||
{
|
|
||||||
private readonly LocalisableString tooltipCounterName;
|
|
||||||
|
|
||||||
public HistoryGraphTooltip(LocalisableString tooltipCounterName)
|
|
||||||
: base(tooltipCounterName)
|
|
||||||
{
|
|
||||||
this.tooltipCounterName = tooltipCounterName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SetContent(object content)
|
|
||||||
{
|
|
||||||
if (!(content is TooltipDisplayContent info) || info.Name != tooltipCounterName)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Counter.Text = info.Count;
|
|
||||||
BottomText.Text = info.Date;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TooltipDisplayContent
|
|
||||||
{
|
|
||||||
public LocalisableString Name;
|
|
||||||
public LocalisableString Count;
|
|
||||||
public LocalisableString Date;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ namespace osu.Game.Overlays.Profile
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TKey">Type of data to be used for X-axis of the graph.</typeparam>
|
/// <typeparam name="TKey">Type of data to be used for X-axis of the graph.</typeparam>
|
||||||
/// <typeparam name="TValue">Type of data to be used for Y-axis of the graph.</typeparam>
|
/// <typeparam name="TValue">Type of data to be used for Y-axis of the graph.</typeparam>
|
||||||
public abstract class UserGraph<TKey, TValue> : Container, IHasCustomTooltip
|
public abstract class UserGraph<TKey, TValue> : Container, IHasCustomTooltip<UserGraphTooltipContent>
|
||||||
{
|
{
|
||||||
protected const float FADE_DURATION = 150;
|
protected const float FADE_DURATION = 150;
|
||||||
|
|
||||||
@ -118,11 +118,9 @@ namespace osu.Game.Overlays.Profile
|
|||||||
protected virtual void ShowGraph() => graph.FadeIn(FADE_DURATION, Easing.Out);
|
protected virtual void ShowGraph() => graph.FadeIn(FADE_DURATION, Easing.Out);
|
||||||
protected virtual void HideGraph() => graph.FadeOut(FADE_DURATION, Easing.Out);
|
protected virtual void HideGraph() => graph.FadeOut(FADE_DURATION, Easing.Out);
|
||||||
|
|
||||||
public ITooltip GetCustomTooltip() => GetTooltip();
|
public ITooltip<UserGraphTooltipContent> GetCustomTooltip() => new UserGraphTooltip();
|
||||||
|
|
||||||
protected abstract UserGraphTooltip GetTooltip();
|
public UserGraphTooltipContent TooltipContent
|
||||||
|
|
||||||
public object TooltipContent
|
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@ -134,7 +132,7 @@ namespace osu.Game.Overlays.Profile
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract object GetTooltipContent(TKey key, TValue value);
|
protected abstract UserGraphTooltipContent GetTooltipContent(TKey key, TValue value);
|
||||||
|
|
||||||
protected class UserLineGraph : LineGraph
|
protected class UserLineGraph : LineGraph
|
||||||
{
|
{
|
||||||
@ -207,12 +205,12 @@ namespace osu.Game.Overlays.Profile
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract class UserGraphTooltip : VisibilityContainer, ITooltip
|
private class UserGraphTooltip : VisibilityContainer, ITooltip<UserGraphTooltipContent>
|
||||||
{
|
{
|
||||||
protected readonly OsuSpriteText Counter, BottomText;
|
protected readonly OsuSpriteText Label, Counter, BottomText;
|
||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
|
|
||||||
protected UserGraphTooltip(LocalisableString tooltipCounterName)
|
public UserGraphTooltip()
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
Masking = true;
|
Masking = true;
|
||||||
@ -238,10 +236,9 @@ namespace osu.Game.Overlays.Profile
|
|||||||
Spacing = new Vector2(3, 0),
|
Spacing = new Vector2(3, 0),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new OsuSpriteText
|
Label = new OsuSpriteText
|
||||||
{
|
{
|
||||||
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
|
||||||
Text = tooltipCounterName
|
|
||||||
},
|
},
|
||||||
Counter = new OsuSpriteText
|
Counter = new OsuSpriteText
|
||||||
{
|
{
|
||||||
@ -268,7 +265,12 @@ namespace osu.Game.Overlays.Profile
|
|||||||
background.Colour = colours.Gray1;
|
background.Colour = colours.Gray1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void SetContent(object content);
|
public void SetContent(UserGraphTooltipContent content)
|
||||||
|
{
|
||||||
|
Label.Text = content.Name;
|
||||||
|
Counter.Text = content.Count;
|
||||||
|
BottomText.Text = content.Time;
|
||||||
|
}
|
||||||
|
|
||||||
private bool instantMove = true;
|
private bool instantMove = true;
|
||||||
|
|
||||||
@ -292,4 +294,19 @@ namespace osu.Game.Overlays.Profile
|
|||||||
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
|
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class UserGraphTooltipContent
|
||||||
|
{
|
||||||
|
// todo: could use init-only properties on C# 9 which read better than a constructor.
|
||||||
|
public LocalisableString Name { get; }
|
||||||
|
public LocalisableString Count { get; }
|
||||||
|
public LocalisableString Time { get; }
|
||||||
|
|
||||||
|
public UserGraphTooltipContent(LocalisableString name, LocalisableString count, LocalisableString time)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Count = count;
|
||||||
|
Time = time;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user