1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-11 17:52:56 +08:00
osu-lazer/osu.Game/Overlays/Profile/Sections/RanksSection.cs

221 lines
7.2 KiB
C#
Raw Normal View History

2017-06-07 22:49:14 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-07-27 00:55:37 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers;
2017-07-27 00:55:37 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Profile.Sections.Ranks;
2017-07-29 06:31:52 +08:00
using osu.Game.Rulesets.Scoring;
2017-07-27 00:55:37 +08:00
using System;
2017-09-14 19:05:43 +08:00
using System.Collections.Generic;
using System.Linq;
2017-09-14 19:05:43 +08:00
using osu.Framework.Allocation;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Rulesets;
using osu.Game.Users;
2017-07-27 00:55:37 +08:00
2017-07-13 12:53:45 +08:00
namespace osu.Game.Overlays.Profile.Sections
2017-06-07 22:49:14 +08:00
{
public class RanksSection : ProfileSection
{
public override string Title => "Ranks";
2017-06-15 23:47:34 +08:00
public override string Identifier => "top_ranks";
2017-07-27 00:55:37 +08:00
private readonly ScoreFlowContainer best, first;
private readonly OsuSpriteText bestMissing, firstMissing;
2017-07-27 00:55:37 +08:00
2017-09-14 19:05:43 +08:00
private APIAccess api;
private RulesetStore rulesets;
2017-07-27 00:55:37 +08:00
public RanksSection()
{
Children = new Drawable[]
{
new OsuSpriteText
{
2017-07-27 00:55:37 +08:00
TextSize = 15,
Text = "Best Performance",
Font = "Exo2.0-RegularItalic",
Margin = new MarginPadding { Top = 10, Bottom = 10 },
2017-07-27 00:55:37 +08:00
},
best = new ScoreFlowContainer
2017-07-27 00:55:37 +08:00
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
},
bestMissing = new OsuSpriteText
{
TextSize = 14,
Text = "No awesome performance records yet. :(",
},
new OsuSpriteText
{
2017-07-27 00:55:37 +08:00
TextSize = 15,
Text = "First Place Ranks",
Font = "Exo2.0-RegularItalic",
Margin = new MarginPadding { Top = 20, Bottom = 10 },
2017-07-27 00:55:37 +08:00
},
first = new ScoreFlowContainer
2017-07-27 00:55:37 +08:00
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
},
firstMissing = new OsuSpriteText
{
TextSize = 14,
Text = "No awesome performance records yet. :(",
2017-07-27 00:55:37 +08:00
},
};
}
2017-09-14 19:05:43 +08:00
[BackgroundDependencyLoader]
private void load(APIAccess api, RulesetStore rulesets)
{
this.api = api;
this.rulesets = rulesets;
}
public override User User
{
get
{
return base.User;
}
set
{
base.User = value;
// fetch online ranks
foreach (ScoreType m in new[] { ScoreType.Best, ScoreType.Firsts })
{
ScoreType thisType = m;
var req = new GetUserScoresRequest(User.Id, m);
req.Success += scores =>
{
foreach (var s in scores)
s.ApplyRuleset(rulesets.GetRuleset(s.OnlineRulesetID));
switch (thisType)
{
case ScoreType.Best:
ScoresBest = scores;
break;
case ScoreType.Firsts:
ScoresFirst = scores;
break;
}
};
Schedule(() => { api.Queue(req); });
}
}
}
public IEnumerable<Score> ScoresBest
2017-07-27 00:55:37 +08:00
{
set
{
best.Clear();
2017-09-14 19:05:43 +08:00
if (!value.Any())
2017-07-27 00:55:37 +08:00
{
bestMissing.Show();
}
else
{
bestMissing.Hide();
int i = 0;
foreach (Score score in value)
2017-07-27 00:55:37 +08:00
{
best.Add(new DrawableScore(score, Math.Pow(0.95, i))
{
RelativeSizeAxes = Axes.X,
Height = 60,
Alpha = 0,
});
i++;
}
2017-07-27 00:55:37 +08:00
}
best.ShowMore();
2017-07-27 00:55:37 +08:00
}
}
2017-09-14 19:05:43 +08:00
public IEnumerable<Score> ScoresFirst
2017-07-27 00:55:37 +08:00
{
set
{
first.Clear();
2017-09-14 19:05:43 +08:00
if (!value.Any())
{
firstMissing.Show();
}
else
{
firstMissing.Hide();
foreach (Score score in value)
first.Add(new DrawableScore(score)
{
RelativeSizeAxes = Axes.X,
Height = 60,
Alpha = 0,
});
}
first.ShowMore();
}
}
2017-08-10 01:20:41 +08:00
public class ScoreFlowContainer : Container<DrawableScore>
{
private FillFlowContainer<DrawableScore> scores;
private OsuClickableContainer showMoreText;
protected override Container<DrawableScore> Content => scores;
protected override void LoadComplete()
{
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Children = new Drawable[]
2017-07-27 00:55:37 +08:00
{
2017-07-29 21:16:31 +08:00
scores = new FillFlowContainer<DrawableScore>
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
},
},
};
}
public override void Clear(bool disposeChildren)
{
base.Clear(disposeChildren);
2017-08-10 04:58:06 +08:00
if (showMoreText == null)
((FillFlowContainer)InternalChild).Add(showMoreText = new OsuHoverContainer
{
Action = ShowMore,
AutoSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Child = new OsuSpriteText
{
TextSize = 14,
Text = "show more",
}
});
else
showMoreText.Show();
}
2017-08-10 00:57:55 +08:00
public void ShowMore() => showMoreText.Alpha = Children.Where(d => !d.IsPresent).Where((d, i) => (d.Alpha = i < 5 ? 1 : 0) == 0).Any() ? 1 : 0;
2017-07-27 00:55:37 +08:00
}
2017-06-07 22:49:14 +08:00
}
}