-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move PreviewKaraokeSpriteText into the child of LyricLayer.
And LyricLayer should: - handle the offset of the PreviewKaraokeSpriteText. - implement the IPreviewLyricPositionProvider and provide the position info.
- Loading branch information
1 parent
a177523
commit 34b82e8
Showing
4 changed files
with
76 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,47 @@ | ||
// Copyright (c) andy840119 <[email protected]>. 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.Graphics; | ||
using osu.Framework.Graphics.Primitives; | ||
using osu.Game.Graphics; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using osu.Game.Screens.Edit; | ||
using osuTK; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Components.Lyrics; | ||
|
||
public partial class LyricLayer : Layer | ||
public partial class LyricLayer : Layer, IPreviewLyricPositionProvider | ||
{ | ||
[Resolved] | ||
private OsuColour colours { get; set; } = null!; | ||
|
||
private readonly PreviewKaraokeSpriteText previewKaraokeSpriteText; | ||
|
||
public Action<Vector2>? SizeChanged; | ||
|
||
public LyricLayer(Lyric lyric) | ||
: base(lyric) | ||
{ | ||
InternalChild = previewKaraokeSpriteText = new PreviewKaraokeSpriteText(lyric); | ||
|
||
previewKaraokeSpriteText.SizeChanged = size => | ||
{ | ||
SizeChanged?.Invoke(size); | ||
}; | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(EditorClock clock) | ||
{ | ||
previewKaraokeSpriteText.Clock = clock; | ||
} | ||
|
||
public void ApplyDrawableLyric(Drawable drawable) | ||
public Vector2 LyricPosition | ||
{ | ||
InternalChild = drawable; | ||
get => previewKaraokeSpriteText.Position; | ||
set => previewKaraokeSpriteText.Position = value; | ||
} | ||
|
||
public override void UpdateDisableEditState(bool editable) | ||
|
@@ -32,4 +53,41 @@ public override void TriggerDisallowEditEffect(LyricEditorMode editorMode) | |
{ | ||
this.FlashColour(colours.Red, 200); | ||
} | ||
|
||
#region Text char index | ||
|
||
public int? GetCharIndexByPosition(float position) | ||
=> previewKaraokeSpriteText.GetCharIndexByPosition(position - LyricPosition.X); | ||
|
||
public RectangleF GetRectByCharIndex(int charIndex) | ||
=> previewKaraokeSpriteText.GetRectByCharIndex(charIndex).Offset(LyricPosition); | ||
|
||
#endregion | ||
|
||
#region Text indicator | ||
|
||
public int GetCharIndicatorByPosition(float position) | ||
=> previewKaraokeSpriteText.GetCharIndicatorByPosition(position - LyricPosition.X); | ||
|
||
public RectangleF GetRectByCharIndicator(int charIndex) | ||
=> previewKaraokeSpriteText.GetRectByCharIndicator(charIndex).Offset(LyricPosition); | ||
|
||
#endregion | ||
|
||
#region Ruby tag | ||
|
||
public RectangleF? GetRubyTagByPosition(RubyTag rubyTag) | ||
=> previewKaraokeSpriteText.GetRubyTagByPosition(rubyTag)?.Offset(LyricPosition); | ||
|
||
#endregion | ||
|
||
#region Time tag | ||
|
||
public TimeTag? GetTimeTagByPosition(float position) | ||
=> previewKaraokeSpriteText.GetTimeTagByPosition(position - LyricPosition.X); | ||
|
||
public Vector2 GetPositionByTimeTag(TimeTag timeTag) | ||
=> previewKaraokeSpriteText.GetPositionByTimeTag(timeTag) + LyricPosition; | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters