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;
|
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.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-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-06-17 17:57:57 +00:00
|
|
|
using osu.Game.Users.Drawables;
|
2020-03-04 11:58:15 +00:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Users
|
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
public abstract class UserPanel : OsuClickableContainer, IHasContextMenu
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-02-13 09:59:15 +00:00
|
|
|
public readonly User User;
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
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;
|
|
|
|
|
2020-03-16 05:06:42 +00:00
|
|
|
protected Action ViewProfile { get; private set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-03-16 05:06:42 +00:00
|
|
|
protected DelayedLoadUnloadWrapper Background { get; private set; }
|
2020-03-04 11:58:15 +00:00
|
|
|
|
2020-03-25 17:58:51 +00:00
|
|
|
protected TextFlowContainer LastVisitMessage { get; private set; }
|
|
|
|
|
2020-03-04 11:58:15 +00:00
|
|
|
private SpriteIcon statusIcon;
|
|
|
|
private OsuSpriteText statusMessage;
|
|
|
|
|
|
|
|
protected UserPanel(User user)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
if (user == null)
|
|
|
|
throw new ArgumentNullException(nameof(user));
|
|
|
|
|
2020-02-13 09:59:15 +00:00
|
|
|
User = user;
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 11:58:15 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private UserProfileOverlay profileOverlay { get; set; }
|
|
|
|
|
2020-03-04 22:41:55 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; }
|
|
|
|
|
2020-03-04 11:58:15 +00:00
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
Masking = true;
|
2020-03-04 22:41:55 +00:00
|
|
|
BorderColour = colourProvider?.Light1 ?? colours.GreyVioletLighter;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-03-04 11:58:15 +00:00
|
|
|
AddRange(new[]
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
new Box
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-04 22:45:49 +00:00
|
|
|
Colour = colourProvider?.Background5 ?? colours.Gray1
|
2018-04-13 09:19:50 +00:00
|
|
|
},
|
2020-03-04 11:58:15 +00:00
|
|
|
Background = new DelayedLoadUnloadWrapper(() => new UserCoverBackground
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
User = User,
|
|
|
|
}, 300, 5000)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
CreateLayout()
|
|
|
|
});
|
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();
|
2020-03-04 11:58:15 +00:00
|
|
|
profileOverlay?.ShowUser(User);
|
2018-04-13 09:19:50 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
Status.TriggerChange();
|
2020-03-16 23:10:20 +00:00
|
|
|
|
|
|
|
// Colour should be applied immediately on first load.
|
|
|
|
statusIcon.FinishTransforms();
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 11:58:15 +00:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
BorderThickness = 2;
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
BorderThickness = 0;
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
[NotNull]
|
|
|
|
protected abstract Drawable CreateLayout();
|
|
|
|
|
|
|
|
protected UpdateableAvatar CreateAvatar() => new UpdateableAvatar
|
|
|
|
{
|
|
|
|
User = User,
|
|
|
|
OpenOnClick = { Value = false }
|
|
|
|
};
|
|
|
|
|
|
|
|
protected UpdateableFlag CreateFlag() => new UpdateableFlag(User.Country)
|
|
|
|
{
|
|
|
|
Size = new Vector2(39, 26)
|
|
|
|
};
|
|
|
|
|
|
|
|
protected OsuSpriteText CreateUsername() => new OsuSpriteText
|
|
|
|
{
|
2020-03-07 01:05:17 +00:00
|
|
|
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
|
2020-03-04 23:38:30 +00:00
|
|
|
Shadow = false,
|
2020-03-04 11:58:15 +00:00
|
|
|
Text = User.Username,
|
|
|
|
};
|
|
|
|
|
|
|
|
protected SpriteIcon CreateStatusIcon() => statusIcon = new SpriteIcon
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
Icon = FontAwesome.Regular.Circle,
|
|
|
|
Size = new Vector2(25)
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-03-04 11:58:15 +00:00
|
|
|
protected FillFlowContainer CreateStatusMessage(bool rightAlignedChildren)
|
|
|
|
{
|
|
|
|
var statusContainer = new FillFlowContainer
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical
|
|
|
|
};
|
|
|
|
|
2020-03-04 22:45:49 +00:00
|
|
|
var alignment = rightAlignedChildren ? Anchor.CentreRight : Anchor.CentreLeft;
|
2020-03-04 11:58:15 +00:00
|
|
|
|
2020-03-25 17:58:51 +00:00
|
|
|
statusContainer.Add(LastVisitMessage = new TextFlowContainer(t => t.Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)).With(text =>
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-03-04 22:45:49 +00:00
|
|
|
text.Anchor = alignment;
|
|
|
|
text.Origin = alignment;
|
2020-03-04 11:58:15 +00:00
|
|
|
text.AutoSizeAxes = Axes.Both;
|
|
|
|
text.Alpha = 0;
|
|
|
|
|
|
|
|
if (User.LastVisit.HasValue)
|
|
|
|
{
|
|
|
|
text.AddText(@"Last seen ");
|
2020-03-04 23:00:46 +00:00
|
|
|
text.AddText(new DrawableDate(User.LastVisit.Value, italic: false)
|
|
|
|
{
|
|
|
|
Shadow = false
|
|
|
|
});
|
2020-03-04 11:58:15 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
statusContainer.Add(statusMessage = new OsuSpriteText
|
|
|
|
{
|
2020-03-04 22:45:49 +00:00
|
|
|
Anchor = alignment,
|
|
|
|
Origin = alignment,
|
2020-03-07 01:05:17 +00:00
|
|
|
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold)
|
2020-03-04 11:58:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return statusContainer;
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-03-04 11:58:15 +00:00
|
|
|
private void displayStatus(UserStatus status, UserActivity activity = null)
|
|
|
|
{
|
|
|
|
if (status != null)
|
2019-06-11 18:00:14 +00:00
|
|
|
{
|
2020-03-25 18:02:45 +00:00
|
|
|
LastVisitMessage.FadeTo(status is UserStatusOffline && User.LastVisit.HasValue ? 1 : 0);
|
|
|
|
|
2020-03-04 23:10:38 +00:00
|
|
|
// Set status message based on activity (if we have one) and status is not offline
|
2020-03-04 11:58:15 +00:00
|
|
|
if (activity != null && !(status is UserStatusOffline))
|
|
|
|
{
|
|
|
|
statusMessage.Text = activity.Status;
|
|
|
|
statusIcon.FadeColour(activity.GetAppropriateColour(colours), 500, Easing.OutQuint);
|
2020-03-04 23:10:38 +00:00
|
|
|
return;
|
2020-03-04 11:58:15 +00:00
|
|
|
}
|
2020-03-04 23:10:38 +00:00
|
|
|
|
|
|
|
// Otherwise use only status
|
|
|
|
statusMessage.Text = status.Message;
|
|
|
|
statusIcon.FadeColour(status.GetAppropriateColour(colours), 500, Easing.OutQuint);
|
2020-03-04 11:58:15 +00:00
|
|
|
|
|
|
|
return;
|
2019-06-11 18:00:14 +00:00
|
|
|
}
|
2020-03-04 11:58:15 +00:00
|
|
|
|
2020-03-04 23:10:38 +00:00
|
|
|
// Fallback to web status if local one is null
|
2020-03-04 11:58:15 +00:00
|
|
|
if (User.IsOnline)
|
2019-06-11 18:00:14 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
Status.Value = new UserStatusOnline();
|
|
|
|
return;
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
2020-03-04 11:58:15 +00:00
|
|
|
|
|
|
|
Status.Value = new UserStatusOffline();
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public MenuItem[] ContextMenuItems => new MenuItem[]
|
|
|
|
{
|
|
|
|
new OsuMenuItem("View Profile", MenuItemType.Highlighted, ViewProfile),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|