1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 19:42:57 +08:00
osu-lazer/osu.Game/Users/ExtendedUserPanel.cs

145 lines
4.7 KiB
C#
Raw Normal View History

2020-07-19 01:24:38 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-07-19 01:24:38 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
2020-07-19 01:24:38 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
2020-07-19 01:24:38 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Users.Drawables;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Online.API.Requests.Responses;
2020-07-19 01:24:38 +08:00
namespace osu.Game.Users
{
2022-11-24 13:32:20 +08:00
public abstract partial class ExtendedUserPanel : UserPanel
2020-07-19 01:24:38 +08:00
{
public readonly Bindable<UserStatus?> Status = new Bindable<UserStatus?>();
2020-07-19 01:24:38 +08:00
public readonly IBindable<UserActivity> Activity = new Bindable<UserActivity>();
protected TextFlowContainer LastVisitMessage { get; private set; }
2023-01-14 04:18:24 +08:00
private StatusIcon statusIcon;
private StatusText statusMessage;
2020-07-19 01:24:38 +08:00
protected ExtendedUserPanel(APIUser user)
2020-07-19 01:24:38 +08:00
: base(user)
{
}
[BackgroundDependencyLoader]
private void load()
{
BorderColour = ColourProvider?.Light1 ?? Colours.GreyVioletLighter;
Status.ValueChanged += status => displayStatus(status.NewValue, Activity.Value);
Activity.ValueChanged += activity => displayStatus(Status.Value, activity.NewValue);
}
protected override void LoadComplete()
{
base.LoadComplete();
Status.TriggerChange();
// Colour should be applied immediately on first load.
statusIcon.FinishTransforms();
}
2023-01-14 04:18:24 +08:00
protected Container CreateStatusIcon() => statusIcon = new StatusIcon();
2020-07-19 01:24:38 +08:00
protected FillFlowContainer CreateStatusMessage(bool rightAlignedChildren)
{
var statusContainer = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical
};
var alignment = rightAlignedChildren ? Anchor.CentreRight : Anchor.CentreLeft;
statusContainer.Add(LastVisitMessage = new TextFlowContainer(t => t.Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)).With(text =>
{
text.Anchor = alignment;
text.Origin = alignment;
text.AutoSizeAxes = Axes.Both;
text.Alpha = 0;
if (User.LastVisit.HasValue)
{
text.AddText(@"Last seen ");
text.AddText(new DrawableDate(User.LastVisit.Value, italic: false)
{
Shadow = false
});
}
}));
statusContainer.Add(statusMessage = new StatusText
2020-07-19 01:24:38 +08:00
{
Anchor = alignment,
Origin = alignment,
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold)
});
return statusContainer;
}
private void displayStatus(UserStatus? status, UserActivity activity = null)
2020-07-19 01:24:38 +08:00
{
if (status != null)
{
LastVisitMessage.FadeTo(status == UserStatus.Offline && User.LastVisit.HasValue ? 1 : 0);
2020-07-19 01:24:38 +08:00
// Set status message based on activity (if we have one) and status is not offline
if (activity != null && status != UserStatus.Offline)
2020-07-19 01:24:38 +08:00
{
statusMessage.Text = activity.GetStatus();
statusMessage.TooltipText = activity.GetDetails();
2020-07-19 01:24:38 +08:00
statusIcon.FadeColour(activity.GetAppropriateColour(Colours), 500, Easing.OutQuint);
return;
}
// Otherwise use only status
statusMessage.Text = status.GetLocalisableDescription();
statusMessage.TooltipText = string.Empty;
statusIcon.FadeColour(status.Value.GetAppropriateColour(Colours), 500, Easing.OutQuint);
2020-07-19 01:24:38 +08:00
return;
}
// Fallback to web status if local one is null
if (User.IsOnline)
{
Status.Value = UserStatus.Online;
2020-07-19 01:24:38 +08:00
return;
}
Status.Value = UserStatus.Offline;
2020-07-19 01:24:38 +08:00
}
protected override bool OnHover(HoverEvent e)
{
BorderThickness = 2;
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
BorderThickness = 0;
base.OnHoverLost(e);
}
private partial class StatusText : OsuSpriteText, IHasTooltip
{
public LocalisableString TooltipText { get; set; }
}
2020-07-19 01:24:38 +08:00
}
}