Skip to content

Commit

Permalink
Merge pull request #1153 from andy840119/implement-clear-notes-section
Browse files Browse the repository at this point in the history
Implement clear notes section in the edit note mode.
  • Loading branch information
andy840119 authored Mar 6, 2022
2 parents 346ff0c + f24012b commit 8c5fc89
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,37 @@ public void TestChangeDisplayStateToNonVisible()
Assert.AreEqual(new Tone(), h.Tone);
});
}

[Test]
public void TestClear()
{
var lyric = new Lyric();

// note that lyric and notes should in the selection.
PrepareHitObject(lyric);
PrepareHitObjects(new[]
{
new Note
{
Text = "カラ",
RubyText = "から",
StartTime = 1000,
Duration = 500,
ParentLyric = lyric,
},
new Note
{
Text = "オケ",
RubyText = "おけ",
StartTime = 1500,
Duration = 500,
ParentLyric = lyric,
}
}, false);

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

AssertHitObjects(Assert.IsEmpty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public interface INotesChangeHandler : IAutoGenerateChangeHandler
void ChangeRubyText(string ruby);

void ChangeDisplayState(bool display);

void Clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ public void ChangeDisplayState(bool display)
});
}

public void Clear()
{
PerformOnLyricSelection(lyric =>
{
var notes = beatmap.HitObjects.OfType<Note>().Where(n => n.ParentLyric == lyric).ToList();
RemoveRange(notes);
});
}

protected void PerformOnLyricSelection(Action<Lyric> action) => beatmap.PerformOnSelection(h =>
{
if (h is Lyric lyric)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public abstract class AutoGenerateSection : Section
[BackgroundDependencyLoader]
private void load(EditorBeatmap beatmap, ILyricSelectionState lyricSelectionState, OsuColour colours)
{
// should wait until BDL in the parent class has been loaded.
Schedule(() =>
{
var disableSelectingLyrics = GetDisableSelectingLyrics(beatmap.HitObjects.OfType<Lyric>());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Notes;
using osu.Game.Rulesets.Karaoke.Edit.Components.Containers;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Components;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Notes
{
public class NoteClearSection : Section
{
protected sealed override string Title => "Clear";

[BackgroundDependencyLoader]
private void load(ILyricSelectionState lyricSelectionState, INotesChangeHandler notesChangeHandler)
{
Children = new Drawable[]
{
new AutoGenerateButton
{
StartSelecting = () => new Dictionary<Lyric, string>()
},
};

lyricSelectionState.Action = e =>
{
if (e != LyricEditorSelectingAction.Apply)
return;

notesChangeHandler.Clear();
};
}

private class AutoGenerateButton : SelectLyricButton
{
protected override string StandardText => "Clear";

protected override string SelectingText => "Cancel clear";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Notes
{
public enum NoteEditModeSpecialAction
{
AutoGenerate,

SyncTime,

Clear,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Edit.Components.Containers;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Notes
{
Expand All @@ -14,15 +14,15 @@ public class NoteEditPropertyModeSection : Section
protected override string Title => "Edit property";

[BackgroundDependencyLoader]
private void load(Bindable<NoteEditPropertyMode> bindableNoteEditPropertyMode)
private void load(IEditNoteModeState editNoteModeState)
{
Children = new Drawable[]
{
new LabelledEnumDropdown<NoteEditPropertyMode>
{
Label = "Edit property",
Description = "Batch edit text, ruby(alternative) text or display from notes",
Current = bindableNoteEditPropertyMode,
Current = editNoteModeState.NoteEditPropertyMode,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ void reCreateEditComponents()
}

[BackgroundDependencyLoader]
private void load(EditorBeatmap beatmap, ILyricCaretState lyricCaretState, Bindable<NoteEditPropertyMode> bindableNoteEditPropertyMode)
private void load(EditorBeatmap beatmap, ILyricCaretState lyricCaretState, IEditNoteModeState editNoteModeState)
{
this.bindableNoteEditPropertyMode.BindTo(bindableNoteEditPropertyMode);
bindableNoteEditPropertyMode.BindTo(editNoteModeState.NoteEditPropertyMode);
lyricCaretState.BindableCaretPosition.BindValueChanged(e =>
{
var lyric = e.NewValue?.Lyric;
Expand Down
38 changes: 35 additions & 3 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Notes/NoteExtend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class NoteExtend : EditExtend

private readonly IBindable<NoteEditMode> bindableMode = new Bindable<NoteEditMode>();

[Cached]
private readonly Bindable<NoteEditPropertyMode> noteEditPropertyMode = new();
private readonly IBindable<NoteEditModeSpecialAction> bindableModeSpecialAction = new Bindable<NoteEditModeSpecialAction>();

public NoteExtend()
{
Expand All @@ -30,8 +29,9 @@ public NoteExtend()
{
new NoteEditModeSection(),
new NoteConfigSection(),
new NoteAutoGenerateSection(),
new SwitchSpecialActionSection(),
};
updateActionArea();
break;

case NoteEditMode.Edit:
Expand All @@ -55,12 +55,44 @@ public NoteExtend()
return;
}
}, true);

bindableModeSpecialAction.BindValueChanged(e =>
{
if (bindableMode.Value != NoteEditMode.Generate)
return;

updateActionArea();
}, true);

void updateActionArea()
{
RemoveAll(x => x is NoteAutoGenerateSection or NoteClearSection);

switch (bindableModeSpecialAction.Value)
{
case NoteEditModeSpecialAction.AutoGenerate:
Add(new NoteAutoGenerateSection());
break;

case NoteEditModeSpecialAction.SyncTime:
// todo: implement
break;

case NoteEditModeSpecialAction.Clear:
Add(new NoteClearSection());
break;

default:
return;
}
}
}

[BackgroundDependencyLoader]
private void load(IEditNoteModeState editNoteModeState)
{
bindableMode.BindTo(editNoteModeState.BindableEditMode);
bindableModeSpecialAction.BindTo(editNoteModeState.BindableSpecialAction);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Edit.Components.Containers;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Notes
{
public class SwitchSpecialActionSection : Section
{
protected sealed override string Title => "Clear";

[BackgroundDependencyLoader]
private void load(IEditNoteModeState editNoteModeState)
{
Children = new[]
{
new LabelledEnumDropdown<NoteEditModeSpecialAction>
{
Label = "Switch special actions",
Description = "Auto-generate, edit or clear the notes.",
Current = editNoteModeState.BindableSpecialAction,
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public void ChangeEditMode(NoteEditMode mode)

public BindableList<Note> SelectedItems { get; } = new();

public Bindable<NoteEditModeSpecialAction> BindableSpecialAction { get; } = new();

public Bindable<NoteEditPropertyMode> NoteEditPropertyMode { get; } = new();

[BackgroundDependencyLoader]
private void load(EditorBeatmap editorBeatmap)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Bindables;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Notes;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes
{
public interface IEditNoteModeState : IHasEditModeState<NoteEditMode>, IHasBlueprintSelection<Note>
{
Bindable<NoteEditModeSpecialAction> BindableSpecialAction { get; }

Bindable<NoteEditPropertyMode> NoteEditPropertyMode { get; }
}
}

0 comments on commit 8c5fc89

Please sign in to comment.