1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 08:12:55 +08:00
osu-lazer/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

244 lines
12 KiB
C#
Raw Normal View History

2019-01-28 06:45:00 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
2019-03-10 06:58:14 +08:00
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2023-01-01 02:58:58 +08:00
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Game.Configuration;
using osu.Game.Graphics;
2023-04-28 07:06:13 +08:00
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
2019-04-26 12:49:44 +08:00
using osu.Game.Overlays.Profile.Header.Components;
2023-01-01 02:36:17 +08:00
using osu.Game.Users;
using osu.Game.Users.Drawables;
using osuTK;
namespace osu.Game.Overlays.Profile.Header
{
2019-03-10 06:58:14 +08:00
public partial class TopHeaderContainer : CompositeDrawable
{
2023-01-01 03:28:28 +08:00
private const float content_height = 65;
private const float vertical_padding = 10;
2023-01-11 02:24:54 +08:00
public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>();
[Resolved]
2022-12-30 20:17:59 +08:00
private IAPIProvider api { get; set; } = null!;
2023-04-28 10:48:54 +08:00
[Resolved]
private RankingsOverlay? rankingsOverlay { get; set; }
2023-01-01 02:36:17 +08:00
private UserCoverBackground cover = null!;
2022-12-30 20:17:59 +08:00
private SupporterIcon supporterTag = null!;
private UpdateableAvatar avatar = null!;
private OsuSpriteText usernameText = null!;
private ExternalLinkButton openUserExternally = null!;
private OsuSpriteText titleText = null!;
private UpdateableFlag userFlag = null!;
2023-04-28 10:48:54 +08:00
private OsuHoverContainer userCountryContainer = null!;
private OsuSpriteText userCountryText = null!;
private GroupBadgeFlow groupBadgeFlow = null!;
2023-01-01 03:28:28 +08:00
private ToggleCoverButton coverToggle = null!;
private Bindable<bool> coverExpanded = null!;
private FillFlowContainer flow = null!;
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider, OsuConfigManager configManager)
{
2023-01-01 02:36:17 +08:00
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
2019-03-10 06:58:14 +08:00
coverExpanded = configManager.GetBindable<bool>(OsuSetting.ProfileCoverExpanded);
2019-03-10 06:58:14 +08:00
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
2023-01-01 01:24:45 +08:00
Colour = colourProvider.Background4,
},
new FillFlowContainer
{
2023-01-01 02:36:17 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
2023-01-01 02:36:17 +08:00
cover = new ProfileCoverBackground
{
2023-01-01 02:36:17 +08:00
RelativeSizeAxes = Axes.X,
},
2023-01-01 03:09:49 +08:00
new Container
{
2023-01-01 02:36:17 +08:00
RelativeSizeAxes = Axes.X,
2023-01-01 03:09:49 +08:00
AutoSizeAxes = Axes.Y,
2023-01-01 02:36:17 +08:00
Children = new Drawable[]
{
flow = new FillFlowContainer
2023-01-01 02:36:17 +08:00
{
2023-01-01 03:09:49 +08:00
Direction = FillDirection.Horizontal,
Padding = new MarginPadding
2023-01-01 02:58:58 +08:00
{
Left = WaveOverlayContainer.HORIZONTAL_PADDING,
2023-01-01 03:28:28 +08:00
Vertical = vertical_padding
2023-01-01 03:09:49 +08:00
},
2023-01-01 03:28:28 +08:00
Height = content_height + 2 * vertical_padding,
2023-01-01 03:09:49 +08:00
RelativeSizeAxes = Axes.X,
Children = new Drawable[]
{
2023-01-01 03:09:49 +08:00
avatar = new UpdateableAvatar(isInteractive: false, showGuestOnNull: false)
{
2023-01-01 03:09:49 +08:00
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Masking = true,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Offset = new Vector2(0, 1),
Radius = 3,
Colour = Colour4.Black.Opacity(0.25f),
}
},
new FillFlowContainer
2023-01-01 03:09:49 +08:00
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Children = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5, 0),
Children = new Drawable[]
{
usernameText = new OsuSpriteText
2023-01-01 03:09:49 +08:00
{
Font = OsuFont.GetFont(size: 24, weight: FontWeight.Regular)
},
supporterTag = new SupporterIcon
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Height = 15,
},
openUserExternally = new ExternalLinkButton
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
groupBadgeFlow = new GroupBadgeFlow
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
}
},
titleText = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Regular),
Margin = new MarginPadding { Bottom = 5 }
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
userFlag = new UpdateableFlag
2023-01-01 03:09:49 +08:00
{
Size = new Vector2(28, 20),
ShowPlaceholderOnUnknown = false,
},
2023-04-28 10:48:54 +08:00
userCountryContainer = new OsuHoverContainer
{
2023-04-28 10:48:54 +08:00
AutoSizeAxes = Axes.Both,
2023-04-29 00:24:07 +08:00
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Left = 5 },
Child = userCountryText = new OsuSpriteText
2023-04-28 10:48:54 +08:00
{
2023-04-29 00:24:07 +08:00
Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular),
2023-04-28 10:48:54 +08:00
},
},
}
},
}
2023-01-01 03:09:49 +08:00
},
}
},
2023-01-01 03:28:28 +08:00
coverToggle = new ToggleCoverButton
2023-01-01 03:09:49 +08:00
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding { Right = 10 },
CoverExpanded = { BindTarget = coverExpanded }
}
2023-01-01 03:09:49 +08:00
},
},
},
},
};
2023-01-01 03:28:28 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
2023-01-01 03:28:28 +08:00
User.BindValueChanged(user => updateUser(user.NewValue), true);
coverExpanded.BindValueChanged(_ => updateCoverState(), true);
2023-01-01 03:28:28 +08:00
FinishTransforms(true);
}
private void updateUser(UserProfileData? data)
{
var user = data?.User;
2023-01-01 02:36:17 +08:00
cover.User = user;
2019-03-10 06:58:14 +08:00
avatar.User = user;
usernameText.Text = user?.Username ?? string.Empty;
openUserExternally.Link = $@"{api.WebsiteRootUrl}/users/{user?.Id ?? 0}";
2022-07-18 13:40:34 +08:00
userFlag.CountryCode = user?.CountryCode ?? default;
2023-04-28 10:48:54 +08:00
userCountryText.Text = (user?.CountryCode ?? default).GetDescription();
userCountryContainer.Action = () => rankingsOverlay?.ShowCountry(user?.CountryCode ?? default);
2019-04-28 19:11:36 +08:00
supporterTag.SupportLevel = user?.SupportLevel ?? 0;
titleText.Text = user?.Title ?? string.Empty;
titleText.Colour = Color4Extensions.FromHex(user?.Colour ?? "fff");
groupBadgeFlow.User.Value = user;
}
2023-01-01 02:36:17 +08:00
2023-01-01 03:28:28 +08:00
private void updateCoverState()
{
const float transition_duration = 500;
2023-01-01 03:28:28 +08:00
bool expanded = coverToggle.CoverExpanded.Value;
cover.ResizeHeightTo(expanded ? 250 : 0, transition_duration, Easing.OutQuint);
avatar.ResizeTo(new Vector2(expanded ? 120 : content_height), transition_duration, Easing.OutQuint);
avatar.TransformTo(nameof(avatar.CornerRadius), expanded ? 40f : 20f, transition_duration, Easing.OutQuint);
flow.TransformTo(nameof(flow.Spacing), new Vector2(expanded ? 20f : 10f), transition_duration, Easing.OutQuint);
2023-01-01 03:28:28 +08:00
}
2023-01-01 02:36:17 +08:00
private partial class ProfileCoverBackground : UserCoverBackground
{
protected override double LoadDelay => 0;
public ProfileCoverBackground()
{
Masking = true;
}
}
}
}