Skip to content

Commit

Permalink
Make the idol/hover caret state better.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Aug 24, 2024
1 parent 6cd8bfd commit 65de336
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public partial class DrawableCreateRemoveTimeTagCaret : DrawableCaret<CreateRemo
{
private const float border_spacing = 5;

private readonly TimeTagsInfo startTimeTagInfo;
private readonly TimeTagsInfo endTimeTagInfo;
private readonly TimeTagsInfo? startTimeTagInfo;
private readonly TimeTagsInfo? endTimeTagInfo;

public DrawableCreateRemoveTimeTagCaret(DrawableCaretState state)
: base(state)
Expand All @@ -42,13 +42,21 @@ public DrawableCreateRemoveTimeTagCaret(DrawableCaretState state)
BorderThickness = border_spacing,
BorderColour = Colour4.White,
RelativeSizeAxes = Axes.Both,
Alpha = GetAlpha(state),
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Colour4.White,
Alpha = 0.1f,
},
},
};

if (state != DrawableCaretState.Idle)
return;

AddRangeInternal(new[]
{
startTimeTagInfo = new TimeTagsInfo(TextIndex.IndexState.Start)
{
X = 18,
Expand All @@ -63,7 +71,7 @@ public DrawableCreateRemoveTimeTagCaret(DrawableCaretState state)
Origin = Anchor.CentreLeft,
Alpha = GetAlpha(state),
},
};
});
}

protected override void ApplyCaretPosition(CreateRemoveTimeTagCaretPosition caret)
Expand All @@ -73,8 +81,8 @@ protected override void ApplyCaretPosition(CreateRemoveTimeTagCaretPosition care
Position = rect.TopLeft - new Vector2(border_spacing);
Size = rect.Size + new Vector2(border_spacing * 2);

startTimeTagInfo.UpdateCaretPosition(caret);
endTimeTagInfo.UpdateCaretPosition(caret);
startTimeTagInfo?.UpdateCaretPosition(caret);
endTimeTagInfo?.UpdateCaretPosition(caret);
}

protected override void TriggerDisallowEditEffect(OsuColour colour)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Compone

public partial class DrawableCuttingCaret : DrawableCaret<CuttingCaretPosition>
{
private const float caret_width = 10;

private readonly Container splitter;
private readonly SpriteIcon splitIcon;

public DrawableCuttingCaret(DrawableCaretState state)
: base(state)
{
Width = 10;
Width = caret_width;
Origin = Anchor.TopCentre;

InternalChildren = new Drawable[]
Expand Down Expand Up @@ -87,7 +89,7 @@ protected override void ApplyCaretPosition(CuttingCaretPosition caret)
{
var rect = LyricPositionProvider.GetRectByCharIndicator(caret.CharGap);

Position = rect.TopLeft;
Position = rect.TopLeft + new Vector2(rect.Width / 2 - caret_width / 2, 0);
Height = rect.Height;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public partial class DrawableRecordingTimeTagCaret : DrawableCaret<RecordingTime
private const float caret_resize_time = 60;

// should be list of indexes.
private readonly TextIndexInfo textIndexInfo;
private readonly Box indicator;
private readonly TextIndexInfo? textIndexInfo;
private readonly Box? indicator;

public DrawableRecordingTimeTagCaret(DrawableCaretState state)
: base(state)
Expand All @@ -43,18 +43,25 @@ public DrawableRecordingTimeTagCaret(DrawableCaretState state)
Alpha = 0.1f,
},
},
textIndexInfo = new TextIndexInfo
{
Y = -10,
Alpha = GetAlpha(state),
},
indicator = new Box
{
Width = border_spacing,
RelativeSizeAxes = Axes.Y,
Alpha = GetAlpha(state),
},
};

if (state == DrawableCaretState.Idle)
{
AddRangeInternal(new Drawable[]
{
textIndexInfo = new TextIndexInfo
{
Y = -10,
Alpha = GetAlpha(state),
},
indicator = new Box
{
Width = border_spacing,
RelativeSizeAxes = Axes.Y,
Alpha = GetAlpha(state),
},
});
}
}

protected override void ApplyCaretPosition(RecordingTimeTagCaretPosition caret)
Expand All @@ -67,13 +74,21 @@ protected override void ApplyCaretPosition(RecordingTimeTagCaretPosition caret)

// update the caret.
changeTheSizeByRect(rect);
textIndexInfo.Anchor = TextIndexUtils.GetValueByState(timeTag.Index, Anchor.TopLeft, Anchor.TopRight);
textIndexInfo.Origin = TextIndexUtils.GetValueByState(timeTag.Index, Anchor.BottomLeft, Anchor.BottomRight);
textIndexInfo.X = TextIndexUtils.GetValueByState(timeTag.Index, -10, 10);
textIndexInfo.UpdateCaret(caret);
indicator.Colour = Colours.GetRecordingTimeTagCaretColour(timeTag);
indicator.Anchor = TextIndexUtils.GetValueByState(timeTag.Index, Anchor.CentreLeft, Anchor.CentreRight);
indicator.Origin = TextIndexUtils.GetValueByState(timeTag.Index, Anchor.CentreLeft, Anchor.CentreRight);

if (textIndexInfo != null)
{
textIndexInfo.Anchor = TextIndexUtils.GetValueByState(timeTag.Index, Anchor.TopLeft, Anchor.TopRight);
textIndexInfo.Origin = TextIndexUtils.GetValueByState(timeTag.Index, Anchor.BottomLeft, Anchor.BottomRight);
textIndexInfo.X = TextIndexUtils.GetValueByState(timeTag.Index, -10, 10);
textIndexInfo.UpdateCaret(caret);
}

if (indicator != null)
{
indicator.Colour = Colours.GetRecordingTimeTagCaretColour(timeTag);
indicator.Anchor = TextIndexUtils.GetValueByState(timeTag.Index, Anchor.CentreLeft, Anchor.CentreRight);
indicator.Origin = TextIndexUtils.GetValueByState(timeTag.Index, Anchor.CentreLeft, Anchor.CentreRight);
}
}

private void changeTheSizeByRect(RectangleF rect)
Expand Down

0 comments on commit 65de336

Please sign in to comment.