1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 18:47:27 +08:00
osu-lazer/osu.Game/Overlays/Profile/ProfileHeader.cs

549 lines
23 KiB
C#
Raw Normal View History

2017-05-25 02:11:07 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
2017-06-06 11:25:16 +08:00
using OpenTK;
using OpenTK.Graphics;
2017-06-14 12:55:01 +08:00
using osu.Framework.Allocation;
2017-06-06 11:25:16 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
2017-06-13 19:43:56 +08:00
using osu.Framework.Graphics.Colour;
2017-05-25 02:11:07 +08:00
using osu.Framework.Graphics.Containers;
2017-06-21 16:03:47 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
2017-06-14 12:55:01 +08:00
using osu.Framework.Graphics.Textures;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
2017-06-06 11:25:16 +08:00
using osu.Game.Graphics.Sprites;
2017-06-16 16:36:23 +08:00
using osu.Game.Users;
using System.Diagnostics;
2017-08-09 05:11:46 +08:00
using System.Collections.Generic;
using osu.Framework.Graphics.Cursor;
2017-05-25 02:11:07 +08:00
2017-06-16 16:36:23 +08:00
namespace osu.Game.Overlays.Profile
2017-05-25 02:11:07 +08:00
{
2017-06-09 14:53:30 +08:00
public class ProfileHeader : Container
2017-05-25 02:11:07 +08:00
{
private readonly OsuTextFlowContainer infoTextLeft;
private readonly LinkFlowContainer infoTextRight;
2017-06-14 12:55:01 +08:00
private readonly FillFlowContainer<SpriteText> scoreText, scoreNumberText;
2017-06-16 15:54:55 +08:00
private readonly Container coverContainer, chartContainer, supporterTag;
2017-06-14 12:55:01 +08:00
private readonly Sprite levelBadge;
private readonly SpriteText levelText;
2017-06-15 09:10:23 +08:00
private readonly GradeBadge gradeSSPlus, gradeSS, gradeSPlus, gradeS, gradeA;
2017-06-16 15:54:55 +08:00
private readonly Box colourBar;
2017-07-18 02:25:57 +08:00
private readonly DrawableFlag countryFlag;
2017-07-17 12:24:05 +08:00
private const float cover_height = 350;
private const float info_height = 150;
private const float info_width = 220;
private const float avatar_size = 110;
private const float level_position = 30;
private const float level_height = 60;
2017-07-13 12:52:40 +08:00
2017-06-09 14:53:30 +08:00
public ProfileHeader(User user)
{
2017-06-06 11:25:16 +08:00
RelativeSizeAxes = Axes.X;
Height = cover_height + info_height;
2017-06-06 11:25:16 +08:00
Children = new Drawable[]
{
2017-06-16 01:04:20 +08:00
coverContainer = new Container
2017-06-06 11:25:16 +08:00
{
RelativeSizeAxes = Axes.X,
Height = cover_height,
Children = new Drawable[]
{
2017-06-13 19:43:56 +08:00
new Box
{
RelativeSizeAxes = Axes.Both,
2017-07-23 13:30:50 +08:00
Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.1f), Color4.Black.Opacity(0.75f))
2017-06-13 19:43:56 +08:00
},
2017-06-06 11:25:16 +08:00
new Container
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
2017-06-16 15:01:09 +08:00
X = UserProfileOverlay.CONTENT_X_MARGIN,
Y = -20,
AutoSizeAxes = Axes.Both,
2017-06-06 11:25:16 +08:00
Children = new Drawable[]
{
2017-06-16 15:01:09 +08:00
new UpdateableAvatar
2017-06-06 11:25:16 +08:00
{
2017-06-16 15:01:09 +08:00
User = user,
Size = new Vector2(avatar_size),
2017-06-06 11:25:16 +08:00
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
2017-06-16 15:01:09 +08:00
Masking = true,
CornerRadius = 5,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.25f),
Radius = 4,
},
2017-06-06 11:25:16 +08:00
},
2017-06-16 15:01:09 +08:00
new Container
2017-06-06 11:25:16 +08:00
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
2017-06-16 15:01:09 +08:00
X = avatar_size + 10,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
2017-06-16 15:54:55 +08:00
supporterTag = new CircularContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Y = -75,
Size = new Vector2(25, 25),
Masking = true,
BorderThickness = 3,
BorderColour = Color4.White,
Alpha = 0,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
},
new SpriteIcon
2017-06-16 15:54:55 +08:00
{
Icon = FontAwesome.fa_heart,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(12),
2017-06-16 15:54:55 +08:00
}
}
},
2017-10-11 20:20:23 +08:00
new LinkFlowContainer.ProfileLink(user)
2017-06-16 15:01:09 +08:00
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
2017-10-11 20:20:23 +08:00
Y = -48,
2017-06-16 15:01:09 +08:00
},
2017-07-24 15:25:49 +08:00
countryFlag = new DrawableFlag(user.Country?.FlagName)
2017-06-16 15:01:09 +08:00
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Width = 30,
Height = 20
}
}
2017-06-06 11:25:16 +08:00
}
}
2017-06-16 15:01:09 +08:00
},
2017-06-16 15:54:55 +08:00
colourBar = new Box
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
X = UserProfileOverlay.CONTENT_X_MARGIN,
Height = 5,
Width = info_width,
Alpha = 0
}
2017-06-06 11:25:16 +08:00
}
},
2017-06-16 13:27:22 +08:00
infoTextLeft = new OsuTextFlowContainer(t =>
{
t.TextSize = 14;
t.Alpha = 0.8f;
})
{
2017-06-16 13:27:22 +08:00
X = UserProfileOverlay.CONTENT_X_MARGIN,
Y = cover_height + 20,
2017-06-16 13:27:22 +08:00
Width = info_width,
AutoSizeAxes = Axes.Y,
ParagraphSpacing = 0.8f,
LineSpacing = 0.2f
},
infoTextRight = new LinkFlowContainer(t =>
2017-06-16 13:27:22 +08:00
{
t.TextSize = 14;
2017-06-16 15:01:09 +08:00
t.Font = @"Exo2.0-RegularItalic";
2017-06-16 13:27:22 +08:00
})
{
X = UserProfileOverlay.CONTENT_X_MARGIN + info_width + 20,
Y = cover_height + 20,
Width = info_width,
AutoSizeAxes = Axes.Y,
2017-06-16 13:27:22 +08:00
ParagraphSpacing = 0.8f,
LineSpacing = 0.2f
2017-06-13 19:43:56 +08:00
},
new Container
{
2017-06-15 17:03:33 +08:00
X = -UserProfileOverlay.CONTENT_X_MARGIN,
2017-06-13 19:43:56 +08:00
RelativeSizeAxes = Axes.Y,
Width = 280,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
Y = level_position,
Height = level_height,
Children = new Drawable[]
{
new Box
{
Colour = Color4.Black.Opacity(0.5f),
RelativeSizeAxes = Axes.Both
2017-06-14 12:55:01 +08:00
},
levelBadge = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Height = 50,
2017-06-16 01:04:20 +08:00
Width = 50,
Alpha = 0
2017-06-14 12:55:01 +08:00
},
levelText = new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Y = 11,
2017-06-15 07:23:30 +08:00
TextSize = 20
2017-06-13 19:43:56 +08:00
}
}
},
new Container
{
RelativeSizeAxes = Axes.X,
Y = cover_height,
Anchor = Anchor.TopCentre,
Origin = Anchor.BottomCentre,
Height = cover_height - level_height - level_position - 5,
Children = new Drawable[]
{
new Box
{
Colour = Color4.Black.Opacity(0.5f),
RelativeSizeAxes = Axes.Both
2017-06-14 12:55:01 +08:00
},
scoreText = new FillFlowContainer<SpriteText>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Horizontal = 20, Vertical = 18 },
Spacing = new Vector2(0, 2)
},
scoreNumberText = new FillFlowContainer<SpriteText>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Horizontal = 20, Vertical = 18 },
Spacing = new Vector2(0, 2)
2017-06-14 14:35:47 +08:00
},
new FillFlowContainer<GradeBadge>
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Y = -64,
Spacing = new Vector2(20, 0),
2017-06-15 07:58:20 +08:00
Children = new[]
2017-06-14 14:35:47 +08:00
{
2017-06-16 01:04:20 +08:00
gradeSSPlus = new GradeBadge("SSPlus") { Alpha = 0 },
gradeSS = new GradeBadge("SS") { Alpha = 0 },
2017-06-14 14:35:47 +08:00
}
},
new FillFlowContainer<GradeBadge>
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Y = -18,
Spacing = new Vector2(20, 0),
2017-06-15 07:58:20 +08:00
Children = new[]
2017-06-14 14:35:47 +08:00
{
2017-06-16 01:04:20 +08:00
gradeSPlus = new GradeBadge("SPlus") { Alpha = 0 },
gradeS = new GradeBadge("S") { Alpha = 0 },
gradeA = new GradeBadge("A") { Alpha = 0 },
2017-06-14 14:35:47 +08:00
}
2017-06-13 19:43:56 +08:00
}
}
},
chartContainer = new Container
2017-06-13 19:43:56 +08:00
{
RelativeSizeAxes = Axes.X,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Height = info_height - 15,
2017-06-13 19:43:56 +08:00
Children = new Drawable[]
{
new Box
{
Colour = Color4.Black.Opacity(0.25f),
RelativeSizeAxes = Axes.Both
}
}
}
}
2017-06-06 11:25:16 +08:00
}
};
2017-06-15 07:58:20 +08:00
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
levelBadge.Texture = textures.Get(@"Profile/levelbadge");
2017-06-16 01:04:20 +08:00
}
2017-06-14 12:55:01 +08:00
private User user;
public User User
{
get
{
return user;
}
set
{
user = value;
loadUser();
}
}
private void loadUser()
2017-06-16 01:04:20 +08:00
{
coverContainer.Add(new AsyncLoadWrapper(new UserCoverBackground(user)
{
RelativeSizeAxes = Axes.Both,
2017-06-16 01:04:20 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(200)
})
{
Masking = true,
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue
});
2017-06-16 15:54:55 +08:00
if (user.IsSupporter) supporterTag.Show();
2017-06-16 20:32:11 +08:00
if (!string.IsNullOrEmpty(user.Colour))
2017-06-16 15:54:55 +08:00
{
colourBar.Colour = OsuColour.FromHex(user.Colour);
colourBar.Show();
}
2017-06-16 13:27:22 +08:00
Action<SpriteText> boldItalic = t =>
{
t.Font = @"Exo2.0-BoldItalic";
t.Alpha = 1;
};
if (user.Age != null)
{
2017-06-23 21:59:22 +08:00
infoTextLeft.AddText($"{user.Age} years old ", boldItalic);
2017-06-16 13:27:22 +08:00
}
if (user.Country != null)
{
2017-06-23 21:59:22 +08:00
infoTextLeft.AddText("from ");
2017-06-16 13:27:22 +08:00
infoTextLeft.AddText(user.Country.FullName, boldItalic);
2017-07-18 02:25:57 +08:00
countryFlag.FlagName = user.Country.FlagName;
2017-06-16 13:27:22 +08:00
}
infoTextLeft.NewParagraph();
2017-06-16 20:32:11 +08:00
if (user.JoinDate.ToUniversalTime().Year < 2008)
{
infoTextLeft.AddText("Here since the beginning", boldItalic);
}
else
{
infoTextLeft.AddText("Joined ");
infoTextLeft.AddText(user.JoinDate.LocalDateTime.ToShortDateString(), boldItalic);
}
2017-06-16 13:27:22 +08:00
infoTextLeft.NewLine();
infoTextLeft.AddText("Last seen ");
infoTextLeft.AddText(user.LastVisit.LocalDateTime.ToShortDateString(), boldItalic);
infoTextLeft.NewParagraph();
if (user.PlayStyle?.Length > 0)
{
infoTextLeft.AddText("Plays with ");
infoTextLeft.AddText(string.Join(", ", user.PlayStyle), boldItalic);
}
2017-07-18 10:07:52 +08:00
string websiteWithoutProtcol = user.Website;
if (!string.IsNullOrEmpty(websiteWithoutProtcol))
{
int protocolIndex = websiteWithoutProtcol.IndexOf("//", StringComparison.Ordinal);
if (protocolIndex >= 0)
websiteWithoutProtcol = websiteWithoutProtcol.Substring(protocolIndex + 2);
}
2017-06-16 13:27:22 +08:00
tryAddInfoRightLine(FontAwesome.fa_map_marker, user.Location);
tryAddInfoRightLine(FontAwesome.fa_heart_o, user.Intrerests);
tryAddInfoRightLine(FontAwesome.fa_suitcase, user.Occupation);
infoTextRight.NewParagraph();
if (!string.IsNullOrEmpty(user.Twitter))
2017-07-18 10:07:52 +08:00
tryAddInfoRightLine(FontAwesome.fa_twitter, "@" + user.Twitter, $@"https://twitter.com/{user.Twitter}");
tryAddInfoRightLine(FontAwesome.fa_globe, websiteWithoutProtcol, user.Website);
tryAddInfoRightLine(FontAwesome.fa_skype, user.Skype, @"skype:" + user.Skype + @"?chat");
2017-06-16 13:27:22 +08:00
if (user.Statistics != null)
{
levelBadge.Show();
levelText.Text = user.Statistics.Level.Current.ToString();
2017-06-14 12:55:01 +08:00
2017-06-16 13:27:22 +08:00
scoreText.Add(createScoreText("Ranked Score"));
scoreNumberText.Add(createScoreNumberText(user.Statistics.RankedScore.ToString(@"#,0")));
scoreText.Add(createScoreText("Accuracy"));
2017-10-15 16:53:30 +08:00
scoreNumberText.Add(createScoreNumberText($"{user.Statistics.Accuracy:0.##}%"));
2017-06-16 13:27:22 +08:00
scoreText.Add(createScoreText("Play Count"));
scoreNumberText.Add(createScoreNumberText(user.Statistics.PlayCount.ToString(@"#,0")));
scoreText.Add(createScoreText("Total Score"));
scoreNumberText.Add(createScoreNumberText(user.Statistics.TotalScore.ToString(@"#,0")));
scoreText.Add(createScoreText("Total Hits"));
scoreNumberText.Add(createScoreNumberText(user.Statistics.TotalHits.ToString(@"#,0")));
scoreText.Add(createScoreText("Max Combo"));
scoreNumberText.Add(createScoreNumberText(user.Statistics.MaxCombo.ToString(@"#,0")));
scoreText.Add(createScoreText("Replays Watched by Others"));
scoreNumberText.Add(createScoreNumberText(user.Statistics.ReplaysWatched.ToString(@"#,0")));
2017-06-15 22:33:08 +08:00
gradeSS.DisplayCount = user.Statistics.GradesCount.SS;
2017-06-16 13:27:22 +08:00
gradeSS.Show();
gradeS.DisplayCount = user.Statistics.GradesCount.S;
2017-06-16 13:27:22 +08:00
gradeS.Show();
gradeA.DisplayCount = user.Statistics.GradesCount.A;
2017-06-16 13:27:22 +08:00
gradeA.Show();
gradeSPlus.DisplayCount = 0;
gradeSSPlus.DisplayCount = 0;
2017-06-16 16:48:46 +08:00
chartContainer.Add(new RankChart(user) { RelativeSizeAxes = Axes.Both });
2017-06-16 13:27:22 +08:00
}
2017-06-15 22:33:08 +08:00
}
2017-06-16 13:27:22 +08:00
// These could be local functions when C# 7 enabled
2017-06-14 12:55:01 +08:00
private OsuSpriteText createScoreText(string text) => new OsuSpriteText
{
TextSize = 14,
Text = text
};
private OsuSpriteText createScoreNumberText(string text) => new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-Bold",
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Text = text
};
2017-06-14 14:35:47 +08:00
private void tryAddInfoRightLine(FontAwesome icon, string str, string url = null)
2017-06-16 13:27:22 +08:00
{
if (string.IsNullOrEmpty(str)) return;
2017-07-13 12:52:40 +08:00
infoTextRight.AddIcon(icon);
infoTextRight.AddLink(" " + str, url);
2017-06-16 13:27:22 +08:00
infoTextRight.NewLine();
}
2017-06-14 14:35:47 +08:00
private class GradeBadge : Container
{
private const float width = 50;
private readonly string grade;
private readonly Sprite badge;
private readonly SpriteText numberText;
public int DisplayCount
2017-06-14 14:35:47 +08:00
{
2017-07-13 12:52:40 +08:00
set { numberText.Text = value.ToString(@"#,0"); }
2017-06-14 14:35:47 +08:00
}
public GradeBadge(string grade)
{
this.grade = grade;
Width = width;
Height = 41;
Add(badge = new Sprite
{
Width = width,
Height = 26
});
Add(numberText = new SpriteText
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
TextSize = 14,
Font = @"Exo2.0-Bold"
});
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
badge.Texture = textures.Get($"Grades/{grade}");
}
}
private class LinkFlowContainer : OsuTextFlowContainer
{
public override bool HandleInput => true;
public LinkFlowContainer(Action<SpriteText> defaultCreationParameters = null) : base(defaultCreationParameters)
{
}
2017-07-18 09:51:11 +08:00
protected override SpriteText CreateSpriteText() => new LinkText();
2017-07-18 09:51:11 +08:00
public void AddLink(string text, string url) => AddText(text, link => ((LinkText)link).Url = url);
2017-07-20 07:03:00 +08:00
public class LinkText : OsuSpriteText
{
2017-08-09 05:11:46 +08:00
private readonly OsuHoverContainer content;
2017-08-09 05:11:46 +08:00
public override bool HandleInput => content.Action != null;
2017-08-09 05:11:46 +08:00
protected override Container<Drawable> Content => content ?? (Container<Drawable>)this;
2017-07-18 09:51:11 +08:00
2017-08-09 05:11:46 +08:00
protected override IEnumerable<Drawable> FlowingChildren => Children;
2017-07-18 09:51:11 +08:00
2017-08-09 05:11:46 +08:00
public string Url
{
2017-08-09 05:11:46 +08:00
set
{
if(value != null)
content.Action = () => Process.Start(value);
}
}
2017-07-18 09:51:11 +08:00
2017-08-09 05:11:46 +08:00
public LinkText()
2017-07-18 09:51:11 +08:00
{
2017-08-09 05:11:46 +08:00
AddInternal(content = new OsuHoverContainer
{
AutoSizeAxes = Axes.Both,
});
2017-07-18 09:51:11 +08:00
}
}
2017-10-11 20:20:23 +08:00
public class ProfileLink : LinkText, IHasTooltip
{
public string TooltipText => "View Profile in Browser";
2017-10-11 20:20:23 +08:00
public ProfileLink(User user)
{
Text = user.Username;
Url = $@"https://osu.ppy.sh/users/{user.Id}";
Font = @"Exo2.0-RegularItalic";
TextSize = 30;
2017-10-11 20:20:23 +08:00
}
}
}
2017-05-25 02:11:07 +08:00
}
}