1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 15:22:55 +08:00

Implement cover toggling

This commit is contained in:
Bartłomiej Dach 2022-12-31 20:28:28 +01:00
parent e74176e5bd
commit 33e91cf512
No known key found for this signature in database
2 changed files with 24 additions and 9 deletions

View File

@ -16,7 +16,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
{ {
public partial class ToggleCoverButton : ProfileHeaderButton public partial class ToggleCoverButton : ProfileHeaderButton
{ {
public readonly BindableBool CoverVisible = new BindableBool(); public readonly BindableBool CoverVisible = new BindableBool(true);
public override LocalisableString TooltipText => CoverVisible.Value ? UsersStrings.ShowCoverTo0 : UsersStrings.ShowCoverTo1; public override LocalisableString TooltipText => CoverVisible.Value ? UsersStrings.ShowCoverTo0 : UsersStrings.ShowCoverTo1;

View File

@ -23,7 +23,8 @@ namespace osu.Game.Overlays.Profile.Header
{ {
public partial class TopHeaderContainer : CompositeDrawable public partial class TopHeaderContainer : CompositeDrawable
{ {
private const float avatar_size = 120; private const float content_height = 65;
private const float vertical_padding = 10;
public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>(); public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>();
@ -39,6 +40,7 @@ namespace osu.Game.Overlays.Profile.Header
private UpdateableFlag userFlag = null!; private UpdateableFlag userFlag = null!;
private OsuSpriteText userCountryText = null!; private OsuSpriteText userCountryText = null!;
private GroupBadgeFlow groupBadgeFlow = null!; private GroupBadgeFlow groupBadgeFlow = null!;
private ToggleCoverButton coverToggle = null!;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider colourProvider)
@ -63,7 +65,6 @@ namespace osu.Game.Overlays.Profile.Header
cover = new ProfileCoverBackground cover = new ProfileCoverBackground
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 250,
}, },
new Container new Container
{ {
@ -77,10 +78,10 @@ namespace osu.Game.Overlays.Profile.Header
Padding = new MarginPadding Padding = new MarginPadding
{ {
Left = UserProfileOverlay.CONTENT_X_MARGIN, Left = UserProfileOverlay.CONTENT_X_MARGIN,
Vertical = 10 Vertical = vertical_padding
}, },
Spacing = new Vector2(20, 0), Spacing = new Vector2(20, 0),
Height = 85, Height = content_height + 2 * vertical_padding,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Children = new Drawable[] Children = new Drawable[]
{ {
@ -88,9 +89,7 @@ namespace osu.Game.Overlays.Profile.Header
{ {
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Size = new Vector2(avatar_size),
Masking = true, Masking = true,
CornerRadius = avatar_size * 0.25f,
EdgeEffect = new EdgeEffectParameters EdgeEffect = new EdgeEffectParameters
{ {
Type = EdgeEffectType.Shadow, Type = EdgeEffectType.Shadow,
@ -172,7 +171,7 @@ namespace osu.Game.Overlays.Profile.Header
}, },
} }
}, },
new ToggleCoverButton coverToggle = new ToggleCoverButton
{ {
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
@ -183,8 +182,15 @@ namespace osu.Game.Overlays.Profile.Header
}, },
}, },
}; };
}
User.BindValueChanged(user => updateUser(user.NewValue)); protected override void LoadComplete()
{
base.LoadComplete();
User.BindValueChanged(user => updateUser(user.NewValue), true);
coverToggle.CoverVisible.BindValueChanged(_ => updateCoverState(), true);
FinishTransforms(true);
} }
private void updateUser(UserProfileData? data) private void updateUser(UserProfileData? data)
@ -203,6 +209,15 @@ namespace osu.Game.Overlays.Profile.Header
groupBadgeFlow.User.Value = user; groupBadgeFlow.User.Value = user;
} }
private void updateCoverState()
{
const float transition_duration = 250;
cover.ResizeHeightTo(coverToggle.CoverVisible.Value ? 250 : 0, transition_duration, Easing.OutQuint);
avatar.ResizeTo(new Vector2(coverToggle.CoverVisible.Value ? 120 : content_height), transition_duration, Easing.OutQuint);
avatar.TransformTo(nameof(avatar.CornerRadius), coverToggle.CoverVisible.Value ? 40f : 20f, transition_duration, Easing.OutQuint);
}
private partial class ProfileCoverBackground : UserCoverBackground private partial class ProfileCoverBackground : UserCoverBackground
{ {
protected override double LoadDelay => 0; protected override double LoadDelay => 0;