From ce1579f2fead9c2c84ff160dff5025ee41603998 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 23 Jun 2023 14:05:02 +0900 Subject: [PATCH] Bind to `API.State` instead of `API.User` --- osu.Game/Overlays/Comments/CommentEditor.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index 8dbafc0ea8..05bdac5966 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -14,7 +14,6 @@ using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Online.API; -using osu.Game.Online.API.Requests.Responses; using osuTK; using osuTK.Graphics; @@ -36,14 +35,14 @@ namespace osu.Game.Overlays.Comments protected TextBox TextBox { get; private set; } = null!; - protected readonly IBindable User = new Bindable(); - [Resolved] protected IAPIProvider API { get; private set; } = null!; [Resolved] private LoginOverlay? loginOverlay { get; set; } + private readonly IBindable apiState = new Bindable(); + /// /// Returns the text content of the main action button. /// When is , the text will apply to a button that posts a comment. @@ -162,14 +161,14 @@ namespace osu.Game.Overlays.Comments }); TextBox.OnCommit += (_, _) => commitButton.TriggerClick(); - User.BindTo(API.LocalUser); + apiState.BindTo(API.State); } protected override void LoadComplete() { base.LoadComplete(); Current.BindValueChanged(_ => updateCommitButtonState(), true); - User.BindValueChanged(_ => updateStateForLoggedIn(), true); + apiState.BindValueChanged(updateStateForLoggedIn, true); } protected abstract void OnCommit(string text); @@ -177,12 +176,14 @@ namespace osu.Game.Overlays.Comments private void updateCommitButtonState() => commitButton.Enabled.Value = loadingSpinner.State.Value == Visibility.Hidden && !string.IsNullOrEmpty(Current.Value); - private void updateStateForLoggedIn() + private void updateStateForLoggedIn(ValueChangedEvent state) { - TextBox.PlaceholderText = GetPlaceholderText(API.IsLoggedIn); - TextBox.ReadOnly = !API.IsLoggedIn; + bool isAvailable = state.NewValue > APIState.Offline; - if (API.IsLoggedIn) + TextBox.PlaceholderText = GetPlaceholderText(isAvailable); + TextBox.ReadOnly = !isAvailable; + + if (isAvailable) { commitButton.Show(); logInButton.Hide();