Allow showing offline data only in profile.

This commit is contained in:
Huo Yaoyuan
2017-06-25 10:40:45 +08:00
parent d24f78ea24
commit be12f318e9

View File

@ -23,8 +23,12 @@ namespace osu.Game.Overlays
public class UserProfileOverlay : WaveOverlayContainer public class UserProfileOverlay : WaveOverlayContainer
{ {
private ProfileSection lastSection; private ProfileSection lastSection;
private ProfileSection[] sections;
private GetUserRequest userReq; private GetUserRequest userReq;
private APIAccess api; private APIAccess api;
private ProfileHeader header;
private SectionsContainer<ProfileSection> sectionsContainer;
private ProfileTabControl tabs;
public const float CONTENT_X_MARGIN = 50; public const float CONTENT_X_MARGIN = 50;
private const float transition_length = 500; private const float transition_length = 500;
@ -69,13 +73,13 @@ namespace osu.Game.Overlays
FadeEdgeEffectTo(0, DISAPPEAR_DURATION, EasingTypes.Out); FadeEdgeEffectTo(0, DISAPPEAR_DURATION, EasingTypes.Out);
} }
public void ShowUser(User user) public void ShowUser(User user, bool fetchOnline = true)
{ {
userReq?.Cancel(); userReq?.Cancel();
Clear(); Clear();
lastSection = null; lastSection = null;
var sections = new ProfileSection[] sections = new ProfileSection[]
{ {
new AboutSection(), new AboutSection(),
new RecentSection(), new RecentSection(),
@ -85,7 +89,7 @@ namespace osu.Game.Overlays
new BeatmapsSection(), new BeatmapsSection(),
new KudosuSection() new KudosuSection()
}; };
var tabs = new ProfileTabControl tabs = new ProfileTabControl
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
@ -99,9 +103,9 @@ namespace osu.Game.Overlays
Colour = OsuColour.Gray(0.2f) Colour = OsuColour.Gray(0.2f)
}); });
var header = new ProfileHeader(user); header = new ProfileHeader(user);
var sectionsContainer = new SectionsContainer<ProfileSection> Add(sectionsContainer = new SectionsContainer<ProfileSection>
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ExpandableHeader = header, ExpandableHeader = header,
@ -111,8 +115,7 @@ namespace osu.Game.Overlays
Colour = OsuColour.Gray(34), Colour = OsuColour.Gray(34),
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
} }
}; });
Add(sectionsContainer);
sectionsContainer.SelectedSection.ValueChanged += s => sectionsContainer.SelectedSection.ValueChanged += s =>
{ {
if (lastSection != s) if (lastSection != s)
@ -138,28 +141,38 @@ namespace osu.Game.Overlays
} }
}; };
userReq = new GetUserRequest(user.Id); //fetch latest full data if (fetchOnline)
userReq.Success += u =>
{ {
header.FillFullData(u); userReq = new GetUserRequest(user.Id);
userReq.Success += fillData;
for (int i = 0; i < u.ProfileOrder.Length; i++) api.Queue(userReq);
{ }
string id = u.ProfileOrder[i]; else
var sec = sections.FirstOrDefault(s => s.Identifier == id); {
if (sec != null) userReq = null;
{ fillData(user);
sec.Depth = -i; }
sectionsContainer.Add(sec);
tabs.AddItem(sec);
}
}
};
api.Queue(userReq);
Show(); Show();
} }
private void fillData(User user)
{
header.FillFullData(user);
for (int i = 0; i < user.ProfileOrder.Length; i++)
{
string id = user.ProfileOrder[i];
var sec = sections.FirstOrDefault(s => s.Identifier == id);
if (sec != null)
{
sec.Depth = -i;
sectionsContainer.Add(sec);
tabs.AddItem(sec);
}
}
}
private class ProfileTabControl : PageTabControl<ProfileSection> private class ProfileTabControl : PageTabControl<ProfileSection>
{ {
private readonly Box bottom; private readonly Box bottom;