Add alignment support for skin versions older than 2.1

This commit is contained in:
Dean Herbert
2020-04-07 19:14:31 +09:00
parent 4b16b2e720
commit d786a2c5b3

View File

@ -18,9 +18,12 @@ namespace osu.Game.Rulesets.Taiko.Skinning
/// </summary> /// </summary>
internal class LegacyInputDrum : Container internal class LegacyInputDrum : Container
{ {
private LegacyHalfDrum left;
private LegacyHalfDrum right;
public LegacyInputDrum() public LegacyInputDrum()
{ {
AutoSizeAxes = Axes.Both; Size = new Vector2(180, 200);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -32,25 +35,47 @@ namespace osu.Game.Rulesets.Taiko.Skinning
{ {
Texture = skin.GetTexture("taiko-bar-left") Texture = skin.GetTexture("taiko-bar-left")
}, },
new LegacyHalfDrum(false) left = new LegacyHalfDrum(false)
{ {
Name = "Left Half", Name = "Left Half",
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Width = 0.5f,
RimAction = TaikoAction.LeftRim, RimAction = TaikoAction.LeftRim,
CentreAction = TaikoAction.LeftCentre CentreAction = TaikoAction.LeftCentre
}, },
new LegacyHalfDrum(true) right = new LegacyHalfDrum(true)
{ {
Name = "Right Half", Name = "Right Half",
Anchor = Anchor.TopRight,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Width = 0.5f, Origin = Anchor.TopRight,
Scale = new Vector2(-1, 1), Scale = new Vector2(-1, 1),
RimAction = TaikoAction.RightRim, RimAction = TaikoAction.RightRim,
CentreAction = TaikoAction.RightCentre CentreAction = TaikoAction.RightCentre
} }
}; };
// this will be used in the future for stable skin alignment. keeping here for reference.
const float taiko_bar_y = 0;
// stable things
const float ratio = 1.6f;
// because the right half is flipped, we need to position using width - position to get the true "topleft" origin position
float negativeScaleAdjust = Width / ratio;
if (skin.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version)?.Value >= 2.1m)
{
left.Centre.Position = new Vector2(0, taiko_bar_y) * ratio;
right.Centre.Position = new Vector2(negativeScaleAdjust - 56, taiko_bar_y) * ratio;
left.Rim.Position = new Vector2(0, taiko_bar_y) * ratio;
right.Rim.Position = new Vector2(negativeScaleAdjust - 56, taiko_bar_y) * ratio;
}
else
{
left.Centre.Position = new Vector2(18, taiko_bar_y + 31) * ratio;
right.Centre.Position = new Vector2(negativeScaleAdjust - 54, taiko_bar_y + 31) * ratio;
left.Rim.Position = new Vector2(8, taiko_bar_y + 23) * ratio;
right.Rim.Position = new Vector2(negativeScaleAdjust - 53, taiko_bar_y + 23) * ratio;
}
} }
/// <summary> /// <summary>
@ -68,8 +93,8 @@ namespace osu.Game.Rulesets.Taiko.Skinning
/// </summary> /// </summary>
public TaikoAction CentreAction; public TaikoAction CentreAction;
private readonly Sprite rimHit; public readonly Sprite Rim;
private readonly Sprite centreHit; public readonly Sprite Centre;
[Resolved] [Resolved]
private DrumSampleMapping sampleMappings { get; set; } private DrumSampleMapping sampleMappings { get; set; }
@ -80,18 +105,16 @@ namespace osu.Game.Rulesets.Taiko.Skinning
Children = new Drawable[] Children = new Drawable[]
{ {
rimHit = new Sprite Rim = new Sprite
{ {
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreLeft, // opposite due to scale inversion.
Scale = new Vector2(-1, 1), Scale = new Vector2(-1, 1),
Origin = flipped ? Anchor.TopLeft : Anchor.TopRight,
Alpha = 0, Alpha = 0,
}, },
centreHit = new Sprite Centre = new Sprite
{ {
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Alpha = 0, Alpha = 0,
Origin = flipped ? Anchor.TopRight : Anchor.TopLeft,
} }
}; };
} }
@ -99,8 +122,8 @@ namespace osu.Game.Rulesets.Taiko.Skinning
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(ISkinSource skin) private void load(ISkinSource skin)
{ {
rimHit.Texture = skin.GetTexture(@"taiko-drum-outer"); Rim.Texture = skin.GetTexture(@"taiko-drum-outer");
centreHit.Texture = skin.GetTexture(@"taiko-drum-inner"); Centre.Texture = skin.GetTexture(@"taiko-drum-inner");
} }
public bool OnPressed(TaikoAction action) public bool OnPressed(TaikoAction action)
@ -110,12 +133,12 @@ namespace osu.Game.Rulesets.Taiko.Skinning
if (action == CentreAction) if (action == CentreAction)
{ {
target = centreHit; target = Centre;
drumSample.Centre?.Play(); drumSample.Centre?.Play();
} }
else if (action == RimAction) else if (action == RimAction)
{ {
target = rimHit; target = Rim;
drumSample.Rim?.Play(); drumSample.Rim?.Play();
} }