1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-19 09:12:58 +08:00

Refactor tooltip construction

This commit is contained in:
Bartłomiej Dach 2020-02-12 19:15:37 +01:00
parent e2ecef732c
commit 2b0bdd1db5
3 changed files with 21 additions and 17 deletions

View File

@ -62,16 +62,13 @@ namespace osu.Game.Overlays.Profile.Header.Components
Graph.FadeTo(Data.Length > 1 ? 1 : 0, FADE_DURATION, Easing.Out);
}
protected override object GetTooltipContent()
protected override object GetTooltipContent(int index, int rank)
{
if (Statistics.Value?.Ranks.Global == null)
return null;
var days = ranked_days - Data[DataIndex].Key + 1;
var days = ranked_days - index + 1;
return new TooltipDisplayContent
{
Rank = $"#{Data[DataIndex].Value:#,##0}",
Rank = $"#{rank:#,##0}",
Time = days == 0 ? "now" : $"{days} days ago"
};
}

View File

@ -42,15 +42,12 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
}
}
protected override object GetTooltipContent()
protected override object GetTooltipContent(DateTime date, long playCount)
{
if (!Data?.Any() ?? true)
return null;
return new TooltipDisplayContent
{
Count = Data[DataIndex].Value.ToString("N0"),
Date = Data[DataIndex].Key.ToString("MMMM yyyy")
Count = playCount.ToString("N0"),
Date = date.ToString("MMMM yyyy")
};
}

View File

@ -23,7 +23,7 @@ namespace osu.Game.Overlays.Profile
protected readonly UserLineGraph Graph;
protected KeyValuePair<TKey, TValue>[] Data;
protected int DataIndex;
private int dataIndex;
protected UserGraph()
{
@ -33,7 +33,7 @@ namespace osu.Game.Overlays.Profile
Alpha = 0
});
Graph.OnBallMove += i => DataIndex = i;
Graph.OnBallMove += i => dataIndex = i;
}
[BackgroundDependencyLoader]
@ -71,11 +71,21 @@ namespace osu.Game.Overlays.Profile
public ITooltip GetCustomTooltip() => GetTooltip();
public object TooltipContent => GetTooltipContent();
protected abstract UserGraphTooltip GetTooltip();
protected abstract object GetTooltipContent();
public object TooltipContent
{
get
{
if (Data == null || Data.Length == 0)
return null;
var (key, value) = Data[dataIndex];
return GetTooltipContent(key, value);
}
}
protected abstract object GetTooltipContent(TKey key, TValue value);
protected class UserLineGraph : LineGraph
{