Skip to content

Commit

Permalink
Merge pull request #2112 from andy840119/should-be-able-to-record-rub…
Browse files Browse the repository at this point in the history
…y-edit-type

Should be able to drag the main lyric text to generate the ruby/romaji text.
  • Loading branch information
andy840119 authored Sep 4, 2023
2 parents 09499a5 + fbd76a1 commit d0fa6ea
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private void load()
Dependencies.Cache(new EditorClock());
Dependencies.CacheAs(state = new TestLyricEditorState());
Dependencies.CacheAs<ITextingModeState>(new TextingModeState());
Dependencies.CacheAs<IEditRubyModeState>(new EditRubyModeState());
Dependencies.CacheAs<ITimeTagModeState>(new TimeTagModeState());
Dependencies.Cache(new KaraokeRulesetLyricEditorConfigManager());

Expand Down Expand Up @@ -107,7 +108,7 @@ public void TestChangeFromEditModeToEditMode()
{
// change from edit mode to view mode for checking that caret position should be clear.
changeMode(LyricEditorMode.Texting);
changeMode(LyricEditorMode.EditRuby);
changeMode(LyricEditorMode.EditRomaji);

// get the action
assertCaretPosition(Assert.IsInstanceOf<NavigateCaretPosition>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public partial class BlueprintLayer : BaseLayer
{
private readonly IBindable<EditorModeWithEditStep> bindableModeWithEditStep = new Bindable<EditorModeWithEditStep>();

// todo: make better way to handle this.
private readonly IBindable<RubyTagEditMode> bindableRubyTagEditMode = new Bindable<RubyTagEditMode>();

// should block all blueprint action if not editable.
public override bool PropagatePositionalInputSubTree => base.PropagatePositionalInputSubTree && editable;

Expand All @@ -27,12 +30,20 @@ public BlueprintLayer(Lyric lyric)
// Initial blueprint container.
InitializeBlueprint();
});

bindableRubyTagEditMode.BindValueChanged(_ =>
{
// Initial blueprint container.
InitializeBlueprint();
});
}

[BackgroundDependencyLoader]
private void load(ILyricEditorState state, ITimeTagModeState timeTagModeState)
private void load(ILyricEditorState state, IEditRubyModeState editRubyModeState)
{
bindableModeWithEditStep.BindTo(state.BindableModeWithEditStep);

bindableRubyTagEditMode.BindTo(editRubyModeState.BindableRubyTagEditMode);
}

protected void InitializeBlueprint()
Expand All @@ -42,16 +53,18 @@ protected void InitializeBlueprint()

// create preview and real caret
var modeWithEditStep = bindableModeWithEditStep.Value;
var blueprintContainer = createBlueprintContainer(modeWithEditStep, Lyric);
var rubyTagEditMode = bindableRubyTagEditMode.Value;

var blueprintContainer = createBlueprintContainer(modeWithEditStep, rubyTagEditMode, Lyric);
if (blueprintContainer == null)
return;

AddInternal(blueprintContainer);

