2021-04-30 11:09:58 +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 System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2021-04-30 14:22:51 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2021-04-30 11:09:58 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-04-30 14:22:51 +08:00
|
|
|
using osu.Framework.Graphics.Effects;
|
2021-04-30 11:35:58 +08:00
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Graphics;
|
2021-04-30 11:09:58 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-04-30 14:22:51 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-04-30 13:37:49 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2021-05-10 17:15:39 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2021-04-30 11:09:58 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning.Editor
|
|
|
|
{
|
2021-04-30 13:37:49 +08:00
|
|
|
public class SkinComponentToolbox : ScrollingToolboxGroup
|
2021-04-30 11:09:58 +08:00
|
|
|
{
|
2021-04-30 11:35:58 +08:00
|
|
|
public Action<Type> RequestPlacement;
|
|
|
|
|
2021-04-30 14:22:51 +08:00
|
|
|
private const float component_display_scale = 0.8f;
|
|
|
|
|
2021-05-10 17:15:39 +08:00
|
|
|
[Cached]
|
|
|
|
private ScoreProcessor scoreProcessor = new ScoreProcessor
|
|
|
|
{
|
|
|
|
Combo = { Value = 727 },
|
|
|
|
TotalScore = { Value = 1337377 }
|
|
|
|
};
|
|
|
|
|
|
|
|
[Cached(typeof(HealthProcessor))]
|
|
|
|
private HealthProcessor healthProcessor = new DrainingHealthProcessor(0);
|
|
|
|
|
2021-04-30 13:37:49 +08:00
|
|
|
public SkinComponentToolbox(float height)
|
|
|
|
: base("Components", height)
|
2021-04-30 11:09:58 +08:00
|
|
|
{
|
2021-04-30 13:37:49 +08:00
|
|
|
RelativeSizeAxes = Axes.None;
|
2021-04-30 11:35:58 +08:00
|
|
|
Width = 200;
|
2021-04-30 11:09:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
FillFlowContainer fill;
|
|
|
|
|
2021-04-30 13:37:49 +08:00
|
|
|
Child = fill = new FillFlowContainer
|
2021-04-30 11:09:58 +08:00
|
|
|
{
|
2021-04-30 13:37:49 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(20)
|
2021-04-30 11:09:58 +08:00
|
|
|
};
|
|
|
|
|
2021-05-13 16:06:00 +08:00
|
|
|
var skinnableTypes = typeof(OsuGame).Assembly.GetTypes().Where(t => typeof(ISkinnableDrawable).IsAssignableFrom(t)).ToArray();
|
2021-04-30 11:09:58 +08:00
|
|
|
|
|
|
|
foreach (var type in skinnableTypes)
|
|
|
|
{
|
2021-04-30 11:35:58 +08:00
|
|
|
var component = attemptAddComponent(type);
|
|
|
|
|
|
|
|
if (component != null)
|
|
|
|
{
|
|
|
|
component.RequestPlacement = t => RequestPlacement?.Invoke(t);
|
|
|
|
fill.Add(component);
|
|
|
|
}
|
2021-04-30 11:09:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-30 14:22:51 +08:00
|
|
|
private static ToolboxComponentButton attemptAddComponent(Type type)
|
2021-04-30 11:09:58 +08:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var instance = (Drawable)Activator.CreateInstance(type);
|
|
|
|
|
|
|
|
Debug.Assert(instance != null);
|
|
|
|
|
2021-05-13 16:06:00 +08:00
|
|
|
if (!((ISkinnableDrawable)instance).IsEditable)
|
2021-05-13 16:03:17 +08:00
|
|
|
return null;
|
|
|
|
|
2021-04-30 14:22:51 +08:00
|
|
|
return new ToolboxComponentButton(instance);
|
2021-04-30 11:09:58 +08:00
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
2021-04-30 11:35:58 +08:00
|
|
|
return null;
|
2021-04-30 11:09:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-30 14:22:51 +08:00
|
|
|
private class ToolboxComponentButton : OsuButton
|
2021-04-30 11:09:58 +08:00
|
|
|
{
|
2021-04-30 11:35:58 +08:00
|
|
|
private readonly Drawable component;
|
|
|
|
|
|
|
|
public Action<Type> RequestPlacement;
|
|
|
|
|
2021-04-30 14:22:51 +08:00
|
|
|
private Container innerContainer;
|
|
|
|
|
|
|
|
public ToolboxComponentButton(Drawable component)
|
2021-04-30 11:09:58 +08:00
|
|
|
{
|
2021-04-30 11:35:58 +08:00
|
|
|
this.component = component;
|
2021-04-30 14:22:51 +08:00
|
|
|
|
|
|
|
Enabled.Value = true;
|
2021-04-30 11:09:58 +08:00
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2021-04-30 14:22:51 +08:00
|
|
|
Height = 70;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
BackgroundColour = colours.Gray3;
|
|
|
|
Content.EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Radius = 2,
|
|
|
|
Offset = new Vector2(0, 1),
|
|
|
|
Colour = Color4.Black.Opacity(0.5f)
|
|
|
|
};
|
2021-04-30 11:09:58 +08:00
|
|
|
|
2021-04-30 14:22:51 +08:00
|
|
|
AddRange(new Drawable[]
|
2021-04-30 11:09:58 +08:00
|
|
|
{
|
2021-04-30 14:22:51 +08:00
|
|
|
new OsuSpriteText
|
2021-04-30 11:09:58 +08:00
|
|
|
{
|
2021-04-30 14:22:51 +08:00
|
|
|
Text = component.GetType().Name,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
},
|
|
|
|
innerContainer = new Container
|
|
|
|
{
|
|
|
|
Y = 10,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Scale = new Vector2(component_display_scale),
|
|
|
|
Masking = true,
|
|
|
|
Child = component
|
2021-04-30 11:09:58 +08:00
|
|
|
}
|
2021-04-30 14:22:51 +08:00
|
|
|
});
|
2021-04-30 11:09:58 +08:00
|
|
|
|
|
|
|
// adjust provided component to fit / display in a known state.
|
2021-04-30 11:35:58 +08:00
|
|
|
component.Anchor = Anchor.Centre;
|
|
|
|
component.Origin = Anchor.Centre;
|
2021-04-30 11:09:58 +08:00
|
|
|
}
|
2021-04-30 11:35:58 +08:00
|
|
|
|
2021-04-30 14:22:51 +08:00
|
|
|
protected override void LoadComplete()
|
2021-04-30 11:35:58 +08:00
|
|
|
{
|
2021-04-30 14:22:51 +08:00
|
|
|
base.LoadComplete();
|
2021-04-30 11:35:58 +08:00
|
|
|
|
2021-04-30 14:22:51 +08:00
|
|
|
if (component.RelativeSizeAxes != Axes.None)
|
|
|
|
{
|
|
|
|
innerContainer.AutoSizeAxes = Axes.None;
|
|
|
|
innerContainer.Height = 100;
|
|
|
|
}
|
2021-04-30 11:35:58 +08:00
|
|
|
}
|
|
|
|
|
2021-04-30 14:22:51 +08:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
2021-04-30 11:35:58 +08:00
|
|
|
{
|
2021-04-30 14:22:51 +08:00
|
|
|
RequestPlacement?.Invoke(component.GetType());
|
|
|
|
return true;
|
2021-04-30 11:35:58 +08:00
|
|
|
}
|
2021-04-30 11:09:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|