Skip to content

Commit

Permalink
Refactor the section.
Browse files Browse the repository at this point in the history
Use edit way can actually affect the created time-tag type indication.

merge.
  • Loading branch information
andy840119 committed Jun 2, 2024
1 parent d126d1c commit b6a81be
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using osu.Game.Rulesets.Karaoke.Edit.Components.Sprites;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.CaretPosition;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States.Modes;
using osu.Game.Rulesets.Karaoke.Utils;
using osuTK;

Expand Down Expand Up @@ -107,7 +108,10 @@ public TimeTagsInfo(TextIndex.IndexState indexState)
}

[BackgroundDependencyLoader]
private void load(LyricEditorColourProvider colourProvider, ILyricEditorState state, ILyricTimeTagsChangeHandler lyricTimeTagsChangeHandler)
private void load(LyricEditorColourProvider colourProvider,
ILyricEditorState state,
ILyricTimeTagsChangeHandler lyricTimeTagsChangeHandler,
IEditTimeTagModeState editTimeTagModeState)
{
InternalChildren = new Drawable[]
{
Expand Down Expand Up @@ -171,6 +175,7 @@ private void load(LyricEditorColourProvider colourProvider, ILyricEditorState st

var textIndex = new TextIndex(previousCaret.Value.CharIndex, indexState);
lyricTimeTagsChangeHandler.AddByPosition(textIndex);
editTimeTagModeState.BindableCreateType.Value = CreateTimeTagType.Mouse;
},
},
},
Expand Down Expand Up @@ -254,6 +259,9 @@ private partial class TimeTagVisualization : CompositeDrawable, IHasTooltip
[Resolved]
private ILyricTimeTagsChangeHandler lyricTimeTagsChangeHandler { get; set; } = null!;

[Resolved]
private IEditTimeTagModeState editTimeTagModeState { get; set; } = null!;

private readonly TimeTag timeTag;

public TimeTagVisualization(TimeTag timeTag)
Expand All @@ -277,6 +285,7 @@ public TimeTagVisualization(TimeTag timeTag)
protected override bool OnClick(ClickEvent e)
{
lyricTimeTagsChangeHandler.Remove(timeTag);
editTimeTagModeState.BindableCreateType.Value = CreateTimeTagType.Mouse;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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.Bindables;
using osu.Framework.Graphics.Sprites;
Expand All @@ -22,9 +21,7 @@ public partial class CreateTimeTagActionSection : EditorSection, IKeyBindingHand
[Resolved]
private ILyricTimeTagsChangeHandler lyricTimeTagsChangeHandler { get; set; } = null!;

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

private readonly IBindable<ICaretPosition?> bindableCaretPosition = new Bindable<ICaretPosition?>();
private readonly Bindable<CreateTimeTagType> bindableCreateType = new();

public CreateTimeTagActionSection()
Expand All @@ -39,43 +36,53 @@ public CreateTimeTagActionSection()
}

[BackgroundDependencyLoader]
private void load(IEditTimeTagModeState editTimeTagModeState)
private void load(IEditTimeTagModeState editTimeTagModeState, ILyricCaretState lyricCaretState)
{
bindableCaretPosition.BindTo(lyricCaretState.BindableCaretPosition);
bindableCreateType.BindTo(editTimeTagModeState.BindableCreateType);
}

public bool OnPressed(KeyBindingPressEvent<KaraokeEditAction> e)
{
var action = e.Action;
var caretPosition = lyricCaretState.CaretPosition;
var caretPosition = bindableCaretPosition.Value;

if (caretPosition is not CreateRemoveTimeTagCaretPosition createRemoveTimeTagCaretPosition)
return false;

return caretPosition switch
if (LyricEditor.ToMovingCaretAction(e.Action) != null)
{
CreateRemoveTimeTagCaretPosition timeTagIndexCaretPosition => processCreateTimeTagAction(timeTagIndexCaretPosition, action),
_ => throw new NotSupportedException(nameof(caretPosition)),
};
bindableCreateType.Value = CreateTimeTagType.Keyboard;
return false;
}

if (createTimeTagByKeyboard(createRemoveTimeTagCaretPosition.CharIndex, action))
{
bindableCreateType.Value = CreateTimeTagType.Keyboard;
return true;
}

return false;
}

private bool processCreateTimeTagAction(CreateRemoveTimeTagCaretPosition createRemoveTimeTagCaretPosition, KaraokeEditAction action)
private bool createTimeTagByKeyboard(int charIndex, KaraokeEditAction action)
{
int index = createRemoveTimeTagCaretPosition.CharIndex;

switch (action)
{
case KaraokeEditAction.CreateStartTimeTag:
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(index));
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(charIndex));
return true;

case KaraokeEditAction.CreateEndTimeTag:
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(index, TextIndex.IndexState.End));
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(charIndex, TextIndex.IndexState.End));
return true;

case KaraokeEditAction.RemoveStartTimeTag:
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(index));
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(charIndex));
return true;

case KaraokeEditAction.RemoveEndTimeTag:
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(index, TextIndex.IndexState.End));
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(charIndex, TextIndex.IndexState.End));
return true;

default:
Expand Down

0 comments on commit b6a81be

Please sign in to comment.