Skip to content

Commit

Permalink
Merge pull request #1093 from andy840119/remove-layout-index-from-lyric
Browse files Browse the repository at this point in the history
Remove layout index from lyric.
  • Loading branch information
andy840119 authored Feb 5, 2022
2 parents 69b3bca + 84a16cd commit 86190a4
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public void TestDisplayToolTip()

foreach ((int key, string value) in layouts)
{
setTooltip($"Test lyric with layout {value}", lyric => { lyric.LayoutIndex = key; });
setTooltip($"Test lyric with layout {value}", lyric =>
{
// todo: should change mapping group id from the lyric.
});
}
}

Expand Down
33 changes: 0 additions & 33 deletions osu.Game.Rulesets.Karaoke.Tests/Utils/LyricsUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,6 @@ public void TestSeparateLyricSinger(int[] singerIndexes, int[] firstSingerIndexe
Assert.AreNotSame(secondLyric.Singers, lyric.Singers);
}

[TestCase(1, 1, 1)]
[TestCase(2, 2, 2)]
[TestCase(-5, -5, -5)] // copy layout index even it's wrong.
public void TestSeparateLyricLayoutIndex(int actualLayout, int firstLayout, int secondLayout)
{
const int split_index = 2;
var lyric = new Lyric
{
Text = "karaoke!",
LayoutIndex = actualLayout
};

var (firstLyric, secondLyric) = LyricsUtils.SplitLyric(lyric, split_index);

Assert.AreEqual(firstLyric.LayoutIndex, firstLayout);
Assert.AreEqual(secondLyric.LayoutIndex, secondLayout);
}

[TestCase(1, 1, 1)]
[TestCase(54, 54, 54)]
[TestCase(null, null, null)]
Expand Down Expand Up @@ -309,21 +291,6 @@ public void TestCombineLyricSinger(int[] firstSingerIndexes, int[] secondSingerI
Assert.AreEqual(combineLyric.Singers, actualSingerIndexes);
}

[TestCase(1, 2, 1)]
[TestCase(1, 3, 1)]
[TestCase(1, -1, 1)]
[TestCase(-1, 1, -1)]
[TestCase(-5, 1, -5)] // Wrong layout index
public void TestCombineLayoutIndex(int firstLayout, int secondLayout, int actualLayout)
{
var lyric1 = new Lyric { LayoutIndex = firstLayout };
var lyric2 = new Lyric { LayoutIndex = secondLayout };

// just use first lyric's layout id.
var combineLyric = LyricsUtils.CombineLyric(lyric1, lyric2);
Assert.AreEqual(combineLyric.LayoutIndex, actualLayout);
}

[TestCase(1, 1, 1)]
[TestCase(54, 54, 54)]
[TestCase(null, 1, null)]
Expand Down
26 changes: 0 additions & 26 deletions osu.Game.Rulesets.Karaoke/Edit/KaraokeSelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Notes;
using osu.Game.Rulesets.Karaoke.Edit.Components.ContextMenu;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Skinning;
using osu.Game.Rulesets.Karaoke.Skinning.Elements;
using osu.Game.Rulesets.Karaoke.UI.Components;
using osu.Game.Rulesets.Karaoke.UI.Position;
using osu.Game.Rulesets.Karaoke.UI.Scrolling;
Expand Down Expand Up @@ -54,7 +52,6 @@ protected override IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumer
{
return new[]
{
createLayoutMenuItem(),
createSingerMenuItem()
};
}
Expand Down Expand Up @@ -98,29 +95,6 @@ private MenuItem createCombineNoteMenuItem()
});
}

private MenuItem createLayoutMenuItem()
{
var lyrics = EditorBeatmap.SelectedHitObjects.Cast<Lyric>();
var layoutDictionary = source.GetConfig<KaraokeIndexLookup, IDictionary<int, string>>(KaraokeIndexLookup.Layout)?.Value;
var selectedLayoutIndexes = lyrics.Select(x => x.LayoutIndex).Distinct().ToList();
int selectedLayoutIndex = selectedLayoutIndexes.Count == 1 ? selectedLayoutIndexes.FirstOrDefault() : -1;

return new OsuMenuItem("Layout")
{
Items = layoutDictionary?.Select(x => new TernaryStateToggleMenuItem(x.Value, selectedLayoutIndex == x.Key ? MenuItemType.Highlighted : MenuItemType.Standard, state =>
{
if (state != TernaryState.True)
return;

int layoutIndex = x.Key;
var layout = source.GetConfig<KaraokeSkinLookup, LyricLayout>(new KaraokeSkinLookup(ElementType.LyricLayout, layoutIndex)).Value;

// todo: should use another way to change the layout.
// lyricLayoutChangeHandler.ChangeLayout(layout);
})).ToArray()
};
}

