Skip to content

Commit

Permalink
Merge pull request #1946 from andy840119/use-applier-in-the-drawable-…
Browse files Browse the repository at this point in the history
…lyric

Use applier in the drawable lyric and playfield.
  • Loading branch information
andy840119 authored Apr 21, 2023
2 parents 975e1d4 + e8bd79e commit 0a27fb9
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 121 deletions.
14 changes: 14 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneLyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages.Preview;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Objects.Drawables;
using osu.Game.Rulesets.Karaoke.Objects.Stages.Preview;
using osu.Game.Rulesets.Mods;

namespace osu.Game.Rulesets.Karaoke.Tests.Skinning;
Expand Down Expand Up @@ -83,6 +85,18 @@ private Drawable testSingle(double timeOffset = 0)
Text = "ke"
}
},
EffectApplier = new LyricPreviewStageEffectApplier(new[]
{
new PreviewLyricLayout(1)
{
StartTime = startTime,
EndTime = startTime + duration,
Timings = new Dictionary<int, double>
{
{ 0, startTime }
}
}
}, new PreviewStageDefinition())
};

lyric.Translates.Add(cultureInfo, "karaoke");
Expand Down
15 changes: 0 additions & 15 deletions osu.Game.Rulesets.Karaoke/Beatmaps/KaraokeBeatmapProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Karaoke.Beatmaps.Patterns;
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages;
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages.Preview;
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages.Types;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Objects.Types;
using osu.Game.Rulesets.Karaoke.Objects.Workings;

Expand Down Expand Up @@ -62,18 +60,5 @@ private void applyInvalidProperty(KaraokeBeatmap beatmap)
hitObject.ValidateWorkingProperty(beatmap);
}
}

public override void PostProcess()
{
base.PostProcess();

var lyrics = Beatmap.HitObjects.OfType<Lyric>().ToList();

if (!lyrics.Any())
return;

var pattern = new LegacyLyricTimeGenerator();
pattern.Generate(lyrics);
}
}
}
13 changes: 0 additions & 13 deletions osu.Game.Rulesets.Karaoke/Beatmaps/Patterns/IPatternGenerator.cs

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions osu.Game.Rulesets.Karaoke/Edit/KaraokeEditorPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@

#nullable disable

