Skip to content

Commit

Permalink
Merge pull request #2265 from andy840119/add-grid-layout
Browse files Browse the repository at this point in the history
Add grid layout in the lyric composer.
  • Loading branch information
andy840119 authored Jul 20, 2024
2 parents d91553d + 417cb59 commit b42fa3e
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 24 deletions.
1 change: 0 additions & 1 deletion osu.Game.Rulesets.Karaoke.Architectures/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Linq;
using System.Text.RegularExpressions;
using ArchUnitNET.Domain;
using ArchUnitNET.Domain.Dependencies;
using ArchUnitNET.Domain.Extensions;
using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Tests;
Expand Down
1 change: 0 additions & 1 deletion osu.Game.Rulesets.Karaoke.Architectures/TestTestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using ArchUnitNET.Domain.Extensions;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Rulesets.Karaoke.Tests;
using osu.Game.Tests.Visual;

namespace osu.Game.Rulesets.Karaoke.Architectures;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ private void load(OsuColour colour)
RelativeSizeAxes = Axes.Both,
Colour = colour.BlueDarker,
},
karaokeSpriteText = new PreviewKaraokeSpriteText(lyric),
karaokeSpriteText = new PreviewKaraokeSpriteText(lyric)
{
Position = new Vector2(24, 8),
},
mask = new Container
{
Masking = true,
Expand Down
1 change: 0 additions & 1 deletion osu.Game.Rulesets.Karaoke/Objects/Utils/LyricUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using osu.Framework.Graphics.Sprites;
using osu.Game.Extensions;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osu.Game.Rulesets.Karaoke.Objects.Types;
using osu.Game.Rulesets.Karaoke.Utils;

namespace osu.Game.Rulesets.Karaoke.Objects.Utils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.CaretPosition.Algorithms;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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.Graphics;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Screens.Edit.Compose.Components;
using osuTK;

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

public partial class GridLayer : Layer
{
private readonly RectangularPositionSnapGrid rectangularPositionSnapGrid;

public GridLayer(Lyric lyric)
: base(lyric)
{
InternalChild = rectangularPositionSnapGrid = new RectangularPositionSnapGrid
{
RelativeSizeAxes = Axes.Both,
};
}

public int Spacing
{
get => rectangularPositionSnapGrid.Spacing;
set => rectangularPositionSnapGrid.Spacing = value;
}

public override void UpdateDisableEditState(bool editable)
{
this.FadeTo(editable ? 1 : 0.5f, 100);
}

private partial class RectangularPositionSnapGrid : LinedPositionSnapGrid
{
protected override void CreateContent()
{
GenerateGridLines(new Vector2(0, -Spacing), DrawSize);
GenerateGridLines(new Vector2(0, Spacing), DrawSize);

GenerateGridLines(new Vector2(-Spacing, 0), DrawSize);
GenerateGridLines(new Vector2(Spacing, 0), DrawSize);

GenerateOutline(DrawSize);
}

public override Vector2 GetSnappedPosition(Vector2 original)
{
return StartPosition.Value + original;
}

private int spacing;

public int Spacing
{
get => spacing;
set
{
spacing = value;
GridCache.Invalidate();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Game.Rulesets.Karaoke.Edit.Utils;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Screens.Edit;
using osuTK;

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

Expand All @@ -28,6 +29,8 @@ public sealed partial class InteractableLyric : CompositeDrawable, IHasTooltip,
private readonly Lyric lyric;
private LocalisableString? lockReason;

public Action<InteractableLyric, Vector2>? TextSizeChanged = null;

public InteractableLyric(Lyric lyric)
{
this.lyric = lyric;
Expand All @@ -36,9 +39,9 @@ public InteractableLyric(Lyric lyric)

karaokeSpriteText = new PreviewKaraokeSpriteText(lyric);

karaokeSpriteText.SizeChanged = () =>
karaokeSpriteText.SizeChanged = (size) =>
{
Height = karaokeSpriteText.DrawHeight;
TextSizeChanged?.Invoke(this, size);
};

bindableMode.BindValueChanged(x =>
Expand All @@ -65,6 +68,12 @@ public IEnumerable<Layer> Layers
}
}

public Vector2 LyricPosition
{
get => karaokeSpriteText.Position;
set => karaokeSpriteText.Position = value;
}

public void TriggerDisallowEditEffect()
{
InternalChildren.OfType<Layer>().ForEach(x => x.TriggerDisallowEditEffect(bindableMode.Value));
Expand Down Expand Up @@ -108,14 +117,14 @@ private void triggerWritableVersionChanged()
return mode switch
{
LyricEditorMode.View => null,
LyricEditorMode.EditText => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Objects.Lyric.Text), nameof(Objects.Lyric.RubyTags), nameof(Objects.Lyric.TimeTags)),
LyricEditorMode.EditReferenceLyric => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Objects.Lyric.ReferenceLyric), nameof(Objects.Lyric.ReferenceLyricConfig)),
LyricEditorMode.EditLanguage => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Objects.Lyric.Language)),
LyricEditorMode.EditRuby => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Objects.Lyric.RubyTags)),
LyricEditorMode.EditTimeTag => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Objects.Lyric.TimeTags)),
LyricEditorMode.EditRomanisation => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Objects.Lyric.TimeTags)),
LyricEditorMode.EditText => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.Text), nameof(Lyric.RubyTags), nameof(Lyric.TimeTags)),
LyricEditorMode.EditReferenceLyric => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.ReferenceLyric), nameof(Lyric.ReferenceLyricConfig)),
LyricEditorMode.EditLanguage => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.Language)),
LyricEditorMode.EditRuby => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.RubyTags)),
LyricEditorMode.EditTimeTag => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.TimeTags)),
LyricEditorMode.EditRomanisation => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.TimeTags)),
LyricEditorMode.EditNote => HitObjectWritableUtils.GetCreateOrRemoveNoteLockedBy(lyric),
LyricEditorMode.EditSinger => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Objects.Lyric.SingerIds)),
LyricEditorMode.EditSinger => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.SingerIds)),
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class PreviewKaraokeSpriteText : DrawableKaraokeSpriteText<Previe

