-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserRankPanel.cs
241 lines (219 loc) · 10.1 KB
/
UserRankPanel.cs
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// 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.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Profile.Header.Components;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets;
using osuTK;
namespace osu.Game.Users
{
/// <summary>
/// User card that shows user's global and country ranks in the bottom.
/// Meant to be used in the toolbar login overlay.
/// </summary>
public partial class UserRankPanel : UserPanel
{
private const int padding = 10;
private const int main_content_height = 80;
private ProfileValueDisplay globalRankDisplay = null!;
private ProfileValueDisplay countryRankDisplay = null!;
private LoadingLayer loadingLayer = null!;
public UserRankPanel(APIUser user)
: base(user)
{
AutoSizeAxes = Axes.Y;
CornerRadius = 10;
}
[BackgroundDependencyLoader]
private void load()
{
BorderColour = ColourProvider?.Light1 ?? Colours.GreyVioletLighter;
}
[Resolved]
private LocalUserStatisticsProvider? statisticsProvider { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
protected override void LoadComplete()
{
base.LoadComplete();
if (statisticsProvider != null)
statisticsProvider.StatisticsUpdated += onStatisticsUpdated;
ruleset.BindValueChanged(_ => updateDisplay(), true);
}
private void onStatisticsUpdated(UserStatisticsUpdate update)
{
if (update.Ruleset.Equals(ruleset.Value))
updateDisplay();
}
private void updateDisplay()
{
var statistics = statisticsProvider?.GetStatisticsFor(ruleset.Value);
loadingLayer.State.Value = statistics == null ? Visibility.Visible : Visibility.Hidden;
globalRankDisplay.Content = statistics?.GlobalRank?.ToLocalisableString("\\##,##0") ?? "-";
countryRankDisplay.Content = statistics?.CountryRank?.ToLocalisableString("\\##,##0") ?? "-";
}
protected override Drawable CreateLayout()
{
FillFlowContainer details;
var layout = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new Container
{
Name = "Main content",
RelativeSizeAxes = Axes.X,
Height = main_content_height,
CornerRadius = 10,
Masking = true,
Children = new Drawable[]
{
new UserCoverBackground
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
User = User,
Alpha = 0.3f
},
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(padding),
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
},
RowDimensions = new[]
{
new Dimension()
},
Content = new[]
{
new Drawable[]
{
CreateAvatar().With(avatar =>
{
avatar.Size = new Vector2(60);
avatar.Masking = true;
avatar.CornerRadius = 6;
}),
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = padding },
ColumnDimensions = new[]
{
new Dimension()
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension()
},
Content = new[]
{
new Drawable[]
{
details = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(6),
Children = new Drawable[]
{
CreateFlag(),
// supporter icon is being added later
}
}
},
new Drawable[]
{
CreateUsername().With(username =>
{
username.Anchor = Anchor.CentreLeft;
username.Origin = Anchor.CentreLeft;
})
}
}
}
}
}
}
}
},
new GridContainer
{
Name = "Bottom content",
Margin = new MarginPadding { Top = main_content_height },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(padding),
ColumnDimensions = new[]
{
new Dimension(),
new Dimension()
},
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
Content = new[]
{
new Drawable[]
{
globalRankDisplay = new ProfileValueDisplay(true)
{
Title = UsersStrings.ShowRankGlobalSimple,
// TODO: implement highest rank tooltip
// `RankHighest` resides in `APIUser`, but `api.LocalUser` doesn't update
// maybe move to `UserStatistics` in api, so `UserStatisticsWatcher` can update the value
},
countryRankDisplay = new ProfileValueDisplay(true)
{
Title = UsersStrings.ShowRankCountrySimple,
}
}
}
},
loadingLayer = new LoadingLayer(true),
}
};
if (User.IsSupporter)
{
details.Add(new SupporterIcon
{
Height = 26,
SupportLevel = User.SupportLevel
});
}
return layout;
}
protected override bool OnHover(HoverEvent e)
{
BorderThickness = 2;
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
BorderThickness = 0;
base.OnHoverLost(e);
}
protected override Drawable? CreateBackground() => null;
protected override void Dispose(bool isDisposing)
{
if (statisticsProvider.IsNotNull())
statisticsProvider.StatisticsUpdated -= onStatisticsUpdated;
base.Dispose(isDisposing);
}
}
}