mirror of
https://github.com/ppy/osu.git
synced 2025-02-05 15:23:11 +08:00
Update RoundedButton
to have new triangles design
This commit is contained in:
parent
44a71741e4
commit
40f706155f
@ -37,7 +37,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
},
|
},
|
||||||
new SettingsButton
|
new SettingsButton
|
||||||
{
|
{
|
||||||
Text = "Test button",
|
Text = "Test settings button",
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Enabled = { BindTarget = enabled },
|
Enabled = { BindTarget = enabled },
|
||||||
|
@ -37,7 +37,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets a custom background colour to this button, replacing the provided default.
|
/// Sets a custom background colour to this button, replacing the provided default.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color4 BackgroundColour
|
public virtual Color4 BackgroundColour
|
||||||
{
|
{
|
||||||
get => backgroundColour ?? defaultBackgroundColour;
|
get => backgroundColour ?? defaultBackgroundColour;
|
||||||
set
|
set
|
||||||
@ -90,6 +90,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Depth = float.MaxValue,
|
||||||
},
|
},
|
||||||
Hover = new Box
|
Hover = new Box
|
||||||
{
|
{
|
||||||
@ -141,13 +142,15 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
return base.OnClick(e);
|
return base.OnClick(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual float HoverLayerFinalAlpha => 0.1f;
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
if (Enabled.Value)
|
if (Enabled.Value)
|
||||||
{
|
{
|
||||||
Hover.FadeTo(0.2f, 40, Easing.OutQuint)
|
Hover.FadeTo(0.2f, 40, Easing.OutQuint)
|
||||||
.Then()
|
.Then()
|
||||||
.FadeTo(0.1f, 800, Easing.OutQuint);
|
.FadeTo(HoverLayerFinalAlpha, 800, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.OnHover(e);
|
return base.OnHover(e);
|
||||||
|
@ -1,19 +1,28 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Game.Graphics.Backgrounds;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterfaceV2
|
namespace osu.Game.Graphics.UserInterfaceV2
|
||||||
{
|
{
|
||||||
public class RoundedButton : OsuButton, IFilterable
|
public class RoundedButton : OsuButton, IFilterable
|
||||||
{
|
{
|
||||||
|
private TrianglesV2? triangles;
|
||||||
|
|
||||||
|
protected override float HoverLayerFinalAlpha => 0;
|
||||||
|
|
||||||
|
private Color4 triangleGradientSecondColour = Color4.Transparent;
|
||||||
|
|
||||||
public override float Height
|
public override float Height
|
||||||
{
|
{
|
||||||
get => base.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)]
|
[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.
|
// 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.
|
// 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`.
|
// 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()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
updateCornerRadius();
|
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;
|
private void updateCornerRadius() => Content.CornerRadius = DrawHeight / 2;
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osu.Game.Graphics.UserInterfaceV2;
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings
|
namespace osu.Game.Overlays.Settings
|
||||||
@ -23,12 +18,6 @@ namespace osu.Game.Overlays.Settings
|
|||||||
Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS, Right = SettingsPanel.CONTENT_MARGINS };
|
Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS, Right = SettingsPanel.CONTENT_MARGINS };
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
|
||||||
private void load([CanBeNull] OverlayColourProvider overlayColourProvider, OsuColour colours)
|
|
||||||
{
|
|
||||||
DefaultBackgroundColour = overlayColourProvider?.Highlight1 ?? colours.Blue3;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalisableString TooltipText { get; set; }
|
public LocalisableString TooltipText { get; set; }
|
||||||
|
|
||||||
public override IEnumerable<LocalisableString> FilterTerms
|
public override IEnumerable<LocalisableString> FilterTerms
|
||||||
|
Loading…
Reference in New Issue
Block a user