1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 00:43:21 +08:00

Merge branch 'skin-editor-toolbox-ui' into skin-editor-borrowed-dependencies

This commit is contained in:
Dean Herbert 2022-03-16 19:38:28 +09:00
commit b07ca87965

View File

@ -6,16 +6,15 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mods;
@ -23,7 +22,6 @@ using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Edit.Components;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Skinning.Editor
{
@ -31,8 +29,6 @@ namespace osu.Game.Skinning.Editor
{
public Action<Type> RequestPlacement;
private const float component_display_scale = 0.8f;
[Cached]
private ScoreProcessor scoreProcessor = new ScoreProcessor(new DummyRuleset())
{
@ -58,12 +54,13 @@ namespace osu.Game.Skinning.Editor
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(20)
Spacing = new Vector2(2)
};
var skinnableTypes = typeof(OsuGame).Assembly.GetTypes()
.Where(t => !t.IsInterface)
.Where(t => typeof(ISkinnableDrawable).IsAssignableFrom(t))
.OrderBy(t => t.Name)
.ToArray();
foreach (var type in skinnableTypes)
@ -109,6 +106,9 @@ namespace osu.Game.Skinning.Editor
private Container innerContainer;
private const float contracted_size = 60;
private const float expanded_size = 120;
public ToolboxComponentButton(Drawable component)
{
this.component = component;
@ -116,39 +116,48 @@ namespace osu.Game.Skinning.Editor
Enabled.Value = true;
RelativeSizeAxes = Axes.X;
Height = 70;
Height = contracted_size;
}
protected override bool OnHover(HoverEvent e)
{
this.Delay(300).ResizeHeightTo(expanded_size, 500, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
this.ResizeHeightTo(contracted_size, 500, Easing.OutQuint);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(OverlayColourProvider colourProvider, 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)
};
BackgroundColour = colourProvider.Background3;
AddRange(new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(10) { Bottom = 20 },
Masking = true,
Child = innerContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Child = component
},
},
new OsuSpriteText
{
Text = component.GetType().Name,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Margin = new MarginPadding(5),
},
innerContainer = new Container
{
Y = 10,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Scale = new Vector2(component_display_scale),
Masking = true,
Child = component
}
});
// adjust provided component to fit / display in a known state.
@ -156,14 +165,17 @@ namespace osu.Game.Skinning.Editor
component.Origin = Anchor.Centre;
}
protected override void LoadComplete()
protected override void Update()
{
base.LoadComplete();
base.Update();
if (component.RelativeSizeAxes != Axes.None)
if (component.DrawSize != Vector2.Zero)
{
innerContainer.AutoSizeAxes = Axes.None;
innerContainer.Height = 100;
float bestScale = Math.Min(
innerContainer.DrawWidth / component.DrawWidth,
innerContainer.DrawHeight / component.DrawHeight);
innerContainer.Scale = new Vector2(bestScale);
}
}