From 848bfded1d28e3e694668f933cd6420cb139a4aa Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 12 Dec 2020 10:39:23 +0900 Subject: [PATCH 1/2] 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; From be7e31037fa60c95ea070bbc1ef73bd9675aa36b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 12 Dec 2020 11:12:22 +0900 Subject: [PATCH 2/2] Create and delete time-tag works. --- .../Edit/Lyrics/LyricEditor.cs | 22 +++++-- .../Edit/Lyrics/TimeTagManager.cs | 62 ++++++++++++++++++- 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs index a87be55e9..f4f75f0bb 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs @@ -58,6 +58,7 @@ protected override bool OnKeyDown(KeyDownEvent e) if (timeTagManager == null) return false; + // moving cursor action switch (e.Key) { case Key.Up: @@ -72,16 +73,27 @@ protected override bool OnKeyDown(KeyDownEvent e) return timeTagManager.MoveCursor(CursorAction.First); case Key.PageDown: return timeTagManager.MoveCursor(CursorAction.Last); + } + + // edit time tag action + var currentTimeTag = timeTagManager?.BindableCursorPosition?.Value; + switch (e.Key) + { 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) + var setTimeSuccess = timeTagManager?.SetTimeTagTime(currentTimeTag) ?? false; + if (setTimeSuccess) timeTagManager.MoveCursor(CursorAction.MoveRight); return setTimeSuccess; + case Key.N: + var createdTimeTag = timeTagManager?.AddTimeTag(currentTimeTag); + if (createdTimeTag != null) + timeTagManager.MoveCursorToTargetPosition(createdTimeTag); + return createdTimeTag != null; + case Key.Delete: + timeTagManager?.MoveCursor(CursorAction.MoveRight); + return timeTagManager?.RemoveTimeTag(currentTimeTag) ?? false; 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 200abd967..d1c2a2cd9 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs @@ -9,6 +9,7 @@ using osu.Game.Rulesets.Karaoke.Edit.Generator.TimeTags.Ja; using osu.Game.Rulesets.Karaoke.Edit.Generator.TimeTags.Zh; using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Utils; using osu.Game.Screens.Edit; using System; using System.Linq; @@ -32,6 +33,8 @@ public class TimeTagManager : Component public Bindable BindableCursorPosition { get; set; } = new Bindable(); + #region Edit Time Tag + /// /// Will auto-detect each 's and apply on them. /// @@ -64,7 +67,10 @@ public bool SetTimeTagTime(TimeTag timeTag) return false; changeHandler?.BeginChange(); + timeTag.Time = framedClock.CurrentTime; + refreshTimeTag(currentLyric); + changeHandler?.EndChange(); currentLyric.TimeTagsBindable.TriggerChange(); @@ -81,13 +87,65 @@ public bool ClearTimeTagTime(TimeTag timeTag) return false; changeHandler?.BeginChange(); + timeTag.Time = null; + refreshTimeTag(currentLyric); + changeHandler?.EndChange(); - currentLyric.TimeTagsBindable.TriggerChange(); return true; } + public TimeTag AddTimeTag(TimeTag timeTag) + { + var currentLyric = timeTagInLyric(timeTag); + if (currentLyric == null) + return null; + + var timeTags = currentLyric.TimeTags.ToList(); + var targetIndex = timeTags.IndexOf(timeTag); + if (targetIndex < 0) + return null; + + var newTimeTag = new TimeTag(timeTag.Index); + timeTags.Insert(targetIndex, newTimeTag); + + changeHandler?.BeginChange(); + + currentLyric.TimeTags = timeTags.ToArray(); + sortingTimeTag(currentLyric); + + changeHandler?.EndChange(); + + return newTimeTag; + } + + public bool RemoveTimeTag(TimeTag timeTag) + { + var currentLyric = timeTagInLyric(timeTag); + if (currentLyric == null) + return false; + + changeHandler?.BeginChange(); + + // delete time tag from list + currentLyric.TimeTags = currentLyric.TimeTags.Where(x => x != timeTag).ToArray(); + + changeHandler?.EndChange(); + + return true; + } + + private void refreshTimeTag(Lyric lyric) + => lyric.TimeTags = lyric.TimeTags.ToArray(); + + private void sortingTimeTag(Lyric lyric) + => lyric.TimeTags = TimeTagsUtils.Sort(lyric.TimeTags); + + #endregion + + #region Time Tag cursor + public bool MoveCursor(CursorAction action) { var currentTimeTag = BindableCursorPosition.Value; @@ -223,6 +281,8 @@ public TimeTag[] GenerateTimeTags(Lyric lyric) } } } + + #endregion } public enum CursorAction