Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow LN tail to have an origin of TopCentre #27726

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions osu.Game.Rulesets.Mania.Tests/Skinning/TestSceneHoldNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Skinning;

namespace osu.Game.Rulesets.Mania.Tests.Skinning
{
Expand Down Expand Up @@ -37,6 +39,25 @@ public void TestFadeOnMiss()
});
}

[Test]
public void TestTailOrigin()
{
AddStep("set tail origin to regular", () =>
{
foreach (var holdNote in CreatedDrawables.SelectMany(d => d.ChildrenOfType<DrawableHoldNote>()))
holdNote.Tail.TailOrigin = HoldNoteTailOrigin.Regular;
});
AddStep("change direction to down", () => ScrollingInfo.Direction.Value = ScrollingDirection.Down);
AddStep("change direction to up", () => ScrollingInfo.Direction.Value = ScrollingDirection.Up);
AddStep("set tail origin to inverted", () =>
{
foreach (var holdNote in CreatedDrawables.SelectMany(d => d.ChildrenOfType<DrawableHoldNote>()))
holdNote.Tail.TailOrigin = HoldNoteTailOrigin.Inverted;
});
AddStep("change direction to down", () => ScrollingInfo.Direction.Value = ScrollingDirection.Down);
AddStep("change direction to up", () => ScrollingInfo.Direction.Value = ScrollingDirection.Up);
}

private IEnumerable<DrawableHoldNote> holdNotes => CreatedDrawables.SelectMany(d => d.ChildrenOfType<DrawableHoldNote>());

protected override DrawableManiaHitObject CreateHitObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,12 @@ protected override void Update()
// Position and resize the body to lie half-way under the head and the tail notes.
// The rationale for this is account for heads/tails with corner radius.
bodyPiece.Y = (Direction.Value == ScrollingDirection.Up ? 1 : -1) * Head.Height / 2;
bodyPiece.Height = DrawHeight - Head.Height / 2 + Tail.Height / 2;
bodyPiece.Height = DrawHeight - Head.Height / 2;

if (Tail.TailOrigin == HoldNoteTailOrigin.Inverted)
bodyPiece.Height -= Tail.Height / 2;
else
bodyPiece.Height += Tail.Height / 2;

if (Time.Current >= HitObject.StartTime)
{
Expand Down
36 changes: 36 additions & 0 deletions osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@

#nullable disable

using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Mania.Skinning;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Skinning;

namespace osu.Game.Rulesets.Mania.Objects.Drawables
{
Expand All @@ -18,6 +22,18 @@ public partial class DrawableHoldNoteTail : DrawableNote

protected internal DrawableHoldNote HoldNote => (DrawableHoldNote)ParentHitObject;

private HoldNoteTailOrigin tailOrigin = HoldNoteTailOrigin.Regular;

public HoldNoteTailOrigin TailOrigin
{
get => tailOrigin;
set
{
tailOrigin = value;
updateTailOrigin();
}
}

public DrawableHoldNoteTail()
: this(null)
{
Expand Down Expand Up @@ -52,5 +68,25 @@ protected override HitResult GetCappedResult(HitResult result)
public override void OnReleased(KeyBindingReleaseEvent<ManiaAction> e)
{
}

protected override void ApplySkin(ISkinSource skin, bool allowFallback)
{
base.ApplySkin(skin, allowFallback);
tailOrigin = skin.GetConfig<ManiaSkinConfigurationLookup, HoldNoteTailOrigin>(new ManiaSkinConfigurationLookup(LegacyManiaSkinConfigurationLookups.HoldNoteTailOrigin))?.Value ?? HoldNoteTailOrigin.Regular;
}

protected override void OnDirectionChanged(ValueChangedEvent<ScrollingDirection> e)
{
base.OnDirectionChanged(e);
updateTailOrigin();
}

private void updateTailOrigin()
{
if (Direction.Value == ScrollingDirection.Up)
Origin = tailOrigin == HoldNoteTailOrigin.Inverted ? Anchor.BottomCentre : Anchor.TopCentre;
else
Origin = tailOrigin == HoldNoteTailOrigin.Inverted ? Anchor.TopCentre : Anchor.BottomCentre;
}
}
}
1 change: 0 additions & 1 deletion osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ protected override void OnApply()
protected override void OnDirectionChanged(ValueChangedEvent<ScrollingDirection> e)
{
base.OnDirectionChanged(e);

headPiece.Anchor = headPiece.Origin = e.NewValue == ScrollingDirection.Up ? Anchor.TopCentre : Anchor.BottomCentre;
}

Expand Down
1 change: 1 addition & 0 deletions osu.Game/Skinning/LegacyManiaSkinConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class LegacyManiaSkinConfiguration : IHasCustomColours
public bool KeysUnderNotes;
public int LightFramePerSecond = 60;

public HoldNoteTailOrigin HoldNoteTailOrigin;
public LegacyNoteBodyStyle? NoteBodyStyle;

public LegacyManiaSkinConfiguration(int keys)
Expand Down
7 changes: 7 additions & 0 deletions osu.Game/Skinning/LegacyManiaSkinConfigurationLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum LegacyManiaSkinConfigurationLookups
HoldNoteBodyImage,
HoldNoteLightImage,
HoldNoteLightScale,
HoldNoteTailOrigin,
WidthForNoteHeightScale,
ExplosionImage,
ExplosionScale,
Expand All @@ -82,4 +83,10 @@ public enum LegacyManiaSkinConfigurationLookups
NoteBodyStyle,
LightFramePerSecond
}

public enum HoldNoteTailOrigin
{
Regular = 0,
Inverted = 1
}
}
5 changes: 5 additions & 0 deletions osu.Game/Skinning/LegacyManiaSkinDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ private void flushPendingLines()
currentConfig.LightFramePerSecond = lightFramePerSecond > 0 ? lightFramePerSecond : 24;
break;

case "HoldNoteTailOrigin":
if (Enum.TryParse<HoldNoteTailOrigin>(pair.Value, out var tailOrigin))
currentConfig.HoldNoteTailOrigin = tailOrigin;
break;

case string when pair.Key.StartsWith("Colour", StringComparison.Ordinal):
HandleColours(currentConfig, line, true);
break;
Expand Down
3 changes: 3 additions & 0 deletions osu.Game/Skinning/LegacySkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ protected override void ParseConfigurationStream(Stream stream)

return SkinUtils.As<TValue>(new Bindable<float>(existing.ColumnWidth[maniaLookup.ColumnIndex.Value] / LegacyManiaSkinConfiguration.DEFAULT_COLUMN_SIZE));

case LegacyManiaSkinConfigurationLookups.HoldNoteTailOrigin:
return SkinUtils.As<TValue>(new Bindable<HoldNoteTailOrigin>(existing.HoldNoteTailOrigin));

case LegacyManiaSkinConfigurationLookups.KeyImage:
Debug.Assert(maniaLookup.ColumnIndex != null);
return SkinUtils.As<TValue>(getManiaImage(existing, $"KeyImage{maniaLookup.ColumnIndex}"));
Expand Down