mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 10:42:54 +08:00
extract button text properties to methods, show login overlay on click
This commit is contained in:
parent
d5d494f07b
commit
591277e0f9
@ -15,7 +15,6 @@ using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Resources.Localisation.Web;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -27,12 +26,6 @@ namespace osu.Game.Overlays.Comments
|
||||
|
||||
protected abstract LocalisableString FooterText { get; }
|
||||
|
||||
protected abstract LocalisableString CommitButtonText { get; }
|
||||
|
||||
private LocalisableString textBoxPlaceholderLoggedOut => AuthorizationStrings.RequireLogin;
|
||||
|
||||
protected abstract LocalisableString TextBoxPlaceholder { get; }
|
||||
|
||||
protected FillFlowContainer ButtonsContainer { get; private set; } = null!;
|
||||
|
||||
protected readonly Bindable<string> Current = new Bindable<string>(string.Empty);
|
||||
@ -47,7 +40,12 @@ namespace osu.Game.Overlays.Comments
|
||||
[Resolved]
|
||||
protected IAPIProvider API { get; private set; } = null!;
|
||||
|
||||
private LocalisableString placeholderText => API.IsLoggedIn ? TextBoxPlaceholder : textBoxPlaceholderLoggedOut;
|
||||
[Resolved]
|
||||
private LoginOverlay? loginOverlay { get; set; }
|
||||
|
||||
protected abstract LocalisableString GetCommitButtonText(bool isLoggedIn);
|
||||
|
||||
protected abstract LocalisableString GetTextBoxPlaceholder(bool isLoggedIn);
|
||||
|
||||
protected bool ShowLoadingSpinner
|
||||
{
|
||||
@ -90,7 +88,7 @@ namespace osu.Game.Overlays.Comments
|
||||
{
|
||||
Height = 40,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
PlaceholderText = placeholderText,
|
||||
PlaceholderText = GetTextBoxPlaceholder(API.IsLoggedIn),
|
||||
Current = Current,
|
||||
ReadOnly = !API.IsLoggedIn
|
||||
},
|
||||
@ -128,8 +126,8 @@ namespace osu.Game.Overlays.Comments
|
||||
Spacing = new Vector2(5, 0),
|
||||
Child = commitButton = new EditorButton
|
||||
{
|
||||
Text = CommitButtonText,
|
||||
Action = () => OnCommit(Current.Value)
|
||||
Text = GetCommitButtonText(API.IsLoggedIn),
|
||||
Action = () => commitOrLogIn(Current.Value)
|
||||
}
|
||||
},
|
||||
loadingSpinner = new LoadingSpinner
|
||||
@ -154,18 +152,34 @@ namespace osu.Game.Overlays.Comments
|
||||
{
|
||||
base.LoadComplete();
|
||||
Current.BindValueChanged(_ => updateCommitButtonState(), true);
|
||||
User.BindValueChanged(_ => updateTextBoxState());
|
||||
User.BindValueChanged(_ => updateStateForLoggedIn());
|
||||
}
|
||||
|
||||
protected abstract void OnCommit(string text);
|
||||
|
||||
private void updateCommitButtonState() =>
|
||||
commitButton.Enabled.Value = loadingSpinner.State.Value == Visibility.Hidden && !string.IsNullOrEmpty(Current.Value);
|
||||
|
||||
private void updateTextBoxState()
|
||||
private void commitOrLogIn(string text)
|
||||
{
|
||||
TextBox.PlaceholderText = placeholderText;
|
||||
if (!API.IsLoggedIn)
|
||||
{
|
||||
loginOverlay?.Show();
|
||||
return;
|
||||
}
|
||||
|
||||
OnCommit(text);
|
||||
}
|
||||
|
||||
private void updateCommitButtonState()
|
||||
{
|
||||
bool textBoxValid = loadingSpinner.State.Value == Visibility.Hidden && !string.IsNullOrEmpty(Current.Value);
|
||||
commitButton.Enabled.Value = textBoxValid || !API.IsLoggedIn;
|
||||
}
|
||||
|
||||
private void updateStateForLoggedIn()
|
||||
{
|
||||
TextBox.PlaceholderText = GetTextBoxPlaceholder(API.IsLoggedIn);
|
||||
TextBox.ReadOnly = !API.IsLoggedIn;
|
||||
commitButton.Text = GetCommitButtonText(API.IsLoggedIn);
|
||||
updateCommitButtonState();
|
||||
}
|
||||
|
||||
private partial class EditorTextBox : OsuTextBox
|
||||
|
@ -410,9 +410,11 @@ namespace osu.Game.Overlays.Comments
|
||||
//TODO should match web, left empty due to no multiline support
|
||||
protected override LocalisableString FooterText => default;
|
||||
|
||||
protected override LocalisableString CommitButtonText => CommonStrings.ButtonsPost;
|
||||
protected override LocalisableString GetCommitButtonText(bool isLoggedIn) =>
|
||||
isLoggedIn ? CommonStrings.ButtonsPost : CommentsStrings.GuestButtonNew;
|
||||
|
||||
protected override LocalisableString TextBoxPlaceholder => CommentsStrings.PlaceholderNew;
|
||||
protected override LocalisableString GetTextBoxPlaceholder(bool isLoggedIn) =>
|
||||
isLoggedIn ? CommentsStrings.PlaceholderNew : AuthorizationStrings.RequireLogin;
|
||||
|
||||
protected override void OnCommit(string text)
|
||||
{
|
||||
|
@ -22,8 +22,12 @@ namespace osu.Game.Overlays.Comments
|
||||
public Action<DrawableComment[]>? OnPost;
|
||||
|
||||
protected override LocalisableString FooterText => default;
|
||||
protected override LocalisableString CommitButtonText => CommonStrings.ButtonsReply;
|
||||
protected override LocalisableString TextBoxPlaceholder => CommentsStrings.PlaceholderReply;
|
||||
|
||||
protected override LocalisableString GetCommitButtonText(bool isLoggedIn) =>
|
||||
isLoggedIn ? CommonStrings.ButtonsReply : CommentsStrings.GuestButtonReply;
|
||||
|
||||
protected override LocalisableString GetTextBoxPlaceholder(bool isLoggedIn) =>
|
||||
isLoggedIn ? CommentsStrings.PlaceholderReply : AuthorizationStrings.RequireLogin;
|
||||
|
||||
public ReplyCommentEditor(Comment parent)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user