1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 07:02:54 +08:00

Merge pull request #21737 from bdach/restore-default-button-hit-area

Fix restore default button having a minuscule hit area
This commit is contained in:
Salman Ahmed 2022-12-22 14:08:46 +03:00 committed by GitHub
commit 15a162a943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,18 +7,20 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osuTK; using osuTK;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public partial class RestoreDefaultValueButton<T> : OsuButton, IHasTooltip, IHasCurrentValue<T> public partial class RestoreDefaultValueButton<T> : OsuClickableContainer, IHasCurrentValue<T>
{ {
public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks; public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks;
@ -51,15 +53,32 @@ namespace osu.Game.Overlays
private const float size = 4; private const float size = 4;
private CircularContainer circle = null!;
private Box background = null!;
public RestoreDefaultValueButton()
: base(HoverSampleSet.Button)
{
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colour) private void load(OsuColour colour)
{ {
BackgroundColour = colour.Lime1; // size intentionally much larger than actual drawn content, so that the button is easier to click.
Size = new Vector2(3 * size); Size = new Vector2(3 * size);
Content.RelativeSizeAxes = Axes.None; Add(circle = new CircularContainer
Content.Size = new Vector2(size); {
Content.CornerRadius = size / 2; Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(size),
Masking = true,
Child = background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colour.Lime1
}
});
Alpha = 0f; Alpha = 0f;
@ -77,7 +96,7 @@ namespace osu.Game.Overlays
FinishTransforms(true); FinishTransforms(true);
} }
public LocalisableString TooltipText => "revert to default"; public override LocalisableString TooltipText => "revert to default";
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
@ -104,8 +123,8 @@ namespace osu.Game.Overlays
if (!Current.Disabled) if (!Current.Disabled)
{ {
this.FadeTo(Current.IsDefault ? 0 : 1, fade_duration, Easing.OutQuint); this.FadeTo(Current.IsDefault ? 0 : 1, fade_duration, Easing.OutQuint);
Background.FadeColour(IsHovered ? colours.Lime0 : colours.Lime1, fade_duration, Easing.OutQuint); background.FadeColour(IsHovered ? colours.Lime0 : colours.Lime1, fade_duration, Easing.OutQuint);
Content.TweenEdgeEffectTo(new EdgeEffectParameters circle.TweenEdgeEffectTo(new EdgeEffectParameters
{ {
Colour = (IsHovered ? colours.Lime1 : colours.Lime3).Opacity(0.4f), Colour = (IsHovered ? colours.Lime1 : colours.Lime3).Opacity(0.4f),
Radius = IsHovered ? 8 : 4, Radius = IsHovered ? 8 : 4,
@ -114,8 +133,8 @@ namespace osu.Game.Overlays
} }
else else
{ {
Background.FadeColour(colours.Lime3, fade_duration, Easing.OutQuint); background.FadeColour(colours.Lime3, fade_duration, Easing.OutQuint);
Content.TweenEdgeEffectTo(new EdgeEffectParameters circle.TweenEdgeEffectTo(new EdgeEffectParameters
{ {
Colour = colours.Lime3.Opacity(0.1f), Colour = colours.Lime3.Opacity(0.1f),
Radius = 2, Radius = 2,