From 448c6ed515572a667524792761056b13889afe70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 28 Dec 2021 15:50:43 +0100 Subject: [PATCH] Generalise `KiaiFlashingSprite` for arbitrary drawables --- .../Skinning/Legacy/KiaiFlashingDrawable.cs | 50 +++++++++++++++ .../Skinning/Legacy/KiaiFlashingSprite.cs | 61 ------------------- .../Skinning/Legacy/LegacyMainCirclePiece.cs | 7 +-- 3 files changed, 53 insertions(+), 65 deletions(-) create mode 100644 osu.Game.Rulesets.Osu/Skinning/Legacy/KiaiFlashingDrawable.cs delete mode 100644 osu.Game.Rulesets.Osu/Skinning/Legacy/KiaiFlashingSprite.cs diff --git a/osu.Game.Rulesets.Osu/Skinning/Legacy/KiaiFlashingDrawable.cs b/osu.Game.Rulesets.Osu/Skinning/Legacy/KiaiFlashingDrawable.cs new file mode 100644 index 0000000000..cd1d05c985 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Skinning/Legacy/KiaiFlashingDrawable.cs @@ -0,0 +1,50 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Audio.Track; +using osu.Framework.Graphics; +using osu.Game.Beatmaps.ControlPoints; +using osu.Game.Graphics.Containers; + +namespace osu.Game.Rulesets.Osu.Skinning.Legacy +{ + internal class KiaiFlashingDrawable : BeatSyncedContainer + { + private readonly Drawable flashingDrawable; + + private const float flash_opacity = 0.3f; + + public KiaiFlashingDrawable(Func creationFunc) + { + AutoSizeAxes = Axes.Both; + + Children = new[] + { + creationFunc.Invoke().With(d => + { + d.Anchor = Anchor.Centre; + d.Origin = Anchor.Centre; + }), + flashingDrawable = creationFunc.Invoke().With(d => + { + d.Anchor = Anchor.Centre; + d.Origin = Anchor.Centre; + d.Alpha = 0; + d.Blending = BlendingParameters.Additive; + }) + }; + } + + protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes) + { + if (!effectPoint.KiaiMode) + return; + + flashingDrawable + .FadeTo(flash_opacity) + .Then() + .FadeOut(timingPoint.BeatLength * 0.75f); + } + } +} diff --git a/osu.Game.Rulesets.Osu/Skinning/Legacy/KiaiFlashingSprite.cs b/osu.Game.Rulesets.Osu/Skinning/Legacy/KiaiFlashingSprite.cs deleted file mode 100644 index 4a1d69ad41..0000000000 --- a/osu.Game.Rulesets.Osu/Skinning/Legacy/KiaiFlashingSprite.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Audio.Track; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Textures; -using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Graphics.Containers; - -namespace osu.Game.Rulesets.Osu.Skinning.Legacy -{ - internal class KiaiFlashingSprite : BeatSyncedContainer - { - private readonly Sprite mainSprite; - private readonly Sprite flashingSprite; - - public Texture Texture - { - set - { - mainSprite.Texture = value; - flashingSprite.Texture = value; - } - } - - private const float flash_opacity = 0.3f; - - public KiaiFlashingSprite() - { - AutoSizeAxes = Axes.Both; - - Children = new Drawable[] - { - mainSprite = new Sprite - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - }, - flashingSprite = new Sprite - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Alpha = 0, - Blending = BlendingParameters.Additive, - } - }; - } - - protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes) - { - if (!effectPoint.KiaiMode) - return; - - flashingSprite - .FadeTo(flash_opacity) - .Then() - .FadeOut(timingPoint.BeatLength * 0.75f); - } - } -} diff --git a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyMainCirclePiece.cs b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyMainCirclePiece.cs index d2f84dcf84..9cda85c20c 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyMainCirclePiece.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyMainCirclePiece.cs @@ -5,6 +5,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; @@ -72,9 +73,8 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy InternalChildren = new[] { - hitCircleSprite = new KiaiFlashingSprite + hitCircleSprite = new KiaiFlashingDrawable(() => new Sprite { Texture = baseTexture }) { - Texture = baseTexture, Anchor = Anchor.Centre, Origin = Anchor.Centre, }, @@ -82,9 +82,8 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Child = hitCircleOverlay = new KiaiFlashingSprite + Child = hitCircleOverlay = new KiaiFlashingDrawable(() => new Sprite { Texture = overlayTexture }) { - Texture = overlayTexture, Anchor = Anchor.Centre, Origin = Anchor.Centre, },