Skip to content

Commit

Permalink
Separate the singer and singer state into 2 different list.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Sep 25, 2024
1 parent 7dc4942 commit 1063d80
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
27 changes: 20 additions & 7 deletions osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/SingerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ public class SingerInfo
public bool SupportSingerState { get; set; }

// todo: should make the property as readonly.
public BindableList<ISinger> Singers { get; set; } = new();
public BindableList<Singer> Singers { get; set; } = new();

// todo: should make the property as readonly.
public BindableList<SingerState> SingerState { get; set; } = new();

public IEnumerable<Singer> GetAllSingers() =>
Singers.OfType<Singer>().OrderBy(x => x.Order);
Singers.OrderBy(x => x.Order);

public IEnumerable<SingerState> GetAllAvailableSingerStates(Singer singer) =>
Singers.OfType<SingerState>().Where(x => x.MainSingerId == singer.ID).OrderBy(x => x.Order);
SingerState.Where(x => x.MainSingerId == singer.ID).OrderBy(x => x.Order);

public IDictionary<Singer, SingerState[]> GetSingerByIds(ElementId[] singerIds)
{
Expand Down Expand Up @@ -58,7 +61,7 @@ public SingerState AddSingerState(Singer singer, Action<SingerState>? action = n
var singerState = new SingerState(mainSingerId);
action?.Invoke(singerState);

Singers.Add(singerState);
SingerState.Add(singerState);

return singerState;
}
Expand All @@ -76,14 +79,24 @@ public bool RemoveSinger(ISinger singer)
RemoveSinger(singerState);
}

return Singers.Remove(singer);
return Singers.Remove(mainSinger);
}

case SingerState:
return Singers.Remove(singer);
case SingerState singerState:
return SingerState.Remove(singerState);

default:
throw new InvalidCastException();
}
}

public bool HasSinger(ISinger singer)
{
return singer switch
{
Singer mainSinger => Singers.Contains(mainSinger),
SingerState singerState => SingerState.Contains(singerState),
_ => throw new InvalidCastException(),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class BeatmapSingersChangeHandler : BeatmapPropertyChangeHandler,

private SingerInfo singerInfo => KaraokeBeatmap.SingerInfo;

public BindableList<ISinger> Singers => singerInfo.Singers;
public BindableList<Singer> Singers => singerInfo.Singers;

public void ChangeOrder(ISinger singer, int newIndex)
{
Expand Down Expand Up @@ -111,7 +111,7 @@ private void performSingerChanged<TSinger>(TSinger singer, Action<TSinger> actio
{
performSingerInfoChanged(singerInfo =>
{
if (!singerInfo.Singers.Contains(singer))
if (!singerInfo.HasSinger(singer))
throw new InvalidOperationException("Singer should be in the beatmap");

action(singer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps;
public interface IBeatmapSingersChangeHandler
{
// todo: should use IBindableList eventually, but cannot do that because it's bind to selection item.
BindableList<ISinger> Singers { get; }
BindableList<Singer> Singers { get; }

void ChangeOrder(ISinger singer, int newIndex);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.Singer

public partial class SingerEditSection : LyricPropertySection
{
private readonly IBindableList<ISinger> bindableSingers = new BindableList<ISinger>();
private readonly IBindableList<Singer> bindableSingers = new BindableList<Singer>();
private readonly IBindableList<ElementId> singerIndexes = new BindableList<ElementId>();
protected override LocalisableString Title => "Singer";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas.Types;
using osu.Game.Rulesets.Karaoke.Graphics.Containers;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Singers.Rows;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Singers;

public partial class SingerRearrangeableList : OrderRearrangeableListContainer<ISinger>
public partial class SingerRearrangeableList : OrderRearrangeableListContainer<Singer>
{
protected override Vector2 Spacing => new(0, 5);

Expand All @@ -24,7 +25,7 @@ public SingerRearrangeableList()
};
}

protected override OsuRearrangeableListItem<ISinger> CreateOsuDrawable(ISinger item)
protected override OsuRearrangeableListItem<Singer> CreateOsuDrawable(Singer item)
=> new SingerRearrangeableListItem(item);

protected override Drawable CreateBottomDrawable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Singers;

public partial class SingerRearrangeableListItem : OsuRearrangeableListItem<ISinger>
public partial class SingerRearrangeableListItem : OsuRearrangeableListItem<Singer>
{
private Box dragAlert = null!;

public SingerRearrangeableListItem(ISinger item)
public SingerRearrangeableListItem(Singer item)
: base(item)
{
}

protected override Drawable CreateContent()
{
if (Model is not Singer singer)
throw new InvalidCastException($"Currently we are only able to edit the {nameof(Singer)}.");

return new Container
{
Masking = true,
Expand All @@ -42,7 +39,7 @@ protected override Drawable CreateContent()
RelativeSizeAxes = Axes.Both,
Alpha = 0,
},
new SingerLyricPlacementColumn(singer)
new SingerLyricPlacementColumn(Model)
{
RelativeSizeAxes = Axes.Both,
},
Expand Down

0 comments on commit 1063d80

Please sign in to comment.