osu/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs

95 lines
2.9 KiB
C#
Raw Normal View History

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 System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-02-11 23:05:45 +00:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2020-02-11 15:46:49 +00:00
using osu.Game.Overlays;
using osu.Game.Overlays.Comments;
2020-02-11 17:47:51 +00:00
using osuTK;
2020-02-11 15:46:49 +00:00
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneCommentEditor : OsuTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(CommentEditor),
2020-02-11 17:47:51 +00:00
typeof(CancellableCommentEditor),
2020-02-11 15:46:49 +00:00
};
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
2020-02-11 23:05:45 +00:00
private readonly OsuSpriteText text;
private readonly TestCommentEditor commentEditor;
private readonly TestCancellableCommentEditor cancellableCommentEditor;
2020-02-11 15:46:49 +00:00
public TestSceneCommentEditor()
{
2020-02-11 23:05:45 +00:00
Add(new Container
{
AutoSizeAxes = Axes.Both,
Child = text = new OsuSpriteText
{
Font = OsuFont.GetFont()
}
});
2020-02-11 17:47:51 +00:00
Add(new FillFlowContainer
2020-02-11 15:46:49 +00:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Y,
Width = 800,
2020-02-11 17:47:51 +00:00
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 20),
Children = new Drawable[]
{
2020-02-11 23:05:45 +00:00
commentEditor = new TestCommentEditor
{
OnCommit = onCommit
},
cancellableCommentEditor = new TestCancellableCommentEditor
{
OnCommit = onCommit
}
2020-02-11 17:47:51 +00:00
}
2020-02-11 15:46:49 +00:00
});
}
2020-02-11 23:05:45 +00:00
private void onCommit(string value)
{
text.Text = $@"Invoked text: {value}";
Scheduler.AddDelayed(() =>
{
commentEditor.IsLoading = false;
cancellableCommentEditor.IsLoading = false;
}, 500);
}
2020-02-11 15:46:49 +00:00
private class TestCommentEditor : CommentEditor
{
2020-02-11 17:08:24 +00:00
protected override string FooterText => @"Footer text. And it is pretty long. Cool.";
2020-02-11 15:46:49 +00:00
2020-02-11 17:08:24 +00:00
protected override string CommitButtonText => @"Commit";
protected override string TextboxPlaceholderText => @"This textbox is empty";
2020-02-11 15:46:49 +00:00
}
2020-02-11 17:47:51 +00:00
private class TestCancellableCommentEditor : CancellableCommentEditor
{
protected override string FooterText => @"Wow, another one. Sicc";
protected override string CommitButtonText => @"Save";
protected override string TextboxPlaceholderText => @"Miltiline textboxes soon";
}
2020-02-11 15:46:49 +00:00
}
}