mirror of
https://github.com/ppy/osu
synced 2025-01-01 20:02:14 +00:00
Implement CommitButton
This commit is contained in:
parent
c022cf72b5
commit
5a3daf1bd7
@ -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()
|
||||
});
|
||||
}
|
||||
|
@ -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<string> 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<Drawable> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user