public Lyric HitObject;

public Action? SizeChanged;
public Action<Vector2>? SizeChanged;

private readonly EditorLyricSpriteText spriteText;

Expand Down Expand Up @@ -59,13 +59,16 @@ private void triggerSizeChangedEvent()
{
ScheduleAfterChildren(() =>
{
SizeChanged?.Invoke();
SizeChanged?.Invoke(DrawSize);
});
}

#region Text char index

public int? GetCharIndexByPosition(float position)
=> getCharIndexByPosition(position - Position.X);

private int? getCharIndexByPosition(float position)
{
for (int i = 0; i < Text.Length; i++)
{
Expand All @@ -84,6 +87,9 @@ Tuple<double, double> getTriggerPositionByTimeIndex(int charIndex)
}

public RectangleF GetRectByCharIndex(int charIndex)
=> getRectByCharIndex(charIndex).Offset(Position);

private RectangleF getRectByCharIndex(int charIndex)
{
if (charIndex < 0 || charIndex >= Text.Length)
throw new ArgumentOutOfRangeException(nameof(charIndex));
Expand All @@ -96,6 +102,9 @@ public RectangleF GetRectByCharIndex(int charIndex)
#region Text indicator

public int GetCharIndicatorByPosition(float position)
=> getCharIndicatorByPosition(position - Position.X);

private int getCharIndicatorByPosition(float position)
{
for (int i = 0; i < Text.Length; i++)
{
Expand All @@ -114,6 +123,9 @@ float getTriggerPositionByTimeIndex(int charIndex)
}

public RectangleF GetRectByCharIndicator(int charIndex)
=> getRectByCharIndicator(charIndex).Offset(Position);

private RectangleF getRectByCharIndicator(int charIndex)
{
if (charIndex < 0 || charIndex > Text.Length)
throw new ArgumentOutOfRangeException(nameof(charIndex));
Expand Down Expand Up @@ -142,13 +154,19 @@ public RectangleF GetRectByCharIndicator(int charIndex)
#region Ruby tag

public RectangleF? GetRubyTagByPosition(RubyTag rubyTag) =>
getRubyTagByPosition(rubyTag)?.Offset(Position);

private RectangleF? getRubyTagByPosition(RubyTag rubyTag) =>
spriteText.GetRubyTagPosition(rubyTag);

#endregion

#region Time tag

public TimeTag? GetTimeTagByPosition(float position)
=> getTimeTagByPosition(position - Position.X);

private TimeTag? getTimeTagByPosition(float position)
{
var hoverIndex = getHoverIndex();
if (hoverIndex == null)
Expand Down Expand Up @@ -184,6 +202,9 @@ Tuple<float, float> getTriggerRange(TextIndex textIndex)
}

public Vector2 GetPositionByTimeTag(TimeTag timeTag)
=> getPositionByTimeTag(timeTag) + Position;

private Vector2 getPositionByTimeTag(TimeTag timeTag)
{
var basePosition = spriteText.GetTimeTagPosition(timeTag.Index);
float extraPosition = extraSpacing(HitObject.TimeTags, timeTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ protected override Drawable CreateContent(Lyric lyric)
Origin = Anchor.BottomLeft,
Margin = new MarginPadding { Left = 10 },
RelativeSizeAxes = Axes.X,
TextSizeChanged = (self, size) =>
{
self.Height = size.Y;
},
Layers = new Layer[]
{
new LyricLayer(lyric),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Components.Lyrics;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States;
using osu.Game.Skinning;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Compose;

Expand Down Expand Up @@ -39,12 +40,24 @@ public LyricEditor()
if (lyric == null)
return;

const int border = 36;

skinProvidingContainer.Add(new InteractableLyric(lyric)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
LyricPosition = new Vector2(border),
TextSizeChanged = (self, size) =>
{
self.Width = size.X + border * 2;
self.Height = size.Y + border * 2;
},
Layers = new Layer[]
{
new GridLayer(lyric)
{
Spacing = 10,
},
new LyricLayer(lyric),
new EditLyricLayer(lyric),
new TimeTagLayer(lyric),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ protected override Drawable CreateContent(Lyric lyric)
{
Margin = new MarginPadding { Left = 10 },
RelativeSizeAxes = Axes.X,
TextSizeChanged = (self, size) =>
{
self.Height = size.Y;
},
Layers = new Layer[]
{
new LyricLayer(lyric),
Expand Down
3 changes: 0 additions & 3 deletions osu.Game.Rulesets.Karaoke/Screens/Edit/GenericEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
Expand All @@ -19,9 +18,7 @@
using osu.Game.Input.Bindings;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Components.Menus;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Components;
using osu.Game.Screens.Edit.Components.Menus;
using osu.Game.Screens.Edit.Components.Timelines.Summary;
using osu.Game.Screens.Play;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using System.ComponentModel;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Localisation;
using osu.Game.Rulesets.Karaoke.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// 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.Extensions.IEnumerableExtensions;
using osu.Framework.Screens;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Import.Lyrics.AssignLanguage;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Import.Lyrics.DragFile;
Expand Down
2 changes: 0 additions & 2 deletions osu.Game.Rulesets.Karaoke/UI/HUD/GeneralSettingOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
using osu.Framework.Graphics;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.UI.PlayerSettings;
using osu.Game.Screens.Play.PlayerSettings;
Expand Down

0 comments on commit b42fa3e

Please sign in to comment.