1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 20:07:29 +08:00
osu-lazer/osu.Game/Skinning/Editor/SkinEditor.cs

98 lines
3.0 KiB
C#
Raw Normal View History

// 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 System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2021-04-29 16:20:22 +08:00
using osu.Framework.Input.Events;
using osu.Framework.Testing;
2021-04-29 16:26:55 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
namespace osu.Game.Skinning.Editor
{
2021-04-29 16:20:22 +08:00
public class SkinEditor : FocusedOverlayContainer
{
2021-04-29 16:20:22 +08:00
public const double TRANSITION_DURATION = 500;
private readonly Drawable target;
2021-04-29 16:26:55 +08:00
private OsuTextFlowContainer headerText;
protected override bool StartHidden => true;
public SkinEditor(Drawable target)
{
this.target = target;
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
2021-04-29 16:26:55 +08:00
private void load(OsuColour colours)
{
InternalChild = new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
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
},
new SkinBlueprintContainer(target),
new SkinComponentToolbox
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RequestPlacement = placeComponent
}
}
};
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;
});
}
private void placeComponent(Type type)
{
var instance = (Drawable)Activator.CreateInstance(type);
var targetContainer = target.ChildrenOfType<IDefaultSkinnableTarget>().FirstOrDefault();
targetContainer?.Add(instance);
}
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;
protected override void PopIn()
{
2021-04-29 16:20:22 +08:00
this.FadeIn(TRANSITION_DURATION, Easing.OutQuint);
}
protected override void PopOut()
{
2021-04-29 16:20:22 +08:00
this.FadeOut(TRANSITION_DURATION, Easing.OutQuint);
}
}
}