Skip to content

Commit

Permalink
Merge pull request #1560 from andy840119/display-reference-lyric-amount
Browse files Browse the repository at this point in the history
Display reference lyric amount at the end of the lyric.
  • Loading branch information
andy840119 authored Sep 4, 2022
2 parents ef11731 + 34f60d9 commit 3ca79d2
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public LyricSelector()
},
new Drawable[]
{
lyricList = new RearrangeableLyricListContainer
lyricList = CreateRearrangeableLyricListContainer().With(x =>
{
RelativeSizeAxes = Axes.Both,
RequestSelection = item =>
x.RelativeSizeAxes = Axes.Both;
x.RequestSelection = item =>
{
Current.Value = item;
},
}
};
})
}
}
};
Expand All @@ -76,6 +76,8 @@ public LyricSelector()
Current.BindValueChanged(e => lyricList.SelectedSet.Value = e.NewValue);
}

protected virtual RearrangeableLyricListContainer CreateRearrangeableLyricListContainer() => new();

[BackgroundDependencyLoader]
private void load(EditorBeatmap editorBeatmap)
{
Expand Down Expand Up @@ -112,7 +114,6 @@ protected class DrawableLyricListItem : DrawableTextListItem
public DrawableLyricListItem(Lyric? item)
: base(item)
{
Padding = new MarginPadding { Left = 5 };
}

public override IEnumerable<LocalisableString> FilterTerms => new[]
Expand All @@ -124,7 +125,7 @@ protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContai
{
if (model == null)
{
// todo: show the empty text to let user select.
textFlowContainer.AddText("<Empty>");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Diagnostics.CodeAnalysis;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Edit.Components.UserInterfaceV2;
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.Extends.Reference
{
Expand Down Expand Up @@ -52,13 +60,13 @@ public Popover GetPopover()
=> new LyricSelectorPopover(Current);
}

public class LyricSelectorPopover : OsuPopover
private class LyricSelectorPopover : OsuPopover
{
private readonly LyricSelector lyricSelector;
private readonly ReferenceLyricSelector lyricSelector;

public LyricSelectorPopover(Bindable<Lyric?> bindable)
{
Child = lyricSelector = new LyricSelector
Child = lyricSelector = new ReferenceLyricSelector
{
Width = 400,
Height = 600,
Expand All @@ -73,5 +81,64 @@ protected override void LoadComplete()
GetContainingInputManager().ChangeFocus(lyricSelector);
}
}

protected class ReferenceLyricSelector : LyricSelector
{
protected override RearrangeableLyricListContainer CreateRearrangeableLyricListContainer()
=> new RearrangeableReferenceLyricListContainer();

protected class RearrangeableReferenceLyricListContainer : RearrangeableLyricListContainer
{
protected override DrawableTextListItem CreateDrawable(Lyric? item)
=> new DrawableReferenceLyricListItem(item);

protected class DrawableReferenceLyricListItem : DrawableLyricListItem
{
[Resolved, AllowNull]
private OsuColour colours { get; set; }

[Resolved, AllowNull]
private EditorBeatmap editorBeatmap { get; set; }

public DrawableReferenceLyricListItem(Lyric? item)
: base(item)
{
}

protected override bool OnClick(ClickEvent e)
{
// cannot select those lyric that already contains reference lyric.
if (!selectable(Model))
return false;

return base.OnClick(e);
}

protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContainer, Lyric? model)
{
base.CreateDisplayContent(textFlowContainer, model);

// should have disable style if lyric is not selectable.
textFlowContainer.Alpha = selectable(model) ? 1 : 0.5f;

if (model == null)
return;

Schedule(() =>
{
// add reference text at the end of the text.
int referenceLyricsAmount = EditorBeatmapUtils.GetAllReferenceLyrics(editorBeatmap, model).Count();

if (referenceLyricsAmount > 0)
{
textFlowContainer.AddText($"({referenceLyricsAmount} reference)", x => x.Colour = colours.Red);
}
});
}

private static bool selectable(Lyric? lyric) => lyric?.ReferenceLyric == null;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public DrawableTextListItem(TModel item)
: base(item)
{
Padding = new MarginPadding { Left = 5 };
ShowDragHandle.Value = false;
}

[BackgroundDependencyLoader]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ private class DrawableLanguageListItem : DrawableTextListItem
public DrawableLanguageListItem(CultureInfo item)
: base(item)
{
Padding = new MarginPadding { Left = 5 };
}

public override IEnumerable<LocalisableString> FilterTerms => new[]
Expand Down

0 comments on commit 3ca79d2

Please sign in to comment.