osu/osu.Game/Overlays/Comments/CommentEditor.cs

111 lines
3.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 osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2020-02-11 17:08:24 +00:00
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Graphics.Sprites;
using osuTK.Graphics;
2020-02-11 15:46:49 +00:00
namespace osu.Game.Overlays.Comments
{
public abstract class CommentEditor : CompositeDrawable
{
private const int footer_height = 40;
2020-02-11 17:08:24 +00:00
private const int side_padding = 8;
protected abstract string FooterText { get; }
protected abstract string CommitButtonText { get; }
protected abstract string TextboxPlaceholderText { get; }
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[]
{
2020-02-11 17:08:24 +00:00
new EditorTextbox
{
Height = footer_height,
RelativeSizeAxes = Axes.X,
PlaceholderText = TextboxPlaceholderText
},
new Container
2020-02-11 15:46:49 +00:00
{
2020-02-11 17:08:24 +00:00
Name = "Footer",
RelativeSizeAxes = Axes.X,
Height = footer_height,
Padding = new MarginPadding { Horizontal = side_padding },
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
Text = FooterText
}
}
2020-02-11 15:46:49 +00:00
}
}
}
});
}
2020-02-11 17:08:24 +00:00
private class EditorTextbox : BasicTextBox
{
protected override float LeftRightPadding => side_padding;
protected override Color4 SelectionColour => Color4.LightSkyBlue;
2020-02-11 15:46:49 +00:00
2020-02-11 17:08:24 +00:00
private OsuSpriteText placeholder;
public EditorTextbox()
{
Masking = false;
TextContainer.Height = 0.4f;
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
BackgroundUnfocused = BackgroundFocused = colourProvider.Background5;
placeholder.Colour = colourProvider.Background3;
BackgroundCommit = Color4.LightSkyBlue;
}
protected override SpriteText CreatePlaceholder() => placeholder = new OsuSpriteText
{
Font = OsuFont.GetFont(weight: FontWeight.Regular),
};
protected override Drawable GetDrawableCharacter(char c) => new OsuSpriteText { Text = c.ToString(), Font = OsuFont.GetFont(size: CalculatedTextSize) };
}
2020-02-11 15:46:49 +00:00
}
}