Skip to content

Commit

Permalink
Merge pull request #1561 from andy840119/disable-click-the-select-ref…
Browse files Browse the repository at this point in the history
…erence-button-if-being-referenced

Disable click the select reference button if being referenced.
  • Loading branch information
andy840119 authored Sep 4, 2022
2 parents 3ca79d2 + 9c1917a commit 70b142e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,13 @@ protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContai
}
else
{
Schedule(() =>
{
// display the lyric order.
textFlowContainer.AddText($"#{model.Order}", x => x.Colour = colours.Yellow);
textFlowContainer.AddText(" ");

// main text
textFlowContainer.AddText(model.Text);
textFlowContainer.AddText(" ");
});
// display the lyric order.
textFlowContainer.AddText($"#{model.Order}", x => x.Colour = colours.Yellow);
textFlowContainer.AddText(" ");

// main text
textFlowContainer.AddText(model.Text);
textFlowContainer.AddText(" ");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Reference
{
public class LabelledLyricSelector : LabelledComponent<LabelledLyricSelector.SelectLyricButton, Lyric?>
public class LabelledReferenceLyricSelector : LabelledComponent<LabelledReferenceLyricSelector.SelectLyricButton, Lyric?>
{
public LabelledLyricSelector()
public LabelledReferenceLyricSelector()
: base(true)
{
}
Expand All @@ -34,8 +34,17 @@ protected override SelectLyricButton CreateComponent()
RelativeSizeAxes = Axes.X
};

public Lyric? IgnoredLyric
{
get => Component.IgnoredLyric;
set => Component.IgnoredLyric = value;
}

public class SelectLyricButton : OsuButton, IHasCurrentValue<Lyric?>, IHasPopover
{
[Resolved, AllowNull]
private EditorBeatmap editorBeatmap { get; set; }

private readonly BindableWithCurrent<Lyric?> current = new();

public Bindable<Lyric?> Current
Expand All @@ -44,6 +53,20 @@ public Bindable<Lyric?> Current
set => current.Current = value;
}

private Lyric? ignoredLyric;

public Lyric? IgnoredLyric
{
get => ignoredLyric;
set
{
ignoredLyric = value;

// should not enable the selection if current lyric is being referenced.
Enabled.Value = ignoredLyric != null && !EditorBeatmapUtils.GetAllReferenceLyrics(editorBeatmap, ignoredLyric).Any();
}
}

public SelectLyricButton()
{
Action = this.ShowPopover;
Expand All @@ -57,15 +80,20 @@ public SelectLyricButton()
}

public Popover GetPopover()
=> new LyricSelectorPopover(Current);
=> new LyricSelectorPopover(Current, IgnoredLyric);
}

private class LyricSelectorPopover : OsuPopover
{
private readonly ReferenceLyricSelector lyricSelector;

public LyricSelectorPopover(Bindable<Lyric?> bindable)
[Cached]
private readonly Lyric? ignoreLyric;

public LyricSelectorPopover(Bindable<Lyric?> bindable, Lyric? ignoreLyric)
{
this.ignoreLyric = ignoreLyric;

Child = lyricSelector = new ReferenceLyricSelector
{
Width = 400,
Expand Down Expand Up @@ -100,6 +128,9 @@ protected class DrawableReferenceLyricListItem : DrawableLyricListItem
[Resolved, AllowNull]
private EditorBeatmap editorBeatmap { get; set; }

[Resolved]
private Lyric? ignoredLyric { get; set; }

public DrawableReferenceLyricListItem(Lyric? item)
: base(item)
{
Expand All @@ -116,27 +147,25 @@ protected override bool OnClick(ClickEvent 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;

base.CreateDisplayContent(textFlowContainer, model);

if (model == null)
return;

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

if (referenceLyricsAmount > 0)
{
// 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);
}
});
textFlowContainer.AddText($"({referenceLyricsAmount} reference)", x => x.Colour = colours.Red);
}
}

private static bool selectable(Lyric? lyric) => lyric?.ReferenceLyric == null;
private bool selectable(Lyric? lyric)
=> lyric != ignoredLyric && lyric?.ReferenceLyric == null;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ public class ReferenceLyricSection : LyricPropertySection
[Resolved, AllowNull]
private ILyricReferenceChangeHandler lyricReferenceChangeHandler { get; set; }

private readonly LabelledLyricSelector labelledLyricSelector;
private readonly LabelledReferenceLyricSelector labelledReferenceLyricSelector;

public ReferenceLyricSection()
{
Children = new[]
{
labelledLyricSelector = new LabelledLyricSelector
labelledReferenceLyricSelector = new LabelledReferenceLyricSelector
{
Label = "Referenced lyric",
Description = "Select the similar lyric that want to reference or sync the property."
}
};

labelledLyricSelector.Current.BindValueChanged(x =>
labelledReferenceLyricSelector.Current.BindValueChanged(x =>
{
if (!IsRebinding)
lyricReferenceChangeHandler.UpdateReferenceLyric(x.NewValue);
Expand All @@ -41,7 +41,8 @@ protected override void OnLyricChanged(Lyric? lyric)
if (lyric == null)
return;

labelledLyricSelector.Current = lyric.ReferenceLyricBindable;
labelledReferenceLyricSelector.Current = lyric.ReferenceLyricBindable;
labelledReferenceLyricSelector.IgnoredLyric = lyric;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ protected override void LoadComplete()
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
}.With(x => CreateDisplayContent(x, Model));
}.With(x =>
{
Schedule(() =>
{
// should create the text after BDL loaded.
CreateDisplayContent(x, Model);
});
});

protected override bool OnClick(ClickEvent e)
{
Expand Down
23 changes: 10 additions & 13 deletions osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,18 @@ public DrawableFontFamilyListItem(string item)
protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContainer, string model)
{
textFlowContainer.TextAnchor = Anchor.BottomLeft;
Schedule(() =>
{
textFlowContainer.AddText(model);
textFlowContainer.AddText(model);

var matchedFormat = fontManager.Fonts
.Where(x => x.Family == Model).Select(x => x.FontFormat)
.Distinct()
.ToArray();
var matchedFormat = fontManager.Fonts
.Where(x => x.Family == Model).Select(x => x.FontFormat)
.Distinct()
.ToArray();

foreach (var format in matchedFormat)
{
textFlowContainer.AddText(" ");
textFlowContainer.AddArbitraryDrawable(new FontFormatBadge(format));
}
});
foreach (var format in matchedFormat)
{
textFlowContainer.AddText(" ");
textFlowContainer.AddArbitraryDrawable(new FontFormatBadge(format));
}
}
}
}
Expand Down

0 comments on commit 70b142e

Please sign in to comment.