osu/osu.Game/Skinning/Editor/SkinEditor.cs

137 lines
4.2 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 08:20:22 +00:00
using osu.Framework.Input.Events;
using osu.Framework.Testing;
2021-04-29 08:26:55 +00:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
2021-05-10 13:43:48 +00:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Play.HUD;
namespace osu.Game.Skinning.Editor
{
2021-04-29 08:20:22 +00:00
public class SkinEditor : FocusedOverlayContainer
{
2021-04-29 08:20:22 +00:00
public const double TRANSITION_DURATION = 500;
private readonly Drawable target;
2021-04-29 08:26:55 +00:00
private OsuTextFlowContainer headerText;
protected override bool StartHidden => true;
2021-05-10 13:43:48 +00:00
[Resolved]
private SkinManager skins { get; set; }
public SkinEditor(Drawable target)
{
this.target = target;
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
2021-04-29 08:26:55 +00:00
private void load(OsuColour colours)
{
InternalChild = new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
2021-04-29 09:23:22 +00:00
headerText = new OsuTextFlowContainer
2021-04-29 08:26:55 +00:00
{
TextAnchor = Anchor.TopCentre,
Padding = new MarginPadding(20),
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X
},
new SkinBlueprintContainer(target),
2021-04-30 05:37:49 +00:00
new SkinComponentToolbox(600)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RequestPlacement = placeComponent
2021-05-10 13:43:48 +00:00
},
new TriangleButton
{
Text = "Save Changes",
Width = 140,
Height = 50,
Padding = new MarginPadding
{
Top = 10,
Left = 10,
},
Margin = new MarginPadding
{
Right = 10,
Bottom = 10,
},
Action = save,
},
}
};
2021-04-29 08:26:55 +00: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();
2021-05-10 13:43:48 +00:00
(targetContainer as Container)?.Add(instance);
}
protected override void LoadComplete()
{
base.LoadComplete();
Show();
}
2021-05-10 13:43:48 +00:00
private void save()
{
var currentSkin = skins.CurrentSkin.Value;
var legacySkin = currentSkin as LegacySkin;
if (legacySkin == null)
return;
SkinnableElementTargetContainer[] targetContainers = target.ChildrenOfType<SkinnableElementTargetContainer>().ToArray();
foreach (var t in targetContainers)
legacySkin.UpdateDrawableTarget(t);
skins.Save(skins.CurrentSkin.Value);
}
2021-04-29 08:20:22 +00:00
protected override bool OnHover(HoverEvent e) => true;
protected override bool OnMouseDown(MouseDownEvent e) => true;
protected override void PopIn()
{
2021-04-29 08:20:22 +00:00
this.FadeIn(TRANSITION_DURATION, Easing.OutQuint);
}
protected override void PopOut()
{
2021-04-29 08:20:22 +00:00
this.FadeOut(TRANSITION_DURATION, Easing.OutQuint);
}
}
}