From 5a3daf1bd71939f6f1c4b34d1911d74b6789a6f1 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 12 Feb 2020 00:57:06 +0300 Subject: [PATCH] Implement CommitButton --- .../Comments/CancellableCommentEditor.cs | 4 +- osu.Game/Overlays/Comments/CommentEditor.cs | 72 ++++++++++++++++++- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/Comments/CancellableCommentEditor.cs b/osu.Game/Overlays/Comments/CancellableCommentEditor.cs index ad5686910a..f58627efb3 100644 --- a/osu.Game/Overlays/Comments/CancellableCommentEditor.cs +++ b/osu.Game/Overlays/Comments/CancellableCommentEditor.cs @@ -22,8 +22,8 @@ namespace osu.Game.Overlays.Comments { ButtonsContainer.Add(new CancelButton { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, Action = () => OnCancel?.Invoke() }); } diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index bb8ae7f114..624e15a047 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -10,6 +10,10 @@ using osu.Game.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.Sprites; using osuTK.Graphics; +using osu.Game.Graphics.UserInterface; +using System.Collections.Generic; +using System; +using osuTK; namespace osu.Game.Overlays.Comments { @@ -17,6 +21,8 @@ namespace osu.Game.Overlays.Comments { private const int side_padding = 8; + public Action OnCommit; + protected abstract string FooterText { get; } protected abstract string CommitButtonText { get; } @@ -28,6 +34,9 @@ namespace osu.Game.Overlays.Comments [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider) { + EditorTextbox textbox; + CommitButton commitButton; + RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; Masking = true; @@ -49,7 +58,7 @@ namespace osu.Game.Overlays.Comments Direction = FillDirection.Vertical, Children = new Drawable[] { - new EditorTextbox + textbox = new EditorTextbox { Height = 40, RelativeSizeAxes = Axes.X, @@ -77,12 +86,21 @@ namespace osu.Game.Overlays.Comments Origin = Anchor.CentreRight, AutoSizeAxes = Axes.Both, Direction = FillDirection.Horizontal, + Spacing = new Vector2(5, 0), + Child = commitButton = new CommitButton(CommitButtonText) + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + Action = () => OnCommit?.Invoke(textbox.Text) + } } } } } } }); + + textbox.OnCommit += (u, v) => commitButton.Click(); } private class EditorTextbox : BasicTextBox @@ -107,7 +125,6 @@ namespace osu.Game.Overlays.Comments BackgroundCommit = Color4.LightSkyBlue; } - protected override SpriteText CreatePlaceholder() => placeholder = new OsuSpriteText { Font = OsuFont.GetFont(weight: FontWeight.Regular), @@ -115,5 +132,56 @@ namespace osu.Game.Overlays.Comments protected override Drawable GetDrawableCharacter(char c) => new OsuSpriteText { Text = c.ToString(), Font = OsuFont.GetFont(size: CalculatedTextSize) }; } + + private class CommitButton : LoadingButton + { + private const int duration = 200; + + protected override IEnumerable EffectTargets => new[] { background }; + + private OsuSpriteText drawableText; + private Box background; + + public CommitButton(string text) + { + AutoSizeAxes = Axes.Both; + LoadingAnimationSize = new Vector2(10); + + drawableText.Text = text; + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider colourProvider) + { + IdleColour = colourProvider.GetColour(0.5f, 0.45f); + HoverColour = colourProvider.GetColour(0.5f, 0.6f); + } + + protected override Drawable CreateContent() => new CircularContainer + { + Masking = true, + Height = 25, + AutoSizeAxes = Axes.X, + Children = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both + }, + drawableText = new OsuSpriteText + { + AlwaysPresent = true, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), + Margin = new MarginPadding { Horizontal = 20 } + } + } + }; + + protected override void OnLoadStarted() => drawableText.FadeOut(duration, Easing.OutQuint); + + protected override void OnLoadFinished() => drawableText.FadeIn(duration, Easing.OutQuint); + } } }