From 950b3a328f6074a96056680d81715efe4af0e053 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 20 Jul 2024 20:37:01 +0800 Subject: [PATCH] Lyric position provider should consider about the lyric's own position. --- .../TestScenePreviewKaraokeSpriteText.cs | 5 ++++- .../Lyrics/PreviewKaraokeSpriteText.cs | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Lyrics/Content/TestScenePreviewKaraokeSpriteText.cs b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Lyrics/Content/TestScenePreviewKaraokeSpriteText.cs index e6e1ccb36..6c97fa4b7 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Lyrics/Content/TestScenePreviewKaraokeSpriteText.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Lyrics/Content/TestScenePreviewKaraokeSpriteText.cs @@ -57,7 +57,10 @@ private void load(OsuColour colour) RelativeSizeAxes = Axes.Both, Colour = colour.BlueDarker, }, - karaokeSpriteText = new PreviewKaraokeSpriteText(lyric), + karaokeSpriteText = new PreviewKaraokeSpriteText(lyric) + { + Position = new Vector2(24, 8), + }, mask = new Container { Masking = true, diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Components/Lyrics/PreviewKaraokeSpriteText.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Components/Lyrics/PreviewKaraokeSpriteText.cs index 141bf10aa..248f1d554 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Components/Lyrics/PreviewKaraokeSpriteText.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Components/Lyrics/PreviewKaraokeSpriteText.cs @@ -66,6 +66,9 @@ private void triggerSizeChangedEvent() #region Text char index public int? GetCharIndexByPosition(float position) + => getCharIndexByPosition(position - Position.X); + + private int? getCharIndexByPosition(float position) { for (int i = 0; i < Text.Length; i++) { @@ -84,6 +87,9 @@ Tuple getTriggerPositionByTimeIndex(int charIndex) } public RectangleF GetRectByCharIndex(int charIndex) + => getRectByCharIndex(charIndex).Offset(Position); + + private RectangleF getRectByCharIndex(int charIndex) { if (charIndex < 0 || charIndex >= Text.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); @@ -96,6 +102,9 @@ public RectangleF GetRectByCharIndex(int charIndex) #region Text indicator public int GetCharIndicatorByPosition(float position) + => getCharIndicatorByPosition(position - Position.X); + + private int getCharIndicatorByPosition(float position) { for (int i = 0; i < Text.Length; i++) { @@ -114,6 +123,9 @@ float getTriggerPositionByTimeIndex(int charIndex) } public RectangleF GetRectByCharIndicator(int charIndex) + => getRectByCharIndicator(charIndex).Offset(Position); + + private RectangleF getRectByCharIndicator(int charIndex) { if (charIndex < 0 || charIndex > Text.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); @@ -142,6 +154,9 @@ public RectangleF GetRectByCharIndicator(int charIndex) #region Ruby tag public RectangleF? GetRubyTagByPosition(RubyTag rubyTag) => + getRubyTagByPosition(rubyTag)?.Offset(Position); + + private RectangleF? getRubyTagByPosition(RubyTag rubyTag) => spriteText.GetRubyTagPosition(rubyTag); #endregion @@ -149,6 +164,9 @@ public RectangleF GetRectByCharIndicator(int charIndex) #region Time tag public TimeTag? GetTimeTagByPosition(float position) + => getTimeTagByPosition(position - Position.X); + + private TimeTag? getTimeTagByPosition(float position) { var hoverIndex = getHoverIndex(); if (hoverIndex == null) @@ -184,6 +202,9 @@ Tuple getTriggerRange(TextIndex textIndex) } public Vector2 GetPositionByTimeTag(TimeTag timeTag) + => getPositionByTimeTag(timeTag) + Position; + + private Vector2 getPositionByTimeTag(TimeTag timeTag) { var basePosition = spriteText.GetTimeTagPosition(timeTag.Index); float extraPosition = extraSpacing(HitObject.TimeTags, timeTag);