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-04-30 11:35:58 +08:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
2021-04-29 12:53:01 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-04-28 14:14:48 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-04-29 16:20:22 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2021-04-30 11:35:58 +08:00
|
|
|
using osu.Framework.Testing;
|
2021-04-29 16:26:55 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
2021-04-28 14:14:48 +08:00
|
|
|
using osu.Game.Graphics.Cursor;
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning.Editor
|
|
|
|
{
|
2021-04-29 16:20:22 +08:00
|
|
|
public class SkinEditor : FocusedOverlayContainer
|
2021-04-28 14:14:48 +08:00
|
|
|
{
|
2021-04-29 16:20:22 +08:00
|
|
|
public const double TRANSITION_DURATION = 500;
|
|
|
|
|
2021-04-28 14:14:48 +08:00
|
|
|
private readonly Drawable target;
|
2021-04-29 12:53:01 +08:00
|
|
|
|
2021-04-29 16:26:55 +08:00
|
|
|
private OsuTextFlowContainer headerText;
|
|
|
|
|
2021-04-29 12:53:01 +08:00
|
|
|
protected override bool StartHidden => true;
|
2021-04-28 14:14:48 +08:00
|
|
|
|
|
|
|
public SkinEditor(Drawable target)
|
|
|
|
{
|
|
|
|
this.target = target;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
2021-04-29 12:53:01 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2021-04-29 16:26:55 +08:00
|
|
|
private void load(OsuColour colours)
|
2021-04-28 14:14:48 +08:00
|
|
|
{
|
|
|
|
InternalChild = new OsuContextMenuContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-04-29 12:53:01 +08:00
|
|
|
Children = new Drawable[]
|
2021-04-28 14:14:48 +08:00
|
|
|
{
|
2021-04-29 17:23:22 +08:00
|
|
|
headerText = new OsuTextFlowContainer
|
2021-04-29 16:26:55 +08:00
|
|
|
{
|
|
|
|
TextAnchor = Anchor.TopCentre,
|
|
|
|
Padding = new MarginPadding(20),
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
RelativeSizeAxes = Axes.X
|
|
|
|
},
|
2021-04-28 14:14:48 +08:00
|
|
|
new SkinBlueprintContainer(target),
|
2021-04-30 11:35:58 +08:00
|
|
|
new SkinComponentToolbox
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
RequestPlacement = placeComponent
|
|
|
|
}
|
2021-04-28 14:14:48 +08:00
|
|
|
}
|
|
|
|
};
|
2021-04-29 16:26:55 +08:00
|
|
|
|
|
|
|
headerText.AddParagraph("Skin editor (preview)", cp => cp.Font = OsuFont.Default.With(size: 24));
|
|
|
|
headerText.AddParagraph("This is a preview of what is to come. Changes are lost on changing screens.", cp =>
|
|
|
|
{
|
|
|
|
cp.Font = OsuFont.Default.With(size: 12);
|
|
|
|
cp.Colour = colours.Yellow;
|
|
|
|
});
|
2021-04-28 14:14:48 +08:00
|
|
|
}
|
2021-04-29 12:53:01 +08:00
|
|
|
|
2021-04-30 11:35:58 +08:00
|
|
|
private void placeComponent(Type type)
|
|
|
|
{
|
|
|
|
var instance = (Drawable)Activator.CreateInstance(type);
|
|
|
|
|
2021-04-30 11:41:18 +08:00
|
|
|
var targetContainer = target.ChildrenOfType<IDefaultSkinnableTarget>().FirstOrDefault();
|
2021-04-30 11:35:58 +08:00
|
|
|
|
|
|
|
targetContainer?.Add(instance);
|
|
|
|
}
|
|
|
|
|
2021-04-29 12:53:01 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|
2021-04-29 16:20:22 +08:00
|
|
|
protected override bool OnHover(HoverEvent e) => true;
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e) => true;
|
2021-04-29 12:53:01 +08:00
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
{
|
2021-04-29 16:20:22 +08:00
|
|
|
this.FadeIn(TRANSITION_DURATION, Easing.OutQuint);
|
2021-04-29 12:53:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
2021-04-29 16:20:22 +08:00
|
|
|
this.FadeOut(TRANSITION_DURATION, Easing.OutQuint);
|
2021-04-29 12:53:01 +08:00
|
|
|
}
|
2021-04-28 14:14:48 +08:00
|
|
|
}
|
|
|
|
}
|