1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:07:38 +08:00

Disable button when there is no text

This commit is contained in:
ansel 2022-10-20 18:12:20 +03:00
parent ed39481932
commit 635900085c

View File

@ -2,11 +2,11 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
@ -19,8 +19,8 @@ namespace osu.Game.Overlays.Comments
{
private readonly DrawableComment comment;
private OsuEnumDropdown<CommentReportReason> reason = null!;
private OsuTextBox info = null!;
private ShakeContainer shaker = null!;
private readonly Bindable<string> commentText = new Bindable<string>();
private RoundedButton submitButton = null!;
public ReportCommentPopover(DrawableComment comment)
{
@ -64,20 +64,13 @@ namespace osu.Game.Overlays.Comments
Text = UsersStrings.ReportComments,
Font = OsuFont.Torus.With(size: 20),
},
info = new OsuTextBox
new OsuTextBox
{
RelativeSizeAxes = Axes.X,
PlaceholderText = UsersStrings.ReportPlaceholder
PlaceholderText = UsersStrings.ReportPlaceholder,
Current = commentText
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = shaker = new ShakeContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = new RoundedButton
submitButton = new RoundedButton
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
@ -88,24 +81,20 @@ namespace osu.Game.Overlays.Comments
Margin = new MarginPadding { Bottom = 5, Top = 10 },
}
}
}
}
};
commentText.BindValueChanged(e =>
{
submitButton.Enabled.Value = !string.IsNullOrWhiteSpace(e.NewValue);
}, true);
}
private void send()
{
string infoValue = info.Current.Value;
var reasonValue = reason.Current.Value;
if (string.IsNullOrWhiteSpace(infoValue))
{
shaker.Shake();
if (string.IsNullOrWhiteSpace(commentText.Value))
return;
}
this.HidePopover();
comment.ReportComment(reasonValue, infoValue);
comment.ReportComment(reason.Current.Value, commentText.Value);
}
}
}