2019-01-24 08:43:03 +00: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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
using System;
|
2018-11-20 07:51:59 +00:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-04-02 05:51:28 +00:00
|
|
|
using osu.Framework.Graphics.Effects;
|
2019-03-27 10:29:27 +00:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
2019-04-26 04:49:44 +00:00
|
|
|
using osu.Game.Overlays.Profile.Header.Components;
|
2019-06-17 17:57:57 +00:00
|
|
|
using osu.Game.Users.Drawables;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Users
|
|
|
|
{
|
|
|
|
public class UserPanel : OsuClickableContainer, IHasContextMenu
|
|
|
|
{
|
|
|
|
private readonly User user;
|
|
|
|
private const float height = 100;
|
|
|
|
private const float content_padding = 10;
|
|
|
|
private const float status_height = 30;
|
|
|
|
|
2019-05-05 18:51:55 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
private Container statusBar;
|
|
|
|
private Box statusBg;
|
|
|
|
private OsuSpriteText statusMessage;
|
|
|
|
|
|
|
|
private Container content;
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
|
|
|
public readonly Bindable<UserStatus> Status = new Bindable<UserStatus>();
|
|
|
|
|
2019-06-12 09:04:57 +00:00
|
|
|
public readonly IBindable<UserActivity> Activity = new Bindable<UserActivity>();
|
2019-05-05 18:51:55 +00:00
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
public new Action Action;
|
|
|
|
|
|
|
|
protected Action ViewProfile;
|
|
|
|
|
|
|
|
public UserPanel(User user)
|
|
|
|
{
|
|
|
|
if (user == null)
|
|
|
|
throw new ArgumentNullException(nameof(user));
|
|
|
|
|
|
|
|
this.user = user;
|
|
|
|
|
|
|
|
Height = height - status_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
2019-05-05 18:51:55 +00:00
|
|
|
private void load(UserProfileOverlay profile)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
if (colours == null)
|
2019-11-28 14:21:21 +00:00
|
|
|
throw new InvalidOperationException($"{nameof(colours)} not initialized!");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
FillFlowContainer infoContainer;
|
|
|
|
|
|
|
|
AddInternal(content = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 5,
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Colour = Color4.Black.Opacity(0.25f),
|
|
|
|
Radius = 4,
|
|
|
|
},
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2019-06-12 10:58:26 +00:00
|
|
|
new DelayedLoadUnloadWrapper(() => new UserCoverBackground
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2019-03-09 22:58:14 +00:00
|
|
|
User = user,
|
2019-06-12 10:58:26 +00:00
|
|
|
}, 300, 5000)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2018-04-13 09:19:50 +00:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Black.Opacity(0.7f),
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Padding = new MarginPadding { Top = content_padding, Horizontal = content_padding },
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new UpdateableAvatar
|
|
|
|
{
|
|
|
|
Size = new Vector2(height - status_height - content_padding * 2),
|
|
|
|
User = user,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 5,
|
2018-12-20 11:08:22 +00:00
|
|
|
OpenOnClick = { Value = false },
|
2018-04-13 09:19:50 +00:00
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Colour = Color4.Black.Opacity(0.25f),
|
|
|
|
Radius = 4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding { Left = height - status_height - content_padding },
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = user.Username,
|
2019-02-12 04:04:46 +00:00
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 18, italics: true),
|
2018-04-13 09:19:50 +00:00
|
|
|
},
|
|
|
|
infoContainer = new FillFlowContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Height = 20f,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(5f, 0f),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2019-06-17 17:57:57 +00:00
|
|
|
new UpdateableFlag(user.Country)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
Width = 30f,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
statusBar = new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Alpha = 0f,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
statusBg = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0.5f,
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Spacing = new Vector2(5f, 0f),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new SpriteIcon
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2019-04-02 10:55:24 +00:00
|
|
|
Icon = FontAwesome.Regular.Circle,
|
2018-04-13 09:19:50 +00:00
|
|
|
Shadow = true,
|
|
|
|
Size = new Vector2(14),
|
|
|
|
},
|
|
|
|
statusMessage = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2019-02-12 04:04:46 +00:00
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.SemiBold),
|
2018-04-13 09:19:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (user.IsSupporter)
|
|
|
|
{
|
|
|
|
infoContainer.Add(new SupporterIcon
|
|
|
|
{
|
2018-12-22 15:51:24 +00:00
|
|
|
Height = 20f,
|
2019-04-28 11:11:36 +00:00
|
|
|
SupportLevel = user.SupportLevel
|
2018-04-13 09:19:50 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-05 18:51:55 +00:00
|
|
|
Status.ValueChanged += status => displayStatus(status.NewValue, Activity.Value);
|
|
|
|
Activity.ValueChanged += activity => displayStatus(Status.Value, activity.NewValue);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
base.Action = ViewProfile = () =>
|
|
|
|
{
|
|
|
|
Action?.Invoke();
|
|
|
|
profile?.ShowUser(user);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
Status.TriggerChange();
|
|
|
|
}
|
|
|
|
|
2019-05-05 18:51:55 +00:00
|
|
|
private void displayStatus(UserStatus status, UserActivity activity = null)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
const float transition_duration = 500;
|
|
|
|
|
|
|
|
if (status == null)
|
|
|
|
{
|
|
|
|
statusBar.ResizeHeightTo(0f, transition_duration, Easing.OutQuint);
|
|
|
|
statusBar.FadeOut(transition_duration, Easing.OutQuint);
|
|
|
|
this.ResizeHeightTo(height - status_height, transition_duration, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
statusBar.ResizeHeightTo(status_height, transition_duration, Easing.OutQuint);
|
|
|
|
statusBar.FadeIn(transition_duration, Easing.OutQuint);
|
|
|
|
this.ResizeHeightTo(height, transition_duration, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
2019-06-11 18:00:14 +00:00
|
|
|
if (status is UserStatusOnline && activity != null)
|
|
|
|
{
|
|
|
|
statusMessage.Text = activity.Status;
|
|
|
|
statusBg.FadeColour(activity.GetAppropriateColour(colours), 500, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
statusMessage.Text = status?.Message;
|
|
|
|
statusBg.FadeColour(status?.GetAppropriateColour(colours) ?? colours.Gray5, 500, Easing.OutQuint);
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public MenuItem[] ContextMenuItems => new MenuItem[]
|
|
|
|
{
|
|
|
|
new OsuMenuItem("View Profile", MenuItemType.Highlighted, ViewProfile),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|