osu/osu.Game/Users/UserPanel.cs

235 lines
9.4 KiB
C#
Raw Normal View History

2018-01-05 11:21:19 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-05-22 06:11:42 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
2017-05-22 06:11:42 +00:00
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2017-05-22 06:11:42 +00:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2017-06-16 08:23:20 +00:00
using osu.Game.Overlays;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.Cursor;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays.Profile;
2017-05-22 06:11:42 +00:00
namespace osu.Game.Users
{
public class UserPanel : OsuClickableContainer, IHasContextMenu
2017-05-22 06:11:42 +00:00
{
private readonly User user;
2017-05-22 06:11:42 +00:00
private const float height = 100;
private const float content_padding = 10;
private const float status_height = 30;
2018-01-06 10:27:17 +00:00
private Container statusBar;
private Box statusBg;
private OsuSpriteText statusMessage;
private Container content;
protected override Container<Drawable> Content => content;
2017-05-22 06:11:42 +00:00
public readonly Bindable<UserStatus> Status = new Bindable<UserStatus>();
public new Action Action;
protected Action ViewProfile;
2017-05-22 06:11:42 +00:00
public UserPanel(User user)
{
if (user == null)
throw new ArgumentNullException(nameof(user));
this.user = user;
2017-05-24 03:45:56 +00:00
Height = height - status_height;
2018-01-06 10:27:17 +00:00
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuColour colours, UserProfileOverlay profile)
{
if (colours == null)
throw new ArgumentNullException(nameof(colours));
2017-05-22 06:11:42 +00:00
2018-01-06 10:27:17 +00:00
FillFlowContainer infoContainer;
AddInternal(content = new Container
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = 5,
EdgeEffect = new EdgeEffectParameters
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.25f),
Radius = 4,
2017-05-22 06:11:42 +00:00
},
2018-01-06 10:27:17 +00:00
Children = new Drawable[]
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
new DelayedLoadWrapper(new UserCoverBackground(user)
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out)
}, 300) { RelativeSizeAxes = Axes.Both },
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[]
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
new UpdateableAvatar
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
Size = new Vector2(height - status_height - content_padding * 2),
User = user,
Masking = true,
CornerRadius = 5,
EdgeEffect = new EdgeEffectParameters
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.25f),
Radius = 4,
2017-05-22 06:11:42 +00:00
},
2018-01-06 10:27:17 +00:00
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = height - status_height - content_padding },
Children = new Drawable[]
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
new OsuSpriteText
{
Text = user.Username,
TextSize = 18,
Font = @"Exo2.0-SemiBoldItalic",
},
infoContainer = new FillFlowContainer
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
AutoSizeAxes = Axes.X,
Height = 20f,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5f, 0f),
Children = new Drawable[]
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
new DrawableFlag(user.Country)
{
Width = 30f,
RelativeSizeAxes = Axes.Y,
},
2017-05-22 06:11:42 +00:00
},
},
},
},
},
},
2018-01-06 10:27:17 +00:00
statusBar = new Container
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Alpha = 0f,
Children = new Drawable[]
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
statusBg = new Box
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
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[]
2017-05-22 06:11:42 +00:00
{
2018-01-06 10:27:17 +00:00
new SpriteIcon
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Icon = FontAwesome.fa_circle_o,
Shadow = true,
Size = new Vector2(14),
},
statusMessage = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = @"Exo2.0-Semibold",
},
2017-05-22 06:11:42 +00:00
},
},
},
},
2018-01-06 10:27:17 +00:00
}
});
2017-11-16 17:06:49 +00:00
if (user.IsSupporter)
{
2017-11-16 17:06:49 +00:00
infoContainer.Add(new SupporterIcon
{
RelativeSizeAxes = Axes.Y,
Width = 20f,
});
}
2017-05-25 07:31:56 +00:00
Status.ValueChanged += displayStatus;
2017-07-22 18:50:25 +00:00
Status.ValueChanged += status => statusBg.FadeColour(status?.GetAppropriateColour(colours) ?? colours.Gray5, 500, Easing.OutQuint);
base.Action = ViewProfile = () =>
{
Action?.Invoke();
profile?.ShowUser(user);
};
2017-05-25 07:31:56 +00:00
}
protected override void LoadComplete()
{
base.LoadComplete();
Status.TriggerChange();
2017-05-22 06:11:42 +00:00
}
private void displayStatus(UserStatus status)
{
2017-05-24 07:00:39 +00:00
const float transition_duration = 500;
2017-05-24 03:45:56 +00:00
2017-05-24 06:49:06 +00:00
if (status == null)
{
2017-07-22 18:50:25 +00:00
statusBar.ResizeHeightTo(0f, transition_duration, Easing.OutQuint);
statusBar.FadeOut(transition_duration, Easing.OutQuint);
this.ResizeHeightTo(height - status_height, transition_duration, Easing.OutQuint);
2017-05-24 06:49:06 +00:00
}
else
{
2017-07-22 18:50:25 +00:00
statusBar.ResizeHeightTo(status_height, transition_duration, Easing.OutQuint);
statusBar.FadeIn(transition_duration, Easing.OutQuint);
this.ResizeHeightTo(height, transition_duration, Easing.OutQuint);
2017-05-24 06:49:06 +00:00
statusMessage.Text = status.Message;
}
2017-05-22 06:11:42 +00:00
}
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem("View Profile", MenuItemType.Highlighted, ViewProfile),
};
2017-05-22 06:11:42 +00:00
}
}