osu/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs

71 lines
2.0 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 09:19:50 +00:00
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
2019-04-02 05:51:28 +00:00
using osu.Framework.Graphics.Effects;
using osu.Game.Graphics;
2018-04-13 09:19:50 +00:00
using osu.Game.Online.API;
using osu.Game.Users;
using osu.Game.Users.Drawables;
2018-11-20 07:51:59 +00:00
using osuTK;
using osuTK.Graphics;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Overlays.Toolbar
{
2019-03-28 05:01:06 +00:00
public class ToolbarUserButton : ToolbarOverlayToggleButton, IOnlineComponent
2018-04-13 09:19:50 +00:00
{
private readonly UpdateableAvatar avatar;
public ToolbarUserButton()
{
AutoSizeAxes = Axes.X;
2019-02-20 07:52:36 +00:00
DrawableText.Font = OsuFont.GetFont(italics: true);
2018-04-13 09:19:50 +00: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 11:08:22 +00:00
OpenOnClick = { Value = false },
2018-04-13 09:19:50 +00:00
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Radius = 4,
Colour = Color4.Black.Opacity(0.1f),
}
});
}
2019-03-28 05:01:06 +00:00
[BackgroundDependencyLoader(true)]
private void load(IAPIProvider api, LoginOverlay login)
2018-04-13 09:19:50 +00:00
{
api.Register(this);
2019-03-28 05:01:06 +00:00
StateContainer = login;
2018-04-13 09:19:50 +00:00
}
public void APIStateChanged(IAPIProvider api, APIState state)
2018-04-13 09:19:50 +00:00
{
switch (state)
{
default:
Text = @"Guest";
avatar.User = new User();
break;
2019-04-01 03:44:46 +00:00
2018-04-13 09:19:50 +00:00
case APIState.Online:
Text = api.LocalUser.Value.Username;
2019-02-21 09:56:34 +00:00
avatar.User = api.LocalUser.Value;
2018-04-13 09:19:50 +00:00
break;
}
}
}
}