1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00
osu-lazer/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
2.3 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.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
2019-04-02 13:51:28 +08:00
using osu.Framework.Graphics.Effects;
using osu.Game.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Users.Drawables;
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 : ToolbarOverlayToggleButton
{
private readonly UpdateableAvatar avatar;
2018-04-13 17:19:50 +08:00
[Resolved]
private IAPIProvider api { get; set; }
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
public ToolbarUserButton()
{
AutoSizeAxes = Axes.X;
2018-04-13 17:19:50 +08:00
2019-02-20 15:52:36 +08:00
DrawableText.Font = OsuFont.GetFont(italics: true);
2018-04-13 17:19:50 +08:00
Add(new OpaqueBackground { Depth = 1 });
2018-04-13 17:19:50 +08:00
2021-09-10 13:18:40 +08:00
Flow.Add(avatar = new UpdateableAvatar(isInteractive: false)
{
Masking = true,
Size = new Vector2(32),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
CornerRadius = 4,
2017-06-12 11:48:47 +08:00
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Radius = 4,
Colour = Color4.Black.Opacity(0.1f),
}
});
}
2018-04-13 17:19:50 +08:00
2020-10-22 13:30:49 +08:00
[BackgroundDependencyLoader(true)]
private void load(LoginOverlay login)
{
apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
2019-03-28 13:01:06 +08:00
StateContainer = login;
}
2018-04-13 17:19:50 +08:00
2020-10-22 13:49:48 +08:00
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
switch (state.NewValue)
{
default:
Text = UsersStrings.AnonymousUsername;
avatar.User = new APIUser();
break;
2019-04-01 11:44:46 +08:00
case APIState.Online:
Text = api.LocalUser.Value.Username;
2019-02-21 17:56:34 +08:00
avatar.User = api.LocalUser.Value;
break;
}
2020-10-22 13:49:48 +08:00
});
}
}