2021-10-11 02:21:41 +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.
|
|
|
|
|
2021-10-11 02:32:56 +08:00
|
|
|
using System.Collections.Generic;
|
2022-11-24 15:33:01 +08:00
|
|
|
using System.Diagnostics;
|
2022-05-10 01:55:26 +08:00
|
|
|
using osu.Framework.Allocation;
|
2022-11-24 14:04:54 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2021-10-11 02:21:41 +08:00
|
|
|
using osu.Framework.Graphics;
|
2022-11-30 09:09:46 +08:00
|
|
|
using osu.Framework.Graphics.Colour;
|
2021-10-11 02:32:56 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-11-24 14:04:54 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2022-05-16 13:09:37 +08:00
|
|
|
using osu.Framework.Localisation;
|
2022-11-24 14:04:54 +08:00
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2021-10-11 02:21:41 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-11-24 14:04:54 +08:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osuTK.Graphics;
|
2021-10-11 02:21:41 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterfaceV2
|
|
|
|
{
|
2021-10-11 02:32:56 +08:00
|
|
|
public partial class RoundedButton : OsuButton, IFilterable
|
2021-10-11 02:21:41 +08:00
|
|
|
{
|
2022-11-25 19:18:35 +08:00
|
|
|
protected TrianglesV2? Triangles { get; private set; }
|
2022-11-24 14:04:54 +08:00
|
|
|
|
|
|
|
protected override float HoverLayerFinalAlpha => 0;
|
|
|
|
|
2022-11-24 15:33:01 +08:00
|
|
|
private Color4? triangleGradientSecondColour;
|
2022-11-24 14:04:54 +08:00
|
|
|
|
2021-10-11 02:21:41 +08:00
|
|
|
public override float Height
|
|
|
|
{
|
|
|
|
get => base.Height;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
base.Height = value;
|
|
|
|
|
|
|
|
if (IsLoaded)
|
|
|
|
updateCornerRadius();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-24 14:04:54 +08:00
|
|
|
public override Color4 BackgroundColour
|
|
|
|
{
|
|
|
|
get => base.BackgroundColour;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
base.BackgroundColour = value;
|
|
|
|
triangleGradientSecondColour = BackgroundColour.Lighten(0.2f);
|
|
|
|
updateColours();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-10 01:55:26 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
2022-11-24 14:04:54 +08:00
|
|
|
private void load(OverlayColourProvider? overlayColourProvider, OsuColour colours)
|
2022-05-10 01:55:26 +08:00
|
|
|
{
|
2022-11-25 21:10:20 +08:00
|
|
|
// Many buttons have local colours, but this provides a sane default for all other cases.
|
2022-11-24 14:04:54 +08:00
|
|
|
DefaultBackgroundColour = overlayColourProvider?.Colour3 ?? colours.Blue3;
|
2022-11-24 15:33:01 +08:00
|
|
|
triangleGradientSecondColour ??= overlayColourProvider?.Colour1 ?? colours.Blue3.Lighten(0.2f);
|
2022-05-10 01:55:26 +08:00
|
|
|
}
|
|
|
|
|
2021-10-11 02:21:41 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2022-11-24 14:04:54 +08:00
|
|
|
|
2021-10-11 02:21:41 +08:00
|
|
|
updateCornerRadius();
|
2022-11-24 14:04:54 +08:00
|
|
|
|
2022-11-25 19:18:35 +08:00
|
|
|
Add(Triangles = new TrianglesV2
|
2022-11-24 14:04:54 +08:00
|
|
|
{
|
|
|
|
Thickness = 0.02f,
|
|
|
|
SpawnRatio = 0.6f,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Depth = float.MaxValue,
|
|
|
|
});
|
|
|
|
|
|
|
|
updateColours();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateColours()
|
|
|
|
{
|
2022-11-25 19:18:35 +08:00
|
|
|
if (Triangles == null)
|
2022-11-24 14:04:54 +08:00
|
|
|
return;
|
|
|
|
|
2022-11-24 15:33:01 +08:00
|
|
|
Debug.Assert(triangleGradientSecondColour != null);
|
|
|
|
|
2022-11-30 09:09:46 +08:00
|
|
|
Triangles.Colour = ColourInfo.GradientVertical(triangleGradientSecondColour.Value, BackgroundColour);
|
2022-11-24 14:04:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
2022-11-24 15:33:01 +08:00
|
|
|
Debug.Assert(triangleGradientSecondColour != null);
|
|
|
|
|
|
|
|
Background.FadeColour(triangleGradientSecondColour.Value, 300, Easing.OutQuint);
|
2022-11-24 14:04:54 +08:00
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
Background.FadeColour(BackgroundColour, 300, Easing.OutQuint);
|
|
|
|
base.OnHoverLost(e);
|
2021-10-11 02:21:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateCornerRadius() => Content.CornerRadius = DrawHeight / 2;
|
2021-10-11 02:32:56 +08:00
|
|
|
|
2022-05-16 13:09:37 +08:00
|
|
|
public virtual IEnumerable<LocalisableString> FilterTerms => new[] { Text };
|
2021-10-11 02:32:56 +08:00
|
|
|
|
|
|
|
public bool MatchingFilter
|
|
|
|
{
|
|
|
|
set => this.FadeTo(value ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool FilteringActive { get; set; }
|
2021-10-11 02:21:41 +08:00
|
|
|
}
|
|
|
|
}
|