1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 14:07:27 +08:00
osu-lazer/osu.Game/Overlays/Comments/Buttons/CommentRepliesButton.cs

114 lines
4.2 KiB
C#
Raw Normal View History

2020-07-11 12:47:17 +08: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;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
2020-07-11 13:13:11 +08:00
using osu.Framework.Input.Events;
2020-07-11 12:47:17 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2020-07-11 13:13:11 +08:00
using osu.Game.Graphics.UserInterface;
2020-07-11 12:47:17 +08:00
using osuTK;
namespace osu.Game.Overlays.Comments.Buttons
{
2020-07-11 13:13:11 +08:00
public abstract class CommentRepliesButton : CompositeDrawable
2020-07-11 12:47:17 +08:00
{
2020-07-12 17:27:26 +08:00
protected string Text
{
get => text.Text;
set => text.Text = value;
}
2020-07-11 13:13:11 +08:00
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
2020-07-11 12:47:17 +08:00
private readonly SpriteIcon icon;
2020-07-12 17:27:26 +08:00
private readonly Box background;
private readonly OsuSpriteText text;
2020-07-11 12:47:17 +08:00
2020-07-12 17:39:48 +08:00
protected CommentRepliesButton()
2020-07-11 12:47:17 +08:00
{
2020-07-11 13:13:11 +08:00
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
2020-07-11 12:47:17 +08:00
{
2020-07-11 13:13:11 +08:00
new CircularContainer
2020-07-11 12:47:17 +08:00
{
2020-07-11 13:13:11 +08:00
AutoSizeAxes = Axes.Both,
Masking = true,
Children = new Drawable[]
2020-07-11 12:47:17 +08:00
{
2020-07-11 13:13:11 +08:00
background = new Box
2020-07-11 12:47:17 +08:00
{
2020-07-12 17:27:26 +08:00
RelativeSizeAxes = Axes.Both
2020-07-11 12:47:17 +08:00
},
2020-07-11 13:13:11 +08:00
new Container
2020-07-11 12:47:17 +08:00
{
AutoSizeAxes = Axes.Both,
2020-07-11 13:13:11 +08:00
Margin = new MarginPadding
2020-07-11 12:47:17 +08:00
{
2020-07-11 13:13:11 +08:00
Vertical = 5,
Horizontal = 10,
},
Child = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(15, 0),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
2020-07-11 12:47:17 +08:00
{
2020-07-12 17:27:26 +08:00
text = new OsuSpriteText
2020-07-11 13:13:11 +08:00
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AlwaysPresent = true,
2020-07-12 17:27:26 +08:00
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)
2020-07-11 13:13:11 +08:00
},
icon = new SpriteIcon
2020-07-11 13:13:11 +08:00
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(7.5f),
2020-07-12 17:27:26 +08:00
Icon = FontAwesome.Solid.ChevronDown
2020-07-11 13:13:11 +08:00
}
2020-07-11 12:47:17 +08:00
}
}
}
}
2020-07-11 13:13:11 +08:00
},
new HoverClickSounds(),
};
2020-07-11 12:47:17 +08:00
}
2020-07-12 17:27:26 +08:00
[BackgroundDependencyLoader]
private void load()
{
background.Colour = colourProvider.Background2;
icon.Colour = colourProvider.Foreground1;
2020-07-12 17:27:26 +08:00
}
2020-07-11 12:47:17 +08:00
2020-07-14 08:01:14 +08:00
protected void SetIconDirection(bool upwards) => icon.ScaleTo(new Vector2(1, upwards ? -1 : 1));
public void ToggleTextVisibility(bool visible) => text.FadeTo(visible ? 1 : 0, 200, Easing.OutQuint);
2020-07-11 13:13:11 +08:00
protected override bool OnHover(HoverEvent e)
2020-07-11 12:47:17 +08:00
{
2020-07-11 13:13:11 +08:00
base.OnHover(e);
background.FadeColour(colourProvider.Background1, 200, Easing.OutQuint);
icon.FadeColour(colourProvider.Light1, 200, Easing.OutQuint);
2020-07-11 13:13:11 +08:00
return true;
}
2020-07-11 12:47:17 +08:00
2020-07-11 13:13:11 +08:00
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
background.FadeColour(colourProvider.Background2, 200, Easing.OutQuint);
icon.FadeColour(colourProvider.Foreground1, 200, Easing.OutQuint);
2020-07-11 13:13:11 +08:00
}
2020-07-11 12:47:17 +08:00
}
}