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