mirror of
https://github.com/ppy/osu
synced 2025-01-05 21:59:46 +00:00
Use bindable for a user
This commit is contained in:
parent
e48c515d52
commit
94a974a397
@ -421,7 +421,7 @@ namespace osu.Game.Overlays.Profile
|
|||||||
gradeSPlus.DisplayCount = 0;
|
gradeSPlus.DisplayCount = 0;
|
||||||
gradeSSPlus.DisplayCount = 0;
|
gradeSSPlus.DisplayCount = 0;
|
||||||
|
|
||||||
rankGraph.Redraw(user);
|
rankGraph.User.Value = user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ using osu.Game.Graphics.Sprites;
|
|||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Profile
|
namespace osu.Game.Overlays.Profile
|
||||||
{
|
{
|
||||||
@ -31,7 +32,7 @@ namespace osu.Game.Overlays.Profile
|
|||||||
private readonly OsuSpriteText placeholder;
|
private readonly OsuSpriteText placeholder;
|
||||||
|
|
||||||
private KeyValuePair<int, int>[] ranks;
|
private KeyValuePair<int, int>[] ranks;
|
||||||
private User user;
|
public Bindable<User> User = new Bindable<User>();
|
||||||
|
|
||||||
public RankChart()
|
public RankChart()
|
||||||
{
|
{
|
||||||
@ -81,6 +82,8 @@ namespace osu.Game.Overlays.Profile
|
|||||||
};
|
};
|
||||||
|
|
||||||
graph.OnBallMove += showHistoryRankTexts;
|
graph.OnBallMove += showHistoryRankTexts;
|
||||||
|
|
||||||
|
User.ValueChanged += userChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -89,25 +92,21 @@ namespace osu.Game.Overlays.Profile
|
|||||||
graph.Colour = colours.Yellow;
|
graph.Colour = colours.Yellow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Redraw(User user)
|
private void userChanged(User newUser)
|
||||||
{
|
{
|
||||||
if (this.user == null && user != null)
|
placeholder.FadeTo(newUser == null ? 1 : 0, fade_duration, Easing.Out);
|
||||||
placeholder.FadeOut(fade_duration, Easing.Out);
|
|
||||||
|
|
||||||
this.user = user;
|
if (newUser == null)
|
||||||
|
|
||||||
if (user == null)
|
|
||||||
{
|
{
|
||||||
rankText.Text = string.Empty;
|
rankText.Text = string.Empty;
|
||||||
performanceText.Text = string.Empty;
|
performanceText.Text = string.Empty;
|
||||||
relativeText.Text = string.Empty;
|
relativeText.Text = string.Empty;
|
||||||
graph.FadeOut(fade_duration, Easing.Out);
|
graph.FadeOut(fade_duration, Easing.Out);
|
||||||
placeholder.FadeIn(fade_duration, Easing.Out);
|
|
||||||
ranks = null;
|
ranks = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int[] userRanks = user.RankHistory?.Data ?? new[] { user.Statistics.Rank };
|
int[] userRanks = newUser.RankHistory?.Data ?? new[] { newUser.Statistics.Rank };
|
||||||
ranks = userRanks.Select((x, index) => new KeyValuePair<int, int>(index, x)).Where(x => x.Value != 0).ToArray();
|
ranks = userRanks.Select((x, index) => new KeyValuePair<int, int>(index, x)).Where(x => x.Value != 0).ToArray();
|
||||||
|
|
||||||
if (ranks.Length > 1)
|
if (ranks.Length > 1)
|
||||||
@ -115,21 +114,18 @@ namespace osu.Game.Overlays.Profile
|
|||||||
graph.DefaultValueCount = ranks.Length;
|
graph.DefaultValueCount = ranks.Length;
|
||||||
graph.Values = ranks.Select(x => -(float)Math.Log(x.Value));
|
graph.Values = ranks.Select(x => -(float)Math.Log(x.Value));
|
||||||
graph.SetStaticBallPosition();
|
graph.SetStaticBallPosition();
|
||||||
graph.FadeIn(fade_duration, Easing.Out);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
graph.FadeOut(fade_duration, Easing.Out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
graph.FadeTo(ranks.Length > 1 ? 1 : 0, fade_duration, Easing.Out);
|
||||||
|
|
||||||
updateRankTexts();
|
updateRankTexts();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRankTexts()
|
private void updateRankTexts()
|
||||||
{
|
{
|
||||||
rankText.Text = user.Statistics.Rank > 0 ? $"#{user.Statistics.Rank:#,0}" : "no rank";
|
rankText.Text = User.Value.Statistics.Rank > 0 ? $"#{User.Value.Statistics.Rank:#,0}" : "no rank";
|
||||||
performanceText.Text = user.Statistics.PP != null ? $"{user.Statistics.PP:#,0}pp" : string.Empty;
|
performanceText.Text = User.Value.Statistics.PP != null ? $"{User.Value.Statistics.PP:#,0}pp" : string.Empty;
|
||||||
relativeText.Text = $"{user.Country?.FullName} #{user.CountryRank:#,0}";
|
relativeText.Text = $"{User.Value.Country?.FullName} #{User.Value.CountryRank:#,0}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showHistoryRankTexts(int dayIndex)
|
private void showHistoryRankTexts(int dayIndex)
|
||||||
|
Loading…
Reference in New Issue
Block a user