1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-22 01:32:54 +08:00

Merge pull request from peppy/skin-blueprint-anchor-origin

This commit is contained in:
Bartłomiej Dach 2021-05-13 17:24:37 +02:00 committed by GitHub
commit 879ef46354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
@ -21,6 +22,8 @@ namespace osu.Game.Skinning.Editor
private Container outlineBox;
private AnchorOriginVisualiser anchorOriginVisualiser;
private Drawable drawable => (Drawable)Item;
protected override bool ShouldBeAlive => drawable.IsAlive && Item.IsPresent;
@ -64,9 +67,13 @@ namespace osu.Game.Skinning.Editor
Font = OsuFont.Default.With(size: 10, weight: FontWeight.Bold),
Anchor = Anchor.BottomRight,
Origin = Anchor.TopRight,
}
},
},
},
anchorOriginVisualiser = new AnchorOriginVisualiser(drawable)
{
Alpha = 0,
}
};
}
@ -75,7 +82,7 @@ namespace osu.Game.Skinning.Editor
base.LoadComplete();
updateSelectedState();
box.FadeInFromZero(200, Easing.OutQuint);
this.FadeInFromZero(200, Easing.OutQuint);
}
protected override void OnSelected()
@ -94,6 +101,8 @@ namespace osu.Game.Skinning.Editor
{
outlineBox.FadeColour(colours.Pink.Opacity(IsSelected ? 1 : 0.5f), 200, Easing.OutQuint);
outlineBox.Child.FadeTo(IsSelected ? 0.2f : 0, 200, Easing.OutQuint);
anchorOriginVisualiser.FadeTo(IsSelected ? 1 : 0, 200, Easing.OutQuint);
}
private Quad drawableQuad;
@ -118,4 +127,58 @@ namespace osu.Game.Skinning.Editor
public override Quad SelectionQuad => drawable.ScreenSpaceDrawQuad;
}
internal class AnchorOriginVisualiser : CompositeDrawable
{
private readonly Drawable drawable;
private readonly Box originBox;
private readonly Box anchorBox;
private readonly Box anchorLine;
public AnchorOriginVisualiser(Drawable drawable)
{
this.drawable = drawable;
InternalChildren = new Drawable[]
{
anchorLine = new Box
{
Colour = Color4.Yellow,
Height = 2,
},
originBox = new Box
{
Colour = Color4.Red,
Origin = Anchor.Centre,
Size = new Vector2(5),
},
anchorBox = new Box
{
Colour = Color4.Red,
Origin = Anchor.Centre,
Size = new Vector2(5),
},
};
}
protected override void Update()
{
base.Update();
if (drawable.Parent == null)
return;
originBox.Position = drawable.ToSpaceOfOtherDrawable(drawable.OriginPosition, this);
anchorBox.Position = drawable.Parent.ToSpaceOfOtherDrawable(drawable.AnchorPosition, this);
var point1 = ToLocalSpace(anchorBox.ScreenSpaceDrawQuad.Centre);
var point2 = ToLocalSpace(originBox.ScreenSpaceDrawQuad.Centre);
anchorLine.Position = point1;
anchorLine.Width = (point2 - point1).Length;
anchorLine.Rotation = MathHelper.RadiansToDegrees(MathF.Atan2(point2.Y - point1.Y, point2.X - point1.X));
}
}
}