Merge branch 'master' into update-framework

This commit is contained in:
Bartłomiej Dach
2022-11-26 16:19:36 +01:00
40 changed files with 252 additions and 180 deletions

View File

@ -172,7 +172,7 @@ namespace osu.Game.Graphics.Backgrounds
// Limited by the maximum size of QuadVertexBuffer for safety.
const int max_triangles = ushort.MaxValue / (IRenderer.VERTICES_PER_QUAD + 2);
AimCount = (int)Math.Min(max_triangles, DrawWidth * DrawHeight * 0.0005f * SpawnRatio);
AimCount = (int)Math.Clamp(DrawWidth * 0.02f * SpawnRatio, 1, max_triangles);
int currentCount = parts.Count;

View File

@ -4,17 +4,16 @@
#nullable disable
using osu.Framework.Allocation;
using osu.Game.Graphics.UserInterfaceV2;
namespace osu.Game.Graphics.UserInterface
{
public partial class DangerousTriangleButton : TriangleButton
public partial class DangerousRoundedButton : RoundedButton
{
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundColour = colours.PinkDark;
Triangles.ColourDark = colours.PinkDarker;
Triangles.ColourLight = colours.Pink;
}
}
}

View File

@ -37,7 +37,7 @@ namespace osu.Game.Graphics.UserInterface
/// <summary>
/// Sets a custom background colour to this button, replacing the provided default.
/// </summary>
public Color4 BackgroundColour
public virtual Color4 BackgroundColour
{
get => backgroundColour ?? defaultBackgroundColour;
set
@ -90,6 +90,7 @@ namespace osu.Game.Graphics.UserInterface
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue,
},
Hover = new Box
{
@ -141,13 +142,15 @@ namespace osu.Game.Graphics.UserInterface
return base.OnClick(e);
}
protected virtual float HoverLayerFinalAlpha => 0.1f;
protected override bool OnHover(HoverEvent e)
{
if (Enabled.Value)
{
Hover.FadeTo(0.2f, 40, Easing.OutQuint)
.Then()
.FadeTo(0.1f, 800, Easing.OutQuint);
.FadeTo(HoverLayerFinalAlpha, 800, Easing.OutQuint);
}
return base.OnHover(e);

View File

@ -1,42 +0,0 @@
// 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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Graphics.Backgrounds;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// A button with moving triangles in the background.
/// </summary>
public partial class TriangleButton : OsuButton, IFilterable
{
protected Triangles Triangles { get; private set; }
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Add(Triangles = new Triangles
{
RelativeSizeAxes = Axes.Both,
ColourDark = colours.BlueDarker,
ColourLight = colours.Blue,
});
}
public virtual IEnumerable<LocalisableString> FilterTerms => new[] { Text };
public bool MatchingFilter
{
set => this.FadeTo(value ? 1 : 0);
}
public bool FilteringActive { get; set; }
}
}

View File

@ -1,19 +1,29 @@
// 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 System.Diagnostics;
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 partial class RoundedButton : OsuButton, IFilterable
{
protected TrianglesV2? Triangles { get; private set; }
protected override float HoverLayerFinalAlpha => 0;
private Color4? triangleGradientSecondColour;
public override float Height
{
get => base.Height;
@ -26,19 +36,65 @@ namespace osu.Game.Graphics.UserInterfaceV2
}
}
[BackgroundDependencyLoader(true)]
private void load(OsuColour colours)
public override Color4 BackgroundColour
{
// 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;
get => base.BackgroundColour;
set
{
base.BackgroundColour = value;
triangleGradientSecondColour = BackgroundColour.Lighten(0.2f);
updateColours();
}
}
[BackgroundDependencyLoader(true)]
private void load(OverlayColourProvider? overlayColourProvider, OsuColour colours)
{
// Many buttons have local colours, but this provides a sane default for all other cases.
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;
Debug.Assert(triangleGradientSecondColour != null);
Triangles.ColourTop = triangleGradientSecondColour.Value;
Triangles.ColourBottom = BackgroundColour;
}
protected override bool OnHover(HoverEvent e)
{
Debug.Assert(triangleGradientSecondColour != null);
Background.FadeColour(triangleGradientSecondColour.Value, 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;