2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-03-14 21:58:28 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-11-08 05:49:32 +08:00
|
|
|
|
using System;
|
2017-03-14 21:58:28 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Users
|
|
|
|
|
{
|
|
|
|
|
public class Avatar : Container
|
|
|
|
|
{
|
2017-03-27 23:04:51 +08:00
|
|
|
|
private readonly User user;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An avatar for specified user.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="user">The user. A null value will get a placeholder avatar.</param>
|
2017-03-28 13:24:21 +08:00
|
|
|
|
public Avatar(User user = null)
|
2017-03-14 21:58:28 +08:00
|
|
|
|
{
|
2017-03-27 23:04:51 +08:00
|
|
|
|
this.user = user;
|
2017-03-15 16:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-28 13:24:21 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-03-27 23:04:51 +08:00
|
|
|
|
private void load(TextureStore textures)
|
2017-03-15 16:04:50 +08:00
|
|
|
|
{
|
2017-11-08 05:49:32 +08:00
|
|
|
|
if (textures == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(textures));
|
|
|
|
|
|
2017-03-28 13:24:21 +08:00
|
|
|
|
Texture texture = null;
|
2017-09-14 11:58:32 +08:00
|
|
|
|
if (user != null && user.Id > 1) texture = textures.Get($@"https://a.ppy.sh/{user.Id}");
|
2017-03-28 13:24:21 +08:00
|
|
|
|
if (texture == null) texture = textures.Get(@"Online/avatar-guest");
|
2017-03-15 16:04:50 +08:00
|
|
|
|
|
2017-03-28 13:24:21 +08:00
|
|
|
|
Add(new Sprite
|
2017-03-15 18:07:26 +08:00
|
|
|
|
{
|
2017-06-28 17:24:23 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-03-28 13:24:21 +08:00
|
|
|
|
Texture = texture,
|
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre
|
|
|
|
|
});
|
2017-03-14 21:58:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|