1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-22 12:13:05 +08:00
osu-lazer/osu.Game/Overlays/Comments/Buttons/CommentRepliesButton.cs

112 lines
4.0 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;
2020-07-11 13:13:11 +08:00
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
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;
2020-07-30 09:51:09 +08:00
using static osu.Game.Graphics.UserInterface.ShowMoreButton;
2020-07-11 12:47:17 +08:00
namespace osu.Game.Overlays.Comments.Buttons
{
2022-11-24 13:32:20 +08:00
public abstract partial class CommentRepliesButton : CompositeDrawable
2020-07-11 12:47:17 +08:00
{
protected LocalisableString Text
2020-07-12 17:27:26 +08:00
{
get => text.Text;
set => text.Text = value;
}
2020-07-11 13:13:11 +08:00
[Resolved]
2023-06-23 00:37:25 +08:00
private OverlayColourProvider colourProvider { get; set; } = null!;
2020-07-11 12:47:17 +08:00
2020-07-30 09:51:09 +08:00
private readonly ChevronIcon 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
},
2020-07-30 09:51:09 +08:00
icon = new ChevronIcon
2020-07-11 13:13:11 +08:00
{
Anchor = Anchor.CentreLeft,
2020-07-30 09:51:09 +08:00
Origin = Anchor.CentreLeft
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;
}
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.SetHoveredState(true);
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.SetHoveredState(false);
2020-07-11 13:13:11 +08:00
}
2020-07-11 12:47:17 +08:00
}
}