Skip to content

Commit

Permalink
Implement set or delete time tag's time.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Dec 12, 2020
1 parent 4475574 commit 848bfde
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ protected override bool OnKeyDown(KeyDownEvent e)
return timeTagManager.MoveCursor(CursorAction.First);
case Key.PageDown:
return timeTagManager.MoveCursor(CursorAction.Last);
case Key.BackSpace:
case Key.Delete:
var currentTimeTag = timeTagManager?.BindableCursorPosition?.Value;
return timeTagManager?.ClearTimeTagTime(currentTimeTag) ?? false;
case Key.Space:
var timeTag = timeTagManager?.BindableCursorPosition?.Value;
var setTimeSuccess = timeTagManager?.SetTimeTagTime(timeTag) ?? false;
if(setTimeSuccess)
timeTagManager.MoveCursor(CursorAction.MoveRight);
return setTimeSuccess;
default:
return base.OnKeyDown(e);
}
Expand Down
40 changes: 39 additions & 1 deletion osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Timing;
using osu.Game.Rulesets.Karaoke.Edit.Generator.TimeTags.Ja;
using osu.Game.Rulesets.Karaoke.Edit.Generator.TimeTags.Zh;
using osu.Game.Rulesets.Karaoke.Objects;
Expand All @@ -23,9 +24,12 @@ public class TimeTagManager : Component
[Resolved]
private EditorBeatmap beatmap { get; set; }

[Resolved(CanBeNull = true)]
[Resolved(canBeNull: true)]
private IEditorChangeHandler changeHandler { get; set; }

[Resolved(canBeNull: true)]
private IFrameBasedClock framedClock { get; set; }

public Bindable<TimeTag> BindableCursorPosition { get; set; } = new Bindable<TimeTag>();

/// <summary>
Expand All @@ -50,6 +54,40 @@ public void AutoGenerateTimeTags()
changeHandler?.EndChange();
}

public bool SetTimeTagTime(TimeTag timeTag)
{
if (framedClock == null)
return false;

var currentLyric = timeTagInLyric(timeTag);
if (currentLyric == null)
return false;

changeHandler?.BeginChange();
timeTag.Time = framedClock.CurrentTime;
changeHandler?.EndChange();

currentLyric.TimeTagsBindable.TriggerChange();
return true;
}

public bool ClearTimeTagTime(TimeTag timeTag)
{
if (framedClock == null)
return false;

var currentLyric = timeTagInLyric(timeTag);
if (currentLyric == null)
return false;

changeHandler?.BeginChange();
timeTag.Time = null;
changeHandler?.EndChange();

currentLyric.TimeTagsBindable.TriggerChange();
return true;
}

public bool MoveCursor(CursorAction action)
{
var currentTimeTag = BindableCursorPosition.Value;
Expand Down

0 comments on commit 848bfde

Please sign in to comment.