From 107c431c1736bd13eb49aaaf986ba93b98bacacc Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 13 Dec 2020 16:54:05 +0900 Subject: [PATCH 1/9] Separate info control into separate file because it might be more complex in future. --- .../Lyrics/Components/DrawableEditorLyric.cs | 59 ++++++++++++++ .../Edit/Lyrics/Components/InfoControl.cs | 79 +++++++++++++++++++ .../Edit/Lyrics/Components/LyricControl.cs | 54 +------------ .../Edit/Lyrics/DrawableLyricEditListItem.cs | 53 +------------ 4 files changed, 143 insertions(+), 102 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/DrawableEditorLyric.cs create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/InfoControl.cs diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/DrawableEditorLyric.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/DrawableEditorLyric.cs new file mode 100644 index 000000000..5944ed43d --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/DrawableEditorLyric.cs @@ -0,0 +1,59 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Graphics; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Objects.Drawables; +using osu.Game.Rulesets.Karaoke.Skinning.Components; + +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components +{ + public class DrawableEditLyric : DrawableLyric + { + public Action ApplyFontAction; + + public DrawableEditLyric(Lyric lyric) + : base(lyric) + { + DisplayRuby = true; + DisplayRomaji = true; + } + + protected override void ApplyFont(KaraokeFont font) + { + base.ApplyFont(font); + + if (TimeTagsBindable.Value == null) + return; + + ApplyFontAction?.Invoke(); + } + + protected override void ApplyLayout(KaraokeLayout layout) + { + base.ApplyLayout(layout); + Padding = new MarginPadding(0); + } + + protected override void UpdateStartTimeStateTransforms() + { + // Do not fade-in / fade-out while changing armed state. + } + + public override double LifetimeStart + { + get => double.MinValue; + set => base.LifetimeStart = double.MinValue; + } + + public override double LifetimeEnd + { + get => double.MaxValue; + set => base.LifetimeEnd = double.MaxValue; + } + + public float GetPercentageWidth(int startIndex, int endIndex, float percentage = 0) + => karaokeText.GetPercentageWidth(startIndex, endIndex, percentage); + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/InfoControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/InfoControl.cs new file mode 100644 index 000000000..924f884c6 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/InfoControl.cs @@ -0,0 +1,79 @@ +// Copyright (c) andy840119 . 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.Shapes; +using osu.Game.Graphics; +using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges; +using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Infos; +using osu.Game.Rulesets.Karaoke.Objects; +using osuTK; + +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components +{ + public class InfoControl : Container + { + private const int max_height = 120; + + private Box headerBackground; + + public Lyric Lyric { get; } + + public InfoControl(Lyric lyric) + { + Lyric = lyric; + + Children = new Drawable[] + { + headerBackground = new Box + { + RelativeSizeAxes = Axes.X, + Height = max_height, + Alpha = 0.7f + }, + new BadgeFillFlowContainer + { + Direction = FillDirection.Vertical, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + Spacing = new Vector2(5), + Children = new Drawable[] + { + new TimeInfoContainer(Lyric) + { + RelativeSizeAxes = Axes.X, + Height = 36, + }, + + // todo : in small display size use badge. + // in larger size should use real icon. + new LanguageInfoBadge(Lyric) + { + Margin = new MarginPadding { Right = 5 } + } + } + }, + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + headerBackground.Colour = colours.Gray2; + } + + public class BadgeFillFlowContainer : FillFlowContainer + { + public override void Add(Drawable drawable) + { + drawable.Anchor = Anchor.TopRight; + drawable.Origin = Anchor.TopRight; + base.Add(drawable); + } + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs index 2fbea9f38..c4f6ec823 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs @@ -10,8 +10,6 @@ using osu.Framework.Timing; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.TimeTags; using osu.Game.Rulesets.Karaoke.Objects; -using osu.Game.Rulesets.Karaoke.Objects.Drawables; -using osu.Game.Rulesets.Karaoke.Skinning.Components; using osuTK; namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components @@ -20,7 +18,7 @@ public class LyricControl : Container { private const int time_tag_spacing = 4; - private readonly DrawableEditorLyric drawableLyric; + private readonly DrawableEditLyric drawableLyric; private readonly Container timeTagContainer; private readonly Container timeTagCursorContainer; @@ -34,7 +32,7 @@ public LyricControl(Lyric lyric) Padding = new MarginPadding { Bottom = 10 }; Children = new Drawable[] { - drawableLyric = new DrawableEditorLyric(lyric) + drawableLyric = new DrawableEditLyric(lyric) { ApplyFontAction = () => { @@ -120,53 +118,5 @@ private float timeTagPosition(TimeTag timeTag) var spacing = duplicatedTagAmount * time_tag_spacing * (isStart ? 1 : -1); return position + spacing; } - - public class DrawableEditorLyric : DrawableLyric - { - public Action ApplyFontAction; - - public DrawableEditorLyric(Lyric lyric) - : base(lyric) - { - DisplayRuby = true; - DisplayRomaji = true; - } - - protected override void ApplyFont(KaraokeFont font) - { - base.ApplyFont(font); - - if (TimeTagsBindable.Value == null) - return; - - ApplyFontAction?.Invoke(); - } - - protected override void ApplyLayout(KaraokeLayout layout) - { - base.ApplyLayout(layout); - Padding = new MarginPadding(0); - } - - protected override void UpdateStartTimeStateTransforms() - { - // Do not fade-in / fade-out while changing armed state. - } - - public override double LifetimeStart - { - get => double.MinValue; - set => base.LifetimeStart = double.MinValue; - } - - public override double LifetimeEnd - { - get => double.MaxValue; - set => base.LifetimeEnd = double.MaxValue; - } - - public float GetPercentageWidth(int startIndex, int endIndex, float percentage = 0) - => karaokeText.GetPercentageWidth(startIndex, endIndex, percentage); - } } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs index a02a0c3a6..b73e8e4b3 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs @@ -9,10 +9,7 @@ using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components; -using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges; -using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Infos; using osu.Game.Rulesets.Karaoke.Objects; -using osuTK; namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics { @@ -25,7 +22,7 @@ public class DrawableLyricEditListItem : OsuRearrangeableListItem private Box background; private Box dragAlert; - private Box headerBackground; + public DrawableLyricEditListItem(Lyric item) : base(item) @@ -73,46 +70,13 @@ protected override Drawable CreateContent() RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize, minSize: min_height, maxSize: max_height) }, Content = new[] { - new[] + new Drawable[] { - new Container + new InfoControl(Model) { // todo : cannot use relative size to both because it will cause size cannot roll-back if make lyric smaller. RelativeSizeAxes = Axes.X, Height = min_height, - Children = new Drawable[] - { - headerBackground = new Box - { - RelativeSizeAxes = Axes.X, - Height = max_height, - Alpha = 0.7f - }, - new BadgeFillFlowContainer - { - Direction = FillDirection.Vertical, - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - Spacing = new Vector2(5), - Children = new Drawable[] - { - new TimeInfoContainer(Model) - { - RelativeSizeAxes = Axes.X, - Height = 36, - }, - - // todo : in small display size use badge. - // in larger size should use real icon. - new LanguageInfoBadge(Model) - { - Margin = new MarginPadding { Right = 5 } - } - } - }, - } }, new LyricControl(Model) { @@ -131,7 +95,6 @@ private void load(OsuColour colours) { background.Colour = colours.Gray7; dragAlert.Colour = colours.YellowDarker; - headerBackground.Colour = colours.Gray2; } protected override bool OnDragStart(DragStartEvent e) @@ -148,15 +111,5 @@ protected override void OnDragEnd(DragEndEvent e) dragAlert.Hide(); base.OnDragEnd(e); } - - public class BadgeFillFlowContainer : FillFlowContainer - { - public override void Add(Drawable drawable) - { - drawable.Anchor = Anchor.TopRight; - drawable.Origin = Anchor.TopRight; - base.Add(drawable); - } - } } } From 8792ab38a3a3d4ad4ed0d56be6bf741e6f2032d6 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 13 Dec 2020 16:58:14 +0900 Subject: [PATCH 2/9] Moving file into better namespace. --- .../Edit/Lyrics/{Components => Infos}/Badges/Badge.cs | 2 +- .../{Components => Infos}/Badges/LanguageInfoBadge.cs | 2 +- .../Lyrics/{Components => Infos}/Badges/LayoutInfoBadge.cs | 2 +- .../Lyrics/{Components => Infos}/Badges/StyleInfoBadge.cs | 2 +- .../Edit/Lyrics/{Components => Infos}/InfoControl.cs | 6 +++--- .../Infos => Infos/TimeInfo}/TimeInfoContainer.cs | 2 +- .../Lyrics/{Components => Lyrics}/DrawableEditorLyric.cs | 2 +- .../Edit/Lyrics/{Components => Lyrics}/LyricControl.cs | 4 ++-- .../{Components => Lyrics}/TimeTags/DrawableTimeTag.cs | 2 +- .../TimeTags/DrawableTimeTagCursor.cs | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/{Components => Infos}/Badges/Badge.cs (95%) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/{Components => Infos}/Badges/LanguageInfoBadge.cs (92%) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/{Components => Infos}/Badges/LayoutInfoBadge.cs (91%) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/{Components => Infos}/Badges/StyleInfoBadge.cs (91%) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/{Components => Infos}/InfoControl.cs (92%) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/{Components/Infos => Infos/TimeInfo}/TimeInfoContainer.cs (96%) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/{Components => Lyrics}/DrawableEditorLyric.cs (96%) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/{Components => Lyrics}/LyricControl.cs (97%) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/{Components => Lyrics}/TimeTags/DrawableTimeTag.cs (96%) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/{Components => Lyrics}/TimeTags/DrawableTimeTagCursor.cs (95%) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/Badge.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/Badge.cs similarity index 95% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/Badge.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/Badge.cs index a572e060d..15643c4c5 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/Badge.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/Badge.cs @@ -8,7 +8,7 @@ using osu.Game.Graphics.Sprites; using osu.Game.Rulesets.Karaoke.Objects; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Infos.Badges { public abstract class Badge : Container { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/LanguageInfoBadge.cs similarity index 92% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/LanguageInfoBadge.cs index ef98df15c..f1dd41115 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/LanguageInfoBadge.cs @@ -5,7 +5,7 @@ using osu.Game.Graphics; using osu.Game.Rulesets.Karaoke.Objects; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Infos.Badges { public class LanguageInfoBadge : Badge { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LayoutInfoBadge.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/LayoutInfoBadge.cs similarity index 91% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LayoutInfoBadge.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/LayoutInfoBadge.cs index fb3e34ede..b0da9d4e4 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LayoutInfoBadge.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/LayoutInfoBadge.cs @@ -5,7 +5,7 @@ using osu.Game.Graphics; using osu.Game.Rulesets.Karaoke.Objects; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Infos.Badges { public class LayoutInfoBadge : Badge { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/StyleInfoBadge.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/StyleInfoBadge.cs similarity index 91% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/StyleInfoBadge.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/StyleInfoBadge.cs index b287b13e1..37c5c5e7b 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/StyleInfoBadge.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/Badges/StyleInfoBadge.cs @@ -5,7 +5,7 @@ using osu.Game.Graphics; using osu.Game.Rulesets.Karaoke.Objects; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Infos.Badges { public class StyleInfoBadge : Badge { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/InfoControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/InfoControl.cs similarity index 92% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/InfoControl.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/InfoControl.cs index 924f884c6..9fc48cf4d 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/InfoControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/InfoControl.cs @@ -6,12 +6,12 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; -using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges; -using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Infos; +using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Infos.Badges; +using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Infos.TimeInfo; using osu.Game.Rulesets.Karaoke.Objects; using osuTK; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Infos { public class InfoControl : Container { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Infos/TimeInfoContainer.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/TimeInfo/TimeInfoContainer.cs similarity index 96% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Infos/TimeInfoContainer.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/TimeInfo/TimeInfoContainer.cs index 219fbd5ea..04a5b9a00 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Infos/TimeInfoContainer.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/TimeInfo/TimeInfoContainer.cs @@ -10,7 +10,7 @@ using osu.Game.Graphics.Sprites; using osu.Game.Rulesets.Karaoke.Objects; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Infos +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Infos.TimeInfo { public class TimeInfoContainer : Container { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/DrawableEditorLyric.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs similarity index 96% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/DrawableEditorLyric.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs index 5944ed43d..657622784 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/DrawableEditorLyric.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs @@ -7,7 +7,7 @@ using osu.Game.Rulesets.Karaoke.Objects.Drawables; using osu.Game.Rulesets.Karaoke.Skinning.Components; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics { public class DrawableEditLyric : DrawableLyric { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs similarity index 97% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs index c4f6ec823..04530cd84 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs @@ -8,11 +8,11 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Timing; -using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.TimeTags; +using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.TimeTags; using osu.Game.Rulesets.Karaoke.Objects; using osuTK; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics { public class LyricControl : Container { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/TimeTags/DrawableTimeTag.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTag.cs similarity index 96% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/TimeTags/DrawableTimeTag.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTag.cs index cf4e7abe0..6c48f2e8b 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/TimeTags/DrawableTimeTag.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTag.cs @@ -11,7 +11,7 @@ using osu.Game.Rulesets.Karaoke.Objects; using osuTK; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.TimeTags +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.TimeTags { public class DrawableTimeTag : CompositeDrawable { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/TimeTags/DrawableTimeTagCursor.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTagCursor.cs similarity index 95% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/TimeTags/DrawableTimeTagCursor.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTagCursor.cs index 5d204cc24..b8ae9adf4 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/TimeTags/DrawableTimeTagCursor.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTagCursor.cs @@ -10,7 +10,7 @@ using osu.Game.Rulesets.Karaoke.Objects; using osuTK; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.TimeTags +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.TimeTags { public class DrawableTimeTagCursor : CompositeDrawable { From 5a469cda83741db2b43ac1844f06c62d025890da Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 13 Dec 2020 17:09:25 +0900 Subject: [PATCH 3/9] Moving namespace and implement splitter. --- .../Edit/Lyrics/DrawableLyricEditListItem.cs | 3 +- .../Components/DrawableLyricSplitter.cs | 51 +++++++++++++++++++ .../DrawableTimeTag.cs | 2 +- .../DrawableTimeTagCursor.cs | 2 +- .../Edit/Lyrics/Lyrics/LyricControl.cs | 2 +- 5 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableLyricSplitter.cs rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/{TimeTags => Components}/DrawableTimeTag.cs (96%) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/{TimeTags => Components}/DrawableTimeTagCursor.cs (95%) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs index b73e8e4b3..b6ff058ef 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs @@ -8,7 +8,8 @@ using osu.Framework.Input.Events; using osu.Game.Graphics; using osu.Game.Graphics.Containers; -using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components; +using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Infos; +using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics; using osu.Game.Rulesets.Karaoke.Objects; namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableLyricSplitter.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableLyricSplitter.cs new file mode 100644 index 000000000..e750aa40a --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableLyricSplitter.cs @@ -0,0 +1,51 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using osuTK; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics; + +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.Components +{ + public class DrawableLyricSplitter : CompositeDrawable + { + public DrawableLyricSplitter() + { + Anchor = Anchor.CentreLeft; + Origin = Anchor.Centre; + RelativePositionAxes = Axes.X; + RelativeSizeAxes = Axes.Y; + AutoSizeAxes = Axes.X; + InternalChildren = new Drawable[] + { + new Triangle + { + Anchor = Anchor.TopCentre, + Origin = Anchor.BottomCentre, + Scale = new Vector2(1, -1), + Size = new Vector2(10, 5), + }, + new Triangle + { + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + Size = new Vector2(10, 5) + }, + new Box + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Y, + Width = 2, + EdgeSmoothness = new Vector2(1, 0) + } + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) => Colour = colours.Red; + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTag.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTag.cs similarity index 96% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTag.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTag.cs index 6c48f2e8b..04c3d346c 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTag.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTag.cs @@ -11,7 +11,7 @@ using osu.Game.Rulesets.Karaoke.Objects; using osuTK; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.TimeTags +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.Components { public class DrawableTimeTag : CompositeDrawable { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTagCursor.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTagCursor.cs similarity index 95% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTagCursor.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTagCursor.cs index b8ae9adf4..a87bbfaae 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/TimeTags/DrawableTimeTagCursor.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTagCursor.cs @@ -10,7 +10,7 @@ using osu.Game.Rulesets.Karaoke.Objects; using osuTK; -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.TimeTags +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.Components { public class DrawableTimeTagCursor : CompositeDrawable { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs index 04530cd84..b9510cd9f 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs @@ -8,7 +8,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Timing; -using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.TimeTags; +using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.Components; using osu.Game.Rulesets.Karaoke.Objects; using osuTK; From 8f29929520fbf709024ba338c8e214d10fa91b54 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 13 Dec 2020 17:26:21 +0900 Subject: [PATCH 4/9] Implement bindable to trigger display mouse position. --- .../Edit/Lyrics/LyricManager.cs | 20 +++++++ .../Edit/Lyrics/Lyrics/LyricControl.cs | 60 ++++++++++++++++--- 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs index c86d51403..45cb80ccb 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs @@ -3,6 +3,7 @@ using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Rulesets.Karaoke.Edit.Generator.Languages; using osu.Game.Rulesets.Karaoke.Objects; @@ -18,6 +19,9 @@ public class LyricManager : Component [Resolved(CanBeNull = true)] private IEditorChangeHandler changeHandler { get; set; } + public Bindable BindableSplitLyric { get; } = new Bindable(); + public Bindable BindableSplitPosition { get; } = new Bindable(); + /// /// Will auto-detect each 's and apply on them. /// @@ -41,5 +45,21 @@ public void AutoDetectLyricLanguage() changeHandler?.EndChange(); } + + public void UpdateSplitPosition(Lyric lyric, int index) + { + BindableSplitLyric.Value = lyric; + BindableSplitPosition.Value = index; + } + + public void ClearSplitPosition() + { + BindableSplitLyric.Value = null; + } + + public void SplitLyric() + { + + } } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs index b9510cd9f..f6d207fef 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs @@ -21,6 +21,10 @@ public class LyricControl : Container private readonly DrawableEditLyric drawableLyric; private readonly Container timeTagContainer; private readonly Container timeTagCursorContainer; + private readonly Container splitCursorContainer; + + [Resolved(canBeNull: true)] + private LyricManager lyricManager { get; set; } public Lyric Lyric { get; } @@ -48,6 +52,13 @@ public LyricControl(Lyric lyric) Scale = new Vector2(2) }, timeTagCursorContainer = new Container + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + RelativeSizeAxes = Axes.Both, + Scale = new Vector2(2) + }, + splitCursorContainer = new Container { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, @@ -70,14 +81,22 @@ private void load(IFrameBasedClock framedClock, TimeTagManager timeTagManager) { UpdateTimeTagCursoe(e.NewValue); }, true); + lyricManager?.BindableSplitLyric.BindValueChanged(e => + { + UpdateSplitter(); + }, true); + lyricManager?.BindableSplitPosition.BindValueChanged(e => + { + UpdateSplitter(); + }, true); } - public void UpdateTimeTagCursoe(TimeTag cursor) + protected void UpdateTimeTagCursoe(TimeTag cursor) { timeTagCursorContainer.Clear(); if (drawableLyric.TimeTagsBindable.Value.Contains(cursor)) { - var spacing = timeTagPosition(cursor); + var spacing = timeTagIndexPosition(cursor.Index) + extraSpacing(cursor); timeTagCursorContainer.Add(new DrawableTimeTagCursor(cursor) { Anchor = Anchor.BottomLeft, @@ -96,7 +115,7 @@ protected void UpdateTimeTags() foreach (var timeTag in timeTags) { - var spacing = timeTagPosition(timeTag); + var spacing = timeTagIndexPosition(timeTag.Index) + extraSpacing(timeTag); timeTagContainer.Add(new DrawableTimeTag(timeTag) { Anchor = Anchor.BottomLeft, @@ -106,17 +125,42 @@ protected void UpdateTimeTags() } } - private float timeTagPosition(TimeTag timeTag) + protected void UpdateSplitter() { - var index = Math.Min(timeTag.Index.Index, Lyric.Text.Length - 1); - var isStart = timeTag.Index.State == TimeTagIndex.IndexState.Start; + splitCursorContainer.Clear(); + var lyric = lyricManager?.BindableSplitLyric.Value; + var index = lyricManager?.BindableSplitPosition.Value; + if (lyric != Lyric || index == null) + return; + + + var spacing = textIndexPosition(index.Value); + splitCursorContainer.Add(new DrawableLyricSplitter + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + X = spacing, + }); + } + + private float textIndexPosition(int index) + => timeTagIndexPosition(new TimeTagIndex(index)); + + private float timeTagIndexPosition(TimeTagIndex timeTagIndex) + { + var index = Math.Min(timeTagIndex.Index, Lyric.Text.Length - 1); + var isStart = timeTagIndex.State == TimeTagIndex.IndexState.Start; var percentage = isStart ? 0 : 1; - var position = drawableLyric.GetPercentageWidth(index, index + 1, percentage); + return drawableLyric.GetPercentageWidth(index, index + 1, percentage); + } + private float extraSpacing(TimeTag timeTag) + { + var isStart = timeTag.Index.State == TimeTagIndex.IndexState.Start; var timeTags = isStart ? drawableLyric.TimeTagsBindable.Value.Reverse() : drawableLyric.TimeTagsBindable.Value; var duplicatedTagAmount = timeTags.SkipWhile(t => t != timeTag).Count(x => x.Index == timeTag.Index) - 1; var spacing = duplicatedTagAmount * time_tag_spacing * (isStart ? 1 : -1); - return position + spacing; + return spacing; } } } From 7d0b2780af84f8301f208545e6ef22283099deca Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 13 Dec 2020 17:40:58 +0900 Subject: [PATCH 5/9] Split cursor moving up and down works. --- .../Edit/Lyrics/LyricEditorScreen.cs | 3 ++ .../Edit/Lyrics/LyricManager.cs | 8 ++--- ...tter.cs => DrawableLyricSplitterCursor.cs} | 7 ++-- .../Lyrics/Components/DrawableTimeTag.cs | 2 +- .../Components/DrawableTimeTagCursor.cs | 2 +- .../Edit/Lyrics/Lyrics/LyricControl.cs | 36 ++++++++++++++----- 6 files changed, 38 insertions(+), 20 deletions(-) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/{DrawableLyricSplitter.cs => DrawableLyricSplitterCursor.cs} (86%) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorScreen.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorScreen.cs index 0418959dd..230da7b4f 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorScreen.cs @@ -34,11 +34,14 @@ public class LyricEditorScreen : EditorScreenWithTimeline, ICanAcceptFiles [Cached] protected readonly TimeTagManager TranslateManager; + [Cached] + protected readonly LyricManager LyricManager; public LyricEditorScreen() : base(EditorScreenMode.Compose) { Content.Add(TranslateManager = new TimeTagManager()); + Content.Add(LyricManager = new LyricManager()); } public Task Import(Stream stream, string filename) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs index 45cb80ccb..facc89519 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs @@ -46,20 +46,20 @@ public void AutoDetectLyricLanguage() changeHandler?.EndChange(); } - public void UpdateSplitPosition(Lyric lyric, int index) + public void UpdateSplitCursorPosition(Lyric lyric, int index) { BindableSplitLyric.Value = lyric; BindableSplitPosition.Value = index; } - public void ClearSplitPosition() + public void ClearSplitCursorPosition() { BindableSplitLyric.Value = null; } - public void SplitLyric() + public void SplitLyric(Lyric lyric, int index) { - + // todo : implement split. } } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableLyricSplitter.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableLyricSplitterCursor.cs similarity index 86% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableLyricSplitter.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableLyricSplitterCursor.cs index e750aa40a..84a940213 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableLyricSplitter.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableLyricSplitterCursor.cs @@ -10,13 +10,10 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.Components { - public class DrawableLyricSplitter : CompositeDrawable + public class DrawableLyricSplitterCursor : CompositeDrawable { - public DrawableLyricSplitter() + public DrawableLyricSplitterCursor() { - Anchor = Anchor.CentreLeft; - Origin = Anchor.Centre; - RelativePositionAxes = Axes.X; RelativeSizeAxes = Axes.Y; AutoSizeAxes = Axes.X; InternalChildren = new Drawable[] diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTag.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTag.cs index 04c3d346c..34763c369 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTag.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTag.cs @@ -18,7 +18,7 @@ public class DrawableTimeTag : CompositeDrawable /// /// Height of major bar line triangles. /// - private const float triangle_width = 3; + private const float triangle_width = 6; private readonly TimeTag timeTag; diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTagCursor.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTagCursor.cs index a87bbfaae..758f29d37 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTagCursor.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/Components/DrawableTimeTagCursor.cs @@ -17,7 +17,7 @@ public class DrawableTimeTagCursor : CompositeDrawable /// /// Height of major bar line triangles. /// - private const float triangle_width = 4; + private const float triangle_width = 8; private readonly TimeTag timeTag; diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs index f6d207fef..88a2e42f2 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; +using osu.Framework.Input.Events; using osu.Framework.Timing; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.Components; using osu.Game.Rulesets.Karaoke.Objects; @@ -16,7 +17,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics { public class LyricControl : Container { - private const int time_tag_spacing = 4; + private const int time_tag_spacing = 8; private readonly DrawableEditLyric drawableLyric; private readonly Container timeTagContainer; @@ -49,21 +50,18 @@ public LyricControl(Lyric lyric) Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, RelativeSizeAxes = Axes.Both, - Scale = new Vector2(2) }, timeTagCursorContainer = new Container { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, RelativeSizeAxes = Axes.Both, - Scale = new Vector2(2) }, splitCursorContainer = new Container { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, RelativeSizeAxes = Axes.Both, - Scale = new Vector2(2) } }; @@ -73,6 +71,26 @@ public LyricControl(Lyric lyric) }); } + protected override bool OnHover(HoverEvent e) + { + // todo : get real index. + lyricManager?.UpdateSplitCursorPosition(Lyric, 2); + return base.OnHover(e); + } + + protected override void OnHoverLost(HoverLostEvent e) + { + lyricManager?.ClearSplitCursorPosition(); + base.OnHoverLost(e); + } + + protected override bool OnClick(ClickEvent e) + { + // todo : get real index. + lyricManager?.SplitLyric(Lyric, 2); + return base.OnClick(e); + } + [BackgroundDependencyLoader(true)] private void load(IFrameBasedClock framedClock, TimeTagManager timeTagManager) { @@ -84,11 +102,11 @@ private void load(IFrameBasedClock framedClock, TimeTagManager timeTagManager) lyricManager?.BindableSplitLyric.BindValueChanged(e => { UpdateSplitter(); - }, true); + }); lyricManager?.BindableSplitPosition.BindValueChanged(e => { UpdateSplitter(); - }, true); + }); } protected void UpdateTimeTagCursoe(TimeTag cursor) @@ -135,7 +153,7 @@ protected void UpdateSplitter() var spacing = textIndexPosition(index.Value); - splitCursorContainer.Add(new DrawableLyricSplitter + splitCursorContainer.Add(new DrawableLyricSplitterCursor { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, @@ -144,14 +162,14 @@ protected void UpdateSplitter() } private float textIndexPosition(int index) - => timeTagIndexPosition(new TimeTagIndex(index)); + => timeTagIndexPosition(new TimeTagIndex(index)) - 10; private float timeTagIndexPosition(TimeTagIndex timeTagIndex) { var index = Math.Min(timeTagIndex.Index, Lyric.Text.Length - 1); var isStart = timeTagIndex.State == TimeTagIndex.IndexState.Start; var percentage = isStart ? 0 : 1; - return drawableLyric.GetPercentageWidth(index, index + 1, percentage); + return drawableLyric.GetPercentageWidth(index, index + 1, percentage) * 2; } private float extraSpacing(TimeTag timeTag) From a8556e8ab9e2f4f83d1134493f8183faa4505693 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 13 Dec 2020 17:47:15 +0900 Subject: [PATCH 6/9] Update cursor size and sanding event. --- .../Edit/Lyrics/Lyrics/DrawableEditorLyric.cs | 8 ++------ .../Edit/Lyrics/Lyrics/LyricControl.cs | 9 ++++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs index 657622784..c71ff7939 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs @@ -11,7 +11,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics { public class DrawableEditLyric : DrawableLyric { - public Action ApplyFontAction; + public Action ApplyFontAction; public DrawableEditLyric(Lyric lyric) : base(lyric) @@ -22,12 +22,8 @@ public DrawableEditLyric(Lyric lyric) protected override void ApplyFont(KaraokeFont font) { + ApplyFontAction?.Invoke(font); base.ApplyFont(font); - - if (TimeTagsBindable.Value == null) - return; - - ApplyFontAction?.Invoke(); } protected override void ApplyLayout(KaraokeLayout layout) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs index 88a2e42f2..7e59ab37a 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs @@ -39,10 +39,13 @@ public LyricControl(Lyric lyric) { drawableLyric = new DrawableEditLyric(lyric) { - ApplyFontAction = () => + ApplyFontAction = font => { // todo : need to delay until karaoke text has been calculated. - ScheduleAfterChildren(UpdateTimeTags); + if (Lyric.TimeTagsBindable.Value != null) + ScheduleAfterChildren(UpdateTimeTags); + + splitCursorContainer.Height = font.LyricTextFontInfo.LyricTextFontInfo.CharSize * 1.7f; } }, timeTagContainer = new Container @@ -61,7 +64,7 @@ public LyricControl(Lyric lyric) { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, - RelativeSizeAxes = Axes.Both, + RelativeSizeAxes = Axes.X, } }; From d4cfdebd70e5044a494b8ae4f16553fd2eee6bd8 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 13 Dec 2020 18:00:13 +0900 Subject: [PATCH 7/9] Add cut login, but not apply because it might got crash. --- .../Edit/Lyrics/LyricManager.cs | 14 ++++++++++++++ .../Edit/Lyrics/Lyrics/LyricControl.cs | 14 ++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs index facc89519..d61ac5df4 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs @@ -1,12 +1,14 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Rulesets.Karaoke.Edit.Generator.Languages; using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Utils; using osu.Game.Screens.Edit; namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics @@ -59,7 +61,19 @@ public void ClearSplitCursorPosition() public void SplitLyric(Lyric lyric, int index) { + // todo: need to got reason why cause null object issue. + return; + // todo : implement split. + var (firstLyric, secondLyric) = LyricUtils.SplitLyric(lyric, index); + + changeHandler?.BeginChange(); + + beatmap.Add(firstLyric); + beatmap.Add(secondLyric); + beatmap.Remove(lyric); + + changeHandler?.EndChange(); } } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs index 7e59ab37a..eacb31186 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs @@ -41,10 +41,8 @@ public LyricControl(Lyric lyric) { ApplyFontAction = font => { - // todo : need to delay until karaoke text has been calculated. - if (Lyric.TimeTagsBindable.Value != null) - ScheduleAfterChildren(UpdateTimeTags); - + // need to delay until karaoke text has been calculated. + ScheduleAfterChildren(UpdateTimeTags); splitCursorContainer.Height = font.LyricTextFontInfo.LyricTextFontInfo.CharSize * 1.7f; } }, @@ -89,8 +87,12 @@ protected override void OnHoverLost(HoverLostEvent e) protected override bool OnClick(ClickEvent e) { - // todo : get real index. - lyricManager?.SplitLyric(Lyric, 2); + var index = lyricManager?.BindableSplitPosition.Value; + if (index == null) + return false; + + // get index then cut. + lyricManager?.SplitLyric(Lyric, index.Value); return base.OnClick(e); } From 806390d1a53498c1f40de4582812af9e30def920 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 13 Dec 2020 18:26:42 +0900 Subject: [PATCH 8/9] Implement take cursor moving around. --- .../Edit/Lyrics/Lyrics/DrawableEditorLyric.cs | 14 ++++++++++++++ .../Edit/Lyrics/Lyrics/LyricControl.cs | 13 ++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs index c71ff7939..96f1154af 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs @@ -51,5 +51,19 @@ public override double LifetimeEnd public float GetPercentageWidth(int startIndex, int endIndex, float percentage = 0) => karaokeText.GetPercentageWidth(startIndex, endIndex, percentage); + + public int GetHoverIndex(float position) + { + var text = karaokeText.Text; + if (string.IsNullOrEmpty(text)) + return 0; + + for (int i = 0; i < text.Length; i++) + { + if (GetPercentageWidth(i, i + 1, 0.5f) > position) + return i; + } + return text.Length; + } } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs index eacb31186..a1acc5d10 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs @@ -11,7 +11,6 @@ using osu.Framework.Timing; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics.Components; using osu.Game.Rulesets.Karaoke.Objects; -using osuTK; namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Lyrics { @@ -72,11 +71,16 @@ public LyricControl(Lyric lyric) }); } - protected override bool OnHover(HoverEvent e) + protected override bool OnMouseMove(MouseMoveEvent e) { + if (lyricManager == null) + return false; + // todo : get real index. - lyricManager?.UpdateSplitCursorPosition(Lyric, 2); - return base.OnHover(e); + var position = ToLocalSpace(e.ScreenSpaceMousePosition).X / 2; + var index = drawableLyric.GetHoverIndex(position); + lyricManager?.UpdateSplitCursorPosition(Lyric, index); + return base.OnMouseMove(e); } protected override void OnHoverLost(HoverLostEvent e) @@ -156,7 +160,6 @@ protected void UpdateSplitter() if (lyric != Lyric || index == null) return; - var spacing = textIndexPosition(index.Value); splitCursorContainer.Add(new DrawableLyricSplitterCursor { From 5ecc442020ec856426efcba8f7a32e45408d8abf Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 13 Dec 2020 20:06:01 +0900 Subject: [PATCH 9/9] Clean-up code. --- .../Edit/Lyrics/DrawableLyricEditListItem.cs | 1 - .../Edit/Lyrics/Infos/InfoControl.cs | 2 +- .../Edit/Lyrics/LyricEditorScreen.cs | 1 + .../Edit/Lyrics/Lyrics/DrawableEditorLyric.cs | 1 + .../Edit/Lyrics/Lyrics/LyricControl.cs | 23 ++++++++++--------- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs index b6ff058ef..26e01af10 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs @@ -23,7 +23,6 @@ public class DrawableLyricEditListItem : OsuRearrangeableListItem private Box background; private Box dragAlert; - public DrawableLyricEditListItem(Lyric item) : base(item) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/InfoControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/InfoControl.cs index 9fc48cf4d..5340c77f9 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/InfoControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Infos/InfoControl.cs @@ -17,7 +17,7 @@ public class InfoControl : Container { private const int max_height = 120; - private Box headerBackground; + private readonly Box headerBackground; public Lyric Lyric { get; } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorScreen.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorScreen.cs index 230da7b4f..3c18294bc 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorScreen.cs @@ -34,6 +34,7 @@ public class LyricEditorScreen : EditorScreenWithTimeline, ICanAcceptFiles [Cached] protected readonly TimeTagManager TranslateManager; + [Cached] protected readonly LyricManager LyricManager; diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs index 96f1154af..43d89c65c 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/DrawableEditorLyric.cs @@ -63,6 +63,7 @@ public int GetHoverIndex(float position) if (GetPercentageWidth(i, i + 1, 0.5f) > position) return i; } + return text.Length; } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs index a1acc5d10..388cde704 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Lyrics/LyricControl.cs @@ -106,7 +106,7 @@ private void load(IFrameBasedClock framedClock, TimeTagManager timeTagManager) drawableLyric.Clock = framedClock; timeTagManager?.BindableCursorPosition.BindValueChanged(e => { - UpdateTimeTagCursoe(e.NewValue); + UpdateTimeTagCursor(e.NewValue); }, true); lyricManager?.BindableSplitLyric.BindValueChanged(e => { @@ -118,19 +118,20 @@ private void load(IFrameBasedClock framedClock, TimeTagManager timeTagManager) }); } - protected void UpdateTimeTagCursoe(TimeTag cursor) + protected void UpdateTimeTagCursor(TimeTag cursor) { timeTagCursorContainer.Clear(); - if (drawableLyric.TimeTagsBindable.Value.Contains(cursor)) + + if (!drawableLyric.TimeTagsBindable.Value.Contains(cursor)) + return; + + var spacing = timeTagIndexPosition(cursor.Index) + extraSpacing(cursor); + timeTagCursorContainer.Add(new DrawableTimeTagCursor(cursor) { - var spacing = timeTagIndexPosition(cursor.Index) + extraSpacing(cursor); - timeTagCursorContainer.Add(new DrawableTimeTagCursor(cursor) - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - X = spacing - }); - } + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + X = spacing + }); } protected void UpdateTimeTags()