From 7047303b0fcf68378f6ea315570ab8a279d0061e Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 26 Apr 2019 13:29:58 +0900 Subject: [PATCH] Add tooltips to all buttons --- .../Profile/Header/CentreHeaderContainer.cs | 63 ++----------------- .../Profile/Header/ExpandDetailsButton.cs | 45 +++++++++++++ .../Overlays/Profile/Header/FriendButton.cs | 58 +++++++++++++++++ .../Profile/Header/ProfileHeaderButton.cs | 7 ++- .../Profile/Header/ProfileMessageButton.cs | 2 + 5 files changed, 114 insertions(+), 61 deletions(-) create mode 100644 osu.Game/Overlays/Profile/Header/ExpandDetailsButton.cs create mode 100644 osu.Game/Overlays/Profile/Header/FriendButton.cs diff --git a/osu.Game/Overlays/Profile/Header/CentreHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/CentreHeaderContainer.cs index 7964d25db6..1d947383a1 100644 --- a/osu.Game/Overlays/Profile/Header/CentreHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/CentreHeaderContainer.cs @@ -3,14 +3,11 @@ 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.Sprites; using osu.Game.Users; using osuTK; @@ -21,7 +18,6 @@ public class CentreHeaderContainer : CompositeDrawable public readonly BindableBool DetailsVisible = new BindableBool(true); public readonly Bindable User = new Bindable(); - private OsuSpriteText followerText; private OverlinedInfoContainer hiddenDetailGlobal; private OverlinedInfoContainer hiddenDetailCountry; @@ -35,7 +31,6 @@ private void load(OsuColour colours, TextureStore textures) { Container hiddenDetailContainer; Container expandedDetailContainer; - SpriteIcon expandButtonIcon; InternalChildren = new Drawable[] { @@ -54,37 +49,10 @@ private void load(OsuColour colours, TextureStore textures) Spacing = new Vector2(10, 0), Children = new Drawable[] { - new ProfileHeaderButton + new FriendButton { RelativeSizeAxes = Axes.Y, - Children = new Drawable[] - { - new FillFlowContainer - { - AutoSizeAxes = Axes.Both, - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Direction = FillDirection.Horizontal, - Padding = new MarginPadding { Right = 10 }, - Children = new Drawable[] - { - new SpriteIcon - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Icon = FontAwesome.Solid.User, - FillMode = FillMode.Fit, - Size = new Vector2(50, 14) - }, - followerText = new OsuSpriteText - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Font = OsuFont.GetFont(weight: FontWeight.Bold) - } - } - } - } + User = { BindTarget = User } }, new ProfileMessageButton { @@ -99,22 +67,12 @@ private void load(OsuColour colours, TextureStore textures) RelativeSizeAxes = Axes.Y, Padding = new MarginPadding { Vertical = 10 }, Width = UserProfileOverlay.CONTENT_X_MARGIN, - Child = new ExpandButton + Child = new ExpandDetailsButton { RelativeSizeAxes = Axes.Y, Anchor = Anchor.Centre, Origin = Anchor.Centre, - Action = () => DetailsVisible.Toggle(), - Children = new Drawable[] - { - expandButtonIcon = new SpriteIcon - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(20, 12), - Icon = FontAwesome.Solid.ChevronUp, - }, - } + DetailsVisible = { BindTarget = DetailsVisible } }, }, new Container @@ -175,7 +133,6 @@ private void load(OsuColour colours, TextureStore textures) DetailsVisible.BindValueChanged(visible => { - expandButtonIcon.Icon = visible.NewValue ? FontAwesome.Solid.ChevronUp : FontAwesome.Solid.ChevronDown; hiddenDetailContainer.Alpha = visible.NewValue ? 1 : 0; expandedDetailContainer.Alpha = visible.NewValue ? 0 : 1; }, true); @@ -185,20 +142,8 @@ private void load(OsuColour colours, TextureStore textures) private void updateDisplay(User user) { - followerText.Text = user?.FollowerCount?.Length > 0 ? user.FollowerCount[0].ToString("#,##0") : "0"; - hiddenDetailGlobal.Content = user?.Statistics?.Ranks.Global?.ToString("#,##0") ?? "-"; hiddenDetailCountry.Content = user?.Statistics?.Ranks.Country?.ToString("#,##0") ?? "-"; } - - private class ExpandButton : ProfileHeaderButton - { - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - IdleColour = colours.CommunityUserGrayGreen; - HoverColour = colours.CommunityUserGrayGreen.Darken(0.2f); - } - } } } diff --git a/osu.Game/Overlays/Profile/Header/ExpandDetailsButton.cs b/osu.Game/Overlays/Profile/Header/ExpandDetailsButton.cs new file mode 100644 index 0000000000..dc507be0b1 --- /dev/null +++ b/osu.Game/Overlays/Profile/Header/ExpandDetailsButton.cs @@ -0,0 +1,45 @@ +// 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.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; +using osuTK; + +namespace osu.Game.Overlays.Profile.Header +{ + public class ExpandDetailsButton : ProfileHeaderButton + { + public readonly BindableBool DetailsVisible = new BindableBool(); + + public override string TooltipText => DetailsVisible.Value ? "collapse" : "expand"; + + private SpriteIcon icon; + + public ExpandDetailsButton() + { + Action = () => DetailsVisible.Toggle(); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + IdleColour = colours.CommunityUserGrayGreen; + HoverColour = colours.CommunityUserGrayGreen.Darken(0.2f); + + Child = icon = new SpriteIcon + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(20, 12) + }; + + DetailsVisible.BindValueChanged(visible => updateState(visible.NewValue), true); + } + + private void updateState(bool detailsVisible) => icon.Icon = detailsVisible ? FontAwesome.Solid.ChevronUp : FontAwesome.Solid.ChevronDown; + } +} diff --git a/osu.Game/Overlays/Profile/Header/FriendButton.cs b/osu.Game/Overlays/Profile/Header/FriendButton.cs new file mode 100644 index 0000000000..3b2f192fb1 --- /dev/null +++ b/osu.Game/Overlays/Profile/Header/FriendButton.cs @@ -0,0 +1,58 @@ +// 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.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Users; +using osuTK; + +namespace osu.Game.Overlays.Profile.Header +{ + public class FriendButton : ProfileHeaderButton + { + public readonly Bindable User = new Bindable(); + + public override string TooltipText => "friends"; + + private OsuSpriteText followerText; + + [BackgroundDependencyLoader] + private void load() + { + Child = new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Direction = FillDirection.Horizontal, + Padding = new MarginPadding { Right = 10 }, + Children = new Drawable[] + { + new SpriteIcon + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Icon = FontAwesome.Solid.User, + FillMode = FillMode.Fit, + Size = new Vector2(50, 14) + }, + followerText = new OsuSpriteText + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Font = OsuFont.GetFont(weight: FontWeight.Bold) + } + } + }; + + User.BindValueChanged(user => updateFollowers(user.NewValue), true); + } + + private void updateFollowers(User user) => followerText.Text = user?.FollowerCount?.Length > 0 ? user.FollowerCount[0].ToString("#,##0") : "0"; + } +} diff --git a/osu.Game/Overlays/Profile/Header/ProfileHeaderButton.cs b/osu.Game/Overlays/Profile/Header/ProfileHeaderButton.cs index 300767cf0d..ddf2338873 100644 --- a/osu.Game/Overlays/Profile/Header/ProfileHeaderButton.cs +++ b/osu.Game/Overlays/Profile/Header/ProfileHeaderButton.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; using osu.Game.Graphics.Containers; @@ -11,8 +12,10 @@ namespace osu.Game.Overlays.Profile.Header { - public class ProfileHeaderButton : OsuHoverContainer + public abstract class ProfileHeaderButton : OsuHoverContainer, IHasTooltip { + public abstract string TooltipText { get; } + private readonly Box background; private readonly Container content; @@ -20,7 +23,7 @@ public class ProfileHeaderButton : OsuHoverContainer protected override IEnumerable EffectTargets => new[] { background }; - public ProfileHeaderButton() + protected ProfileHeaderButton() { AutoSizeAxes = Axes.X; diff --git a/osu.Game/Overlays/Profile/Header/ProfileMessageButton.cs b/osu.Game/Overlays/Profile/Header/ProfileMessageButton.cs index 3121eae727..162d49cf1b 100644 --- a/osu.Game/Overlays/Profile/Header/ProfileMessageButton.cs +++ b/osu.Game/Overlays/Profile/Header/ProfileMessageButton.cs @@ -16,6 +16,8 @@ public class ProfileMessageButton : ProfileHeaderButton { public readonly Bindable User = new Bindable(); + public override string TooltipText => "send message"; + [Resolved(CanBeNull = true)] private ChannelManager channelManager { get; set; }