1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-01 22:03:01 +08:00

Bind to API.State instead of API.User

This commit is contained in:
Dean Herbert 2023-06-23 14:05:02 +09:00
parent c06b825d9b
commit ce1579f2fe

View File

@ -14,7 +14,6 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -36,14 +35,14 @@ namespace osu.Game.Overlays.Comments
protected TextBox TextBox { get; private set; } = null!; protected TextBox TextBox { get; private set; } = null!;
protected readonly IBindable<APIUser> User = new Bindable<APIUser>();
[Resolved] [Resolved]
protected IAPIProvider API { get; private set; } = null!; protected IAPIProvider API { get; private set; } = null!;
[Resolved] [Resolved]
private LoginOverlay? loginOverlay { get; set; } private LoginOverlay? loginOverlay { get; set; }
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
/// <summary> /// <summary>
/// Returns the text content of the main action button. /// Returns the text content of the main action button.
/// When <paramref name="isLoggedIn"/> is <see langword="true"/>, the text will apply to a button that posts a comment. /// When <paramref name="isLoggedIn"/> is <see langword="true"/>, the text will apply to a button that posts a comment.
@ -162,14 +161,14 @@ namespace osu.Game.Overlays.Comments
}); });
TextBox.OnCommit += (_, _) => commitButton.TriggerClick(); TextBox.OnCommit += (_, _) => commitButton.TriggerClick();
User.BindTo(API.LocalUser); apiState.BindTo(API.State);
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Current.BindValueChanged(_ => updateCommitButtonState(), true); Current.BindValueChanged(_ => updateCommitButtonState(), true);
User.BindValueChanged(_ => updateStateForLoggedIn(), true); apiState.BindValueChanged(updateStateForLoggedIn, true);
} }
protected abstract void OnCommit(string text); protected abstract void OnCommit(string text);
@ -177,12 +176,14 @@ namespace osu.Game.Overlays.Comments
private void updateCommitButtonState() => private void updateCommitButtonState() =>
commitButton.Enabled.Value = loadingSpinner.State.Value == Visibility.Hidden && !string.IsNullOrEmpty(Current.Value); commitButton.Enabled.Value = loadingSpinner.State.Value == Visibility.Hidden && !string.IsNullOrEmpty(Current.Value);
private void updateStateForLoggedIn() private void updateStateForLoggedIn(ValueChangedEvent<APIState> state)
{ {
TextBox.PlaceholderText = GetPlaceholderText(API.IsLoggedIn); bool isAvailable = state.NewValue > APIState.Offline;
TextBox.ReadOnly = !API.IsLoggedIn;
if (API.IsLoggedIn) TextBox.PlaceholderText = GetPlaceholderText(isAvailable);
TextBox.ReadOnly = !isAvailable;
if (isAvailable)
{ {
commitButton.Show(); commitButton.Show();
logInButton.Hide(); logInButton.Hide();