1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +08:00

Make button text a property

This commit is contained in:
Andrei Zavatski 2020-07-12 12:27:26 +03:00
parent 40aa6c7453
commit da40f29b44
4 changed files with 29 additions and 19 deletions

View File

@ -36,7 +36,10 @@ namespace osu.Game.Tests.Visual.UserInterface
private class TestButton : CommentRepliesButton
{
protected override string GetText() => "sample text";
public TestButton()
{
Text = "sample text";
}
}
}
}

View File

@ -19,14 +19,20 @@ namespace osu.Game.Overlays.Comments.Buttons
{
public Action Action { get; set; }
protected string Text
{
get => text.Text;
set => text.Text = value;
}
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
protected SpriteIcon Icon;
private Box background;
protected readonly SpriteIcon Icon;
private readonly Box background;
private readonly OsuSpriteText text;
[BackgroundDependencyLoader]
private void load()
public CommentRepliesButton()
{
AutoSizeAxes = Axes.Both;
Margin = new MarginPadding
@ -43,8 +49,7 @@ namespace osu.Game.Overlays.Comments.Buttons
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background2
RelativeSizeAxes = Axes.Both
},
new Container
{
@ -63,20 +68,18 @@ namespace osu.Game.Overlays.Comments.Buttons
Origin = Anchor.Centre,
Children = new Drawable[]
{
new OsuSpriteText
text = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
Text = GetText()
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)
},
Icon = new SpriteIcon
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(7.5f),
Icon = FontAwesome.Solid.ChevronDown,
Colour = colourProvider.Foreground1
Icon = FontAwesome.Solid.ChevronDown
}
}
}
@ -87,7 +90,12 @@ namespace osu.Game.Overlays.Comments.Buttons
};
}
protected abstract string GetText();
[BackgroundDependencyLoader]
private void load()
{
background.Colour = colourProvider.Background2;
Icon.Colour = colourProvider.Foreground1;
}
protected override bool OnHover(HoverEvent e)
{

View File

@ -5,6 +5,9 @@ namespace osu.Game.Overlays.Comments.Buttons
{
public class LoadRepliesButton : CommentRepliesButton
{
protected override string GetText() => "load replies";
public LoadRepliesButton()
{
Text = "load replies";
}
}
}

View File

@ -13,11 +13,9 @@ namespace osu.Game.Overlays.Comments.Buttons
{
public readonly BindableBool Expanded = new BindableBool(true);
private readonly int count;
public ShowRepliesButton(int count)
{
this.count = count;
Text = "reply".ToQuantity(count);
}
protected override void LoadComplete()
@ -36,7 +34,5 @@ namespace osu.Game.Overlays.Comments.Buttons
Expanded.Toggle();
return base.OnClick(e);
}
protected override string GetText() => "reply".ToQuantity(count);
}
}