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
|
|
|
|
|
2020-07-28 11:50:55 +00:00
|
|
|
|
using System;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-09 22:58:14 +00:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2021-11-04 09:02:44 +00:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2019-03-09 22:58:14 +00:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Users
|
|
|
|
|
{
|
2021-11-04 09:02:44 +00:00
|
|
|
|
public class UserCoverBackground : ModelBackedDrawable<APIUser>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2021-11-04 09:02:44 +00:00
|
|
|
|
public APIUser User
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-03-09 22:58:14 +00:00
|
|
|
|
get => Model;
|
|
|
|
|
set => Model = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-04 09:02:44 +00:00
|
|
|
|
protected override Drawable CreateDrawable(APIUser user) => new Cover(user);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-07-28 11:50:55 +00:00
|
|
|
|
protected override double LoadDelay => 300;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delay before the background is unloaded while off-screen.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual double UnloadDelay => 5000;
|
|
|
|
|
|
|
|
|
|
protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Func<Drawable> createContentFunc, double timeBeforeLoad)
|
|
|
|
|
=> new DelayedLoadUnloadWrapper(createContentFunc, timeBeforeLoad, UnloadDelay);
|
|
|
|
|
|
2019-11-29 04:02:15 +00:00
|
|
|
|
[LongRunningLoad]
|
2019-06-12 10:58:26 +00:00
|
|
|
|
private class Cover : CompositeDrawable
|
2019-03-09 22:58:14 +00:00
|
|
|
|
{
|
2021-11-04 09:02:44 +00:00
|
|
|
|
private readonly APIUser user;
|
2019-06-12 10:58:26 +00:00
|
|
|
|
|
2021-11-04 09:02:44 +00:00
|
|
|
|
public Cover(APIUser user)
|
2019-03-09 22:58:14 +00:00
|
|
|
|
{
|
2019-06-12 10:58:26 +00:00
|
|
|
|
this.user = user;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2019-03-09 22:58:14 +00:00
|
|
|
|
}
|
2019-06-12 10:58:26 +00:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(LargeTextureStore textures)
|
2019-03-09 22:58:14 +00:00
|
|
|
|
{
|
2019-06-12 10:58:26 +00:00
|
|
|
|
if (user == null)
|
2019-03-09 22:58:14 +00:00
|
|
|
|
{
|
2019-06-12 10:58:26 +00:00
|
|
|
|
InternalChild = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.1f), Color4.Black.Opacity(0.75f))
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
2019-11-11 11:53:22 +00:00
|
|
|
|
{
|
2019-06-12 10:58:26 +00:00
|
|
|
|
InternalChild = new Sprite
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Texture = textures.Get(user.CoverUrl),
|
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre
|
|
|
|
|
};
|
2019-11-11 11:53:22 +00:00
|
|
|
|
}
|
2019-06-12 10:58:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
this.FadeInFromZero(400);
|
2019-03-09 22:58:14 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|