1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 23:47:24 +08:00
osu-lazer/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs

67 lines
1.9 KiB
C#
Raw Normal View History

// 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 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Game.Online.API;
using osu.Game.Users;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.Toolbar
{
public class ToolbarUserButton : ToolbarButton, IOnlineComponent
{
private readonly UpdateableAvatar avatar;
public ToolbarUserButton()
{
AutoSizeAxes = Axes.X;
DrawableText.Font = OsuFont.GetFont(weight: FontWeight.Medium, italics: true);
2018-04-13 17:19:50 +08:00
Add(new OpaqueBackground { Depth = 1 });
Flow.Add(avatar = new UpdateableAvatar
{
Masking = true,
Size = new Vector2(32),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
CornerRadius = 4,
2018-12-20 19:08:22 +08:00
OpenOnClick = { Value = false },
2018-04-13 17:19:50 +08:00
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Radius = 4,
Colour = Color4.Black.Opacity(0.1f),
}
});
}
[BackgroundDependencyLoader]
private void load(APIAccess api)
{
api.Register(this);
}
public void APIStateChanged(APIAccess api, APIState state)
{
switch (state)
{
default:
Text = @"Guest";
avatar.User = new User();
break;
case APIState.Online:
Text = api.LocalUser.Value.Username;
avatar.User = api.LocalUser;
break;
}
}
}
}