From d55f42dc2eed23c66208bd906386c09ff0a8dcb4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 12 May 2021 15:05:53 +0900 Subject: [PATCH 1/2] Show anchor and origin in skin blueprints when selected --- osu.Game/Skinning/Editor/SkinBlueprint.cs | 64 ++++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/osu.Game/Skinning/Editor/SkinBlueprint.cs b/osu.Game/Skinning/Editor/SkinBlueprint.cs index 23411f2b3d..7db5bc7ead 100644 --- a/osu.Game/Skinning/Editor/SkinBlueprint.cs +++ b/osu.Game/Skinning/Editor/SkinBlueprint.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . 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; /// @@ -69,9 +72,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, + } }; } @@ -80,7 +87,7 @@ namespace osu.Game.Skinning.Editor base.LoadComplete(); updateSelectedState(); - box.FadeInFromZero(200, Easing.OutQuint); + this.FadeInFromZero(200, Easing.OutQuint); } protected override void OnSelected() @@ -99,6 +106,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; @@ -123,4 +132,55 @@ 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(); + + 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)); + } + } } From df77b28b48b8a58a92380c458251efcaf73773c2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 May 2021 18:39:21 +0900 Subject: [PATCH 2/2] Add a flimsy guard against null parent to avoid crashes on exit sequence --- osu.Game/Skinning/Editor/SkinBlueprint.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Skinning/Editor/SkinBlueprint.cs b/osu.Game/Skinning/Editor/SkinBlueprint.cs index 7db5bc7ead..b337aa53c4 100644 --- a/osu.Game/Skinning/Editor/SkinBlueprint.cs +++ b/osu.Game/Skinning/Editor/SkinBlueprint.cs @@ -172,6 +172,9 @@ namespace osu.Game.Skinning.Editor { base.Update(); + if (drawable.Parent == null) + return; + originBox.Position = drawable.ToSpaceOfOtherDrawable(drawable.OriginPosition, this); anchorBox.Position = drawable.Parent.ToSpaceOfOtherDrawable(drawable.AnchorPosition, this);