Skip to content

Commit

Permalink
Merge pull request #1665 from andy840119/add-button-to-set-time-tag-t…
Browse files Browse the repository at this point in the history
…ime-im-composer

Add button to set and clear the time tag time in the composer.
  • Loading branch information
andy840119 authored Oct 16, 2022
2 parents 949663e + ab6b433 commit cbd7589
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ public void TestClearTimeTagTime()
});
}

[Test]
public void TestClearAllTimeTagTime()
{
PrepareHitObject(new Lyric
{
Text = "カラオケ",
TimeTags = new[]
{
new TimeTag(new TextIndex()), // without time.
new TimeTag(new TextIndex(), 1000),
new TimeTag(new TextIndex(3, TextIndex.IndexState.End), 3000),
}
});

TriggerHandlerChanged(c => c.ClearAllTimeTagTime());

AssertSelectedHitObject(h =>
{
Assert.IsTrue(h.TimeTags.All(x => x.Time == null));
});
}

[Test]
public void TestAdd()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface ILyricTimeTagsChangeHandler : ILyricListPropertyChangeHandler<T

void ClearTimeTagTime(TimeTag timeTag);

void ClearAllTimeTagTime();

void AddByPosition(TextIndex index);

void RemoveByPosition(TextIndex index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public void ClearTimeTagTime(TimeTag timeTag)
});
}

public void ClearAllTimeTagTime()
{
PerformOnSelection(lyric =>
{
foreach (var timeTag in lyric.TimeTags)
{
timeTag.Time = null;
}
});
}

public void Add(TimeTag timeTag)
{
CheckExactlySelectedOneHitObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,16 @@ static IEnumerable<Drawable> createItemsForEditTimeTagMode(TimeTagEditMode timeT
new CreateTimeTagButton(),
new RemoveTimeTagButton(),
},
TimeTagEditMode.Recording => Array.Empty<Drawable>(),
TimeTagEditMode.Recording => new Drawable[]
{
new MoveToFirstIndexButton(),
new MoveToPreviousIndexButton(),
new MoveToNextIndexButton(),
new MoveToLastIndexButton(),
new SetTimeTagTimeButton(),
new ClearTimeTagTimeButton(),
new ClearAllTimeTagTimeButton(),
},
TimeTagEditMode.Adjust => Array.Empty<Drawable>(),
_ => throw new ArgumentOutOfRangeException(nameof(timeTagEditMode), timeTagEditMode, null)
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Diagnostics.CodeAnalysis;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Compose.Toolbar.TimeTags
{
public class ClearAllTimeTagTimeButton : ActionButton
{
[Resolved, AllowNull]
private ILyricTimeTagsChangeHandler lyricTimeTagsChangeHandler { get; set; }

public ClearAllTimeTagTimeButton()
{
SetIcon(FontAwesome.Solid.Redo);

Action = () =>
{
lyricTimeTagsChangeHandler.ClearAllTimeTagTime();
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 System.Diagnostics.CodeAnalysis;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Compose.Toolbar.TimeTags
{
public class ClearTimeTagTimeButton : KeyActionButton
{
protected override KaraokeEditAction EditAction => KaraokeEditAction.ClearTime;

[Resolved, AllowNull]
private ILyricCaretState lyricCaretState { get; set; }

[Resolved, AllowNull]
private ILyricTimeTagsChangeHandler lyricTimeTagsChangeHandler { get; set; }

public ClearTimeTagTimeButton()
{
SetIcon(FontAwesome.Solid.Eraser);

Action = () =>
{
if (lyricCaretState.BindableCaretPosition.Value is not TimeTagCaretPosition timeTagCaretPosition)
throw new InvalidOperationException();

var timeTag = timeTagCaretPosition.TimeTag;
lyricTimeTagsChangeHandler.ClearTimeTagTime(timeTag);
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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 System.Diagnostics.CodeAnalysis;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States;
using TagLib;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Compose.Toolbar.TimeTags
{
Expand All @@ -28,7 +28,7 @@ public CreateTimeTagButton()
Action = () =>
{
if (lyricCaretState.BindableCaretPosition.Value is not TimeTagIndexCaretPosition timeTagIndexCaretPosition)
throw new UnsupportedFormatException();
throw new InvalidOperationException();

var index = timeTagIndexCaretPosition.Index;
lyricTimeTagsChangeHandler.AddByPosition(index);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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 System.Diagnostics.CodeAnalysis;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States;
using TagLib;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Compose.Toolbar.TimeTags
{
Expand All @@ -28,7 +28,7 @@ public RemoveTimeTagButton()
Action = () =>
{
if (lyricCaretState.BindableCaretPosition.Value is not TimeTagIndexCaretPosition timeTagIndexCaretPosition)
throw new UnsupportedFormatException();
throw new InvalidOperationException();

var index = timeTagIndexCaretPosition.Index;
lyricTimeTagsChangeHandler.RemoveByPosition(index);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 System.Diagnostics.CodeAnalysis;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States;
using osu.Game.Screens.Edit;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Compose.Toolbar.TimeTags
{
public class SetTimeTagTimeButton : KeyActionButton
{
protected override KaraokeEditAction EditAction => KaraokeEditAction.SetTime;

[Resolved, AllowNull]
private ILyricCaretState lyricCaretState { get; set; }

[Resolved, AllowNull]
private ILyricTimeTagsChangeHandler lyricTimeTagsChangeHandler { get; set; }

[Resolved, AllowNull]
private EditorClock editorClock { get; set; }

public SetTimeTagTimeButton()
{
SetIcon(FontAwesome.Solid.Stopwatch);

Action = () =>
{
if (lyricCaretState.BindableCaretPosition.Value is not TimeTagCaretPosition timeTagCaretPosition)
throw new InvalidOperationException();

var timeTag = timeTagCaretPosition.TimeTag;
double currentTime = editorClock.CurrentTime;
lyricTimeTagsChangeHandler.SetTimeTagTime(timeTag, currentTime);
};
}
}
}

0 comments on commit cbd7589

Please sign in to comment.