Skip to content

Commit

Permalink
Use layer loader because it's on OK to assign the lyric to the layer …
Browse files Browse the repository at this point in the history
…outside of the InteractableLyric class.
  • Loading branch information
andy840119 committed Aug 17, 2024
1 parent 9cfd5fd commit 3dc7e2f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,38 @@ public InteractableLyric(Lyric lyric)
});
}

public IEnumerable<Layer> Layers
public IEnumerable<LayerLoader> Loaders
{
get => InternalChildren.OfType<Layer>();
init
{
AddRangeInternal(value);
foreach (var loader in value)
{
var layer = loader.CreateLayer(lyric);
AddInternal(layer);
}

var lyricLayers = value.OfType<LyricLayer>().Single();
var lyricLayers = layers.OfType<LyricLayer>().Single();
lyricLayers.SizeChanged = size =>
{
TextSizeChanged?.Invoke(this, size);
};
}
}

private IEnumerable<Layer> layers => InternalChildren.OfType<Layer>();

protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var baseDependencies = new DependencyContainer(base.CreateChildDependencies(parent));

var lyricLayer = Layers.OfType<LyricLayer>().Single();
var lyricLayer = layers.OfType<LyricLayer>().Single();
baseDependencies.CacheAs<IPreviewLyricPositionProvider>(lyricLayer);
return baseDependencies;
}

public void TriggerDisallowEditEffect()
{
Layers.ForEach(x => x.TriggerDisallowEditEffect(bindableMode.Value));
layers.ForEach(x => x.TriggerDisallowEditEffect(bindableMode.Value));
}

[BackgroundDependencyLoader]
Expand All @@ -86,7 +91,7 @@ private void triggerWritableVersionChanged()

// adjust the style.
bool editable = lockReason == null;
Layers.ForEach(x => x.UpdateDisableEditState(editable));
layers.ForEach(x => x.UpdateDisableEditState(editable));
}

public LocalisableString TooltipText => lockReason ?? string.Empty;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Utils;

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

public class LayerLoader<TLayer> : LayerLoader where TLayer : Layer
{
public Action<TLayer>? OnLoad { get; init; }

public override Layer CreateLayer(Lyric lyric)
{
var layer = ActivatorUtils.CreateInstance<TLayer>(lyric);
OnLoad?.Invoke(layer);
return layer;
}
}

public abstract class LayerLoader
{
public abstract Layer CreateLayer(Lyric lyric);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ protected override Drawable CreateContent(Lyric lyric)
{
self.Height = size.Y;
},
Layers = new Layer[]
Loaders = new LayerLoader[]
{
new LyricLayer(lyric),
new InteractLyricLayer(lyric),
new TimeTagLayer(lyric),
new LayerLoader<LyricLayer>(),
new LayerLoader<InteractLyricLayer>(),
new LayerLoader<TimeTagLayer>(),
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,26 @@ public LyricEditor()
self.Width = size.X + border * 2;
self.Height = size.Y + border * 2;
},
Layers = new Layer[]
Loaders = new LayerLoader[]
{
new GridLayer(lyric)
new LayerLoader<GridLayer>
{
Spacing = 10,
OnLoad = layer =>
{
layer.Spacing = 10;
},
},
new LyricLayer(lyric)
new LayerLoader<LyricLayer>
{
LyricPosition = new Vector2(border),
OnLoad = layer =>
{
layer.LyricPosition = new Vector2(border);
},
},
new EditLyricLayer(lyric),
new TimeTagLayer(lyric),
new CaretLayer(lyric),
new BlueprintLayer(lyric),
new LayerLoader<EditLyricLayer>(),
new LayerLoader<TimeTagLayer>(),
new LayerLoader<CaretLayer>(),
new LayerLoader<BlueprintLayer>(),
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ protected override Drawable CreateContent(Lyric lyric)
{
self.Height = size.Y;
},
Layers = new Layer[]
Loaders = new LayerLoader[]
{
new LyricLayer(lyric),
new EditLyricLayer(lyric),
new TimeTagLayer(lyric),
new CaretLayer(lyric),
new BlueprintLayer(lyric),
new LayerLoader<LyricLayer>(),
new LayerLoader<EditLyricLayer>(),
new LayerLoader<TimeTagLayer>(),
new LayerLoader<CaretLayer>(),
new LayerLoader<BlueprintLayer>(),
},
};
}
Expand Down

0 comments on commit 3dc7e2f

Please sign in to comment.