1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 16:12:54 +08:00

Move out into a separate method

This commit is contained in:
smoogipoo 2020-08-25 15:16:41 +09:00
parent 08078b9513
commit ab8d9be095
11 changed files with 73 additions and 48 deletions

View File

@ -66,7 +66,7 @@ namespace osu.Game.Rulesets.Catch.Skinning
if (result == null)
return null;
result.Value = result.Value.ToLegacyColour();
result.Value = LegacyColourCompatibility.DisallowZeroAlpha(result.Value);
return (IBindable<TValue>)result;
}

View File

@ -75,7 +75,7 @@ namespace osu.Game.Rulesets.Catch.Skinning
{
base.LoadComplete();
accentColour.BindValueChanged(colour => colouredSprite.Colour = colour.NewValue.ToLegacyColour(), true);
accentColour.BindValueChanged(colour => colouredSprite.Colour = LegacyColourCompatibility.DisallowZeroAlpha(colour.NewValue), true);
}
}
}

View File

@ -58,14 +58,20 @@ namespace osu.Game.Rulesets.Mania.Skinning
InternalChildren = new Drawable[]
{
new Box { RelativeSizeAxes = Axes.Both }.WithLegacyColour(backgroundColour),
LegacyColourCompatibility.ApplyWithDoubledAlpha(new Box
{
RelativeSizeAxes = Axes.Both
}, backgroundColour),
new Container
{
RelativeSizeAxes = Axes.Y,
Width = leftLineWidth,
Scale = new Vector2(0.740f, 1),
Alpha = hasLeftLine ? 1 : 0,
Child = new Box { RelativeSizeAxes = Axes.Both }.WithLegacyColour(lineColour)
Child = LegacyColourCompatibility.ApplyWithDoubledAlpha(new Box
{
RelativeSizeAxes = Axes.Both
}, lineColour)
},
new Container
{
@ -75,7 +81,10 @@ namespace osu.Game.Rulesets.Mania.Skinning
Width = rightLineWidth,
Scale = new Vector2(0.740f, 1),
Alpha = hasRightLine ? 1 : 0,
Child = new Box { RelativeSizeAxes = Axes.Both }.WithLegacyColour(lineColour)
Child = LegacyColourCompatibility.ApplyWithDoubledAlpha(new Box
{
RelativeSizeAxes = Axes.Both
}, lineColour)
},
lightContainer = new Container
{
@ -86,7 +95,7 @@ namespace osu.Game.Rulesets.Mania.Skinning
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Colour = lightColour.ToLegacyColour(),
Colour = LegacyColourCompatibility.DisallowZeroAlpha(lightColour),
Texture = skin.GetTexture(lightImage),
RelativeSizeAxes = Axes.X,
Width = 1,

View File

@ -56,7 +56,7 @@ namespace osu.Game.Rulesets.Mania.Skinning
Anchor = Anchor.CentreLeft,
RelativeSizeAxes = Axes.X,
Height = 1,
Colour = lineColour.ToLegacyColour(),
Colour = LegacyColourCompatibility.DisallowZeroAlpha(lineColour),
Alpha = showJudgementLine ? 0.9f : 0
}
}

View File

@ -106,7 +106,7 @@ namespace osu.Game.Rulesets.Osu.Skinning
base.LoadComplete();
state.BindValueChanged(updateState, true);
accentColour.BindValueChanged(colour => hitCircleSprite.Colour = colour.NewValue.ToLegacyColour(), true);
accentColour.BindValueChanged(colour => hitCircleSprite.Colour = LegacyColourCompatibility.DisallowZeroAlpha(colour.NewValue), true);
indexInCurrentCombo.BindValueChanged(index => hitCircleText.Text = (index.NewValue + 1).ToString(), true);
}

View File

@ -39,11 +39,11 @@ namespace osu.Game.Rulesets.Osu.Skinning
Texture = skin.GetTexture("sliderb-nd"),
Colour = new Color4(5, 5, 5, 255),
},
animationContent.WithLegacyColour(ballColour).With(d =>
LegacyColourCompatibility.ApplyWithDoubledAlpha(animationContent.With(d =>
{
d.Anchor = Anchor.Centre;
d.Origin = Anchor.Centre;
}),
}), ballColour),
layerSpec = new Sprite
{
Anchor = Anchor.Centre,

View File

@ -90,7 +90,7 @@ namespace osu.Game.Rulesets.Taiko.Skinning
private void updateAccentColour()
{
backgroundLayer.Colour = accentColour.ToLegacyColour();
backgroundLayer.Colour = LegacyColourCompatibility.DisallowZeroAlpha(accentColour);
}
}
}

