Cleanup positioning factor definition

This commit is contained in:
smoogipoo 2020-04-02 14:24:09 +09:00
parent 09eb9facdd
commit b375a02cff
3 changed files with 48 additions and 21 deletions

View File

@ -1,45 +1,64 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Animations;
using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Mania.Skinning namespace osu.Game.Rulesets.Mania.Skinning
{ {
public class LegacyHitExplosion : LegacyManiaColumnElement public class LegacyHitExplosion : LegacyManiaElement
{ {
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>(); private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
private Drawable explosion; private Drawable explosion;
[BackgroundDependencyLoader] public LegacyHitExplosion()
private void load(IScrollingInfo scrollingInfo)
{ {
InternalChild = explosion = new Sprite RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(ISkinSource skin, IScrollingInfo scrollingInfo)
{
string imageName = GetManiaSkinConfig<string>(skin, LegacyManiaSkinConfigurationLookups.ExplosionImage)?.Value
?? "lightingN";
InternalChild = explosion = skin.GetAnimation(imageName, true, false, startAtCurrentTime: true).With(d =>
{ {
}; if (d == null)
return;
d.Origin = Anchor.Centre;
d.Blending = BlendingParameters.Additive;
if (!(d is TextureAnimation texAnimation))
return;
if (texAnimation.FrameCount > 0)
texAnimation.DefaultFrameLength = Math.Max(texAnimation.DefaultFrameLength, 170.0 / texAnimation.FrameCount);
});
direction.BindTo(scrollingInfo.Direction); direction.BindTo(scrollingInfo.Direction);
direction.BindValueChanged(onDirectionChanged, true); direction.BindValueChanged(onDirectionChanged, true);
// Todo: LightingN
// Todo: LightingL
} }
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> obj) private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
{ {
throw new System.NotImplementedException(); if (explosion != null)
explosion.Anchor = direction.NewValue == ScrollingDirection.Up ? Anchor.TopCentre : Anchor.BottomCentre;
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
lighting.FadeInFromZero(80) explosion?.FadeInFromZero(80)
.Then().FadeOut(120); .Then().FadeOut(120);
} }
} }
} }

View File

@ -7,14 +7,24 @@ namespace osu.Game.Skinning
{ {
public class LegacyManiaSkinConfiguration public class LegacyManiaSkinConfiguration
{ {
/// <summary>
/// Conversion factor from converting legacy positioning values (based in x480 dimensions) to x768.
/// </summary>
public const float POSITION_SCALE_FACTOR = 1.6f;
/// <summary>
/// Size of a legacy column in the default skin, used for determining relative scale factors.
/// </summary>
public const float DEFAULT_COLUMN_SIZE = 30 * POSITION_SCALE_FACTOR;
public readonly int Keys; public readonly int Keys;
public readonly float[] ColumnLineWidth; public readonly float[] ColumnLineWidth;
public readonly float[] ColumnSpacing; public readonly float[] ColumnSpacing;
public readonly float[] ColumnWidth; public readonly float[] ColumnWidth;
public float HitPosition = 124.8f; // (480 - 402) * 1.6f public float HitPosition = (480 - 402) * POSITION_SCALE_FACTOR;
public float LightPosition = 107.2f; // (480 - 413) * 1.6f public float LightPosition = (480 - 413) * POSITION_SCALE_FACTOR;
public bool ShowJudgementLine = true; public bool ShowJudgementLine = true;
public LegacyManiaSkinConfiguration(int keys) public LegacyManiaSkinConfiguration(int keys)
@ -26,7 +36,7 @@ namespace osu.Game.Skinning
ColumnWidth = new float[keys]; ColumnWidth = new float[keys];
ColumnLineWidth.AsSpan().Fill(2); ColumnLineWidth.AsSpan().Fill(2);
ColumnWidth.AsSpan().Fill(48); ColumnWidth.AsSpan().Fill(DEFAULT_COLUMN_SIZE);
} }
} }
} }

View File

@ -11,8 +11,6 @@ namespace osu.Game.Skinning
{ {
public class LegacyManiaSkinDecoder : LegacyDecoder<List<LegacyManiaSkinConfiguration>> public class LegacyManiaSkinDecoder : LegacyDecoder<List<LegacyManiaSkinConfiguration>>
{ {
private const float size_scale_factor = 1.6f;
public LegacyManiaSkinDecoder() public LegacyManiaSkinDecoder()
: base(1) : base(1)
{ {
@ -88,11 +86,11 @@ namespace osu.Game.Skinning
break; break;
case "HitPosition": case "HitPosition":
currentConfig.HitPosition = (480 - float.Parse(pair.Value, CultureInfo.InvariantCulture)) * size_scale_factor; currentConfig.HitPosition = (480 - float.Parse(pair.Value, CultureInfo.InvariantCulture)) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
break; break;
case "LightPosition": case "LightPosition":
currentConfig.LightPosition = (480 - float.Parse(pair.Value, CultureInfo.InvariantCulture)) * size_scale_factor; currentConfig.LightPosition = (480 - float.Parse(pair.Value, CultureInfo.InvariantCulture)) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
break; break;
case "JudgementLine": case "JudgementLine":
@ -111,7 +109,7 @@ namespace osu.Game.Skinning
if (i >= output.Length) if (i >= output.Length)
break; break;
output[i] = float.Parse(values[i], CultureInfo.InvariantCulture) * size_scale_factor; output[i] = float.Parse(values[i], CultureInfo.InvariantCulture) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
} }
} }
} }