using osu.Framework.Graphics;
using osu.Game.Rulesets.Karaoke.UI;
using osu.Game.Rulesets.Karaoke.UI.Scrolling;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Edit
{
public partial class KaraokeEditorPlayfield : KaraokePlayfield
{
public KaraokeEditorPlayfield()
{
LyricPlayfield.Anchor = LyricPlayfield.Origin = Anchor.BottomCentre;
LyricPlayfield.Margin = new MarginPadding { Top = 150, Bottom = -100 };
LyricPlayfield.Scale = new Vector2(0.7f);
}

protected override ScrollingNotePlayfield CreateNotePlayfield(int columns)
=> new EditorNotePlayfield(columns);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Karaoke.Judgements;
using osu.Game.Rulesets.Karaoke.Objects.Types;
using osu.Game.Rulesets.Objects.Drawables;

namespace osu.Game.Rulesets.Karaoke.Objects.Drawables
Expand All @@ -16,8 +17,43 @@ protected DrawableKaraokeHitObject(KaraokeHitObject hitObject)
{
}

protected sealed override double InitialLifetimeOffset => HitObject.TimePreempt;
protected sealed override double InitialLifetimeOffset
{
get
{
if (HitObject is IHasEffectApplier hitObjectWithEffectApplier)
{
return hitObjectWithEffectApplier.EffectApplier.PreemptTime;
}

return base.InitialLifetimeOffset;
}
}

protected override JudgementResult CreateResult(Judgement judgement) => new KaraokeJudgementResult(HitObject, judgement);

protected override void UpdateInitialTransforms()
{
if (HitObject is IHasEffectApplier hitObjectWithEffectApplier)
{
hitObjectWithEffectApplier.EffectApplier.UpdateInitialTransforms(this);
}
}

protected override void UpdateStartTimeStateTransforms()
{
if (HitObject is IHasEffectApplier hitObjectWithEffectApplier)
{
hitObjectWithEffectApplier.EffectApplier.UpdateStartTimeStateTransforms(this);
}
}

protected override void UpdateHitStateTransforms(ArmedState state)
{
if (HitObject is IHasEffectApplier hitObjectWithEffectApplier)
{
hitObjectWithEffectApplier.EffectApplier.UpdateHitStateTransforms(this, state);
}
}
}
}
26 changes: 0 additions & 26 deletions osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
using osu.Game.Rulesets.Karaoke.Scoring;
using osu.Game.Rulesets.Karaoke.Skinning.Default;
using osu.Game.Rulesets.Karaoke.Skinning.Elements;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Skinning;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Objects.Drawables
{
Expand Down Expand Up @@ -60,14 +58,11 @@ public DrawableLyric()
public DrawableLyric([CanBeNull] Lyric hitObject)
: base(hitObject)
{
// todo: it's a reservable size, should be removed eventually.
Padding = new MarginPadding(30);
}

[BackgroundDependencyLoader(true)]
private void load([CanBeNull] KaraokeSessionStatics session)
{
Scale = new Vector2(2);
AutoSizeAxes = Axes.Both;

AddInternal(lyricPieces = new Container<DefaultLyricPiece>
Expand Down Expand Up @@ -150,7 +145,6 @@ protected override void ApplySkin(ISkinSource skin, bool allowFallback)

updateFontStyle();
updateLyricFontInfo();
updateLayout();
}

private void updateFontStyle()
Expand All @@ -177,18 +171,6 @@ private void updateLyricFontInfo()
lyricFontInfo?.ApplyTo(this);
}

private void updateLayout()
{
if (CurrentSkin == null)
return;

if (HitObject == null)
return;

var layout = CurrentSkin.GetConfig<Lyric, LyricLayout>(HitObject)?.Value;
layout?.ApplyTo(this);
}

private void applyTranslate()
{
var language = preferLanguageBindable.Value;
Expand Down Expand Up @@ -231,14 +213,6 @@ protected override void UpdateInitialTransforms()
lyricPieces.ForEach(x => x.RefreshStateTransforms());
}

protected override void UpdateHitStateTransforms(ArmedState state)
{
base.UpdateHitStateTransforms(state);

const float fade_out_time = 500;
this.FadeOut(fade_out_time);
}

public void ApplyToLyricPieces(Action<DefaultLyricPiece> action)
{
foreach (var lyricPiece in lyricPieces)
Expand Down
6 changes: 6 additions & 0 deletions osu.Game.Rulesets.Karaoke/UI/DrawableKaraokeRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public partial class DrawableKaraokeRuleset : DrawableScrollingRuleset<KaraokeHi
[Cached(typeof(IKaraokeBeatmapResourcesProvider))]
private KaraokeBeatmapResourcesProvider karaokeBeatmapResourcesProvider;

public new KaraokeBeatmap Beatmap => base.Beatmap as KaraokeBeatmap;

protected virtual bool DisplayNotePlayfield => Beatmap.IsScorable();

public DrawableKaraokeRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods)
Expand All @@ -70,6 +72,10 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
[BackgroundDependencyLoader]
private void load()
{
// todo: use better way to assign the stage info.
// also, should monitor the stage info change.
updatePlayfieldArrangement(Beatmap.CurrentStageInfo);

// TODO : it should be moved into NotePlayfield
new BarLineGenerator<BarLine>(Beatmap).BarLines.ForEach(bar => base.Playfield.Add(bar));

Expand Down
19 changes: 19 additions & 0 deletions osu.Game.Rulesets.Karaoke/UI/DrawableKaraokeRuleset_Stage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Bindables;
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages;

namespace osu.Game.Rulesets.Karaoke.UI;

public partial class DrawableKaraokeRuleset
{
private readonly IBindable<StageInfo> currentStageInfo = new Bindable<StageInfo>();
private readonly IBindable<bool> scorable = new Bindable<bool>();

private void updatePlayfieldArrangement(StageInfo stageInfo)
{
var applier = stageInfo.GetPlayfieldStageApplier();
applier.UpdatePlayfieldArrangement(Playfield, DisplayNotePlayfield);
}
}
13 changes: 3 additions & 10 deletions osu.Game.Rulesets.Karaoke/UI/KaraokePlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Configuration;
Expand Down Expand Up @@ -49,16 +48,10 @@ public KaraokePlayfield()
x.RelativeSizeAxes = Axes.Both;
}));

AddInternal(new Container
AddInternal(NotePlayfield = CreateNotePlayfield(9).With(x =>
{
Padding = new MarginPadding(50),
RelativeSizeAxes = Axes.Both,
Child = NotePlayfield = CreateNotePlayfield(9).With(x =>
{
x.Alpha = 0;
x.RelativeSizeAxes = Axes.X;
})
});
x.RelativeSizeAxes = Axes.X;
}));

AddNested(LyricPlayfield);
AddNested(NotePlayfield);
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/UI/LyricPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public LyricHitObjectLifetimeEntry(HitObject hitObject)
{
// Manually set to reduce the number of future alive objects to a bare minimum.
LifetimeEnd = Lyric.EndTime;
LifetimeStart = HitObject.StartTime - Lyric.TimePreempt;
LifetimeStart = HitObject.StartTime - Lyric.EffectApplier.PreemptTime;
}

protected Lyric Lyric => (Lyric)HitObject;

protected override double InitialLifetimeOffset => Lyric.TimePreempt;
protected override double InitialLifetimeOffset => Lyric.EffectApplier.PreemptTime;
}
}
}

0 comments on commit 0a27fb9

Please sign in to comment.