Skip to content

Commit

Permalink
Merge pull request #1631 from andy840119/implement-view-only-lyric
Browse files Browse the repository at this point in the history
Separate editable and view-only into two different lyric.
  • Loading branch information
andy840119 authored Oct 8, 2022
2 parents a0c5301 + cac7d2d commit fa1eed3
Show file tree
Hide file tree
Showing 20 changed files with 163 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics.Blueprints;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes;
using osu.Game.Rulesets.Karaoke.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
using osu.Framework.Bindables;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics.Blueprints;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Screens.Edit.Compose.Components;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics
namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics.Blueprints
{
public class RomajiBlueprintContainer : TextTagBlueprintContainer<RomajiTag>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
using osu.Framework.Bindables;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics.Blueprints;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Screens.Edit.Compose.Components;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics
namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics.Blueprints
{
public class RubyBlueprintContainer : TextTagBlueprintContainer<RubyTag>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using osu.Game.Screens.Edit.Compose.Components;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics
namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics.Blueprints
{
public abstract class TextTagBlueprintContainer<T> : BindableBlueprintContainer<T> where T : class, ITextTag
{
Expand All @@ -44,7 +44,7 @@ protected override IEnumerable<SelectionBlueprint<T>> SortForMovement(IReadOnlyL
protected abstract class TextTagSelectionHandler : BindableSelectionHandler
{
[Resolved]
private EditorKaraokeSpriteText karaokeSpriteText { get; set; }
private InteractableKaraokeSpriteText karaokeSpriteText { get; set; }

private float deltaScaleSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class TextTagSelectionBlueprint<T> : SelectionBlueprint<T> where
private readonly Container indexRangeBackground;

[Resolved]
private EditorKaraokeSpriteText karaokeSpriteText { get; set; }
private InteractableKaraokeSpriteText karaokeSpriteText { get; set; }

protected TextTagSelectionBlueprint(T item)
: base(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics.Blueprints;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Screens.Edit.Compose.Components;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics
namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics.Blueprints
{
public class TimeTagBlueprintContainer : BindableBlueprintContainer<TimeTag>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TimeTagSelectionBlueprint : SelectionBlueprint<TimeTag>
private const float time_tag_size = 10;

[Resolved]
private EditorKaraokeSpriteText karaokeSpriteText { get; set; }
private InteractableKaraokeSpriteText karaokeSpriteText { get; set; }

public TimeTagSelectionBlueprint(TimeTag item)
: base(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics
public class CaretLayer : BaseLayer
{
[Resolved, AllowNull]
private EditorKaraokeSpriteText karaokeSpriteText { get; set; }
private InteractableKaraokeSpriteText karaokeSpriteText { get; set; }

[Resolved, AllowNull]
private ILyricCaretState lyricCaretState { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected DrawableCaret(bool preview)
}

[BackgroundDependencyLoader]
private void load(ILyricCaretState lyricCaretState, EditorKaraokeSpriteText karaokeSpriteText)
private void load(ILyricCaretState lyricCaretState, InteractableKaraokeSpriteText karaokeSpriteText)
{
caretPosition = Preview ? lyricCaretState.BindableHoverCaretPosition.GetBoundCopy() : lyricCaretState.BindableCaretPosition.GetBoundCopy();
caretPosition.BindValueChanged(e =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DrawableLyricInputCaret : DrawableLyricTextCaret
private OsuColour colours { get; set; }

[Resolved]
private EditorKaraokeSpriteText karaokeSpriteText { get; set; }
private InteractableKaraokeSpriteText karaokeSpriteText { get; set; }

private Box drawableCaret;
private InputCaretTextBox inputCaretTextBox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DrawableLyricSplitterCaret : DrawableLyricTextCaret
private OsuColour colours { get; set; }

[Resolved]
private EditorKaraokeSpriteText karaokeSpriteText { get; set; }
private InteractableKaraokeSpriteText karaokeSpriteText { get; set; }

public DrawableLyricSplitterCaret(bool preview)
: base(preview)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics.Carets
public abstract class DrawableLyricTextCaret : DrawableCaret<TextCaretPosition>
{
[Resolved]
private EditorKaraokeSpriteText karaokeSpriteText { get; set; }
private InteractableKaraokeSpriteText karaokeSpriteText { get; set; }

protected DrawableLyricTextCaret(bool preview)
: base(preview)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DrawableTimeTagEditCaret : DrawableCaret<TimeTagIndexCaretPosition>
private OsuColour colours { get; set; }

[Resolved]
private EditorKaraokeSpriteText karaokeSpriteText { get; set; }
private InteractableKaraokeSpriteText karaokeSpriteText { get; set; }

private readonly DrawableTextIndex drawableTextIndex;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DrawableTimeTagRecordCaret : DrawableCaret<TimeTagCaretPosition>
private OsuColour colours { get; set; }

[Resolved]
private EditorKaraokeSpriteText karaokeSpriteText { get; set; }
private InteractableKaraokeSpriteText karaokeSpriteText { get; set; }

private readonly DrawableTextIndex drawableTextIndex;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,117 +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.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
using osu.Game.Rulesets.Karaoke.Edit.Utils;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Screens.Edit;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics
{
[Cached(typeof(IEditableLyricState))]
public class EditableLyric : CompositeDrawable, IEditableLyricState, IHasTooltip
public class EditableLyric : InteractableLyric, IEditableLyricState
{
[Cached]
private readonly EditorKaraokeSpriteText karaokeSpriteText;

private readonly IBindable<LyricEditorMode> bindableMode = new Bindable<LyricEditorMode>();
private readonly IBindable<int> bindableLyricPropertyWritableVersion;

private readonly Lyric lyric;
private LocalisableString? lockReason;

public EditableLyric(Lyric lyric)
: base(lyric)
{
this.lyric = lyric;

bindableLyricPropertyWritableVersion = lyric.LyricPropertyWritableVersion.GetBoundCopy();

CornerRadius = 5;
Padding = new MarginPadding { Bottom = 10 };
InternalChildren = new Drawable[]
}

protected override IEnumerable<BaseLayer> CreateLayers(Lyric lyric)
{
return new BaseLayer[]
{
new LyricLayer(lyric, karaokeSpriteText = new EditorKaraokeSpriteText(lyric)),
new TimeTagLayer(lyric),
new CaretLayer(lyric),
new BlueprintLayer(lyric),
};

karaokeSpriteText.SizeChanged = () =>
{
Height = karaokeSpriteText.DrawHeight;
};

bindableMode.BindValueChanged(x =>
{
triggerWritableVersionChanged();
});

bindableLyricPropertyWritableVersion.BindValueChanged(_ =>
{
triggerWritableVersionChanged();
});
}

[BackgroundDependencyLoader]
private void load(EditorClock clock, ILyricEditorState state)
{
bindableMode.BindTo(state.BindableMode);
karaokeSpriteText.Clock = clock;
}

private void triggerWritableVersionChanged()
{
var loadReason = GetLyricPropertyLockedReason(lyric, bindableMode.Value);
lockReason = loadReason;

// adjust the style.
bool editable = lockReason == null;
InternalChildren.OfType<BaseLayer>().ForEach(x => x.UpdateDisableEditState(editable));
}

public void TriggerDisallowEditEffect()
{
InternalChildren.OfType<BaseLayer>().ForEach(x => x.TriggerDisallowEditEffect(bindableMode.Value));
}

public LocalisableString TooltipText => lockReason ?? string.Empty;

public static LocalisableString? GetLyricPropertyLockedReason(Lyric lyric, LyricEditorMode mode)
{
var reasons = getLyricPropertyLockedReasons(lyric, mode);

return reasons switch
{
LockLyricPropertyBy.ReferenceLyricConfig => "Cannot modify this property due to this lyric is property is sync from another lyric.",
LockLyricPropertyBy.LockState => "This property is locked and not editable",
null => default(LocalisableString?),
_ => throw new ArgumentOutOfRangeException()
};
}

private static LockLyricPropertyBy? getLyricPropertyLockedReasons(Lyric lyric, LyricEditorMode mode)
{
return mode switch
{
LyricEditorMode.View => null,
LyricEditorMode.Texting => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.Text), nameof(Lyric.RubyTags), nameof(Lyric.RomajiTags), nameof(Lyric.TimeTags)),
LyricEditorMode.Reference => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.ReferenceLyric), nameof(Lyric.ReferenceLyricConfig)),
LyricEditorMode.Language => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.Language)),
LyricEditorMode.EditRuby => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.RubyTags)),
LyricEditorMode.EditRomaji => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.RomajiTags)),
LyricEditorMode.EditTimeTag => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.TimeTags)),
LyricEditorMode.EditNote => HitObjectWritableUtils.GetCreateOrRemoveNoteLockedBy(lyric),
LyricEditorMode.Singer => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.Singers)),
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null)
};
InternalChildren.OfType<BaseLayer>().ForEach(x => x.TriggerDisallowEditEffect(BindableMode.Value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Lyrics
{
public class EditorKaraokeSpriteText : DrawableKaraokeSpriteText<EditorKaraokeSpriteText.EditorLyricSpriteText>
public class InteractableKaraokeSpriteText : DrawableKaraokeSpriteText<InteractableKaraokeSpriteText.EditorLyricSpriteText>
{
private const int time_tag_spacing = 8;

public Lyric HitObject;

public Action SizeChanged;

public EditorKaraokeSpriteText(Lyric lyric)
public InteractableKaraokeSpriteText(Lyric lyric)
: base(lyric)
{
HitObject = lyric;
Expand Down
Loading

0 comments on commit fa1eed3

Please sign in to comment.