2021-04-28 14:14:48 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-05-13 17:54:40 +08:00
|
|
|
using System;
|
2021-04-28 14:14:48 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-05-12 12:51:29 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2021-04-28 14:14:48 +08:00
|
|
|
using osu.Framework.Graphics;
|
2023-02-17 16:51:52 +08:00
|
|
|
using osu.Framework.Graphics.Colour;
|
2021-04-28 14:14:48 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2023-02-17 16:51:52 +08:00
|
|
|
using osu.Framework.Utils;
|
2021-04-28 14:14:48 +08:00
|
|
|
using osu.Game.Graphics;
|
2021-05-12 12:51:29 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-04-28 14:14:48 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2023-02-17 16:51:52 +08:00
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
2023-01-26 17:21:04 +08:00
|
|
|
using osu.Game.Skinning;
|
2021-04-28 14:14:48 +08:00
|
|
|
using osuTK;
|
2021-05-12 12:51:29 +08:00
|
|
|
using osuTK.Graphics;
|
2021-04-28 14:14:48 +08:00
|
|
|
|
2023-01-26 17:21:04 +08:00
|
|
|
namespace osu.Game.Overlays.SkinEditor
|
2021-04-28 14:14:48 +08:00
|
|
|
{
|
2023-02-15 15:01:26 +08:00
|
|
|
public partial class SkinBlueprint : SelectionBlueprint<ISerialisableDrawable>
|
2021-04-28 14:14:48 +08:00
|
|
|
{
|
2023-01-26 16:46:19 +08:00
|
|
|
private Container box = null!;
|
2021-04-28 17:34:34 +08:00
|
|
|
|
2023-01-26 16:46:19 +08:00
|
|
|
private Container outlineBox = null!;
|
2021-05-12 12:51:29 +08:00
|
|
|
|
2023-01-26 16:46:19 +08:00
|
|
|
private AnchorOriginVisualiser anchorOriginVisualiser = null!;
|
2021-05-12 14:05:53 +08:00
|
|
|
|
2021-05-03 14:18:18 +08:00
|
|
|
private Drawable drawable => (Drawable)Item;
|
2021-04-28 14:14:48 +08:00
|
|
|
|
2021-05-12 12:51:29 +08:00
|
|
|
protected override bool ShouldBeAlive => drawable.IsAlive && Item.IsPresent;
|
2021-04-28 14:14:48 +08:00
|
|
|
|
2023-02-15 15:01:26 +08:00
|
|
|
public SkinBlueprint(ISerialisableDrawable component)
|
2021-04-28 14:14:48 +08:00
|
|
|
: base(component)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2023-02-17 16:51:52 +08:00
|
|
|
private void load(OsuColour colours)
|
2021-04-28 14:14:48 +08:00
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
box = new Container
|
|
|
|
{
|
2023-02-17 16:51:52 +08:00
|
|
|
Padding = new MarginPadding(-SkinSelectionHandler.INFLATE_SIZE),
|
2021-04-28 14:14:48 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-05-12 12:51:29 +08:00
|
|
|
outlineBox = new Container
|
2021-04-28 14:14:48 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-05-12 12:51:29 +08:00
|
|
|
Masking = true,
|
2023-02-17 16:51:52 +08:00
|
|
|
CornerRadius = 3,
|
|
|
|
BorderThickness = SelectionBox.BORDER_RADIUS / 2,
|
|
|
|
BorderColour = ColourInfo.GradientVertical(colours.Pink4.Darken(0.4f), colours.Pink4),
|
2021-05-12 12:51:29 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2023-02-17 16:51:52 +08:00
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
Alpha = 0.2f,
|
|
|
|
Colour = ColourInfo.GradientVertical(colours.Pink2, colours.Pink4),
|
2021-05-12 12:51:29 +08:00
|
|
|
AlwaysPresent = true,
|
|
|
|
},
|
|
|
|
}
|
2021-04-28 14:14:48 +08:00
|
|
|
},
|
2021-05-12 12:51:29 +08:00
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = Item.GetType().Name,
|
|
|
|
Font = OsuFont.Default.With(size: 10, weight: FontWeight.Bold),
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
Origin = Anchor.TopRight,
|
2021-05-12 14:05:53 +08:00
|
|
|
},
|
2021-05-12 12:51:29 +08:00
|
|
|
},
|
2021-04-28 14:14:48 +08:00
|
|
|
},
|
2021-05-12 14:05:53 +08:00
|
|
|
anchorOriginVisualiser = new AnchorOriginVisualiser(drawable)
|
|
|
|
{
|
|
|
|
Alpha = 0,
|
|
|
|
}
|
2021-04-28 14:14:48 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-12 12:51:29 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
updateSelectedState();
|
2021-05-12 14:05:53 +08:00
|
|
|
this.FadeInFromZero(200, Easing.OutQuint);
|
2021-05-12 12:51:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnSelected()
|
|
|
|
{
|
2021-05-12 18:37:00 +08:00
|
|
|
// base logic hides selected blueprints when not selected, but skin blueprints don't do that.
|
2021-05-12 12:51:29 +08:00
|
|
|
updateSelectedState();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDeselected()
|
|
|
|
{
|
2021-05-12 18:37:00 +08:00
|
|
|
// base logic hides selected blueprints when not selected, but skin blueprints don't do that.
|
2021-05-12 12:51:29 +08:00
|
|
|
updateSelectedState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSelectedState()
|
|
|
|
{
|
2021-05-12 14:05:53 +08:00
|
|
|
anchorOriginVisualiser.FadeTo(IsSelected ? 1 : 0, 200, Easing.OutQuint);
|
2021-05-12 12:51:29 +08:00
|
|
|
}
|
|
|
|
|
2021-04-28 14:14:48 +08:00
|
|
|
private Quad drawableQuad;
|
|
|
|
|
|
|
|
public override Quad ScreenSpaceDrawQuad => drawableQuad;
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
drawableQuad = drawable.ScreenSpaceDrawQuad;
|
|
|
|
var quad = ToLocalSpace(drawable.ScreenSpaceDrawQuad);
|
|
|
|
|
2021-05-13 17:54:40 +08:00
|
|
|
box.Position = drawable.ToSpaceOfOtherDrawable(Vector2.Zero, this);
|
2021-04-28 14:14:48 +08:00
|
|
|
box.Size = quad.Size;
|
2021-04-28 17:34:34 +08:00
|
|
|
box.Rotation = drawable.Rotation;
|
2021-05-13 17:54:40 +08:00
|
|
|
box.Scale = new Vector2(MathF.Sign(drawable.Scale.X), MathF.Sign(drawable.Scale.Y));
|
2021-04-28 14:14:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => drawable.ReceivePositionalInputAt(screenSpacePos);
|
|
|
|
|
2021-05-18 17:31:57 +08:00
|
|
|
public override Vector2 ScreenSpaceSelectionPoint => drawable.ToScreenSpace(drawable.OriginPosition);
|
2021-04-28 14:14:48 +08:00
|
|
|
|
|
|
|
public override Quad SelectionQuad => drawable.ScreenSpaceDrawQuad;
|
|
|
|
}
|
2021-05-12 14:05:53 +08:00
|
|
|
|
|
|
|
internal partial class AnchorOriginVisualiser : CompositeDrawable
|
|
|
|
{
|
|
|
|
private readonly Drawable drawable;
|
|
|
|
|
2023-02-17 16:51:52 +08:00
|
|
|
private Drawable originBox = null!;
|
2021-05-12 14:05:53 +08:00
|
|
|
|
2023-02-17 16:51:52 +08:00
|
|
|
private Drawable anchorBox = null!;
|
|
|
|
private Drawable anchorLine = null!;
|
2021-05-12 14:05:53 +08:00
|
|
|
|
|
|
|
public AnchorOriginVisualiser(Drawable drawable)
|
|
|
|
{
|
|
|
|
this.drawable = drawable;
|
2023-02-17 16:51:52 +08:00
|
|
|
}
|
2021-05-12 14:05:53 +08:00
|
|
|
|
2023-02-17 16:51:52 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
Color4 anchorColour = colours.Red1;
|
|
|
|
Color4 originColour = colours.Red3;
|
|
|
|
|
|
|
|
InternalChildren = new[]
|
2021-05-12 14:05:53 +08:00
|
|
|
{
|
2023-02-17 16:51:52 +08:00
|
|
|
anchorLine = new Circle
|
2021-05-12 14:05:53 +08:00
|
|
|
{
|
2023-02-17 16:51:52 +08:00
|
|
|
Height = 3f,
|
2022-04-21 15:16:52 +08:00
|
|
|
Origin = Anchor.CentreLeft,
|
2023-02-17 16:51:52 +08:00
|
|
|
Colour = ColourInfo.GradientHorizontal(originColour.Opacity(0.5f), originColour),
|
2021-05-12 14:05:53 +08:00
|
|
|
},
|
2023-02-17 16:51:52 +08:00
|
|
|
originBox = new Circle
|
2021-05-12 14:05:53 +08:00
|
|
|
{
|
2023-02-17 16:51:52 +08:00
|
|
|
Colour = originColour,
|
2021-05-12 14:05:53 +08:00
|
|
|
Origin = Anchor.Centre,
|
2023-02-17 16:51:52 +08:00
|
|
|
Size = new Vector2(7),
|
2021-05-12 14:05:53 +08:00
|
|
|
},
|
2023-02-17 16:51:52 +08:00
|
|
|
anchorBox = new Circle
|
2021-05-12 14:05:53 +08:00
|
|
|
{
|
2023-02-17 16:51:52 +08:00
|
|
|
Colour = anchorColour,
|
2021-05-12 14:05:53 +08:00
|
|
|
Origin = Anchor.Centre,
|
2023-02-17 16:51:52 +08:00
|
|
|
Size = new Vector2(10),
|
2021-05-12 14:05:53 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-17 16:51:52 +08:00
|
|
|
private Vector2? anchorPosition;
|
|
|
|
|
2021-05-12 14:05:53 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2021-05-13 17:39:21 +08:00
|
|
|
if (drawable.Parent == null)
|
|
|
|
return;
|
|
|
|
|
2023-02-17 16:51:52 +08:00
|
|
|
var newAnchor = drawable.Parent.ToSpaceOfOtherDrawable(drawable.AnchorPosition, this);
|
|
|
|
|
|
|
|
anchorPosition ??= newAnchor;
|
|
|
|
|
|
|
|
anchorPosition =
|
|
|
|
new Vector2(
|
|
|
|
(float)Interpolation.DampContinuously(anchorPosition.Value.X, newAnchor.X, 25, Clock.ElapsedFrameTime),
|
|
|
|
(float)Interpolation.DampContinuously(anchorPosition.Value.Y, newAnchor.Y, 25, Clock.ElapsedFrameTime)
|
|
|
|
);
|
|
|
|
|
2021-05-12 14:05:53 +08:00
|
|
|
originBox.Position = drawable.ToSpaceOfOtherDrawable(drawable.OriginPosition, this);
|
2023-02-17 16:51:52 +08:00
|
|
|
anchorBox.Position = anchorPosition.Value;
|
2021-05-12 14:05:53 +08:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2021-04-28 14:14:48 +08:00
|
|
|
}
|