From 0195ed600e88109c2baf9dd71ae84b4ccd1f097f Mon Sep 17 00:00:00 2001 From: Derrick Timmermans Date: Sat, 1 Oct 2022 17:39:42 +0200 Subject: [PATCH] Introduce abstractions for pieces --- .../Objects/Drawables/DrawableHold.cs | 6 ++--- .../Objects/Drawables/DrawableSlideTap.cs | 20 +++++++++++------ .../Objects/Drawables/DrawableTap.cs | 22 +++++++++---------- .../Objects/Drawables/DrawableTouch.cs | 2 +- .../Objects/Drawables/DrawableTouchHold.cs | 2 +- .../Skinning/Default/Slides/SlideTapPiece.cs | 12 ++++++---- .../Default/TouchHolds/TouchHoldBody.cs | 8 ++++++- .../Skinning/Default/Touches/TouchBody.cs | 4 +++- .../Skinning/ISlideTapPiece.cs | 11 ++++++++++ .../Skinning/ITouchHoldPiece.cs | 10 +++++++++ .../Skinning/ITouchPiece.cs | 10 +++++++++ 11 files changed, 77 insertions(+), 30 deletions(-) create mode 100644 osu.Game.Rulesets.Sentakki/Skinning/ISlideTapPiece.cs create mode 100644 osu.Game.Rulesets.Sentakki/Skinning/ITouchHoldPiece.cs create mode 100644 osu.Game.Rulesets.Sentakki/Skinning/ITouchPiece.cs diff --git a/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableHold.cs b/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableHold.cs index 5b03bf76d..9b08fe799 100644 --- a/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableHold.cs +++ b/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableHold.cs @@ -81,7 +81,7 @@ protected override void UpdateInitialTransforms() double animTime = AdjustedAnimationDuration / 2; NoteBody.FadeInFromZero(animTime).ScaleTo(1, animTime); - ((HoldBody)NoteBody.Drawable).FadeColour(AccentColour.Value); + NoteBody.Drawable.FadeColour(AccentColour.Value); using (BeginDelayedSequence(animTime, true)) { @@ -99,7 +99,7 @@ protected override void UpdateInitialTransforms() .ResizeHeightTo(0, stretchTime); if (HoldStartTime == null && !Auto) - ((HoldBody)NoteBody.Drawable).Delay(animTime).FadeColour(Color4.Gray, 100); + NoteBody.Drawable.Delay(animTime).FadeColour(Color4.Gray, 100); } } @@ -142,7 +142,7 @@ protected override void UpdateHitStateTransforms(ArmedState state) break; case ArmedState.Miss: - ((HoldBody)NoteBody.Drawable).ScaleTo(0.5f, time_fade_miss, Easing.InCubic) + NoteBody.Drawable.ScaleTo(0.5f, time_fade_miss, Easing.InCubic) .FadeColour(Color4.Red, time_fade_miss, Easing.OutQuint) .MoveToOffset(new Vector2(0, -100), time_fade_miss, Easing.OutCubic) .FadeOut(time_fade_miss); diff --git a/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableSlideTap.cs b/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableSlideTap.cs index 4f13aca85..f46b41843 100644 --- a/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableSlideTap.cs +++ b/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableSlideTap.cs @@ -1,15 +1,21 @@ -using System; -using System.Linq; +using System.Linq; using osu.Framework.Graphics; using osu.Game.Rulesets.Sentakki.Skinning; using osu.Game.Rulesets.Sentakki.Skinning.Default.Slides; +using osu.Game.Rulesets.Sentakki.UI; +using osuTK; namespace osu.Game.Rulesets.Sentakki.Objects.Drawables { public class DrawableSlideTap : DrawableTap { - protected override SentakkiSkinComponents TapPieceComponent => SentakkiSkinComponents.SlideStar; - protected override Type fallbackPieceType => typeof(SlideTapPiece); + protected override Drawable CreateTapVisual() => new SlideTapPiece() + { + Scale = new Vector2(0f), + Position = new Vector2(0, -SentakkiPlayfield.NOTESTARTDISTANCE), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }; public DrawableSlideTap() : this(null) { } public DrawableSlideTap(SlideTap? hitObject) @@ -19,7 +25,7 @@ protected override void UpdateInitialTransforms() { base.UpdateInitialTransforms(); - var note = (SlideTapPiece)TapVisual.Drawable; + var note = (ISlideTapPiece)TapVisual; double spinDuration = 0; @@ -27,9 +33,9 @@ protected override void UpdateInitialTransforms() { spinDuration = ((Slide)slide.HitObject).SlideInfoList.FirstOrDefault().Duration; if (slide.SlideBodies.Count > 1) - note.SecondStar.Alpha = 1; + note.Stars[1].Alpha = 1; else - note.SecondStar.Alpha = 0; + note.Stars[1].Alpha = 0; } note.Stars.Spin(spinDuration, RotationDirection.Counterclockwise, 0).Loop(); diff --git a/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTap.cs b/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTap.cs index 6067e1841..84ac13fcd 100644 --- a/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTap.cs +++ b/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTap.cs @@ -1,4 +1,4 @@ -using System; + using System.Diagnostics; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -9,7 +9,6 @@ using osu.Game.Rulesets.Sentakki.Skinning; using osu.Game.Rulesets.Sentakki.Skinning.Default; using osu.Game.Rulesets.Sentakki.UI; -using osu.Game.Skinning; using osuTK; using osuTK.Graphics; @@ -17,8 +16,13 @@ namespace osu.Game.Rulesets.Sentakki.Objects.Drawables { public class DrawableTap : DrawableSentakkiLanedHitObject, IKeyBindingHandler { - protected virtual SentakkiSkinComponents TapPieceComponent => SentakkiSkinComponents.Tap; - protected virtual Type fallbackPieceType => typeof(TapPiece); + protected virtual Drawable CreateTapVisual() => new ProxyableSkinnableDrawable(new SentakkiSkinComponent(SentakkiSkinComponents.Tap), _ => new TapPiece()) + { + Scale = new Vector2(0f), + Position = new Vector2(0, -SentakkiPlayfield.NOTESTARTDISTANCE), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }; public override double LifetimeStart { @@ -39,7 +43,7 @@ public override double LifetimeEnd } } - public SkinnableDrawable TapVisual = null!; + public Drawable TapVisual = null!; public DrawableTap() : this(null) { } @@ -52,13 +56,7 @@ private void load() Origin = Anchor.Centre; Anchor = Anchor.Centre; AddRangeInternal(new Drawable[] { - TapVisual = new ProxyableSkinnableDrawable(new SentakkiSkinComponent(TapPieceComponent), _ => (Drawable)Activator.CreateInstance(fallbackPieceType)) - { - Scale = new Vector2(0f), - Position = new Vector2(0, -SentakkiPlayfield.NOTESTARTDISTANCE), - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - } + TapVisual = CreateTapVisual() }); } diff --git a/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTouch.cs b/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTouch.cs index 76b968e60..857b32d8e 100644 --- a/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTouch.cs +++ b/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTouch.cs @@ -89,7 +89,7 @@ protected override void UpdateInitialTransforms() using (BeginDelayedSequence(AdjustedAnimationDuration, true)) { TouchBody.ResizeTo(90, moveTo, Easing.InCirc); - ((TouchBody)TouchBody.Drawable).BorderContainer.Delay(moveTo).FadeIn(); + ((ITouchPiece)TouchBody.Drawable).TouchBorder.Delay(moveTo).FadeIn(); } } diff --git a/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTouchHold.cs b/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTouchHold.cs index 206cf8b77..d8306cbd8 100644 --- a/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTouchHold.cs +++ b/osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTouchHold.cs @@ -110,7 +110,7 @@ protected override void UpdateInitialTransforms() TouchHoldBody.FadeInFromZero(fadeIn).ScaleTo(1, fadeIn); using (BeginDelayedSequence(fadeIn, true)) { - ((TouchHoldBody)TouchHoldBody.Drawable).ProgressPiece.TransformBindableTo(((TouchHoldBody)TouchHoldBody.Drawable).ProgressPiece.ProgressBindable, 1, ((IHasDuration)HitObject).Duration); + ((ITouchHoldPiece)TouchHoldBody.Drawable).TransformTo(nameof(ITouchHoldPiece.Progress), 1.0, ((IHasDuration)HitObject).Duration); } } diff --git a/osu.Game.Rulesets.Sentakki/Skinning/Default/Slides/SlideTapPiece.cs b/osu.Game.Rulesets.Sentakki/Skinning/Default/Slides/SlideTapPiece.cs index b103a982d..2f9c26c13 100644 --- a/osu.Game.Rulesets.Sentakki/Skinning/Default/Slides/SlideTapPiece.cs +++ b/osu.Game.Rulesets.Sentakki/Skinning/Default/Slides/SlideTapPiece.cs @@ -9,10 +9,14 @@ namespace osu.Game.Rulesets.Sentakki.Skinning.Default.Slides { - public class SlideTapPiece : CompositeDrawable + public class SlideTapPiece : CompositeDrawable, ISlideTapPiece { - public readonly Container Stars; - public readonly SkinnableDrawable SecondStar; + public override bool RemoveWhenNotAlive => false; + private readonly SkinnableDrawable secondStar; + + public Container Stars { get; private set; } + + public Drawable SecondStar => secondStar; public SlideTapPiece() { @@ -34,7 +38,7 @@ public SlideTapPiece() Origin = Anchor.Centre, RelativeSizeAxes = Axes.None, }, - SecondStar = new SkinnableDrawable(new SentakkiSkinComponent(SentakkiSkinComponents.SlideStar), _ => new StarPiece()) + secondStar = new SkinnableDrawable(new SentakkiSkinComponent(SentakkiSkinComponents.SlideStar), _ => new StarPiece()) { Anchor = Anchor.Centre, Origin = Anchor.Centre, diff --git a/osu.Game.Rulesets.Sentakki/Skinning/Default/TouchHolds/TouchHoldBody.cs b/osu.Game.Rulesets.Sentakki/Skinning/Default/TouchHolds/TouchHoldBody.cs index 8008aa29e..17badc052 100644 --- a/osu.Game.Rulesets.Sentakki/Skinning/Default/TouchHolds/TouchHoldBody.cs +++ b/osu.Game.Rulesets.Sentakki/Skinning/Default/TouchHolds/TouchHoldBody.cs @@ -8,8 +8,14 @@ namespace osu.Game.Rulesets.Sentakki.Skinning.Default.TouchHolds { - public class TouchHoldBody : CircularContainer + public class TouchHoldBody : CircularContainer, ITouchHoldPiece { + public double Progress + { + get => ProgressPiece.ProgressBindable.Value; + set => ProgressPiece.ProgressBindable.Value = value; + } + public readonly TouchHoldProgressPiece ProgressPiece; private readonly TouchHoldCentrePiece centrePiece; diff --git a/osu.Game.Rulesets.Sentakki/Skinning/Default/Touches/TouchBody.cs b/osu.Game.Rulesets.Sentakki/Skinning/Default/Touches/TouchBody.cs index e05be9912..3e0e05762 100644 --- a/osu.Game.Rulesets.Sentakki/Skinning/Default/Touches/TouchBody.cs +++ b/osu.Game.Rulesets.Sentakki/Skinning/Default/Touches/TouchBody.cs @@ -9,8 +9,10 @@ namespace osu.Game.Rulesets.Sentakki.Skinning.Default.Touches { - public class TouchBody : Container + public class TouchBody : Container, ITouchPiece { + public Drawable TouchBorder => BorderContainer; + public Container BorderContainer; public Container PieceContainer; public TouchBody() diff --git a/osu.Game.Rulesets.Sentakki/Skinning/ISlideTapPiece.cs b/osu.Game.Rulesets.Sentakki/Skinning/ISlideTapPiece.cs new file mode 100644 index 000000000..101748283 --- /dev/null +++ b/osu.Game.Rulesets.Sentakki/Skinning/ISlideTapPiece.cs @@ -0,0 +1,11 @@ +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; + +namespace osu.Game.Rulesets.Sentakki.Skinning +{ + public interface ISlideTapPiece : IDrawable + { + public Container Stars { get; } + public Drawable SecondStar { get; } + } +} diff --git a/osu.Game.Rulesets.Sentakki/Skinning/ITouchHoldPiece.cs b/osu.Game.Rulesets.Sentakki/Skinning/ITouchHoldPiece.cs new file mode 100644 index 000000000..9e8e482b1 --- /dev/null +++ b/osu.Game.Rulesets.Sentakki/Skinning/ITouchHoldPiece.cs @@ -0,0 +1,10 @@ +using osu.Framework.Graphics; + +namespace osu.Game.Rulesets.Sentakki.Skinning +{ + public interface ITouchHoldPiece : IDrawable + { + // Used to fill the progress bar after HitObject start time + double Progress { get; set; } + } +} diff --git a/osu.Game.Rulesets.Sentakki/Skinning/ITouchPiece.cs b/osu.Game.Rulesets.Sentakki/Skinning/ITouchPiece.cs new file mode 100644 index 000000000..3f9541b9a --- /dev/null +++ b/osu.Game.Rulesets.Sentakki/Skinning/ITouchPiece.cs @@ -0,0 +1,10 @@ +using osu.Framework.Graphics; + +namespace osu.Game.Rulesets.Sentakki.Skinning +{ + public interface ITouchPiece : IDrawable + { + // Shows as soon as Time >= StartTime + Drawable TouchBorder { get; } + } +}