private MenuItem createSingerMenuItem()
{
return new SingerContextMenu(beatmap, lyricSingerChangeHandler, "Singer");
Expand Down
9 changes: 0 additions & 9 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/Rows/EditLyricRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Rows
public class EditLyricRow : LyricEditorRow
{
private const int min_height = 75;
private const int continuous_spacing = 20;

public EditLyricRow(Lyric lyric)
: base(lyric)
Expand All @@ -43,16 +42,8 @@ public EditLyricRow(Lyric lyric)

protected override Drawable CreateLyricInfo(Lyric lyric)
{
// todo : need to refactor this part.
bool isContinuous = lyric.LayoutIndex == -1;
int continuousSpacing = isContinuous ? continuous_spacing : 0;

return new InfoControl(lyric)
{
Margin = new MarginPadding
{
Left = continuousSpacing,
},
// 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,
Expand Down
13 changes: 0 additions & 13 deletions osu.Game.Rulesets.Karaoke/Objects/Lyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,6 @@ public IList<int> Singers
}
}

[JsonIgnore]
public readonly Bindable<int> LayoutIndexBindable = new();

/// <summary>
/// Layout index
/// </summary>
[JsonIgnore]
public int LayoutIndex
{
get => LayoutIndexBindable.Value;
set => LayoutIndexBindable.Value = value;
}

[JsonIgnore]
public readonly BindableDictionary<CultureInfo, string> TranslateTextBindable = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ private void load(LayoutManager manager)
manager.EditLayout.BindValueChanged(v =>
{
if (Child is PreviewDrawableLyric lyric)
lyric.HitObject.LayoutIndex = v.NewValue.ID;
{
// todo: should trigger the skin change instead.
}
}, true);
}

Expand Down
13 changes: 1 addition & 12 deletions osu.Game.Rulesets.Karaoke/Screens/Skin/Layout/LayoutSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class LayoutSelectionItem : FillFlowContainer
{
private const float selection_size = (240 - layout_setting_horizontal_padding * 2 - SECTION_SPACING) / 2;

// todo: should changed into selected layout index
private readonly Bindable<int> selectedLayoutIndex = new();

private readonly DrawableLayoutPreview drawableLayoutPreview;
Expand Down Expand Up @@ -131,20 +132,8 @@ public Lyric Lyric
if (drawableLayoutPreview.Lyric == value)
return;

// unbind previous event
if (Lyric != null)
{
selectedLayoutIndex.UnbindFrom(Lyric.LayoutIndexBindable);
}

// update lyric
drawableLayoutPreview.Lyric = value;

// bind layout index.
if (Lyric != null)
{
selectedLayoutIndex.BindTo(Lyric.LayoutIndexBindable);
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions osu.Game.Rulesets.Karaoke/Utils/LyricsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public static Tuple<Lyric, Lyric> SplitLyric(Lyric lyric, int splitIndex)
RomajiTags = lyric.RomajiTags?.Where(x => x.StartIndex < splitIndex && x.EndIndex <= splitIndex).ToArray(),
// todo : should implement time and duration
Singers = lyric.Singers,
LayoutIndex = lyric.LayoutIndex,
Language = lyric.Language,
};

Expand All @@ -78,7 +77,6 @@ public static Tuple<Lyric, Lyric> SplitLyric(Lyric lyric, int splitIndex)
RomajiTags = shiftingTextTag(lyric.RomajiTags?.Where(x => x.StartIndex >= splitIndex && x.EndIndex > splitIndex).ToArray(), secondLyricText, -splitIndex),
// todo : should implement time and duration
Singers = lyric.Singers,
LayoutIndex = lyric.LayoutIndex,
Language = lyric.Language,
};

Expand Down Expand Up @@ -127,7 +125,6 @@ public static Lyric CombineLyric(Lyric firstLyric, Lyric secondLyric)
StartTime = startTime,
Duration = endTime - startTime,
Singers = singers.Distinct().ToArray(),
LayoutIndex = firstLyric.LayoutIndex,
Language = language,
};
}
Expand Down

0 comments on commit 86190a4

Please sign in to comment.