From 2525f5bcb787955ab3a315c62143e76bd26825b7 Mon Sep 17 00:00:00 2001 From: jorolf Date: Sat, 9 Mar 2019 23:58:14 +0100 Subject: [PATCH] Apply most suggestions --- osu.Game.Tests/Visual/TestCaseUserProfile.cs | 13 -- .../Visual/TestCaseUserProfileHeader.cs | 8 +- .../Profile/Header/BottomHeaderContainer.cs | 26 +-- .../Profile/Header/CenterHeaderContainer.cs | 138 +++------------- .../Profile/Header/DetailHeaderContainer.cs | 40 ++--- .../Overlays/Profile/Header/DrawableBadge.cs | 46 ++++++ .../Profile/Header/MedalHeaderContainer.cs | 63 ++------ .../Profile/Header/OverlinedInfoContainer.cs | 63 ++++++++ .../Profile/Header/ProfileHeaderButton.cs | 50 ++++++ .../Profile/Header/ProfileHeaderTabControl.cs | 8 +- .../Profile/Header/ProfileMessageButton.cs | 57 +++++++ .../Overlays/Profile/Header/SupporterIcon.cs | 48 +++--- .../Profile/Header/TopHeaderContainer.cs | 34 ++-- osu.Game/Overlays/Profile/ProfileHeader.cs | 153 +++--------------- osu.Game/Overlays/UserProfileOverlay.cs | 4 +- osu.Game/Users/UserCoverBackground.cs | 47 ++++-- osu.Game/Users/UserPanel.cs | 4 +- 17 files changed, 375 insertions(+), 427 deletions(-) create mode 100644 osu.Game/Overlays/Profile/Header/DrawableBadge.cs create mode 100644 osu.Game/Overlays/Profile/Header/OverlinedInfoContainer.cs create mode 100644 osu.Game/Overlays/Profile/Header/ProfileHeaderButton.cs create mode 100644 osu.Game/Overlays/Profile/Header/ProfileMessageButton.cs diff --git a/osu.Game.Tests/Visual/TestCaseUserProfile.cs b/osu.Game.Tests/Visual/TestCaseUserProfile.cs index d0c4e495b8..3abb2584ce 100644 --- a/osu.Game.Tests/Visual/TestCaseUserProfile.cs +++ b/osu.Game.Tests/Visual/TestCaseUserProfile.cs @@ -87,8 +87,6 @@ namespace osu.Game.Tests.Visual AddStep("Show offline dummy", () => profile.ShowUser(TEST_USER, false)); - checkSupporterTag(false); - AddStep("Show null dummy", () => profile.ShowUser(new User { Username = @"Null", @@ -104,8 +102,6 @@ namespace osu.Game.Tests.Visual CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg" }, api.IsLoggedIn)); - checkSupporterTag(true); - AddStep("Show flyte", () => profile.ShowUser(new User { Username = @"flyte", @@ -118,15 +114,6 @@ namespace osu.Game.Tests.Visual AddStep("Show without reload", profile.Show); } - private void checkSupporterTag(bool isSupporter) - { - AddUntilStep(() => profile.Header.User != null, "wait for load"); - if (isSupporter) - AddAssert("is supporter", () => profile.Header.SupporterTag.Alpha == 1); - else - AddAssert("no supporter", () => profile.Header.SupporterTag.Alpha == 0); - } - private class TestUserProfileOverlay : UserProfileOverlay { public new ProfileHeader Header => base.Header; diff --git a/osu.Game.Tests/Visual/TestCaseUserProfileHeader.cs b/osu.Game.Tests/Visual/TestCaseUserProfileHeader.cs index 49ffa2d63f..8f36b4dda8 100644 --- a/osu.Game.Tests/Visual/TestCaseUserProfileHeader.cs +++ b/osu.Game.Tests/Visual/TestCaseUserProfileHeader.cs @@ -33,9 +33,9 @@ namespace osu.Game.Tests.Visual header = new ProfileHeader(); Add(header); - AddStep("Show offline dummy", () => header.User = TestCaseUserProfile.TEST_USER); + AddStep("Show offline dummy", () => header.User.Value = TestCaseUserProfile.TEST_USER); - AddStep("Show null dummy", () => header.User = new User + AddStep("Show null dummy", () => header.User.Value = new User { Username = "Null" }); @@ -65,11 +65,11 @@ namespace osu.Game.Tests.Visual if (api.IsLoggedIn) { var request = new GetUserRequest(fallback.Id); - request.Success += user => header.User = user; + request.Success += user => header.User.Value = user; api.Queue(request); } else - header.User = fallback; + header.User.Value = fallback; }); } } diff --git a/osu.Game/Overlays/Profile/Header/BottomHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/BottomHeaderContainer.cs index 7bb1b8acc2..1f9d741b8d 100644 --- a/osu.Game/Overlays/Profile/Header/BottomHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/BottomHeaderContainer.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -17,32 +18,21 @@ using osuTK.Graphics; namespace osu.Game.Overlays.Profile.Header { - public class BottomHeaderContainer : Container + public class BottomHeaderContainer : CompositeDrawable { private LinkFlowContainer bottomTopLinkContainer; private LinkFlowContainer bottomLinkContainer; private Color4 linkBlue, communityUserGrayGreenLighter; - private User user; - - public User User - { - get => user; - set - { - if (user == value) - return; - - user = value; - - updateDisplay(); - } - } + public readonly Bindable User = new Bindable(); [BackgroundDependencyLoader] private void load(OsuColour colours) { - Children = new Drawable[] + AutoSizeAxes = Axes.Y; + User.ValueChanged += e => updateDisplay(e.NewValue); + + InternalChildren = new Drawable[] { new Box { @@ -76,7 +66,7 @@ namespace osu.Game.Overlays.Profile.Header communityUserGrayGreenLighter = colours.CommunityUserGrayGreenLighter; } - private void updateDisplay() + private void updateDisplay(User user) { void bold(SpriteText t) => t.Font = @"Exo2.0-Bold"; void addSpacer(OsuTextFlowContainer textFlow) => textFlow.AddArbitraryDrawable(new Container { Width = 15 }); diff --git a/osu.Game/Overlays/Profile/Header/CenterHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/CenterHeaderContainer.cs index ca615ccf4b..b5e04bee9e 100644 --- a/osu.Game/Overlays/Profile/Header/CenterHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/CenterHeaderContainer.cs @@ -1,75 +1,48 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; +using System; using osu.Framework.Allocation; using osu.Framework.Bindables; -using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Game.Graphics; -using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; -using osu.Game.Online.API; -using osu.Game.Online.Chat; using osu.Game.Users; using osuTK; using osuTK.Graphics; namespace osu.Game.Overlays.Profile.Header { - public class CenterHeaderContainer : Container + public class CenterHeaderContainer : CompositeDrawable { - public readonly BindableBool DetailsVisible = new BindableBool(); + public Action DetailsVisibilityAction; + private bool detailsVisible; private OsuSpriteText followerText; - private ProfileHeaderButton messageButton; private OsuSpriteText levelBadgeText; private Bar levelProgressBar; private OsuSpriteText levelProgressText; - private ProfileHeader.OverlinedInfoContainer hiddenDetailGlobal, hiddenDetailCountry; + private OverlinedInfoContainer hiddenDetailGlobal, hiddenDetailCountry; - [Resolved(CanBeNull = true)] - private ChannelManager channelManager { get; set; } - - [Resolved(CanBeNull = true)] - private UserProfileOverlay userOverlay { get; set; } - - [Resolved(CanBeNull = true)] - private ChatOverlay chatOverlay { get; set; } - - [Resolved] - private APIAccess apiAccess { get; set; } - - private User user; - - public User User - { - get => user; - set - { - if (user == value) - return; - - user = value; - - updateDisplay(); - } - } + public readonly Bindable User = new Bindable(); [BackgroundDependencyLoader] private void load(OsuColour colours, TextureStore textures) { Container hiddenDetailContainer, expandedDetailContainer; SpriteIcon expandButtonIcon; + ProfileHeaderButton detailsToggleButton; + Height = 60; + User.ValueChanged += e => updateDisplay(e.NewValue); - Children = new Drawable[] + InternalChildren = new Drawable[] { new Box { @@ -118,21 +91,9 @@ namespace osu.Game.Overlays.Profile.Header } } }, - messageButton = new ProfileHeaderButton + new ProfileMessageButton { - Alpha = 0, - RelativeSizeAxes = Axes.Y, - Children = new Drawable[] - { - new SpriteIcon - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Icon = FontAwesome.fa_envelope, - FillMode = FillMode.Fit, - Size = new Vector2(50, 14) - }, - } + User = { BindTarget = User } }, } }, @@ -143,12 +104,11 @@ namespace osu.Game.Overlays.Profile.Header RelativeSizeAxes = Axes.Y, Padding = new MarginPadding { Vertical = 10 }, Width = UserProfileOverlay.CONTENT_X_MARGIN, - Child = new ProfileHeaderButton + Child = detailsToggleButton = new ProfileHeaderButton { RelativeSizeAxes = Axes.Y, Anchor = Anchor.Centre, Origin = Anchor.Centre, - Action = DetailsVisible.Toggle, Children = new Drawable[] { expandButtonIcon = new SpriteIcon @@ -233,12 +193,12 @@ namespace osu.Game.Overlays.Profile.Header Margin = new MarginPadding { Right = 50 }, Children = new[] { - hiddenDetailGlobal = new ProfileHeader.OverlinedInfoContainer + hiddenDetailGlobal = new OverlinedInfoContainer { Title = "Global Ranking", LineColour = colours.Yellow }, - hiddenDetailCountry = new ProfileHeader.OverlinedInfoContainer + hiddenDetailCountry = new OverlinedInfoContainer { Title = "Country Ranking", LineColour = colours.Yellow @@ -249,76 +209,26 @@ namespace osu.Game.Overlays.Profile.Header } }; - DetailsVisible.ValueChanged += visible => + detailsToggleButton.Action = () => { - expandButtonIcon.Icon = visible.NewValue ? FontAwesome.fa_chevron_down : FontAwesome.fa_chevron_up; - hiddenDetailContainer.Alpha = visible.NewValue ? 1 : 0; - expandedDetailContainer.Alpha = visible.NewValue ? 0 : 1; + detailsVisible = !detailsVisible; + expandButtonIcon.Icon = detailsVisible ? FontAwesome.fa_chevron_down : FontAwesome.fa_chevron_up; + hiddenDetailContainer.Alpha = detailsVisible ? 1 : 0; + expandedDetailContainer.Alpha = detailsVisible ? 0 : 1; + DetailsVisibilityAction(detailsVisible); }; } - private void updateDisplay() + private void updateDisplay(User user) { followerText.Text = user.FollowerCount?.Length > 0 ? user.FollowerCount[0].ToString("#,##0") : "0"; - if (!user.PMFriendsOnly && apiAccess.LocalUser.Value.Id != user.Id) - { - messageButton.Show(); - messageButton.Action = () => - { - channelManager?.OpenPrivateChannel(user); - userOverlay?.Hide(); - chatOverlay?.Show(); - }; - } - else - { - messageButton.Hide(); - } - levelBadgeText.Text = user.Statistics?.Level.Current.ToString() ?? "0"; levelProgressBar.Length = user.Statistics?.Level.Progress / 100f ?? 0; levelProgressText.Text = user.Statistics?.Level.Progress.ToString("0'%'"); - hiddenDetailGlobal.Content = user?.Statistics?.Ranks.Global?.ToString("#,##0") ?? "-"; - hiddenDetailCountry.Content = user?.Statistics?.Ranks.Country?.ToString("#,##0") ?? "-"; - } - - private class ProfileHeaderButton : OsuHoverContainer - { - private readonly Box background; - private readonly Container content; - - protected override Container Content => content; - - protected override IEnumerable EffectTargets => new[] { background }; - - public ProfileHeaderButton() - { - HoverColour = Color4.Black.Opacity(0.75f); - IdleColour = Color4.Black.Opacity(0.7f); - AutoSizeAxes = Axes.X; - - base.Content.Add(new CircularContainer - { - Masking = true, - AutoSizeAxes = Axes.X, - RelativeSizeAxes = Axes.Y, - Children = new Drawable[] - { - background = new Box - { - RelativeSizeAxes = Axes.Both, - }, - content = new Container - { - AutoSizeAxes = Axes.X, - RelativeSizeAxes = Axes.Y, - Padding = new MarginPadding { Horizontal = 10 }, - } - } - }); - } + hiddenDetailGlobal.Content = user.Statistics?.Ranks.Global?.ToString("#,##0") ?? "-"; + hiddenDetailCountry.Content = user.Statistics?.Ranks.Country?.ToString("#,##0") ?? "-"; } } } diff --git a/osu.Game/Overlays/Profile/Header/DetailHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/DetailHeaderContainer.cs index a7d21bcdf3..19894f0301 100644 --- a/osu.Game/Overlays/Profile/Header/DetailHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/DetailHeaderContainer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -17,34 +18,23 @@ using osuTK; namespace osu.Game.Overlays.Profile.Header { - public class DetailHeaderContainer : Container + public class DetailHeaderContainer : CompositeDrawable { private ProfileHeader.HasTooltipContainer totalPlayTimeTooltip; - private ProfileHeader.OverlinedInfoContainer totalPlayTimeInfo, medalInfo, ppInfo; + private OverlinedInfoContainer totalPlayTimeInfo, medalInfo, ppInfo; private readonly Dictionary scoreRankInfos = new Dictionary(); - private ProfileHeader.OverlinedInfoContainer detailGlobalRank, detailCountryRank; + private OverlinedInfoContainer detailGlobalRank, detailCountryRank; private RankGraph rankGraph; - private User user; - - public User User - { - get => user; - set - { - if (user == value) - return; - - user = value; - - updateDisplay(); - } - } + public readonly Bindable User = new Bindable(); [BackgroundDependencyLoader] private void load(OsuColour colours) { - Children = new Drawable[] + AutoSizeAxes = Axes.Y; + User.ValueChanged += e => updateDisplay(e.NewValue); + + InternalChildren = new Drawable[] { new Box { @@ -79,18 +69,18 @@ namespace osu.Game.Overlays.Profile.Header { AutoSizeAxes = Axes.Both, TooltipText = "0 hours", - Child = totalPlayTimeInfo = new ProfileHeader.OverlinedInfoContainer + Child = totalPlayTimeInfo = new OverlinedInfoContainer { Title = "Total Play Time", LineColour = colours.Yellow, }, }, - medalInfo = new ProfileHeader.OverlinedInfoContainer + medalInfo = new OverlinedInfoContainer { Title = "Medals", LineColour = colours.GreenLight, }, - ppInfo = new ProfileHeader.OverlinedInfoContainer + ppInfo = new OverlinedInfoContainer { Title = "pp", LineColour = colours.Red, @@ -135,12 +125,12 @@ namespace osu.Game.Overlays.Profile.Header Spacing = new Vector2(0, 20), Children = new Drawable[] { - detailGlobalRank = new ProfileHeader.OverlinedInfoContainer(true, 110) + detailGlobalRank = new OverlinedInfoContainer(true, 110) { Title = "Global Ranking", LineColour = colours.Yellow, }, - detailCountryRank = new ProfileHeader.OverlinedInfoContainer(false, 110) + detailCountryRank = new OverlinedInfoContainer(false, 110) { Title = "Country Ranking", LineColour = colours.Yellow, @@ -154,7 +144,7 @@ namespace osu.Game.Overlays.Profile.Header }; } - private void updateDisplay() + private void updateDisplay(User user) { medalInfo.Content = user?.Achievements?.Length.ToString() ?? "0"; ppInfo.Content = user?.Statistics?.PP?.ToString("#,##0") ?? "0"; diff --git a/osu.Game/Overlays/Profile/Header/DrawableBadge.cs b/osu.Game/Overlays/Profile/Header/DrawableBadge.cs new file mode 100644 index 0000000000..75a8f4e415 --- /dev/null +++ b/osu.Game/Overlays/Profile/Header/DrawableBadge.cs @@ -0,0 +1,46 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Game.Users; +using osuTK; + +namespace osu.Game.Overlays.Profile.Header +{ + public class DrawableBadge : CompositeDrawable, IHasTooltip + { + public static readonly Vector2 DRAWABLE_BADGE_SIZE = new Vector2(86, 40); + + private readonly Badge badge; + + public DrawableBadge(Badge badge) + { + this.badge = badge; + Size = DRAWABLE_BADGE_SIZE; + } + + [BackgroundDependencyLoader] + private void load(LargeTextureStore textures) + { + InternalChild = new Sprite + { + FillMode = FillMode.Fit, + RelativeSizeAxes = Axes.Both, + Texture = textures.Get(badge.ImageUrl), + }; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + InternalChild.FadeInFromZero(200); + } + + public string TooltipText => badge.Description; + } +} diff --git a/osu.Game/Overlays/Profile/Header/MedalHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/MedalHeaderContainer.cs index 45c1e1e208..69b1203b9f 100644 --- a/osu.Game/Overlays/Profile/Header/MedalHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/MedalHeaderContainer.cs @@ -2,14 +2,12 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Textures; using osu.Game.Graphics; using osu.Game.Users; using osuTK; @@ -17,31 +15,20 @@ using osuTK.Graphics; namespace osu.Game.Overlays.Profile.Header { - public class MedalHeaderContainer : Container + public class MedalHeaderContainer : CompositeDrawable { private FillFlowContainer badgeFlowContainer; - private User user; - - public User User - { - get => user; - set - { - if (user == value) - return; - - user = value; - - updateDisplay(); - } - } + public readonly Bindable User = new Bindable(); [BackgroundDependencyLoader] private void load(OsuColour colours) { Alpha = 0; - Children = new Drawable[] + AutoSizeAxes = Axes.Y; + User.ValueChanged += e => updateDisplay(e.NewValue); + + InternalChildren = new Drawable[] { new Box { @@ -76,9 +63,9 @@ namespace osu.Game.Overlays.Profile.Header }; } - private void updateDisplay() + private void updateDisplay(User user) { - var badges = User.Badges; + var badges = user.Badges; badgeFlowContainer.Clear(); if (badges?.Length > 0) { @@ -100,37 +87,5 @@ namespace osu.Game.Overlays.Profile.Header Hide(); } } - - private class DrawableBadge : CompositeDrawable, IHasTooltip - { - public static readonly Vector2 DRAWABLE_BADGE_SIZE = new Vector2(86, 40); - - private readonly Badge badge; - - public DrawableBadge(Badge badge) - { - this.badge = badge; - Size = DRAWABLE_BADGE_SIZE; - } - - [BackgroundDependencyLoader] - private void load(LargeTextureStore textures) - { - InternalChild = new Sprite - { - FillMode = FillMode.Fit, - RelativeSizeAxes = Axes.Both, - Texture = textures.Get(badge.ImageUrl), - }; - } - - protected override void LoadComplete() - { - base.LoadComplete(); - InternalChild.FadeInFromZero(200); - } - - public string TooltipText => badge.Description; - } } } diff --git a/osu.Game/Overlays/Profile/Header/OverlinedInfoContainer.cs b/osu.Game/Overlays/Profile/Header/OverlinedInfoContainer.cs new file mode 100644 index 0000000000..6d15f96eea --- /dev/null +++ b/osu.Game/Overlays/Profile/Header/OverlinedInfoContainer.cs @@ -0,0 +1,63 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osuTK.Graphics; + +namespace osu.Game.Overlays.Profile.Header +{ + public class OverlinedInfoContainer : CompositeDrawable + { + private readonly Circle line; + private readonly OsuSpriteText title, content; + + public string Title + { + set => title.Text = value; + } + + public string Content + { + set => content.Text = value; + } + + public Color4 LineColour + { + set => line.Colour = value; + } + + public OverlinedInfoContainer(bool big = false, int minimumWidth = 60) + { + AutoSizeAxes = Axes.Both; + InternalChild = new FillFlowContainer + { + Direction = FillDirection.Vertical, + AutoSizeAxes = Axes.Both, + Children = new Drawable[] + { + line = new Circle + { + RelativeSizeAxes = Axes.X, + Height = 4, + }, + title = new OsuSpriteText + { + Font = OsuFont.GetFont(size: big ? 14 : 12, weight: FontWeight.Bold) + }, + content = new OsuSpriteText + { + Font = OsuFont.GetFont(size: big ? 40 : 18, weight: FontWeight.Light) + }, + new Container //Add a minimum size to the FillFlowContainer + { + Width = minimumWidth, + } + } + }; + } + } +} diff --git a/osu.Game/Overlays/Profile/Header/ProfileHeaderButton.cs b/osu.Game/Overlays/Profile/Header/ProfileHeaderButton.cs new file mode 100644 index 0000000000..6d9ab7a4d8 --- /dev/null +++ b/osu.Game/Overlays/Profile/Header/ProfileHeaderButton.cs @@ -0,0 +1,50 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics.Containers; +using osuTK.Graphics; + +namespace osu.Game.Overlays.Profile.Header +{ + public class ProfileHeaderButton : OsuHoverContainer + { + private readonly Box background; + private readonly Container content; + + protected override Container Content => content; + + protected override IEnumerable EffectTargets => new[] { background }; + + public ProfileHeaderButton() + { + HoverColour = Color4.Black.Opacity(0.75f); + IdleColour = Color4.Black.Opacity(0.7f); + AutoSizeAxes = Axes.X; + + base.Content.Add(new CircularContainer + { + Masking = true, + AutoSizeAxes = Axes.X, + RelativeSizeAxes = Axes.Y, + Children = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both, + }, + content = new Container + { + AutoSizeAxes = Axes.X, + RelativeSizeAxes = Axes.Y, + Padding = new MarginPadding { Horizontal = 10 }, + } + } + }); + } + } +} diff --git a/osu.Game/Overlays/Profile/Header/ProfileHeaderTabControl.cs b/osu.Game/Overlays/Profile/Header/ProfileHeaderTabControl.cs index a8e50e00fe..e7c9676550 100644 --- a/osu.Game/Overlays/Profile/Header/ProfileHeaderTabControl.cs +++ b/osu.Game/Overlays/Profile/Header/ProfileHeaderTabControl.cs @@ -93,11 +93,11 @@ namespace osu.Game.Overlays.Profile.Header { text = new OsuSpriteText { - Margin = new MarginPadding { Bottom = 15 }, + Margin = new MarginPadding { Bottom = 10 }, Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, Text = value, - Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold) + Font = OsuFont.GetFont() }, bar = new Circle { @@ -134,7 +134,7 @@ namespace osu.Game.Overlays.Profile.Header { text.FadeColour(AccentColour, 120, Easing.InQuad); bar.ResizeHeightTo(0, 120, Easing.InQuad); - text.Font = text.Font.With(Typeface.Exo, weight: FontWeight.Medium); + text.Font = text.Font.With(weight: FontWeight.Medium); } private void onActivated(bool fake = false) @@ -142,7 +142,7 @@ namespace osu.Game.Overlays.Profile.Header text.FadeColour(Color4.White, 120, Easing.InQuad); bar.ResizeHeightTo(7.5f, 120, Easing.InQuad); if (!fake) - text.Font = text.Font.With(Typeface.Exo, weight: FontWeight.Bold); + text.Font = text.Font.With(weight: FontWeight.Bold); } } } diff --git a/osu.Game/Overlays/Profile/Header/ProfileMessageButton.cs b/osu.Game/Overlays/Profile/Header/ProfileMessageButton.cs new file mode 100644 index 0000000000..a14c0324d7 --- /dev/null +++ b/osu.Game/Overlays/Profile/Header/ProfileMessageButton.cs @@ -0,0 +1,57 @@ +// Copyright (c) ppy Pty Ltd . 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.Graphics; +using osu.Game.Graphics; +using osu.Game.Online.API; +using osu.Game.Online.Chat; +using osu.Game.Users; +using osuTK; + +namespace osu.Game.Overlays.Profile.Header +{ + public class ProfileMessageButton : ProfileHeaderButton + { + public readonly Bindable User = new Bindable(); + + [Resolved(CanBeNull = true)] + private ChannelManager channelManager { get; set; } + + [Resolved(CanBeNull = true)] + private UserProfileOverlay userOverlay { get; set; } + + [Resolved(CanBeNull = true)] + private ChatOverlay chatOverlay { get; set; } + + [Resolved] + private APIAccess apiAccess { get; set; } + + public ProfileMessageButton() + { + Content.Alpha = 0; + RelativeSizeAxes = Axes.Y; + + Child = new SpriteIcon + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Icon = FontAwesome.fa_envelope, + FillMode = FillMode.Fit, + Size = new Vector2(50, 14) + }; + + Action = () => + { + if (!Content.IsPresent) return; + + channelManager?.OpenPrivateChannel(User.Value); + userOverlay?.Hide(); + chatOverlay?.Show(); + }; + + User.ValueChanged += e => Content.Alpha = !e.NewValue.PMFriendsOnly && apiAccess.LocalUser.Value.Id != e.NewValue.Id ? 1 : 0; + } + } +} diff --git a/osu.Game/Overlays/Profile/Header/SupporterIcon.cs b/osu.Game/Overlays/Profile/Header/SupporterIcon.cs index d7e25e32c2..04d6db8b3c 100644 --- a/osu.Game/Overlays/Profile/Header/SupporterIcon.cs +++ b/osu.Game/Overlays/Profile/Header/SupporterIcon.cs @@ -10,10 +10,11 @@ using osu.Game.Graphics; namespace osu.Game.Overlays.Profile.Header { - public class SupporterIcon : CircularContainer, IHasTooltip + public class SupporterIcon : CompositeDrawable, IHasTooltip { private readonly Box background; private readonly FillFlowContainer iconContainer; + private readonly CircularContainer content; public string TooltipText => "osu!supporter"; @@ -23,11 +24,11 @@ namespace osu.Game.Overlays.Profile.Header { if (value == 0) { - Hide(); + content.Hide(); } else { - Show(); + content.Show(); iconContainer.Clear(); for (int i = 0; i < value; i++) { @@ -38,43 +39,38 @@ namespace osu.Game.Overlays.Profile.Header Icon = FontAwesome.fa_heart, }); } + + iconContainer.Padding = new MarginPadding { Horizontal = DrawHeight / 2 }; } } } public SupporterIcon() { - Masking = true; AutoSizeAxes = Axes.X; - Hide(); - Children = new Drawable[] + InternalChild = content = new CircularContainer { - background = new Box { RelativeSizeAxes = Axes.Both }, - iconContainer = new FillFlowContainer + RelativeSizeAxes = Axes.Y, + AutoSizeAxes = Axes.X, + Masking = true, + Alpha = 0, + Children = new Drawable[] { - Direction = FillDirection.Horizontal, - RelativeSizeAxes = Axes.Y, - AutoSizeAxes = Axes.X, - Height = 0.6f, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, + background = new Box { RelativeSizeAxes = Axes.Both }, + iconContainer = new FillFlowContainer + { + Direction = FillDirection.Horizontal, + RelativeSizeAxes = Axes.Y, + AutoSizeAxes = Axes.X, + Height = 0.6f, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } } }; } - public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true) - { - bool invalid = base.Invalidate(invalidation, source, shallPropagate); - - if ((invalidation & Invalidation.DrawSize) != 0) - { - iconContainer.Padding = new MarginPadding { Horizontal = DrawHeight / 2 }; - } - - return invalid; - } - [BackgroundDependencyLoader] private void load(OsuColour colours) { diff --git a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs index 13a7951170..8e4d72c702 100644 --- a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs @@ -3,6 +3,7 @@ using System; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -14,9 +15,9 @@ using osuTK; namespace osu.Game.Overlays.Profile.Header { - public class TopHeaderContainer : Container + public class TopHeaderContainer : CompositeDrawable { - public SupporterIcon SupporterTag; + private SupporterIcon supporterTag; private UpdateableAvatar avatar; private OsuSpriteText usernameText; private ExternalLinkButton openUserExternally; @@ -27,26 +28,15 @@ namespace osu.Game.Overlays.Profile.Header private const float avatar_size = 110; - private User user; - - public User User - { - get => user; - set - { - if (user == value) - return; - - user = value; - - updateDisplay(); - } - } + public readonly Bindable User = new Bindable(); [BackgroundDependencyLoader] private void load(OsuColour colours) { - Children = new Drawable[] + Height = 150; + User.ValueChanged += e => updateDisplay(e.NewValue); + + InternalChildren = new Drawable[] { new Box { @@ -109,7 +99,7 @@ namespace osu.Game.Overlays.Profile.Header TextSize = 18, Font = "Exo2.0-Regular" }, - SupporterTag = new SupporterIcon + supporterTag = new SupporterIcon { Height = 20, Margin = new MarginPadding { Top = 5 } @@ -161,14 +151,14 @@ namespace osu.Game.Overlays.Profile.Header }; } - private void updateDisplay() + private void updateDisplay(User user) { - avatar.User = User; + avatar.User = user; usernameText.Text = user.Username; openUserExternally.Link = $@"https://osu.ppy.sh/users/{user.Id}"; userFlag.Country = user.Country; userCountryText.Text = user.Country?.FullName ?? "Alien"; - SupporterTag.SupporterLevel = user.SupportLevel; + supporterTag.SupporterLevel = user.SupportLevel; titleText.Text = user.Title; titleText.Colour = OsuColour.FromHex(user.Colour ?? "fff"); diff --git a/osu.Game/Overlays/Profile/ProfileHeader.cs b/osu.Game/Overlays/Profile/ProfileHeader.cs index fdb515270b..988fa3afd9 100644 --- a/osu.Game/Overlays/Profile/ProfileHeader.cs +++ b/osu.Game/Overlays/Profile/ProfileHeader.cs @@ -2,43 +2,31 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; -using osuTK.Graphics; -using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; -using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Textures; using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; using osu.Game.Overlays.Profile.Header; using osu.Game.Users; using osu.Framework.Bindables; +using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Profile { public class ProfileHeader : Container { - private readonly Container coverContainer; - private readonly OsuSpriteText coverInfoText; + private readonly UserCoverBackground coverContainer; + private readonly ScreenTitle coverTitle; private readonly ProfileHeaderTabControl infoTabControl; - private readonly TopHeaderContainer topHeaderContainer; - public SupporterIcon SupporterTag => topHeaderContainer.SupporterTag; - - private readonly CenterHeaderContainer centerHeaderContainer; - public readonly BindableBool DetailsVisible = new BindableBool(); - - private readonly DetailHeaderContainer detailHeaderContainer; - private readonly MedalHeaderContainer medalHeaderContainer; - private readonly BottomHeaderContainer bottomHeaderContainer; - private const float cover_height = 150; private const float cover_info_height = 75; public ProfileHeader() { + CenterHeaderContainer centerHeaderContainer; + DetailHeaderContainer detailHeaderContainer; Container expandedDetailContainer; FillFlowContainer hiddenDetailContainer, headerDetailContainer; SpriteIcon expandButtonIcon; @@ -48,19 +36,10 @@ namespace osu.Game.Overlays.Profile Children = new Drawable[] { - coverContainer = new Container + coverContainer = new UserCoverBackground { RelativeSizeAxes = Axes.X, Height = cover_height, - Masking = true, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.1f), Color4.Black.Opacity(0.75f)) - }, - } }, new Container { @@ -73,25 +52,10 @@ namespace osu.Game.Overlays.Profile Depth = -float.MaxValue, Children = new Drawable[] { - new FillFlowContainer + coverTitle = new ScreenTitle { - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Children = new[] - { - new OsuSpriteText - { - Text = "Player ", - Font = "Exo2.0-Regular", - TextSize = 30 - }, - coverInfoText = new OsuSpriteText - { - Text = "Info", - Font = "Exo2.0-Regular", - TextSize = 30 - } - } + Title = "Player ", + Page = "Info" }, infoTabControl = new ProfileHeaderTabControl { @@ -112,30 +76,30 @@ namespace osu.Game.Overlays.Profile Direction = FillDirection.Vertical, Children = new Drawable[] { - topHeaderContainer = new TopHeaderContainer + new TopHeaderContainer { RelativeSizeAxes = Axes.X, - Height = 150, + User = { BindTarget = User }, }, centerHeaderContainer = new CenterHeaderContainer { RelativeSizeAxes = Axes.X, - Height = 60, + User = { BindTarget = User }, }, detailHeaderContainer = new DetailHeaderContainer { RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, + User = { BindTarget = User }, }, - medalHeaderContainer = new MedalHeaderContainer + new MedalHeaderContainer { RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, + User = { BindTarget = User }, }, - bottomHeaderContainer = new BottomHeaderContainer + new BottomHeaderContainer { RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, + User = { BindTarget = User }, }, } } @@ -144,99 +108,28 @@ namespace osu.Game.Overlays.Profile infoTabControl.AddItem("Info"); infoTabControl.AddItem("Modding"); - centerHeaderContainer.DetailsVisible.BindTo(DetailsVisible); - DetailsVisible.ValueChanged += visible => detailHeaderContainer.Alpha = visible.NewValue ? 0 : 1; + centerHeaderContainer.DetailsVisibilityAction = visible => detailHeaderContainer.Alpha = visible ? 0 : 1; + User.ValueChanged += e => updateDisplay(e.NewValue); } [BackgroundDependencyLoader] private void load(OsuColour colours, TextureStore textures) { - coverInfoText.Colour = colours.CommunityUserGreen; + coverTitle.AccentColour = colours.CommunityUserGreen; infoTabControl.AccentColour = colours.CommunityUserGreen; } - private User user; + public Bindable User = new Bindable(); - public User User + private void updateDisplay(User user) { - get => user; - set - { - medalHeaderContainer.User = detailHeaderContainer.User = bottomHeaderContainer.User = - centerHeaderContainer.User = topHeaderContainer.User = user = value; - updateDisplay(); - } - } - - private void updateDisplay() - { - coverContainer.RemoveAll(d => d is UserCoverBackground); - LoadComponentAsync(new UserCoverBackground(user) - { - RelativeSizeAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - FillMode = FillMode.Fill, - OnLoadComplete = d => d.FadeInFromZero(200), - Depth = float.MaxValue, - }, coverContainer.Add); + coverContainer.User = user; } public class HasTooltipContainer : Container, IHasTooltip { public string TooltipText { get; set; } } - - public class OverlinedInfoContainer : CompositeDrawable - { - private readonly Circle line; - private readonly OsuSpriteText title, content; - - public string Title - { - set => title.Text = value; - } - - public string Content - { - set => content.Text = value; - } - - public Color4 LineColour - { - set => line.Colour = value; - } - - public OverlinedInfoContainer(bool big = false, int minimumWidth = 60) - { - AutoSizeAxes = Axes.Both; - InternalChild = new FillFlowContainer - { - Direction = FillDirection.Vertical, - AutoSizeAxes = Axes.Both, - Children = new Drawable[] - { - line = new Circle - { - RelativeSizeAxes = Axes.X, - Height = 4, - }, - title = new OsuSpriteText - { - Font = OsuFont.GetFont(size: big ? 14 : 12, weight: FontWeight.Bold) - }, - content = new OsuSpriteText - { - Font = OsuFont.GetFont(size: big ? 40 : 18, weight: FontWeight.Light) - }, - new Container //Add a minimum size to the FillFlowContainer - { - Width = minimumWidth, - } - } - }; - } - } } } diff --git a/osu.Game/Overlays/UserProfileOverlay.cs b/osu.Game/Overlays/UserProfileOverlay.cs index 60e2921127..9b6e34d399 100644 --- a/osu.Game/Overlays/UserProfileOverlay.cs +++ b/osu.Game/Overlays/UserProfileOverlay.cs @@ -81,7 +81,7 @@ namespace osu.Game.Overlays Show(); - if (user.Id == Header?.User?.Id) + if (user.Id == Header?.User.Value?.Id) return; userReq?.Cancel(); @@ -167,7 +167,7 @@ namespace osu.Game.Overlays private void userLoadComplete(User user) { - Header.User = user; + Header.User.Value = user; if (user.ProfileOrder != null) { diff --git a/osu.Game/Users/UserCoverBackground.cs b/osu.Game/Users/UserCoverBackground.cs index 4c72762498..d037f809b4 100644 --- a/osu.Game/Users/UserCoverBackground.cs +++ b/osu.Game/Users/UserCoverBackground.cs @@ -1,30 +1,51 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using osu.Framework.Allocation; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Colour; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; +using osuTK.Graphics; namespace osu.Game.Users { - public class UserCoverBackground : Sprite + public class UserCoverBackground : ModelBackedDrawable { - private readonly User user; - - public UserCoverBackground(User user) + public User User { - this.user = user; + get => Model; + set => Model = value; } - [BackgroundDependencyLoader] - private void load(LargeTextureStore textures) - { - if (textures == null) - throw new ArgumentNullException(nameof(textures)); + [Resolved] + private LargeTextureStore textures { get; set; } - if (!string.IsNullOrEmpty(user.CoverUrl)) - Texture = textures.Get(user.CoverUrl); + protected override Drawable CreateDrawable(User user) + { + if (user == null) + { + return new Box + { + RelativeSizeAxes = Axes.Both, + Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.1f), Color4.Black.Opacity(0.75f)) + }; + } + else + { + return new Sprite + { + RelativeSizeAxes = Axes.Both, + Texture = textures.Get(user.CoverUrl), + FillMode = FillMode.Fill, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + OnLoadComplete = d => d.FadeInFromZero(400), + }; + } } } } diff --git a/osu.Game/Users/UserPanel.cs b/osu.Game/Users/UserPanel.cs index cebbc74d50..def967e69b 100644 --- a/osu.Game/Users/UserPanel.cs +++ b/osu.Game/Users/UserPanel.cs @@ -73,12 +73,12 @@ namespace osu.Game.Users Children = new Drawable[] { - new DelayedLoadWrapper(new UserCoverBackground(user) + new DelayedLoadWrapper(new UserCoverBackground { RelativeSizeAxes = Axes.Both, Anchor = Anchor.Centre, Origin = Anchor.Centre, - FillMode = FillMode.Fill, + User = user, OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out) }, 300) { RelativeSizeAxes = Axes.Both }, new Box