2020-10-01 15:34:34 +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 System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Input.Events;
|
2021-06-26 01:10:04 +08:00
|
|
|
using osu.Framework.Localisation;
|
2020-10-01 15:34:34 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components
|
|
|
|
{
|
2021-04-24 12:46:38 +08:00
|
|
|
public sealed partial class SelectionBoxButton : SelectionBoxControl, IHasTooltip
|
2020-10-01 15:34:34 +08:00
|
|
|
{
|
2023-06-27 16:01:06 +08:00
|
|
|
private SpriteIcon icon = null!;
|
2020-10-01 15:34:34 +08:00
|
|
|
|
|
|
|
private readonly IconUsage iconUsage;
|
|
|
|
|
2023-06-27 16:01:06 +08:00
|
|
|
public Action? Action;
|
2020-10-01 15:34:34 +08:00
|
|
|
|
2024-09-21 20:59:47 +08:00
|
|
|
public event Action? HoverLost;
|
|
|
|
|
2021-04-24 12:46:38 +08:00
|
|
|
public SelectionBoxButton(IconUsage iconUsage, string tooltip)
|
2020-10-01 15:34:34 +08:00
|
|
|
{
|
|
|
|
this.iconUsage = iconUsage;
|
|
|
|
|
|
|
|
TooltipText = tooltip;
|
|
|
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-04-24 12:46:38 +08:00
|
|
|
Size = new Vector2(20);
|
2020-10-01 15:34:34 +08:00
|
|
|
AddInternal(icon = new SpriteIcon
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Size = new Vector2(0.5f),
|
|
|
|
Icon = iconUsage,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
2023-06-27 16:01:06 +08:00
|
|
|
Circle.FlashColour(Colours.GrayF, 300);
|
|
|
|
|
2021-05-06 02:50:11 +08:00
|
|
|
TriggerOperationStarted();
|
2020-10-01 15:34:34 +08:00
|
|
|
Action?.Invoke();
|
2021-12-10 13:04:31 +08:00
|
|
|
TriggerOperationEnded();
|
2020-10-01 15:34:34 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateHoverState()
|
|
|
|
{
|
|
|
|
base.UpdateHoverState();
|
2021-05-04 11:40:43 +08:00
|
|
|
icon.FadeColour(!IsHeld && IsHovered ? Color4.White : Color4.Black, TRANSFORM_DURATION, Easing.OutQuint);
|
2020-10-01 15:34:34 +08:00
|
|
|
}
|
|
|
|
|
2024-09-21 20:59:47 +08:00
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
|
|
|
HoverLost?.Invoke();
|
|
|
|
}
|
|
|
|
|
2021-06-26 01:10:04 +08:00
|
|
|
public LocalisableString TooltipText { get; }
|
2020-10-01 15:34:34 +08:00
|
|
|
}
|
|
|
|
}
|