osu/osu.Game/Overlays/Comments/Buttons/CommentRepliesButton.cs

124 lines
4.3 KiB
C#
Raw Normal View History

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