From 6a7b0786c9231df3313d918ad752a15b31b796a9 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 15 Aug 2023 13:33:49 +0900 Subject: [PATCH] Add barline pooling for mania --- .../ManiaSkinComponentLookup.cs | 1 + osu.Game.Rulesets.Mania/Objects/BarLine.cs | 11 ++- .../Objects/Drawables/DrawableBarLine.cs | 60 ++++++++-------- .../Skinning/Default/DefaultBarLine.cs | 72 +++++++++++++++++++ .../Legacy/ManiaLegacySkinTransformer.cs | 3 + osu.Game.Rulesets.Mania/UI/Stage.cs | 4 +- 6 files changed, 118 insertions(+), 33 deletions(-) create mode 100644 osu.Game.Rulesets.Mania/Skinning/Default/DefaultBarLine.cs diff --git a/osu.Game.Rulesets.Mania/ManiaSkinComponentLookup.cs b/osu.Game.Rulesets.Mania/ManiaSkinComponentLookup.cs index c9ee5af809..44120e16e6 100644 --- a/osu.Game.Rulesets.Mania/ManiaSkinComponentLookup.cs +++ b/osu.Game.Rulesets.Mania/ManiaSkinComponentLookup.cs @@ -33,5 +33,6 @@ namespace osu.Game.Rulesets.Mania HitExplosion, StageBackground, StageForeground, + BarLine } } diff --git a/osu.Game.Rulesets.Mania/Objects/BarLine.cs b/osu.Game.Rulesets.Mania/Objects/BarLine.cs index 09a746042b..cf576239ed 100644 --- a/osu.Game.Rulesets.Mania/Objects/BarLine.cs +++ b/osu.Game.Rulesets.Mania/Objects/BarLine.cs @@ -1,6 +1,7 @@ // 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.Bindables; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects; @@ -8,7 +9,15 @@ namespace osu.Game.Rulesets.Mania.Objects { public class BarLine : ManiaHitObject, IBarLine { - public bool Major { get; set; } + private HitObjectProperty major; + + public Bindable MajorBindable => major.Bindable; + + public bool Major + { + get => major.Value; + set => major.Value = value; + } public override Judgement CreateJudgement() => new IgnoreJudgement(); } diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableBarLine.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableBarLine.cs index 8381b8b24b..25fed1a84c 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableBarLine.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableBarLine.cs @@ -1,9 +1,11 @@ // 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.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Graphics.Shapes; -using osuTK; +using osu.Game.Rulesets.Mania.Skinning.Default; +using osu.Game.Skinning; namespace osu.Game.Rulesets.Mania.Objects.Drawables { @@ -13,45 +15,41 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables /// public partial class DrawableBarLine : DrawableManiaHitObject { + public readonly Bindable Major = new Bindable(); + + public DrawableBarLine() + : this(null!) + { + } + public DrawableBarLine(BarLine barLine) : base(barLine) { RelativeSizeAxes = Axes.X; - Height = barLine.Major ? 1.7f : 1.2f; + } - AddInternal(new Box + [BackgroundDependencyLoader] + private void load() + { + AddInternal(new SkinnableDrawable(new ManiaSkinComponentLookup(ManiaSkinComponents.BarLine), _ => new DefaultBarLine()) { - Name = "Bar line", - Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre, - RelativeSizeAxes = Axes.Both, - Alpha = barLine.Major ? 0.5f : 0.2f + Anchor = Anchor.Centre, + Origin = Anchor.Centre, }); - if (barLine.Major) - { - Vector2 size = new Vector2(22, 6); - const float line_offset = 4; + Major.BindValueChanged(major => Height = major.NewValue ? 1.7f : 1.2f, true); + } - AddInternal(new Circle - { - Name = "Left line", - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreRight, + protected override void OnApply() + { + base.OnApply(); + Major.BindTo(HitObject.MajorBindable); + } - Size = size, - X = -line_offset, - }); - - AddInternal(new Circle - { - Name = "Right line", - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreLeft, - Size = size, - X = line_offset, - }); - } + protected override void OnFree() + { + base.OnFree(); + Major.UnbindFrom(HitObject.MajorBindable); } protected override void UpdateStartTimeStateTransforms() => this.FadeOut(150); diff --git a/osu.Game.Rulesets.Mania/Skinning/Default/DefaultBarLine.cs b/osu.Game.Rulesets.Mania/Skinning/Default/DefaultBarLine.cs new file mode 100644 index 0000000000..cd85901a65 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Skinning/Default/DefaultBarLine.cs @@ -0,0 +1,72 @@ +// 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.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Rulesets.Mania.Objects.Drawables; +using osu.Game.Rulesets.Objects.Drawables; +using osuTK; + +namespace osu.Game.Rulesets.Mania.Skinning.Default +{ + public partial class DefaultBarLine : CompositeDrawable + { + private Bindable major = null!; + + private Drawable mainLine = null!; + private Drawable leftAnchor = null!; + private Drawable rightAnchor = null!; + + [BackgroundDependencyLoader] + private void load(DrawableHitObject drawableHitObject) + { + RelativeSizeAxes = Axes.Both; + + AddInternal(mainLine = new Box + { + Name = "Bar line", + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + RelativeSizeAxes = Axes.Both, + }); + + Vector2 size = new Vector2(22, 6); + const float line_offset = 4; + + AddInternal(leftAnchor = new Circle + { + Name = "Left anchor", + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreRight, + Size = size, + X = -line_offset, + }); + + AddInternal(rightAnchor = new Circle + { + Name = "Right anchor", + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreLeft, + Size = size, + X = line_offset, + }); + + major = ((DrawableBarLine)drawableHitObject).Major.GetBoundCopy(); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + major.BindValueChanged(updateMajor, true); + } + + private void updateMajor(ValueChangedEvent major) + { + mainLine.Alpha = major.NewValue ? 0.5f : 0.2f; + leftAnchor.Alpha = rightAnchor.Alpha = major.NewValue ? 1 : 0; + } + } +} diff --git a/osu.Game.Rulesets.Mania/Skinning/Legacy/ManiaLegacySkinTransformer.cs b/osu.Game.Rulesets.Mania/Skinning/Legacy/ManiaLegacySkinTransformer.cs index f8519beb22..446dfae0f6 100644 --- a/osu.Game.Rulesets.Mania/Skinning/Legacy/ManiaLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Mania/Skinning/Legacy/ManiaLegacySkinTransformer.cs @@ -119,6 +119,9 @@ namespace osu.Game.Rulesets.Mania.Skinning.Legacy case ManiaSkinComponents.StageForeground: return new LegacyStageForeground(); + case ManiaSkinComponents.BarLine: + return null; // Not yet implemented. + default: throw new UnsupportedSkinComponentException(lookup); } diff --git a/osu.Game.Rulesets.Mania/UI/Stage.cs b/osu.Game.Rulesets.Mania/UI/Stage.cs index 879c704450..4382f8e84a 100644 --- a/osu.Game.Rulesets.Mania/UI/Stage.cs +++ b/osu.Game.Rulesets.Mania/UI/Stage.cs @@ -136,6 +136,8 @@ namespace osu.Game.Rulesets.Mania.UI columnFlow.SetContentForColumn(i, column); AddNested(column); } + + RegisterPool(50, 200); } private ISkinSource currentSkin; @@ -186,7 +188,7 @@ namespace osu.Game.Rulesets.Mania.UI public override bool Remove(DrawableHitObject h) => Columns.ElementAt(((ManiaHitObject)h.HitObject).Column - firstColumnIndex).Remove(h); - public void Add(BarLine barLine) => base.Add(new DrawableBarLine(barLine)); + public void Add(BarLine barLine) => base.Add(barLine); internal void OnNewResult(DrawableHitObject judgedObject, JudgementResult result) {