2021-04-30 03:09:58 +00: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 System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-04-30 03:35:58 +00:00
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Graphics;
|
2021-04-30 03:09:58 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning.Editor
|
|
|
|
{
|
|
|
|
public class SkinComponentToolbox : CompositeDrawable
|
|
|
|
{
|
2021-04-30 03:35:58 +00:00
|
|
|
public Action<Type> RequestPlacement;
|
|
|
|
|
2021-04-30 03:09:58 +00:00
|
|
|
public SkinComponentToolbox()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2021-04-30 03:35:58 +00:00
|
|
|
Width = 200;
|
2021-04-30 03:09:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
FillFlowContainer fill;
|
|
|
|
|
|
|
|
InternalChild = new OsuScrollContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = fill = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(20)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var skinnableTypes = typeof(OsuGame).Assembly.GetTypes().Where(t => typeof(ISkinnableComponent).IsAssignableFrom(t)).ToArray();
|
|
|
|
|
|
|
|
foreach (var type in skinnableTypes)
|
|
|
|
{
|
2021-04-30 03:35:58 +00:00
|
|
|
var component = attemptAddComponent(type);
|
|
|
|
|
|
|
|
if (component != null)
|
|
|
|
{
|
|
|
|
component.RequestPlacement = t => RequestPlacement?.Invoke(t);
|
|
|
|
fill.Add(component);
|
|
|
|
}
|
2021-04-30 03:09:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-30 03:35:58 +00:00
|
|
|
private static ToolboxComponent attemptAddComponent(Type type)
|
2021-04-30 03:09:58 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var instance = (Drawable)Activator.CreateInstance(type);
|
|
|
|
|
|
|
|
Debug.Assert(instance != null);
|
|
|
|
|
|
|
|
return new ToolboxComponent(instance);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
2021-04-30 03:35:58 +00:00
|
|
|
return null;
|
2021-04-30 03:09:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ToolboxComponent : CompositeDrawable
|
|
|
|
{
|
2021-04-30 03:35:58 +00:00
|
|
|
private readonly Drawable component;
|
|
|
|
private readonly Box box;
|
|
|
|
|
|
|
|
public Action<Type> RequestPlacement;
|
|
|
|
|
|
|
|
public ToolboxComponent(Drawable component)
|
2021-04-30 03:09:58 +00:00
|
|
|
{
|
2021-04-30 03:35:58 +00:00
|
|
|
this.component = component;
|
2021-04-30 03:09:58 +00:00
|
|
|
Container innerContainer;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-04-30 03:35:58 +00:00
|
|
|
new OsuSpriteText { Text = component.GetType().Name },
|
2021-04-30 03:09:58 +00:00
|
|
|
innerContainer = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 10,
|
|
|
|
Children = new[]
|
|
|
|
{
|
2021-04-30 03:35:58 +00:00
|
|
|
box = new Box
|
2021-04-30 03:09:58 +00:00
|
|
|
{
|
|
|
|
Colour = Color4.Black,
|
|
|
|
Alpha = 0.5f,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2021-04-30 03:35:58 +00:00
|
|
|
component
|
2021-04-30 03:09:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// adjust provided component to fit / display in a known state.
|
|
|
|
|
2021-04-30 03:35:58 +00:00
|
|
|
component.Anchor = Anchor.Centre;
|
|
|
|
component.Origin = Anchor.Centre;
|
2021-04-30 03:09:58 +00:00
|
|
|
|
2021-04-30 03:35:58 +00:00
|
|
|
if (component.RelativeSizeAxes != Axes.None)
|
2021-04-30 03:09:58 +00:00
|
|
|
{
|
|
|
|
innerContainer.AutoSizeAxes = Axes.None;
|
|
|
|
innerContainer.Height = 100;
|
|
|
|
}
|
|
|
|
|
2021-04-30 03:35:58 +00:00
|
|
|
switch (component)
|
2021-04-30 03:09:58 +00:00
|
|
|
{
|
|
|
|
case IScoreCounter score:
|
|
|
|
score.Current.Value = 133773;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IComboCounter combo:
|
|
|
|
combo.Current.Value = 727;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-04-30 03:35:58 +00:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
|
|
|
RequestPlacement?.Invoke(component.GetType());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
box.FadeColour(colours.Yellow, 100);
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
box.FadeColour(Color4.Black, 100);
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
2021-04-30 03:09:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|