-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathMatchmakingStatsTooltip.cs
More file actions
135 lines (118 loc) · 5.11 KB
/
MatchmakingStatsTooltip.cs
File metadata and controls
135 lines (118 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays.Profile.Header.Components
{
public partial class MatchmakingStatsTooltip : VisibilityContainer, ITooltip<MatchmakingStatsTooltipData>
{
private Box background = null!;
private Container<TableContainer> tableContainer = null!;
public MatchmakingStatsTooltip()
{
AutoSizeAxes = Axes.Both;
CornerRadius = 20f;
Masking = true;
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.25f),
Radius = 30f,
};
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
tableContainer = new Container<TableContainer>
{
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding(15f),
}
};
}
public void SetContent(MatchmakingStatsTooltipData content)
{
var statistics = content.Statistics;
var colourProvider = content.ColourProvider;
background.Colour = colourProvider.Background4;
tableContainer.Child = new MatchmakingStatsTooltipTable(colourProvider)
{
AutoSizeAxes = Axes.Both,
Columns =
[
new TableColumn(dimension: new Dimension(GridSizeMode.AutoSize)),
new TableColumn(dimension: new Dimension(GridSizeMode.AutoSize)),
new TableColumn(RankingsStrings.MatchmakingWins, dimension: new Dimension(GridSizeMode.AutoSize)),
new TableColumn(RankingsStrings.MatchmakingPlays, dimension: new Dimension(GridSizeMode.AutoSize)),
new TableColumn(RankingsStrings.MatchmakingPoints, dimension: new Dimension(GridSizeMode.AutoSize)),
new TableColumn(RankingsStrings.MatchmakingRating, dimension: new Dimension(GridSizeMode.AutoSize)),
],
RowSize = new Dimension(GridSizeMode.AutoSize),
Content = statistics.Select(s => createRow(colourProvider, s)).ToArray().ToRectangular()
};
}
private Drawable[] createRow(OverlayColourProvider colourProvider, APIUserMatchmakingStatistics stat)
{
return
[
new StatisticText(colourProvider)
{
Text = stat.Pool.Name,
Colour = Color4.White
},
new StatisticText(colourProvider) { Text = $"#{stat.Rank:N0}" },
new StatisticText(colourProvider) { Text = stat.FirstPlacements.ToString("N0") },
new StatisticText(colourProvider) { Text = stat.Plays.ToString("N0") },
new StatisticText(colourProvider) { Text = stat.TotalPoints.ToString("N0") },
new StatisticText(colourProvider) { Text = stat.Rating.ToString("N0") + (stat.IsRatingProvisional ? "*" : string.Empty) }
];
}
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
public void Move(Vector2 pos) => Position = pos;
private partial class MatchmakingStatsTooltipTable : TableContainer
{
private readonly OverlayColourProvider colourProvider;
public MatchmakingStatsTooltipTable(OverlayColourProvider colourProvider)
{
this.colourProvider = colourProvider;
}
protected override Drawable CreateHeader(int index, TableColumn? column)
{
return new StatisticText(colourProvider)
{
Text = column?.Header ?? string.Empty,
};
}
}
private partial class StatisticText : OsuSpriteText
{
public StatisticText(OverlayColourProvider colourProvider)
{
Font = OsuFont.GetFont(size: 12);
Padding = new MarginPadding { Horizontal = 5, Vertical = 2 };
Colour = colourProvider.Content2;
}
}
}
public record MatchmakingStatsTooltipData(OverlayColourProvider ColourProvider, APIUserMatchmakingStatistics[] Statistics);
}