mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 00:09:55 +09:00
Display connecting / failing states on toolbar user display
This commit is contained in:
@ -1,17 +1,19 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
using System;
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Effects;
|
using osu.Framework.Graphics.Effects;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Localisation;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Resources.Localisation.Web;
|
|
||||||
using osu.Game.Users.Drawables;
|
using osu.Game.Users.Drawables;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -20,59 +22,97 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
{
|
{
|
||||||
public class ToolbarUserButton : ToolbarOverlayToggleButton
|
public class ToolbarUserButton : ToolbarOverlayToggleButton
|
||||||
{
|
{
|
||||||
private readonly UpdateableAvatar avatar;
|
private UpdateableAvatar avatar = null!;
|
||||||
|
|
||||||
[Resolved]
|
private IBindable<APIUser> localUser = null!;
|
||||||
private IAPIProvider api { get; set; }
|
|
||||||
|
|
||||||
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
|
private LoadingSpinner spinner = null!;
|
||||||
|
|
||||||
|
private SpriteIcon failingIcon = null!;
|
||||||
|
|
||||||
|
private IBindable<APIState> apiState = null!;
|
||||||
|
|
||||||
public ToolbarUserButton()
|
public ToolbarUserButton()
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.X;
|
AutoSizeAxes = Axes.X;
|
||||||
|
}
|
||||||
|
|
||||||
DrawableText.Font = OsuFont.GetFont(italics: true);
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colours, IAPIProvider api, LoginOverlay? login)
|
||||||
|
{
|
||||||
Add(new OpaqueBackground { Depth = 1 });
|
Add(new OpaqueBackground { Depth = 1 });
|
||||||
|
|
||||||
Flow.Add(avatar = new UpdateableAvatar(isInteractive: false)
|
Flow.Add(new Container
|
||||||
{
|
{
|
||||||
Masking = true,
|
Masking = true,
|
||||||
|
CornerRadius = 4,
|
||||||
Size = new Vector2(32),
|
Size = new Vector2(32),
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
CornerRadius = 4,
|
|
||||||
EdgeEffect = new EdgeEffectParameters
|
EdgeEffect = new EdgeEffectParameters
|
||||||
{
|
{
|
||||||
Type = EdgeEffectType.Shadow,
|
Type = EdgeEffectType.Shadow,
|
||||||
Radius = 4,
|
Radius = 4,
|
||||||
Colour = Color4.Black.Opacity(0.1f),
|
Colour = Color4.Black.Opacity(0.1f),
|
||||||
|
},
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
avatar = new UpdateableAvatar(isInteractive: false)
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
},
|
||||||
|
spinner = new LoadingLayer(dimBackground: true, withBox: false, blockInput: false)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
},
|
||||||
|
failingIcon = new SpriteIcon
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Alpha = 0,
|
||||||
|
Size = new Vector2(0.3f),
|
||||||
|
Icon = FontAwesome.Solid.ExclamationTriangle,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = colours.YellowLight,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
apiState = api.State.GetBoundCopy();
|
||||||
private void load(LoginOverlay login)
|
|
||||||
{
|
|
||||||
apiState.BindTo(api.State);
|
|
||||||
apiState.BindValueChanged(onlineStateChanged, true);
|
apiState.BindValueChanged(onlineStateChanged, true);
|
||||||
|
|
||||||
|
localUser = api.LocalUser.GetBoundCopy();
|
||||||
|
localUser.BindValueChanged(userChanged, true);
|
||||||
|
|
||||||
StateContainer = login;
|
StateContainer = login;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void userChanged(ValueChangedEvent<APIUser> user)
|
||||||
|
{
|
||||||
|
Text = user.NewValue.Username;
|
||||||
|
avatar.User = user.NewValue;
|
||||||
|
}
|
||||||
|
|
||||||
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
|
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
|
||||||
{
|
{
|
||||||
|
failingIcon.FadeTo(state.NewValue == APIState.Failing ? 1 : 0, 200, Easing.OutQuint);
|
||||||
|
|
||||||
switch (state.NewValue)
|
switch (state.NewValue)
|
||||||
{
|
{
|
||||||
default:
|
case APIState.Connecting:
|
||||||
Text = UsersStrings.AnonymousUsername;
|
case APIState.Failing:
|
||||||
avatar.User = new APIUser();
|
spinner.Show();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case APIState.Offline:
|
||||||
case APIState.Online:
|
case APIState.Online:
|
||||||
Text = api.LocalUser.Value.Username;
|
spinner.Hide();
|
||||||
avatar.User = api.LocalUser.Value;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user