From 848bfded1d28e3e694668f933cd6420cb139a4aa Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 12 Dec 2020 10:39:23 +0900 Subject: [PATCH] Implement set or delete time tag's time. --- .../Edit/Lyrics/LyricEditor.cs | 10 +++++ .../Edit/Lyrics/TimeTagManager.cs | 40 ++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs index a8ea20269..a87be55e9 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs @@ -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); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs index e5c105dfd..200abd967 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs @@ -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; @@ -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 BindableCursorPosition { get; set; } = new Bindable(); /// @@ -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;