static Drawable? createBlueprintContainer(EditorModeWithEditStep modeWithEditStep, Lyric lyric) =>
static Drawable? createBlueprintContainer(EditorModeWithEditStep modeWithEditStep, RubyTagEditMode rubyTagEditMode, Lyric lyric) =>
modeWithEditStep.Mode switch
{
LyricEditorMode.EditRuby => new RubyBlueprintContainer(lyric),
LyricEditorMode.EditRuby => rubyTagEditMode == RubyTagEditMode.Create ? null : new RubyBlueprintContainer(lyric),
LyricEditorMode.EditRomaji => new RomajiBlueprintContainer(lyric),
LyricEditorMode.EditTimeTag => modeWithEditStep.EditStep is TimeTagEditStep.Adjust ? new TimeTagBlueprintContainer(lyric) : null,
_ => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ private void updateDrawableCaret(ICaretPosition? position, DrawableCaretType typ
CuttingCaretPosition => new DrawableCuttingCaret(type),
// typing
TypingCaretPosition => new DrawableTypingCaret(type),
// creat ruby-tag
CreateRubyTagCaretPosition => new DrawableCreateRubyTagCaretPosition(type),
// creat time-tag
TimeTagIndexCaretPosition => new DrawableTimeTagIndexCaret(type),
// record time-tag
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// 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.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Logging;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.CaretPosition;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Components.Lyrics.Carets;

public partial class DrawableCreateRubyTagCaretPosition : DrawableRangeCaret<CreateRubyTagCaretPosition>
{
private const float border_spacing = 5;
private const float caret_move_time = 60;
private const float caret_resize_time = 60;

[Resolved]
private ILyricRubyTagsChangeHandler lyricRubyTagsChangeHandler { get; set; } = null!;

[Resolved]
private ILyricCaretState lyricCaretState { get; set; } = null!;

private readonly IconButton icon;

public DrawableCreateRubyTagCaretPosition(DrawableCaretType type)
: base(type)
{
InternalChildren = new Drawable[]
{
new Container
{
Masking = true,
BorderThickness = border_spacing,
BorderColour = Colour4.White,
RelativeSizeAxes = Axes.Both,
Alpha = GetAlpha(type),
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Colour4.White,
Alpha = 0.1f,
},
},
icon = new IconButton
{
Anchor = Anchor.TopRight,
Origin = Anchor.BottomLeft,
Icon = FontAwesome.Solid.PlusCircle,
Size = new Vector2(15),
Alpha = GetAlpha(type),
},
};
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
icon.IconColour = colours.Green;
icon.IconHoverColour = colours.GreenLight;
}

protected override void ApplyCaretPosition(CreateRubyTagCaretPosition caret)
{
// should not show the hover caret if already contains the selected range.
if (Type == DrawableCaretType.HoverCaret && lyricCaretState.CaretPosition?.Lyric == caret.Lyric)
{
Hide();
return;
}

var rect = LyricPositionProvider.GetRectByCharIndex(caret.CharIndex);
changeTheSizeByRect(rect);

icon.Action = () =>
{
lyricRubyTagsChangeHandler.Add(new RubyTag
{
StartIndex = caret.CharIndex,
EndIndex = caret.CharIndex,
Text = "Ruby",
});
};
}

protected override void ApplyRangeCaretPosition(RangeCaretPosition<CreateRubyTagCaretPosition> caret)
{
int minIndex = caret.GetRangeCaretPosition().Item1.CharIndex;
int maxIndex = caret.GetRangeCaretPosition().Item2.CharIndex;

Logger.Log($"{minIndex}, {maxIndex}");

var rect = RectangleF.Union(LyricPositionProvider.GetRectByCharIndex(minIndex), LyricPositionProvider.GetRectByCharIndex(maxIndex));
changeTheSizeByRect(rect);

icon.Action = () =>
{
lyricRubyTagsChangeHandler.Add(new RubyTag
{
StartIndex = minIndex,
EndIndex = maxIndex,
Text = "Ruby",
});
};
}

private void changeTheSizeByRect(RectangleF rect)
{
var position = rect.TopLeft - new Vector2(border_spacing);
float width = rect.Width + border_spacing * 2;

this.MoveTo(position, caret_move_time, Easing.Out);
this.ResizeWidthTo(width, caret_resize_time, Easing.Out);
Height = rect.Height + border_spacing * 2;
}

protected override void TriggerDisallowEditEffect(OsuColour colour)
{
this.FlashColour(colour.Red, 200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DrawableTimeTagIndexCaret(DrawableCaretType type)
InternalChild = new Container
{
Masking = true,
BorderThickness = 4,
BorderThickness = border_spacing,
BorderColour = Colour4.White,
RelativeSizeAxes = Axes.Both,
Child = new Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class DrawableTypingCaret : DrawableRangeCaret<TypingCaretPositio
{
private const float fading_time = 200;
private const float caret_move_time = 60;
private const float caret_resize_time = 60;
private const float caret_width = 3;

private readonly Box drawableCaret;
Expand Down Expand Up @@ -92,11 +93,11 @@ protected override void ApplyRangeCaretPosition(RangeCaretPosition<TypingCaretPo

private void changeTheSizeByRect(RectangleF rect)
{
var position = rect.TopLeft;
var position = rect.TopLeft - new Vector2(caret_width / 2, 0);
float width = rect.Width + caret_width;

this.MoveTo(new Vector2(position.X - caret_width / 2, position.Y), caret_move_time, Easing.Out);
this.ResizeWidthTo(width, caret_move_time, Easing.Out);
this.MoveTo(position, caret_move_time, Easing.Out);
this.ResizeWidthTo(width, caret_resize_time, Easing.Out);
Height = rect.Height;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ protected override void OnDrag(DragEvent e)
CuttingCaretPosition => karaokeSpriteText.GetCharIndicatorByPosition(position),
TypingCaretPosition => karaokeSpriteText.GetCharIndicatorByPosition(position),
NavigateCaretPosition => null,
CreateRubyTagCaretPosition => karaokeSpriteText.GetCharIndexByPosition(position),
TimeTagIndexCaretPosition => karaokeSpriteText.GetCharIndexByPosition(position),
TimeTagCaretPosition => karaokeSpriteText.GetTimeTagByPosition(position),
_ => 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States.Modes;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.RubyRomaji;

public partial class RubyTagConfigToolSection : EditorSection
{
protected override LocalisableString Title => "Config Tool";

[BackgroundDependencyLoader]
private void load(IEditRubyModeState editRubyModeState)
{
Children = new Drawable[]
{
new RubyTagEditModeSubsection()
{
Current = editRubyModeState.BindableRubyTagEditMode,
},
};
}
}
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 osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States.Modes;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Components.Markdown;
using osuTK.Graphics;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.RubyRomaji;

public partial class RubyTagEditModeSubsection : EditModeSwitchSubsection<RubyTagEditMode>
{
protected override LocalisableString GetButtonTitle(RubyTagEditMode mode)
=> mode switch
{
RubyTagEditMode.Create => "Create",
RubyTagEditMode.Modify => "Modify",
_ => throw new InvalidOperationException(nameof(mode)),
};

protected override Color4 GetButtonColour(OsuColour colours, RubyTagEditMode mode, bool active)
=> mode switch
{
RubyTagEditMode.Create => active ? colours.Green : colours.GreenDarker,
RubyTagEditMode.Modify => active ? colours.Pink : colours.PinkDarker,
_ => throw new InvalidOperationException(nameof(mode)),
};

protected override DescriptionFormat GetDescription(RubyTagEditMode mode) =>
mode switch
{
RubyTagEditMode.Create => "Use mouse to select range of the lyric text to create the ruby tag.",
RubyTagEditMode.Modify => "Select ruby to change the start/end position or delete it.",
_ => throw new InvalidOperationException(nameof(mode)),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ private void load(IEditRubyModeState editRubyModeState)
RubyTagEditStep.Generate => new Drawable[]
{
new RubyTagEditStepSection(),
new RubyTagConfigToolSection(),
new RubyTagAutoGenerateSection(),
},
RubyTagEditStep.Edit => new Drawable[]
{
new RubyTagEditStepSection(),
new RubyTagConfigToolSection(),
new RubyTagEditSection(),
},
RubyTagEditStep.Verify => new Drawable[]
{
new RubyTagEditStepSection(),
new RubyTagConfigToolSection(),
new RubyTagIssueSection(),
},
_ => throw new ArgumentOutOfRangeException(),
Expand Down
Loading

0 comments on commit d0fa6ea

Please sign in to comment.