View File

@ -76,9 +76,9 @@ namespace osu.Game.Rulesets.Taiko.Skinning
private void updateAccentColour()
{
headCircle.AccentColour = accentColour.ToLegacyColour();
body.Colour = accentColour.ToLegacyColour();
end.Colour = accentColour.ToLegacyColour();
headCircle.AccentColour = LegacyColourCompatibility.DisallowZeroAlpha(accentColour);
body.Colour = LegacyColourCompatibility.DisallowZeroAlpha(accentColour);
end.Colour = LegacyColourCompatibility.DisallowZeroAlpha(accentColour);
}
}
}

View File

@ -19,9 +19,10 @@ namespace osu.Game.Rulesets.Taiko.Skinning
[BackgroundDependencyLoader]
private void load()
{
AccentColour = (component == TaikoSkinComponents.CentreHit
? new Color4(235, 69, 44, 255)
: new Color4(67, 142, 172, 255)).ToLegacyColour();
AccentColour = LegacyColourCompatibility.DisallowZeroAlpha(
component == TaikoSkinComponents.CentreHit
? new Color4(235, 69, 44, 255)
: new Color4(67, 142, 172, 255));
}
}
}

View File

@ -0,0 +1,46 @@
// 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.
using osu.Framework.Graphics;
using osuTK.Graphics;
namespace osu.Game.Skinning
{
/// <summary>
/// Compatibility methods to convert osu!stable colours to osu!lazer-compatible ones. Should be used for legacy skins only.
/// </summary>
public static class LegacyColourCompatibility
{
/// <summary>
/// Forces an alpha of 1 if a given <see cref="Color4"/> is fully transparent.
/// </summary>
/// <remarks>
/// This is equivalent to setting colour post-constructor in osu!stable.
/// </remarks>
/// <param name="colour">The <see cref="Color4"/> to disallow zero alpha on.</param>
/// <returns>The resultant <see cref="Color4"/>.</returns>
public static Color4 DisallowZeroAlpha(Color4 colour)
{
if (colour.A == 0)
colour.A = 1;
return colour;
}
/// <summary>
/// Applies a <see cref="Color4"/> to a <see cref="Drawable"/>, doubling the alpha value into the <see cref="Drawable.Alpha"/> property.
/// </summary>
/// <remarks>
/// This is equivalent to setting colour in the constructor in osu!stable.
/// </remarks>
/// <param name="drawable">The <see cref="Drawable"/> to apply the colour to.</param>
/// <param name="colour">The <see cref="Color4"/> to apply.</param>
/// <returns>The given <paramref name="drawable"/>.</returns>
public static T ApplyWithDoubledAlpha<T>(T drawable, Color4 colour)
where T : Drawable
{
drawable.Alpha = colour.A;
drawable.Colour = DisallowZeroAlpha(colour);
return drawable;
}
}
}

View File

@ -9,7 +9,6 @@ using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osuTK.Graphics;
using static osu.Game.Skinning.LegacySkinConfiguration;
namespace osu.Game.Skinning
@ -63,36 +62,6 @@ namespace osu.Game.Skinning
}
}
/// <summary>
/// The resultant colour after setting a post-constructor colour in osu!stable.
/// </summary>
/// <param name="colour">The <see cref="Color4"/> to convert.</param>
/// <returns>The converted <see cref="Color4"/>.</returns>
public static Color4 ToLegacyColour(this Color4 colour)
{
if (colour.A == 0)
colour.A = 1;
return colour;
}
/// <summary>
/// Equivalent of setting a colour in the constructor in osu!stable.
/// Doubles the alpha channel into <see cref="Drawable.Alpha"/> and uses <see cref="ToLegacyColour"/> to set <see cref="Drawable.Colour"/>.
/// </summary>
/// <remarks>
/// Beware: Any existing value in <see cref="Drawable.Alpha"/> is overwritten.
/// </remarks>
/// <param name="drawable">The <see cref="Drawable"/> to set the colour of.</param>
/// <param name="colour">The <see cref="Color4"/> to set.</param>
/// <returns>The given <see cref="Drawable"/>.</returns>
public static T WithLegacyColour<T>(this T drawable, Color4 colour)
where T : Drawable
{
drawable.Alpha = colour.A;
drawable.Colour = ToLegacyColour(colour);
return drawable;
}
public class SkinnableTextureAnimation : TextureAnimation
{
[Resolved(canBeNull: true)]