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.
|
|
|
|
|
|
|
|
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;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
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;
|
|
|
|
using osuTK;
|
2021-05-12 12:51:29 +08:00
|
|
|
using osuTK.Graphics;
|
2021-04-28 14:14:48 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Skinning.Editor
|
|
|
|
{
|
2021-04-28 17:34:34 +08:00
|
|
|
public class SkinBlueprint : SelectionBlueprint<ISkinnableComponent>
|
2021-04-28 14:14:48 +08:00
|
|
|
{
|
|
|
|
private Container box;
|
2021-04-28 17:34:34 +08:00
|
|
|
|
2021-05-12 12:51:29 +08:00
|
|
|
private Container outlineBox;
|
|
|
|
|
2021-05-03 14:18:18 +08:00
|
|
|
private Drawable drawable => (Drawable)Item;
|
2021-04-28 14:14:48 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2021-05-03 14:18:18 +08:00
|
|
|
/// Whether the blueprint should be shown even when the <see cref="SelectionBlueprint{T}.Item"/> is not alive.
|
2021-04-28 14:14:48 +08:00
|
|
|
/// </summary>
|
2021-05-12 12:51:29 +08:00
|
|
|
protected virtual bool AlwaysShowWhenSelected => true;
|
|
|
|
|
|
|
|
protected override bool ShouldBeAlive => drawable.IsAlive && Item.IsPresent;
|
2021-04-28 14:14:48 +08:00
|
|
|
|
2021-05-12 12:51:29 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
2021-04-28 14:14:48 +08:00
|
|
|
|
2021-04-28 17:34:34 +08:00
|
|
|
public SkinBlueprint(ISkinnableComponent component)
|
2021-04-28 14:14:48 +08:00
|
|
|
: base(component)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-05-12 12:51:29 +08:00
|
|
|
private void load()
|
2021-04-28 14:14:48 +08:00
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
box = new Container
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
BorderThickness = 3,
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0f,
|
|
|
|
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-04-28 14:14:48 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-12 12:51:29 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
updateSelectedState();
|
|
|
|
box.FadeInFromZero(200, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
outlineBox.FadeColour(colours.Pink.Opacity(IsSelected ? 1 : 0.5f), 200, Easing.OutQuint);
|
|
|
|
outlineBox.Child.FadeTo(IsSelected ? 0.2f : 0, 200, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
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:00:25 +08:00
|
|
|
box.Position = new Vector2(
|
|
|
|
drawable.Scale.X < 0 ? quad.TopRight.X : quad.TopLeft.X,
|
|
|
|
drawable.Scale.Y < 0 ? quad.BottomLeft.Y : quad.TopLeft.Y
|
|
|
|
);
|
|
|
|
|
2021-04-28 14:14:48 +08:00
|
|
|
box.Size = quad.Size;
|
2021-05-13 17:00:25 +08:00
|
|
|
|
2021-04-28 17:34:34 +08:00
|
|
|
box.Rotation = drawable.Rotation;
|
2021-04-28 14:14:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => drawable.ReceivePositionalInputAt(screenSpacePos);
|
|
|
|
|
2021-04-29 14:29:25 +08:00
|
|
|
public override Vector2 ScreenSpaceSelectionPoint => drawable.ScreenSpaceDrawQuad.Centre;
|
2021-04-28 14:14:48 +08:00
|
|
|
|
|
|
|
public override Quad SelectionQuad => drawable.ScreenSpaceDrawQuad;
|
|
|
|
}
|
|
|
|
}
|