From be12f318e94112e49a6d1dc8ffbc79f80c896fc2 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 25 Jun 2017 10:40:45 +0800 Subject: [PATCH] Allow showing offline data only in profile. --- osu.Game/Overlays/UserProfileOverlay.cs | 61 +++++++++++++++---------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/osu.Game/Overlays/UserProfileOverlay.cs b/osu.Game/Overlays/UserProfileOverlay.cs index 1cc11bc4e9..854382c5d5 100644 --- a/osu.Game/Overlays/UserProfileOverlay.cs +++ b/osu.Game/Overlays/UserProfileOverlay.cs @@ -23,8 +23,12 @@ namespace osu.Game.Overlays public class UserProfileOverlay : WaveOverlayContainer { private ProfileSection lastSection; + private ProfileSection[] sections; private GetUserRequest userReq; private APIAccess api; + private ProfileHeader header; + private SectionsContainer sectionsContainer; + private ProfileTabControl tabs; public const float CONTENT_X_MARGIN = 50; private const float transition_length = 500; @@ -69,13 +73,13 @@ protected override void PopOut() FadeEdgeEffectTo(0, DISAPPEAR_DURATION, EasingTypes.Out); } - public void ShowUser(User user) + public void ShowUser(User user, bool fetchOnline = true) { userReq?.Cancel(); Clear(); lastSection = null; - var sections = new ProfileSection[] + sections = new ProfileSection[] { new AboutSection(), new RecentSection(), @@ -85,7 +89,7 @@ public void ShowUser(User user) new BeatmapsSection(), new KudosuSection() }; - var tabs = new ProfileTabControl + tabs = new ProfileTabControl { RelativeSizeAxes = Axes.X, Anchor = Anchor.TopCentre, @@ -99,9 +103,9 @@ public void ShowUser(User user) Colour = OsuColour.Gray(0.2f) }); - var header = new ProfileHeader(user); + header = new ProfileHeader(user); - var sectionsContainer = new SectionsContainer + Add(sectionsContainer = new SectionsContainer { RelativeSizeAxes = Axes.Both, ExpandableHeader = header, @@ -111,8 +115,7 @@ public void ShowUser(User user) Colour = OsuColour.Gray(34), RelativeSizeAxes = Axes.Both } - }; - Add(sectionsContainer); + }); sectionsContainer.SelectedSection.ValueChanged += s => { if (lastSection != s) @@ -138,28 +141,38 @@ public void ShowUser(User user) } }; - userReq = new GetUserRequest(user.Id); //fetch latest full data - userReq.Success += u => + if (fetchOnline) { - header.FillFullData(u); - - for (int i = 0; i < u.ProfileOrder.Length; i++) - { - string id = u.ProfileOrder[i]; - var sec = sections.FirstOrDefault(s => s.Identifier == id); - if (sec != null) - { - sec.Depth = -i; - sectionsContainer.Add(sec); - tabs.AddItem(sec); - } - } - }; - api.Queue(userReq); + userReq = new GetUserRequest(user.Id); + userReq.Success += fillData; + api.Queue(userReq); + } + else + { + userReq = null; + fillData(user); + } 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 { private readonly Box bottom;