Skip to content

Commit

Permalink
Add a new role in the base range caret index:
Browse files Browse the repository at this point in the history
- if user is start dragging the caret, should hide the hover caret.
  • Loading branch information
andy840119 committed Aug 24, 2024
1 parent 2925095 commit 68f92d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public partial class DrawableCreateRubyTagCaret : DrawableRangeCaret<CreateRubyT
private const float caret_move_time = 60;
private const float caret_resize_time = 60;

[Resolved]
private ILyricCaretState lyricCaretState { get; set; } = null!;

private readonly SpriteIcon icon;

public DrawableCreateRubyTagCaret(DrawableCaretState state)
Expand Down Expand Up @@ -74,19 +71,6 @@ private void load(OsuColour colours)

protected override void ApplyCaretPosition(CreateRubyTagCaretPosition caret)
{
// should not show the hover caret if already contains the selected range.
if (State == DrawableCaretState.Hover)
{
bool isClickToThisCaret = lyricCaretState.CaretPosition?.Lyric == caret.Lyric;
bool isDraggingToThisCaret = lyricCaretState.RangeCaretPosition?.IsInRange(caret.Lyric) ?? false;

if (isClickToThisCaret || isDraggingToThisCaret)
{
Hide();
return;
}
}

startCharIndex = caret.CharIndex;
endCharIndex = caret.CharIndex;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.CaretPosition;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States;

Expand All @@ -10,9 +12,26 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Compone
public abstract partial class DrawableRangeCaret<TCaretPosition> : DrawableCaret, ICanAcceptRangeIndex
where TCaretPosition : struct, IIndexCaretPosition
{
private readonly IBindable<RangeCaretPosition?> bindableRangeCaretPosition = new Bindable<RangeCaretPosition?>();

protected DrawableRangeCaret(DrawableCaretState state)
: base(state)
{
// should auto hide the hover caret if selecting.
bindableRangeCaretPosition.BindValueChanged(x =>
{
if (State != DrawableCaretState.Hover)
return;

if (x.NewValue != null)
Hide();
});
}

[BackgroundDependencyLoader]
private void load(ILyricCaretState lyricCaretState)
{
bindableRangeCaretPosition.BindTo(lyricCaretState.BindableRangeCaretPosition);
}

public sealed override void ApplyCaretPosition(ICaretPosition caret)
Expand Down

0 comments on commit 68f92d1

Please sign in to comment.