2020-02-11 15:46:49 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2023-01-09 06:52:08 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-02-11 15:46:49 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2023-01-09 06:52:08 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-02-11 15:46:49 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2023-01-09 06:52:08 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Localisation;
|
2020-02-11 15:46:49 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-02-11 21:57:06 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-11-29 03:17:02 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2023-01-09 06:52:08 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2020-02-11 15:46:49 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Comments
|
|
|
|
|
{
|
|
|
|
|
public abstract partial class CommentEditor : CompositeDrawable
|
|
|
|
|
{
|
2020-02-11 17:08:24 +00:00
|
|
|
|
private const int side_padding = 8;
|
|
|
|
|
|
2022-11-29 02:13:54 +00:00
|
|
|
|
protected abstract LocalisableString FooterText { get; }
|
2020-02-11 17:08:24 +00:00
|
|
|
|
|
2022-11-29 02:13:54 +00:00
|
|
|
|
protected abstract LocalisableString CommitButtonText { get; }
|
2020-02-11 17:08:24 +00:00
|
|
|
|
|
2022-11-29 02:13:54 +00:00
|
|
|
|
protected abstract LocalisableString TextBoxPlaceholder { get; }
|
2020-02-11 15:46:49 +00:00
|
|
|
|
|
2022-11-29 02:17:44 +00:00
|
|
|
|
protected FillFlowContainer ButtonsContainer { get; private set; } = null!;
|
2020-02-11 17:47:51 +00:00
|
|
|
|
|
2023-01-10 23:26:25 +00:00
|
|
|
|
protected readonly Bindable<string> Current = new Bindable<string>(string.Empty);
|
2020-02-11 22:35:08 +00:00
|
|
|
|
|
2023-01-09 20:37:36 +00:00
|
|
|
|
private RoundedButton commitButton = null!;
|
|
|
|
|
private LoadingSpinner loadingSpinner = null!;
|
|
|
|
|
|
2023-01-19 07:08:27 +00:00
|
|
|
|
protected TextBox TextBox { get; private set; } = null!;
|
|
|
|
|
|
2023-01-09 20:37:36 +00:00
|
|
|
|
protected bool ShowLoadingSpinner
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value)
|
|
|
|
|
loadingSpinner.Show();
|
|
|
|
|
else
|
|
|
|
|
loadingSpinner.Hide();
|
2023-01-10 14:57:38 +00:00
|
|
|
|
|
|
|
|
|
updateCommitButtonState();
|
2023-01-09 20:37:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-11 22:35:08 +00:00
|
|
|
|
|
2020-02-11 15:46:49 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2020-02-11 17:08:24 +00:00
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2020-02-11 15:46:49 +00:00
|
|
|
|
Masking = true;
|
|
|
|
|
CornerRadius = 6;
|
2020-02-11 17:08:24 +00:00
|
|
|
|
BorderThickness = 3;
|
|
|
|
|
BorderColour = colourProvider.Background3;
|
2020-02-11 15:46:49 +00:00
|
|
|
|
|
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colourProvider.Background3
|
|
|
|
|
},
|
2020-02-11 17:08:24 +00:00
|
|
|
|
new FillFlowContainer
|
2020-02-11 15:46:49 +00:00
|
|
|
|
{
|
2020-02-11 17:08:24 +00:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-02-11 15:46:49 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2020-02-11 17:08:24 +00:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2020-02-11 15:46:49 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2023-01-19 07:08:27 +00:00
|
|
|
|
TextBox = new EditorTextBox
|
2020-02-11 17:08:24 +00:00
|
|
|
|
{
|
2020-02-11 17:11:22 +00:00
|
|
|
|
Height = 40,
|
2020-02-11 17:08:24 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2020-02-13 20:04:53 +00:00
|
|
|
|
PlaceholderText = TextBoxPlaceholder,
|
2020-02-13 01:06:34 +00:00
|
|
|
|
Current = Current
|
2020-02-11 17:08:24 +00:00
|
|
|
|
},
|
|
|
|
|
new Container
|
2020-02-11 15:46:49 +00:00
|
|
|
|
{
|
2022-11-29 02:17:44 +00:00
|
|
|
|
Name = @"Footer",
|
2020-02-11 17:08:24 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2023-01-12 16:48:11 +00:00
|
|
|
|
Height = 35,
|
2020-02-11 17:08:24 +00:00
|
|
|
|
Padding = new MarginPadding { Horizontal = side_padding },
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
2023-01-12 16:48:11 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
|
2020-02-11 17:08:24 +00:00
|
|
|
|
Text = FooterText
|
2020-02-11 17:47:51 +00:00
|
|
|
|
},
|
2023-01-09 20:37:36 +00:00
|
|
|
|
new FillFlowContainer
|
2020-02-11 17:47:51 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
2020-02-11 21:57:06 +00:00
|
|
|
|
Spacing = new Vector2(5, 0),
|
2023-01-09 20:37:36 +00:00
|
|
|
|
Children = new Drawable[]
|
2020-02-11 21:57:06 +00:00
|
|
|
|
{
|
2023-01-09 20:37:36 +00:00
|
|
|
|
ButtonsContainer = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Name = @"Buttons",
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(5, 0),
|
2023-01-12 16:48:11 +00:00
|
|
|
|
Child = commitButton = new EditorButton
|
2023-01-09 20:37:36 +00:00
|
|
|
|
{
|
|
|
|
|
Text = CommitButtonText,
|
|
|
|
|
Action = () => OnCommit(Current.Value)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
loadingSpinner = new LoadingSpinner
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Size = new Vector2(18),
|
|
|
|
|
},
|
2020-02-11 21:57:06 +00:00
|
|
|
|
}
|
2023-01-09 20:37:36 +00:00
|
|
|
|
},
|
2020-02-11 17:08:24 +00:00
|
|
|
|
}
|
2020-02-11 15:46:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-02-11 21:57:06 +00:00
|
|
|
|
|
2023-01-19 07:08:27 +00:00
|
|
|
|
TextBox.OnCommit += (_, _) => commitButton.TriggerClick();
|
2020-02-11 22:35:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2023-01-10 14:57:38 +00:00
|
|
|
|
Current.BindValueChanged(_ => updateCommitButtonState(), true);
|
2020-02-11 15:46:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 19:51:57 +00:00
|
|
|
|
protected abstract void OnCommit(string text);
|
|
|
|
|
|
2023-01-10 14:57:38 +00:00
|
|
|
|
private void updateCommitButtonState() =>
|
|
|
|
|
commitButton.Enabled.Value = loadingSpinner.State.Value == Visibility.Hidden && !string.IsNullOrEmpty(Current.Value);
|
|
|
|
|
|
2023-01-22 01:08:42 +00:00
|
|
|
|
private partial class EditorTextBox : OsuTextBox
|
2020-02-11 17:08:24 +00:00
|
|
|
|
{
|
|
|
|
|
protected override float LeftRightPadding => side_padding;
|
|
|
|
|
|
2020-02-11 22:35:08 +00:00
|
|
|
|
protected override Color4 SelectionColour => Color4.Gray;
|
2020-02-11 15:46:49 +00:00
|
|
|
|
|
2022-11-29 02:17:44 +00:00
|
|
|
|
private OsuSpriteText placeholder = null!;
|
2020-02-11 17:08:24 +00:00
|
|
|
|
|
2020-02-13 20:04:53 +00:00
|
|
|
|
public EditorTextBox()
|
2020-02-11 17:08:24 +00:00
|
|
|
|
{
|
|
|
|
|
Masking = false;
|
|
|
|
|
TextContainer.Height = 0.4f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
|
{
|
|
|
|
|
BackgroundUnfocused = BackgroundFocused = colourProvider.Background5;
|
|
|
|
|
placeholder.Colour = colourProvider.Background3;
|
2020-02-11 22:35:08 +00:00
|
|
|
|
BackgroundCommit = colourProvider.Background3;
|
2020-02-11 17:08:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override SpriteText CreatePlaceholder() => placeholder = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Regular),
|
|
|
|
|
};
|
|
|
|
|
}
|
2023-01-12 16:48:11 +00:00
|
|
|
|
|
|
|
|
|
protected partial class EditorButton : RoundedButton
|
|
|
|
|
{
|
|
|
|
|
public EditorButton()
|
|
|
|
|
{
|
|
|
|
|
Width = 80;
|
|
|
|
|
Height = 25;
|
|
|
|
|
Anchor = Anchor.CentreRight;
|
|
|
|
|
Origin = Anchor.CentreRight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override SpriteText CreateText()
|
|
|
|
|
{
|
|
|
|
|
var t = base.CreateText();
|
|
|
|
|
t.Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 12);
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-11 15:46:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|