From 275b22c477592a5d614ed196eab17de7a07fd9fb Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 24 Dec 2020 10:36:35 +0900 Subject: [PATCH 1/8] Writing as pooling playfield style. --- .../Objects/Drawables/DrawableNote.cs | 24 ++++++--- .../UI/DrawableKaraokeRuleset.cs | 15 +----- .../UI/KaraokePlayfield.cs | 49 +++++++++++++++++-- .../UI/LyricPlayfield.cs | 2 + osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs | 2 + 5 files changed, 68 insertions(+), 24 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableNote.cs b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableNote.cs index 9913ce984..b86cfc9a5 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableNote.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableNote.cs @@ -2,6 +2,8 @@ // See the LICENCE file in the repository root for full licence text. using System.Diagnostics; +using JetBrains.Annotations; +using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; @@ -22,7 +24,7 @@ namespace osu.Game.Rulesets.Karaoke.Objects.Drawables /// public class DrawableNote : DrawableKaraokeScrollingHitObject, IKeyBindingHandler { - private readonly OsuSpriteText textPiece; + private OsuSpriteText textPiece; /// /// Time at which the user started holding this hold note. Null if the user is not holding this hold note. @@ -37,8 +39,18 @@ public class DrawableNote : DrawableKaraokeScrollingHitObject, IKeyBinding public IBindable Singers => HitObject.SingersBindable; - public DrawableNote(Note note) - : base(note) + public DrawableNote() + : this(null) + { + } + + public DrawableNote([CanBeNull] Note hitObject) + : base(hitObject) + { + } + + [BackgroundDependencyLoader] + private void load() { Height = DefaultColumnBackground.COLUMN_HEIGHT; @@ -58,11 +70,11 @@ public DrawableNote(Note note) Display.BindValueChanged(e => { (Result.Judgement as KaraokeNoteJudgement).Saitenable = e.NewValue; }); - note.TextBindable.BindValueChanged(_ => { changeText(note); }, true); + HitObject.TextBindable.BindValueChanged(_ => { changeText(HitObject); }, true); - note.AlternativeTextBindable.BindValueChanged(_ => { changeText(note); }, true); + HitObject.AlternativeTextBindable.BindValueChanged(_ => { changeText(HitObject); }, true); - note.SingersBindable.BindValueChanged(index => { ApplySkin(CurrentSkin, false); }, true); + HitObject.SingersBindable.BindValueChanged(index => { ApplySkin(CurrentSkin, false); }, true); } protected override void ApplySkin(ISkinSource skin, bool allowFallback) diff --git a/osu.Game.Rulesets.Karaoke/UI/DrawableKaraokeRuleset.cs b/osu.Game.Rulesets.Karaoke/UI/DrawableKaraokeRuleset.cs index 41b61bf09..f4e8d64de 100644 --- a/osu.Game.Rulesets.Karaoke/UI/DrawableKaraokeRuleset.cs +++ b/osu.Game.Rulesets.Karaoke/UI/DrawableKaraokeRuleset.cs @@ -93,20 +93,7 @@ private void load() Playfield.NotePlayfield.Hide(); } - public override DrawableHitObject CreateDrawableRepresentation(KaraokeHitObject h) - { - switch (h) - { - case Lyric lyric: - return new DrawableLyric(lyric); - - case Note note: - return new DrawableNote(note); - - default: - throw new NotSupportedException(); - } - } + public override DrawableHitObject CreateDrawableRepresentation(KaraokeHitObject h) => null; protected override ReplayInputHandler CreateReplayInputHandler(Replay replay) => new KaraokeFramedReplayInputHandler(replay); diff --git a/osu.Game.Rulesets.Karaoke/UI/KaraokePlayfield.cs b/osu.Game.Rulesets.Karaoke/UI/KaraokePlayfield.cs index 7bf300eab..f118655c0 100644 --- a/osu.Game.Rulesets.Karaoke/UI/KaraokePlayfield.cs +++ b/osu.Game.Rulesets.Karaoke/UI/KaraokePlayfield.cs @@ -1,6 +1,7 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -9,6 +10,7 @@ using osu.Game.Rulesets.Karaoke.Configuration; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Objects.Drawables; +using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI.Scrolling; using osuTK; @@ -74,6 +76,48 @@ public KaraokePlayfield() }); } + #region Pooling support + + public override void Add(HitObject h) + { + switch (h) + { + case Lyric _: + LyricPlayfield.Add(h); + break; + + case Note _: + case BarLine _: + // hidden the note playfield until receive any note. + NotePlayfield.Alpha = 1; + NotePlayfield.Add(h); + break; + + default: + throw new ArgumentException($"Unsupported {nameof(HitObject)} type: {h.GetType()}"); + } + } + + public override bool Remove(HitObject h) + { + switch (h) + { + case Lyric _: + return LyricPlayfield.Remove(h); + + case Note _: + case BarLine _: + return NotePlayfield.Remove(h); + + default: + throw new ArgumentException($"Unsupported {nameof(HitObject)} type: {h.GetType()}"); + } + } + + #endregion + + #region Non-pooling support + public override void Add(DrawableHitObject h) { switch (h) @@ -109,10 +153,7 @@ public override bool Remove(DrawableHitObject h) } } - public void Add(BarLine barLine) - { - NotePlayfield.Add(barLine); - } + #endregion [BackgroundDependencyLoader] private void load(KaraokeRulesetConfigManager rulesetConfig, KaraokeSessionStatics session) diff --git a/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs b/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs index 91121cf29..e989eaa66 100644 --- a/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs +++ b/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs @@ -121,6 +121,8 @@ private void load(KaraokeRulesetConfigManager rulesetConfig, KaraokeSessionStati // Practice rulesetConfig.BindWith(KaraokeRulesetSetting.PracticePreemptTime, preemptTime); session.BindWith(KaraokeRulesetSession.NowLyric, nowLyric); + + RegisterPool(50); } } } diff --git a/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs b/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs index b45a7f969..ecdd0d6e8 100644 --- a/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs +++ b/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs @@ -310,6 +310,8 @@ private void load(OsuColour colours, KaraokeSessionStatics session) session.BindWith(KaraokeRulesetSession.SaitenPitch, saitenPitch); session.GetBindable(KaraokeRulesetSession.SaitenStatus).BindValueChanged(e => { saitenStatus.SaitenStatusMode = e.NewValue; }); + + RegisterPool(50); } public bool OnPressed(KaraokeSaitenAction action) From 12c5da4768f0153214b14ced026cf7e117bec58e Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 24 Dec 2020 11:08:25 +0900 Subject: [PATCH 2/8] Fix some running issue. --- .../Edit/DrawableKaraokeEditRuleset.cs | 14 +----- .../Objects/Drawables/DrawableLyric.cs | 8 ++-- .../Objects/Drawables/DrawableNote.cs | 47 ++++++++++++++----- .../Drawables/Pieces/DefaultBodyPiece.cs | 4 +- .../Skinning/LegacyNotePiece.cs | 4 +- osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs | 11 +++-- 6 files changed, 51 insertions(+), 37 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/DrawableKaraokeEditRuleset.cs b/osu.Game.Rulesets.Karaoke/Edit/DrawableKaraokeEditRuleset.cs index 5582697a2..7f6c13e05 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/DrawableKaraokeEditRuleset.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/DrawableKaraokeEditRuleset.cs @@ -30,19 +30,7 @@ public DrawableKaraokeEditRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyLi { } - public override DrawableHitObject CreateDrawableRepresentation(KaraokeHitObject h) - { - switch (h) - { - case Lyric lyric: - return new DrawableLyric(lyric); - - case Note note: - return new DrawableNote(note); - } - - return null; - } + public override DrawableHitObject CreateDrawableRepresentation(KaraokeHitObject h) => null; protected override bool OnKeyDown(KeyDownEvent e) { diff --git a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs index 83f514c23..771d615cb 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs @@ -68,9 +68,7 @@ private void load() Origin = Anchor.TopLeft, } }; - - LifetimeEnd = HitObject.EndTime + 1000; - + TextBindable.BindValueChanged(text => { KaraokeText.Text = text.NewValue; }); TimeTagsBindable.BindValueChanged(timeTags => { KaraokeText.TimeTags = TimeTagsUtils.ToDictionary(timeTags.NewValue); }); RubyTagsBindable.BindValueChanged(rubyTags => { ApplyRuby(); }); @@ -111,6 +109,7 @@ protected override void UpdateInitialTransforms() base.UpdateInitialTransforms(); // Manually set to reduce the number of future alive objects to a bare minimum. + LifetimeEnd = HitObject.EndTime + 1000; LifetimeStart = HitObject.StartTime - HitObject.TimePreempt; } @@ -148,6 +147,9 @@ protected override void ApplySkin(ISkinSource skin, bool allowFallback) if (CurrentSkin == null) return; + if (HitObject == null) + return; + skin.GetConfig(new KaraokeSkinLookup(KaraokeSkinConfiguration.LyricStyle, HitObject.Singers))?.BindValueChanged(karaokeFont => { if (karaokeFont.NewValue != null) diff --git a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableNote.cs b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableNote.cs index b86cfc9a5..61ed645f7 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableNote.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableNote.cs @@ -35,9 +35,11 @@ public class DrawableNote : DrawableKaraokeScrollingHitObject, IKeyBinding private readonly Bindable isHitting = new Bindable(); - public IBindable Display => HitObject.DisplayBindable; - - public IBindable Singers => HitObject.SingersBindable; + public readonly IBindable TextBindable = new Bindable(); + public readonly IBindable AlternativeTextBindable = new Bindable(); + public readonly IBindable SingersBindable = new Bindable(); + public readonly IBindable DisplayBindable = new Bindable(); + public readonly IBindable ToneBindable = new Bindable(); public DrawableNote() : this(null) @@ -46,11 +48,6 @@ public DrawableNote() public DrawableNote([CanBeNull] Note hitObject) : base(hitObject) - { - } - - [BackgroundDependencyLoader] - private void load() { Height = DefaultColumnBackground.COLUMN_HEIGHT; @@ -67,14 +64,37 @@ private void load() bodyPiece.AccentColour = colour.NewValue; }, true); */ + } - Display.BindValueChanged(e => { (Result.Judgement as KaraokeNoteJudgement).Saitenable = e.NewValue; }); + [BackgroundDependencyLoader] + private void load() + { + TextBindable.BindValueChanged(_ => { changeText(HitObject); }); + AlternativeTextBindable.BindValueChanged(_ => { changeText(HitObject); }); + SingersBindable.BindValueChanged(index => { ApplySkin(CurrentSkin, false); }); + DisplayBindable.BindValueChanged(e => { (Result.Judgement as KaraokeNoteJudgement).Saitenable = e.NewValue; }); + } + + protected override void OnApply() + { + base.OnApply(); - HitObject.TextBindable.BindValueChanged(_ => { changeText(HitObject); }, true); + TextBindable.BindTo(HitObject.TextBindable); + AlternativeTextBindable.BindTo(HitObject.AlternativeTextBindable); + SingersBindable.BindTo(HitObject.SingersBindable); + DisplayBindable.BindTo(HitObject.DisplayBindable); + ToneBindable.BindTo(HitObject.ToneBindable); + } - HitObject.AlternativeTextBindable.BindValueChanged(_ => { changeText(HitObject); }, true); + protected override void OnFree() + { + base.OnFree(); - HitObject.SingersBindable.BindValueChanged(index => { ApplySkin(CurrentSkin, false); }, true); + TextBindable.UnbindFrom(HitObject.TextBindable); + AlternativeTextBindable.UnbindFrom(HitObject.AlternativeTextBindable); + SingersBindable.UnbindFrom(HitObject.SingersBindable); + DisplayBindable.UnbindFrom(HitObject.DisplayBindable); + ToneBindable.UnbindFrom(HitObject.ToneBindable); } protected override void ApplySkin(ISkinSource skin, bool allowFallback) @@ -84,6 +104,9 @@ protected override void ApplySkin(ISkinSource skin, bool allowFallback) if (CurrentSkin == null) return; + if (HitObject == null) + return; + var noteSkin = skin.GetConfig(new KaraokeSkinLookup(KaraokeSkinConfiguration.NoteStyle, HitObject.Singers))?.Value; if (noteSkin == null) return; diff --git a/osu.Game.Rulesets.Karaoke/Objects/Drawables/Pieces/DefaultBodyPiece.cs b/osu.Game.Rulesets.Karaoke/Objects/Drawables/Pieces/DefaultBodyPiece.cs index 707960512..11f04d9d1 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Drawables/Pieces/DefaultBodyPiece.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Drawables/Pieces/DefaultBodyPiece.cs @@ -60,8 +60,8 @@ private void load([CanBeNull] DrawableHitObject drawableObject, ISkinSource skin var holdNote = (DrawableNote)drawableObject; isHitting.BindTo(holdNote.IsHitting); - display.BindTo(holdNote.Display); - singer.BindTo(holdNote.Singers); + display.BindTo(holdNote.DisplayBindable); + singer.BindTo(holdNote.SingersBindable); } AccentColour.BindValueChanged(onAccentChanged); diff --git a/osu.Game.Rulesets.Karaoke/Skinning/LegacyNotePiece.cs b/osu.Game.Rulesets.Karaoke/Skinning/LegacyNotePiece.cs index 2ea3bb9aa..2db6f196a 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/LegacyNotePiece.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/LegacyNotePiece.cs @@ -65,8 +65,8 @@ private void load(DrawableHitObject drawableObject, ISkinSource skin, IScrolling var holdNote = (DrawableNote)drawableObject; isHitting.BindTo(holdNote.IsHitting); - display.BindTo(holdNote.Display); - singer.BindTo(holdNote.Singers); + display.BindTo(holdNote.DisplayBindable); + singer.BindTo(holdNote.SingersBindable); } AccentColour.BindValueChanged(onAccentChanged); diff --git a/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs b/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs index ecdd0d6e8..604a87213 100644 --- a/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs +++ b/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs @@ -220,6 +220,8 @@ protected override void LoadComplete() { base.LoadComplete(); + NewResult += OnNewResult; + saitenPitch.BindValueChanged(value => { var newValue = value.NewValue; @@ -241,11 +243,10 @@ public void AddColumn(DefaultColumnBackground c) public override void Add(DrawableHitObject h) { - var note = (Note)h.HitObject; - - note.ToneBindable.BindValueChanged(tone => { h.Y = calculator.YPositionAt(tone.NewValue); }, true); - - h.OnNewResult += OnNewResult; + if (h is DrawableNote drawableNote) + { + drawableNote.ToneBindable.BindValueChanged(tone => { h.Y = calculator.YPositionAt(tone.NewValue); }, true); + } base.Add(h); } From 346897aceffdffb09aaa34dc24758338dbf3d893 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 24 Dec 2020 11:51:51 +0900 Subject: [PATCH 3/8] Make barline in polling. --- .../Objects/Drawables/DrawableBarLine.cs | 8 +++++++- osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs | 12 +----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs index df6776aae..da91ff912 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs @@ -1,6 +1,7 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. +using JetBrains.Annotations; using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; using osuTK; @@ -24,7 +25,12 @@ public class DrawableBarLine : DrawableKaraokeScrollingHitObject /// private const float triangle_offset = 9; - public DrawableBarLine(BarLine barLine) + public DrawableBarLine() + : this(null) + { + } + + public DrawableBarLine([CanBeNull] BarLine barLine) : base(barLine) { RelativeSizeAxes = Axes.Y; diff --git a/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs b/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs index 604a87213..9f9c7083d 100644 --- a/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs +++ b/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs @@ -251,17 +251,6 @@ public override void Add(DrawableHitObject h) base.Add(h); } - public override bool Remove(DrawableHitObject h) - { - if (!base.Remove(h)) - return false; - - h.OnNewResult -= OnNewResult; - return true; - } - - public void Add(BarLine barLine) => base.Add(new DrawableBarLine(barLine)); - public void AddReplay(KaraokeReplayFrame frame) { replaySaitenVisualization.Add(frame); @@ -313,6 +302,7 @@ private void load(OsuColour colours, KaraokeSessionStatics session) session.GetBindable(KaraokeRulesetSession.SaitenStatus).BindValueChanged(e => { saitenStatus.SaitenStatusMode = e.NewValue; }); RegisterPool(50); + RegisterPool(15); } public bool OnPressed(KaraokeSaitenAction action) From 62b82826a7a9562e2751605106c00338d21e1200 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 24 Dec 2020 12:02:07 +0900 Subject: [PATCH 4/8] Fix barline broken issue. --- osu.Game.Rulesets.Karaoke/Objects/BarLine.cs | 12 +- .../Objects/Drawables/DrawableBarLine.cs | 109 +++++++++++++----- 2 files changed, 90 insertions(+), 31 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Objects/BarLine.cs b/osu.Game.Rulesets.Karaoke/Objects/BarLine.cs index 988c52b5e..d2e2068f6 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/BarLine.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/BarLine.cs @@ -1,12 +1,22 @@ // Copyright (c) andy840119 . Licensed under the GPL 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; namespace osu.Game.Rulesets.Karaoke.Objects { public class BarLine : KaraokeHitObject, IBarLine { - public bool Major { get; set; } + public bool Major + { + get => MajorBindable.Value; + set => MajorBindable.Value = value; + } + + public readonly Bindable MajorBindable = new BindableBool(); + + public override Judgement CreateJudgement() => new IgnoreJudgement(); } } diff --git a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs index da91ff912..4b355f77c 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs @@ -2,7 +2,10 @@ // See the LICENCE file in the repository root for full licence text. using JetBrains.Annotations; +using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osuTK; using osuTK.Graphics; @@ -25,6 +28,18 @@ public class DrawableBarLine : DrawableKaraokeScrollingHitObject /// private const float triangle_offset = 9; + /// + /// The visual line tracker. + /// + private Container line; + + /// + /// Container with triangles. Only visible for major lines. + /// + private Container triangleContainer; + + private readonly Bindable major = new Bindable(); + public DrawableBarLine() : this(null) { @@ -32,44 +47,78 @@ public DrawableBarLine() public DrawableBarLine([CanBeNull] BarLine barLine) : base(barLine) + { + + } + + [BackgroundDependencyLoader] + private void load() { RelativeSizeAxes = Axes.Y; Width = 2f; - AddInternal(new Box + AddRangeInternal(new Drawable[] { - Name = "Bar line", - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - RelativeSizeAxes = Axes.Both, - Colour = new Color4(255, 204, 33, 255), - }); - - if (barLine.Major) - { - AddInternal(new EquilateralTriangle + new Box { - Name = "Up triangle", - Anchor = Anchor.TopCentre, - Origin = Anchor.Centre, - Size = new Vector2(triangle_width), - Y = -triangle_offset, - Rotation = 180 - }); - - AddInternal(new EquilateralTriangle + Name = "Bar line", + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + RelativeSizeAxes = Axes.Both, + Colour = new Color4(255, 204, 33, 255), + }, + triangleContainer = new Container { - Name = "Down triangle", - Anchor = Anchor.BottomCentre, + Anchor = Anchor.Centre, Origin = Anchor.Centre, - Size = new Vector2(triangle_width), - Y = triangle_offset, - Rotation = 0 - }); - } - - if (!barLine.Major) - Alpha = 0.2f; + RelativeSizeAxes = Axes.Both, + Children = new [] + { + new EquilateralTriangle + { + Name = "Up triangle", + Anchor = Anchor.TopCentre, + Origin = Anchor.Centre, + Size = new Vector2(triangle_width), + Y = -triangle_offset, + Rotation = 180 + }, + new EquilateralTriangle + { + Name = "Down triangle", + Anchor = Anchor.BottomCentre, + Origin = Anchor.Centre, + Size = new Vector2(triangle_width), + Y = triangle_offset, + Rotation = 0 + } + } + } + }); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + major.BindValueChanged(updateMajor, true); + } + + private void updateMajor(ValueChangedEvent major) + { + line.Alpha = major.NewValue ? 1f : 0.75f; + triangleContainer.Alpha = major.NewValue ? 1 : 0; + } + + protected override void OnApply() + { + base.OnApply(); + major.BindTo(HitObject.MajorBindable); + } + + protected override void OnFree() + { + base.OnFree(); + major.UnbindFrom(HitObject.MajorBindable); } protected override void UpdateInitialTransforms() From 545c2fa0c6a65fec1950f795bd42ad64a6ab54b5 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 24 Dec 2020 12:04:31 +0900 Subject: [PATCH 5/8] Fix hitobject is null issue. --- .../Objects/Drawables/DrawableKaraokeScrollingHitObject.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableKaraokeScrollingHitObject.cs b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableKaraokeScrollingHitObject.cs index 0e95123f8..d15381d5b 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableKaraokeScrollingHitObject.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableKaraokeScrollingHitObject.cs @@ -59,12 +59,11 @@ protected override void UpdateInitialTransforms() public abstract class DrawableKaraokeScrollingHitObject : DrawableKaraokeScrollingHitObject where TObject : KaraokeHitObject { - public new readonly TObject HitObject; + public new TObject HitObject => base.HitObject as TObject; protected DrawableKaraokeScrollingHitObject(TObject hitObject) : base(hitObject) { - HitObject = hitObject; } } } From 1a51d6484a7e41585c2d74263fb7041db0590ed3 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 24 Dec 2020 22:06:25 +0900 Subject: [PATCH 6/8] Fox lyric not display after roll-back. --- .../Objects/Drawables/DrawableBarLine.cs | 1 - .../Objects/Drawables/DrawableLyric.cs | 49 +++---------------- .../UI/LyricPlayfield.cs | 28 ++++++++++- 3 files changed, 32 insertions(+), 46 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs index 4b355f77c..f1735670e 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs @@ -48,7 +48,6 @@ public DrawableBarLine() public DrawableBarLine([CanBeNull] BarLine barLine) : base(barLine) { - } [BackgroundDependencyLoader] diff --git a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs index 771d615cb..0c442ed4c 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs @@ -59,15 +59,13 @@ private void load() { Scale = new Vector2(2f); AutoSizeAxes = Axes.Both; - InternalChildren = new Drawable[] + + AddInternal(KaraokeText = new KarakeSpriteText()); + AddInternal(translateText = new OsuSpriteText { - KaraokeText = new KarakeSpriteText(), - translateText = new OsuSpriteText - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.TopLeft, - } - }; + Anchor = Anchor.BottomLeft, + Origin = Anchor.TopLeft, + }); TextBindable.BindValueChanged(text => { KaraokeText.Text = text.NewValue; }); TimeTagsBindable.BindValueChanged(timeTags => { KaraokeText.TimeTags = TimeTagsUtils.ToDictionary(timeTags.NewValue); }); @@ -104,19 +102,6 @@ protected override void OnFree() TranslateTextBindable.UnbindFrom(HitObject.TranslateTextBindable); } - protected override void UpdateInitialTransforms() - { - base.UpdateInitialTransforms(); - - // Manually set to reduce the number of future alive objects to a bare minimum. - LifetimeEnd = HitObject.EndTime + 1000; - LifetimeStart = HitObject.StartTime - HitObject.TimePreempt; - } - - protected override void ClearInternal(bool disposeChildren = true) - { - } - protected virtual void ApplyRuby() { KaraokeText.Rubies = DisplayRuby ? HitObject.RubyTags?.Select(x => new PositionText(x.Text, x.StartIndex, x.EndIndex)).ToArray() : null; @@ -256,28 +241,6 @@ protected override void UpdateStartTimeStateTransforms() } } - public override double LifetimeStart - { - get => base.LifetimeStart; - set - { - base.LifetimeStart = value; - KaraokeText.LifetimeStart = value; - translateText.LifetimeStart = value; - } - } - - public override double LifetimeEnd - { - get => base.LifetimeEnd; - set - { - base.LifetimeEnd = value; - KaraokeText.LifetimeEnd = value; - translateText.LifetimeEnd = value; - } - } - private bool displayRuby; public bool DisplayRuby diff --git a/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs b/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs index e989eaa66..1cf09dc19 100644 --- a/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs +++ b/osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs @@ -14,6 +14,7 @@ using osu.Game.Rulesets.Karaoke.Judgements; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Objects.Drawables; +using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI; @@ -64,6 +65,13 @@ public LyricPlayfield() seekCache.Validate(); } + protected override void LoadComplete() + { + base.LoadComplete(); + + NewResult += OnNewResult; + } + private void updateLyricTranslate() { var isTranslate = translate.Value; @@ -77,12 +85,12 @@ public override void Add(DrawableHitObject h) { if (h is DrawableLyric drawableLyric) { + // todo : not really sure should cancel binding action in here? drawableLyric.OnLyricStart += OnNewResult; drawableLyric.DisplayRuby = displayRuby.Value; drawableLyric.DisplayRomaji = displayRomaji.Value; } - h.OnNewResult += OnNewResult; base.Add(h); } @@ -91,7 +99,6 @@ public override bool Remove(DrawableHitObject h) if (h is DrawableLyric drawableLyric) drawableLyric.OnLyricStart -= OnNewResult; - h.OnNewResult -= OnNewResult; return base.Remove(h); } @@ -124,5 +131,22 @@ private void load(KaraokeRulesetConfigManager rulesetConfig, KaraokeSessionStati RegisterPool(50); } + + protected override HitObjectLifetimeEntry CreateLifetimeEntry(HitObject hitObject) => new LyricHitObjectLifetimeEntry(hitObject); + + private class LyricHitObjectLifetimeEntry : HitObjectLifetimeEntry + { + public LyricHitObjectLifetimeEntry(HitObject hitObject) + : base(hitObject) + { + // Manually set to reduce the number of future alive objects to a bare minimum. + LifetimeEnd = Lyric.EndTime; + LifetimeStart = HitObject.StartTime - Lyric.TimePreempt; + } + + protected Lyric Lyric => (Lyric)HitObject; + + protected override double InitialLifetimeOffset => Lyric.TimePreempt; + } } } From 066535be0a723d06ad1cff1a2e12fdefcbb0daad Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 24 Dec 2020 22:13:33 +0900 Subject: [PATCH 7/8] Fix test case error. --- osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs index f1735670e..84de39482 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs @@ -99,7 +99,7 @@ private void load() protected override void LoadComplete() { base.LoadComplete(); - major.BindValueChanged(updateMajor, true); + major.BindValueChanged(updateMajor); } private void updateMajor(ValueChangedEvent major) From e30ddccbc177a226119fb8f44121996b93a0a1b9 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 24 Dec 2020 22:19:36 +0900 Subject: [PATCH 8/8] Fix compile error. --- .../Objects/Drawables/DrawableBarLine.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs index 84de39482..ad1b619b5 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs @@ -31,7 +31,7 @@ public class DrawableBarLine : DrawableKaraokeScrollingHitObject /// /// The visual line tracker. /// - private Container line; + private Box line; /// /// Container with triangles. Only visible for major lines. @@ -58,7 +58,7 @@ private void load() AddRangeInternal(new Drawable[] { - new Box + line = new Box { Name = "Bar line", Anchor = Anchor.CentreLeft, @@ -99,7 +99,7 @@ private void load() protected override void LoadComplete() { base.LoadComplete(); - major.BindValueChanged(updateMajor); + major.BindValueChanged(updateMajor, true); } private void updateMajor(ValueChangedEvent major)