-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1581 from andy840119/should-reset-selected-items-…
…in-the-mode-status Should reset selected items in the mode status
- Loading branch information
Showing
10 changed files
with
159 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 17 additions & 5 deletions
22
osu.Game.Rulesets.Karaoke/Edit/Lyrics/States/Modes/EditNoteModeState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,50 @@ | ||
// 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 System.Diagnostics.CodeAnalysis; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Notes; | ||
using osu.Game.Rulesets.Karaoke.Edit.Utils; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using osu.Game.Rulesets.Karaoke.Utils; | ||
using osu.Game.Rulesets.Objects; | ||
using osu.Game.Screens.Edit; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes | ||
{ | ||
public class EditNoteModeState : Component, IEditNoteModeState | ||
public class EditNoteModeState : ModeStateWithBlueprintContainer<Note>, IEditNoteModeState | ||
{ | ||
private readonly Bindable<NoteEditMode> bindableEditMode = new(); | ||
private readonly BindableList<HitObject> selectedHitObjects = new(); | ||
|
||
[Resolved, AllowNull] | ||
private EditorBeatmap editorBeatmap { get; set; } | ||
|
||
public IBindable<NoteEditMode> BindableEditMode => bindableEditMode; | ||
|
||
public void ChangeEditMode(NoteEditMode mode) | ||
=> bindableEditMode.Value = 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) | ||
private void load() | ||
{ | ||
BindablesUtils.Sync(SelectedItems, selectedHitObjects); | ||
selectedHitObjects.BindTo(editorBeatmap.SelectedHitObjects); | ||
} | ||
|
||
protected override bool IsWriteLyricPropertyLocked(Lyric lyric) | ||
=> HitObjectWritableUtils.IsCreateOrRemoveNoteLocked(lyric); | ||
|
||
protected override bool SelectFirstProperty(Lyric lyric) | ||
=> BindableEditMode.Value == NoteEditMode.Edit; | ||
|
||
protected override IEnumerable<Note> SelectableProperties(Lyric lyric) | ||
=> EditorBeatmapUtils.GetNotesByLyric(editorBeatmap, lyric); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
// 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.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Game.Rulesets.Karaoke.Edit.Utils; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes | ||
{ | ||
public class EditRomajiModeState : Component, IEditRomajiModeState | ||
public class EditRomajiModeState : ModeStateWithBlueprintContainer<RomajiTag>, IEditRomajiModeState | ||
{ | ||
private readonly Bindable<TextTagEditMode> bindableEditMode = new(); | ||
|
||
|
@@ -16,6 +17,13 @@ public class EditRomajiModeState : Component, IEditRomajiModeState | |
public void ChangeEditMode(TextTagEditMode mode) | ||
=> bindableEditMode.Value = mode; | ||
|
||
public BindableList<RomajiTag> SelectedItems { get; } = new(); | ||
protected override bool IsWriteLyricPropertyLocked(Lyric lyric) | ||
=> HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.RomajiTags)); | ||
|
||
protected override bool SelectFirstProperty(Lyric lyric) | ||
=> BindableEditMode.Value == TextTagEditMode.Edit; | ||
|
||
protected override IEnumerable<RomajiTag> SelectableProperties(Lyric lyric) | ||
=> lyric.RomajiTags; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
// 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.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Game.Rulesets.Karaoke.Edit.Utils; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes | ||
{ | ||
public class EditRubyModeState : Component, IEditRubyModeState | ||
public class EditRubyModeState : ModeStateWithBlueprintContainer<RubyTag>, IEditRubyModeState | ||
{ | ||
private readonly Bindable<TextTagEditMode> bindableEditMode = new(); | ||
|
||
|
@@ -16,6 +17,13 @@ public class EditRubyModeState : Component, IEditRubyModeState | |
public void ChangeEditMode(TextTagEditMode mode) | ||
=> bindableEditMode.Value = mode; | ||
|
||
public BindableList<RubyTag> SelectedItems { get; } = new(); | ||
protected override bool IsWriteLyricPropertyLocked(Lyric lyric) | ||
=> HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.RubyTags)); | ||
|
||
protected override bool SelectFirstProperty(Lyric lyric) | ||
=> BindableEditMode.Value == TextTagEditMode.Edit; | ||
|
||
protected override IEnumerable<RubyTag> SelectableProperties(Lyric lyric) | ||
=> lyric.RubyTags; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
osu.Game.Rulesets.Karaoke/Edit/Lyrics/States/Modes/ModeStateWithBlueprintContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// 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.Collections.Generic; | ||
using System.Linq; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes | ||
{ | ||
public abstract class ModeStateWithBlueprintContainer<TObject> : Component, IHasBlueprintSelection<TObject> where TObject : class | ||
{ | ||
private readonly IBindable<LyricEditorMode> bindableMode = new Bindable<LyricEditorMode>(); | ||
private readonly IBindable<ICaretPosition?> bindableCaretPosition = new Bindable<ICaretPosition?>(); | ||
private readonly IBindable<int> bindableLyricPropertyWritableVersion = new Bindable<int>(); | ||
|
||
public BindableList<TObject> SelectedItems { get; } = new(); | ||
|
||
protected ModeStateWithBlueprintContainer() | ||
{ | ||
bindableMode.BindValueChanged(e => | ||
{ | ||
TriggerDisableStateChanged(); | ||
}); | ||
|
||
bindableCaretPosition.BindValueChanged(e => | ||
{ | ||
bindableLyricPropertyWritableVersion.UnbindBindings(); | ||
|
||
var lyric = e.NewValue?.Lyric; | ||
|
||
if (lyric == null) | ||
return; | ||
|
||
bindableLyricPropertyWritableVersion.BindTo(lyric.LyricPropertyWritableVersion); | ||
TriggerDisableStateChanged(); | ||
}); | ||
|
||
bindableLyricPropertyWritableVersion.BindValueChanged(_ => | ||
{ | ||
TriggerDisableStateChanged(); | ||
}); | ||
} | ||
|
||
protected virtual void TriggerDisableStateChanged() | ||
{ | ||
var caret = bindableCaretPosition.Value; | ||
if (caret == null) | ||
return; | ||
|
||
var lyric = caret.Lyric; | ||
var generateType = caret.GenerateType; | ||
|
||
SelectedItems.Clear(); | ||
bool locked = IsWriteLyricPropertyLocked(lyric); | ||
if (locked) | ||
return; | ||
|
||
switch (generateType) | ||
{ | ||
case CaretGenerateType.Action: | ||
if (SelectFirstProperty(lyric)) | ||
SelectedItems.Add(SelectableProperties(lyric).FirstOrDefault()); | ||
break; | ||
|
||
case CaretGenerateType.TargetLyric: | ||
break; | ||
|
||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
} | ||
|
||
protected abstract bool IsWriteLyricPropertyLocked(Lyric lyric); | ||
|
||
protected abstract bool SelectFirstProperty(Lyric lyric); | ||
|
||
protected abstract IEnumerable<TObject> SelectableProperties(Lyric lyric); | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(ILyricEditorState state, ILyricCaretState lyricCaretState) | ||
{ | ||
bindableMode.BindTo(state.BindableMode); | ||
bindableCaretPosition.BindTo(lyricCaretState.BindableCaretPosition); | ||
} | ||
} | ||
} |
Oops, something went wrong.