Update RoundedButton to have new triangles design

This commit is contained in:
Dean Herbert
2022-11-24 15:04:54 +09:00
parent 44a71741e4
commit 40f706155f
4 changed files with 63 additions and 18 deletions

View File

@ -1,19 +1,28 @@
// 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.
#nullable disable
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osuTK.Graphics;
namespace osu.Game.Graphics.UserInterfaceV2
{
public class RoundedButton : OsuButton, IFilterable
{
private TrianglesV2? triangles;
protected override float HoverLayerFinalAlpha => 0;
private Color4 triangleGradientSecondColour = Color4.Transparent;
public override float Height
{
get => base.Height;
@ -26,19 +35,63 @@ namespace osu.Game.Graphics.UserInterfaceV2
}
}
public override Color4 BackgroundColour
{
get => base.BackgroundColour;
set
{
base.BackgroundColour = value;
triangleGradientSecondColour = BackgroundColour.Lighten(0.2f);
updateColours();
}
}
[BackgroundDependencyLoader(true)]
private void load(OsuColour colours)
private void load(OverlayColourProvider? overlayColourProvider, OsuColour colours)
{
// According to flyte, buttons are supposed to have explicit colours for now.
// Not sure this is the correct direction, but we haven't decided on an `OverlayColourProvider` stand-in yet.
// This is a better default. See `SettingsButton` for an override which uses `OverlayColourProvider`.
DefaultBackgroundColour = colours.Blue3;
DefaultBackgroundColour = overlayColourProvider?.Colour3 ?? colours.Blue3;
triangleGradientSecondColour = overlayColourProvider?.Colour1 ?? colours.Blue3.Lighten(0.2f);
}
protected override void LoadComplete()
{
base.LoadComplete();
updateCornerRadius();
Add(triangles = new TrianglesV2
{
Thickness = 0.02f,
SpawnRatio = 0.6f,
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue,
});
updateColours();
}
private void updateColours()
{
if (triangles == null)
return;
triangles.ColourTop = triangleGradientSecondColour;
triangles.ColourBottom = BackgroundColour;
}
protected override bool OnHover(HoverEvent e)
{
Background.FadeColour(triangleGradientSecondColour, 300, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
Background.FadeColour(BackgroundColour, 300, Easing.OutQuint);
base.OnHoverLost(e);
}
private void updateCornerRadius() => Content.CornerRadius = DrawHeight / 2;