Skip to content

Commit

Permalink
Merge branch 'master' into skin-blueprint-aspect-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed May 13, 2021
2 parents 25b1443 + 879ef46 commit 6a64a70
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions osu.Game/Skinning/Editor/SkinBlueprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class SkinBlueprint : SelectionBlueprint<ISkinnableDrawable>

private Container outlineBox;

private AnchorOriginVisualiser anchorOriginVisualiser;

private Drawable drawable => (Drawable)Item;

protected override bool ShouldBeAlive => drawable.IsAlive && Item.IsPresent;
Expand Down Expand Up @@ -65,9 +67,13 @@ private void load()
Font = OsuFont.Default.With(size: 10, weight: FontWeight.Bold),
Anchor = Anchor.BottomRight,
Origin = Anchor.TopRight,
}
},
},
},
anchorOriginVisualiser = new AnchorOriginVisualiser(drawable)
{
Alpha = 0,
}
};
}

Expand All @@ -76,7 +82,7 @@ protected override void LoadComplete()
base.LoadComplete();

updateSelectedState();
box.FadeInFromZero(200, Easing.OutQuint);
this.FadeInFromZero(200, Easing.OutQuint);
}

protected override void OnSelected()
Expand All @@ -95,6 +101,8 @@ private void updateSelectedState()
{
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;
Expand All @@ -120,4 +128,58 @@ protected override void Update()

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));
}
}
}

0 comments on commit 6a64a70

Please sign in to comment.