Enable NRT in user profile overlay

This commit is contained in:
Bartłomiej Dach
2022-12-30 13:17:59 +01:00
parent b97d4b571e
commit 88e90d5fa0
55 changed files with 172 additions and 279 deletions

View File

@ -1,12 +1,9 @@
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -26,12 +23,12 @@ namespace osu.Game.Overlays.Profile
/// </summary>
/// <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>
public abstract partial class UserGraph<TKey, TValue> : Container, IHasCustomTooltip<UserGraphTooltipContent>
public abstract partial class UserGraph<TKey, TValue> : Container, IHasCustomTooltip<UserGraphTooltipContent?>
{
protected const float FADE_DURATION = 150;
private readonly UserLineGraph graph;
private KeyValuePair<TKey, TValue>[] data;
private KeyValuePair<TKey, TValue>[]? data;
private int hoveredIndex = -1;
protected UserGraph()
@ -83,8 +80,7 @@ namespace osu.Game.Overlays.Profile
/// <summary>
/// Set of values which will be used to create a graph.
/// </summary>
[CanBeNull]
protected KeyValuePair<TKey, TValue>[] Data
protected KeyValuePair<TKey, TValue>[]? Data
{
set
{
@ -120,9 +116,9 @@ namespace osu.Game.Overlays.Profile
protected virtual void ShowGraph() => graph.FadeIn(FADE_DURATION, Easing.Out);
protected virtual void HideGraph() => graph.FadeOut(FADE_DURATION, Easing.Out);
public ITooltip<UserGraphTooltipContent> GetCustomTooltip() => new UserGraphTooltip();
public ITooltip<UserGraphTooltipContent?> GetCustomTooltip() => new UserGraphTooltip();
public UserGraphTooltipContent TooltipContent
public UserGraphTooltipContent? TooltipContent
{
get
{
@ -143,7 +139,7 @@ namespace osu.Game.Overlays.Profile
private readonly Box ballBg;
private readonly Box line;
public Action<int> OnBallMove;
public Action<int>? OnBallMove;
public UserLineGraph()
{
@ -191,7 +187,7 @@ namespace osu.Game.Overlays.Profile
Vector2 position = calculateBallPosition(index);
movingBall.MoveToY(position.Y, duration, Easing.OutQuint);
bar.MoveToX(position.X, duration, Easing.OutQuint);
OnBallMove.Invoke(index);
OnBallMove?.Invoke(index);
}
public void ShowBar() => bar.FadeIn(FADE_DURATION);
@ -207,7 +203,7 @@ namespace osu.Game.Overlays.Profile
}
}
private partial class UserGraphTooltip : VisibilityContainer, ITooltip<UserGraphTooltipContent>
private partial class UserGraphTooltip : VisibilityContainer, ITooltip<UserGraphTooltipContent?>
{
protected readonly OsuSpriteText Label, Counter, BottomText;
private readonly Box background;
@ -267,8 +263,11 @@ namespace osu.Game.Overlays.Profile
background.Colour = colours.Gray1;
}
public void SetContent(UserGraphTooltipContent content)
public void SetContent(UserGraphTooltipContent? content)
{
if (content == null)
return;
Label.Text = content.Name;
Counter.Text = content.Count;
BottomText.Text = content.Time;