1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-06 14:37:21 +08:00

Merge pull request #1022 from jorolf/user-profile-fixes

User profile improvements
This commit is contained in:
Dean Herbert 2017-07-20 19:40:26 +09:00 committed by GitHub
commit 8bc2df8749
4 changed files with 92 additions and 21 deletions

@ -1 +1 @@
Subproject commit a7edf9bb3bae6908f316ba0ee9dacdbbb66e8c19 Subproject commit 2d2e2fe698ab32d80d5e856f52c8c398ceb35540

View File

@ -175,11 +175,11 @@ namespace osu.Game
LoadComponentAsync(direct = new DirectOverlay { Depth = -1 }, mainContent.Add); LoadComponentAsync(direct = new DirectOverlay { Depth = -1 }, mainContent.Add);
LoadComponentAsync(social = new SocialOverlay { Depth = -1 }, mainContent.Add); LoadComponentAsync(social = new SocialOverlay { Depth = -1 }, mainContent.Add);
LoadComponentAsync(chat = new ChatOverlay { Depth = -1 }, mainContent.Add); LoadComponentAsync(chat = new ChatOverlay { Depth = -1 }, mainContent.Add);
LoadComponentAsync(userProfile = new UserProfileOverlay { Depth = -1 }, mainContent.Add);
LoadComponentAsync(settings = new SettingsOverlay { Depth = -1 }, overlayContent.Add); LoadComponentAsync(settings = new SettingsOverlay { Depth = -1 }, overlayContent.Add);
LoadComponentAsync(userProfile = new UserProfileOverlay { Depth = -2 }, mainContent.Add);
LoadComponentAsync(musicController = new MusicController LoadComponentAsync(musicController = new MusicController
{ {
Depth = -2, Depth = -3,
Position = new Vector2(0, Toolbar.HEIGHT), Position = new Vector2(0, Toolbar.HEIGHT),
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
@ -187,14 +187,14 @@ namespace osu.Game
LoadComponentAsync(notificationManager = new NotificationManager LoadComponentAsync(notificationManager = new NotificationManager
{ {
Depth = -2, Depth = -3,
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
}, overlayContent.Add); }, overlayContent.Add);
LoadComponentAsync(dialogOverlay = new DialogOverlay LoadComponentAsync(dialogOverlay = new DialogOverlay
{ {
Depth = -4, Depth = -5,
}, overlayContent.Add); }, overlayContent.Add);
Logger.NewEntry += entry => Logger.NewEntry += entry =>
@ -221,7 +221,7 @@ namespace osu.Game
LoadComponentAsync(Toolbar = new Toolbar LoadComponentAsync(Toolbar = new Toolbar
{ {
Depth = -3, Depth = -4,
OnHome = delegate { intro?.ChildScreen?.MakeCurrent(); }, OnHome = delegate { intro?.ChildScreen?.MakeCurrent(); },
}, overlayContent.Add); }, overlayContent.Add);

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics; using osu.Game.Graphics;
@ -11,6 +12,7 @@ using OpenTK.Graphics;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Users;
namespace osu.Game.Overlays.Chat namespace osu.Game.Overlays.Chat
{ {
@ -62,6 +64,8 @@ namespace osu.Game.Overlays.Chat
private const float message_padding = 200; private const float message_padding = 200;
private const float text_size = 20; private const float text_size = 20;
private Action<User> loadProfile;
private Color4 customUsernameColour; private Color4 customUsernameColour;
public ChatLine(Message message) public ChatLine(Message message)
@ -75,9 +79,10 @@ namespace osu.Game.Overlays.Chat
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours, UserProfileOverlay profile)
{ {
customUsernameColour = colours.ChatBlue; customUsernameColour = colours.ChatBlue;
loadProfile = u => profile?.ShowUser(u);
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -87,8 +92,6 @@ namespace osu.Game.Overlays.Chat
bool hasBackground = !string.IsNullOrEmpty(Message.Sender.Colour); bool hasBackground = !string.IsNullOrEmpty(Message.Sender.Colour);
Drawable username = new OsuSpriteText Drawable username = new OsuSpriteText
{ {
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
Font = @"Exo2.0-BoldItalic", Font = @"Exo2.0-BoldItalic",
Text = $@"{Message.Sender.Username}" + (hasBackground ? "" : ":"), Text = $@"{Message.Sender.Username}" + (hasBackground ? "" : ":"),
Colour = hasBackground ? customUsernameColour : username_colours[Message.UserId % username_colours.Length], Colour = hasBackground ? customUsernameColour : username_colours[Message.UserId % username_colours.Length],
@ -132,7 +135,7 @@ namespace osu.Game.Overlays.Chat
new Container new Container
{ {
Size = new Vector2(message_padding, text_size), Size = new Vector2(message_padding, text_size),
Children = new[] Children = new Drawable[]
{ {
new OsuSpriteText new OsuSpriteText
{ {
@ -144,7 +147,14 @@ namespace osu.Game.Overlays.Chat
TextSize = text_size * 0.75f, TextSize = text_size * 0.75f,
Alpha = 0.4f, Alpha = 0.4f,
}, },
username new ClickableContainer
{
AutoSizeAxes = Axes.Both,
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
Child = username,
Action = () => loadProfile(Message.Sender),
},
} }
}, },
new Container new Container

View File

@ -12,16 +12,20 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Input;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Users; using osu.Game.Users;
using System.Diagnostics;
using System.Globalization;
namespace osu.Game.Overlays.Profile namespace osu.Game.Overlays.Profile
{ {
public class ProfileHeader : Container public class ProfileHeader : Container
{ {
private readonly OsuTextFlowContainer infoTextLeft, infoTextRight; private readonly OsuTextFlowContainer infoTextLeft;
private readonly LinkFlowContainer infoTextRight;
private readonly FillFlowContainer<SpriteText> scoreText, scoreNumberText; private readonly FillFlowContainer<SpriteText> scoreText, scoreNumberText;
private readonly Container coverContainer, chartContainer, supporterTag; private readonly Container coverContainer, chartContainer, supporterTag;
@ -29,6 +33,7 @@ namespace osu.Game.Overlays.Profile
private readonly SpriteText levelText; private readonly SpriteText levelText;
private readonly GradeBadge gradeSSPlus, gradeSS, gradeSPlus, gradeS, gradeA; private readonly GradeBadge gradeSSPlus, gradeSS, gradeSPlus, gradeS, gradeA;
private readonly Box colourBar; private readonly Box colourBar;
private readonly DrawableFlag countryFlag;
private const float cover_height = 350; private const float cover_height = 350;
private const float info_height = 150; private const float info_height = 150;
@ -114,16 +119,17 @@ namespace osu.Game.Overlays.Profile
} }
} }
}, },
new OsuSpriteText new LinkFlowContainer.LinkText
{ {
Text = user.Username, Text = user.Username,
Url = $@"https://osu.ppy.sh/users/{user.Id}",
TextSize = 30, TextSize = 30,
Font = @"Exo2.0-RegularItalic", Font = @"Exo2.0-RegularItalic",
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Y = -48 Y = -48
}, },
new DrawableFlag(user.Country?.FlagName ?? "__") countryFlag = new DrawableFlag(user.Country?.FlagName ?? "__")
{ {
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
@ -158,7 +164,7 @@ namespace osu.Game.Overlays.Profile
ParagraphSpacing = 0.8f, ParagraphSpacing = 0.8f,
LineSpacing = 0.2f LineSpacing = 0.2f
}, },
infoTextRight = new OsuTextFlowContainer(t => infoTextRight = new LinkFlowContainer(t =>
{ {
t.TextSize = 14; t.TextSize = 14;
t.Font = @"Exo2.0-RegularItalic"; t.Font = @"Exo2.0-RegularItalic";
@ -350,6 +356,7 @@ namespace osu.Game.Overlays.Profile
{ {
infoTextLeft.AddText("from "); infoTextLeft.AddText("from ");
infoTextLeft.AddText(user.Country.FullName, boldItalic); infoTextLeft.AddText(user.Country.FullName, boldItalic);
countryFlag.FlagName = user.Country.FlagName;
} }
infoTextLeft.NewParagraph(); infoTextLeft.NewParagraph();
@ -373,14 +380,22 @@ namespace osu.Game.Overlays.Profile
infoTextLeft.AddText(string.Join(", ", user.PlayStyle), boldItalic); infoTextLeft.AddText(string.Join(", ", user.PlayStyle), boldItalic);
} }
string websiteWithoutProtcol = user.Website;
if (!string.IsNullOrEmpty(websiteWithoutProtcol))
{
int protocolIndex = websiteWithoutProtcol.IndexOf("//", StringComparison.Ordinal);
if (protocolIndex >= 0)
websiteWithoutProtcol = websiteWithoutProtcol.Substring(protocolIndex + 2);
}
tryAddInfoRightLine(FontAwesome.fa_map_marker, user.Location); tryAddInfoRightLine(FontAwesome.fa_map_marker, user.Location);
tryAddInfoRightLine(FontAwesome.fa_heart_o, user.Intrerests); tryAddInfoRightLine(FontAwesome.fa_heart_o, user.Intrerests);
tryAddInfoRightLine(FontAwesome.fa_suitcase, user.Occupation); tryAddInfoRightLine(FontAwesome.fa_suitcase, user.Occupation);
infoTextRight.NewParagraph(); infoTextRight.NewParagraph();
if (!string.IsNullOrEmpty(user.Twitter)) if (!string.IsNullOrEmpty(user.Twitter))
tryAddInfoRightLine(FontAwesome.fa_twitter, "@" + user.Twitter); tryAddInfoRightLine(FontAwesome.fa_twitter, "@" + user.Twitter, $@"https://twitter.com/{user.Twitter}");
tryAddInfoRightLine(FontAwesome.fa_globe, user.Website); tryAddInfoRightLine(FontAwesome.fa_globe, websiteWithoutProtcol, user.Website);
tryAddInfoRightLine(FontAwesome.fa_skype, user.Skype); tryAddInfoRightLine(FontAwesome.fa_skype, user.Skype, @"skype:" + user.Skype + @"?chat");
if (user.Statistics != null) if (user.Statistics != null)
{ {
@ -390,7 +405,7 @@ namespace osu.Game.Overlays.Profile
scoreText.Add(createScoreText("Ranked Score")); scoreText.Add(createScoreText("Ranked Score"));
scoreNumberText.Add(createScoreNumberText(user.Statistics.RankedScore.ToString(@"#,0"))); scoreNumberText.Add(createScoreNumberText(user.Statistics.RankedScore.ToString(@"#,0")));
scoreText.Add(createScoreText("Accuracy")); scoreText.Add(createScoreText("Accuracy"));
scoreNumberText.Add(createScoreNumberText($"{user.Statistics.Accuracy}%")); scoreNumberText.Add(createScoreNumberText($"{user.Statistics.Accuracy.ToString("0.##", CultureInfo.CurrentCulture)}%"));
scoreText.Add(createScoreText("Play Count")); scoreText.Add(createScoreText("Play Count"));
scoreNumberText.Add(createScoreNumberText(user.Statistics.PlayCount.ToString(@"#,0"))); scoreNumberText.Add(createScoreNumberText(user.Statistics.PlayCount.ToString(@"#,0")));
scoreText.Add(createScoreText("Total Score")); scoreText.Add(createScoreText("Total Score"));
@ -433,12 +448,12 @@ namespace osu.Game.Overlays.Profile
Text = text Text = text
}; };
private void tryAddInfoRightLine(FontAwesome icon, string str) private void tryAddInfoRightLine(FontAwesome icon, string str, string url = null)
{ {
if (string.IsNullOrEmpty(str)) return; if (string.IsNullOrEmpty(str)) return;
infoTextRight.AddIcon(icon); infoTextRight.AddIcon(icon);
infoTextRight.AddText(" " + str); infoTextRight.AddLink(" " + str, url);
infoTextRight.NewLine(); infoTextRight.NewLine();
} }
@ -479,5 +494,51 @@ namespace osu.Game.Overlays.Profile
badge.Texture = textures.Get($"Grades/{grade}"); badge.Texture = textures.Get($"Grades/{grade}");
} }
} }
private class LinkFlowContainer : OsuTextFlowContainer
{
public override bool HandleInput => true;
public LinkFlowContainer(Action<SpriteText> defaultCreationParameters = null) : base(defaultCreationParameters)
{
}
protected override SpriteText CreateSpriteText() => new LinkText();
public void AddLink(string text, string url) => AddText(text, link => ((LinkText)link).Url = url);
public class LinkText : OsuSpriteText
{
public override bool HandleInput => Url != null;
public string Url;
private Color4 hoverColour;
protected override bool OnHover(InputState state)
{
FadeColour(hoverColour, 500, EasingTypes.OutQuint);
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
FadeColour(Color4.White, 500, EasingTypes.OutQuint);
base.OnHoverLost(state);
}
protected override bool OnClick(InputState state)
{
Process.Start(Url);
return true;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
hoverColour = colours.Yellow;
}
}
}
} }
} }