1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 06:52:56 +08:00

Merge pull request #12636 from peppy/skin-components-list

Add initial implementation of skin editor component list
This commit is contained in:
Dan Balasescu 2021-05-11 18:03:28 +09:00 committed by GitHub
commit 4be15cfc5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 329 additions and 43 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
@ -21,6 +22,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("add editor overlay", () =>
{
skinEditor?.Expire();
Player.ScaleTo(SkinEditorOverlay.VISIBLE_TARGET_SCALE);
LoadComponentAsync(skinEditor = new SkinEditor(Player), Add);
});
}

View File

@ -0,0 +1,26 @@
// 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 NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Skinning.Editor;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneSkinEditorComponentsList : SkinnableTestScene
{
[Test]
public void TestToggleEditor()
{
AddStep("show available components", () => SetContents(() => new SkinComponentToolbox(300)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
}));
}
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
}
}

View File

@ -82,6 +82,21 @@ namespace osu.Game
private SkinEditorOverlay skinEditor;
private Container overlayContent;
private Container rightFloatingOverlayContent;
private Container leftFloatingOverlayContent;
private Container topMostOverlayContent;
private ScalingContainer screenContainer;
private Container screenOffsetContainer;
[Resolved]
private FrameworkConfigManager frameworkConfig { get; set; }
[Cached]
private readonly DifficultyRecommender difficultyRecommender = new DifficultyRecommender();
@ -597,28 +612,35 @@ namespace osu.Game
ActionRequested = action => volume.Adjust(action),
ScrollActionRequested = (action, amount, isPrecise) => volume.Adjust(action, amount, isPrecise),
},
screenContainer = new ScalingContainer(ScalingMode.ExcludeOverlays)
screenOffsetContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
receptor = new BackButton.Receptor(),
ScreenStack = new OsuScreenStack { RelativeSizeAxes = Axes.Both },
BackButton = new BackButton(receptor)
screenContainer = new ScalingContainer(ScalingMode.ExcludeOverlays)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Action = () =>
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
var currentScreen = ScreenStack.CurrentScreen as IOsuScreen;
receptor = new BackButton.Receptor(),
ScreenStack = new OsuScreenStack { RelativeSizeAxes = Axes.Both },
BackButton = new BackButton(receptor)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Action = () =>
{
var currentScreen = ScreenStack.CurrentScreen as IOsuScreen;
if (currentScreen?.AllowBackButton == true && !currentScreen.OnBackButton())
ScreenStack.Exit();
if (currentScreen?.AllowBackButton == true && !currentScreen.OnBackButton())
ScreenStack.Exit();
}
},
logoContainer = new Container { RelativeSizeAxes = Axes.Both },
}
},
logoContainer = new Container { RelativeSizeAxes = Axes.Both },
}
},
overlayContent = new Container { RelativeSizeAxes = Axes.Both },
@ -768,7 +790,7 @@ namespace osu.Game
if (notifications.State.Value == Visibility.Visible)
offset -= Toolbar.HEIGHT / 2;
screenContainer.MoveToX(offset, SettingsPanel.TRANSITION_LENGTH, Easing.OutQuint);
screenOffsetContainer.MoveToX(offset, SettingsPanel.TRANSITION_LENGTH, Easing.OutQuint);
}
Settings.State.ValueChanged += _ => updateScreenOffset();
@ -935,19 +957,6 @@ namespace osu.Game
{
}
private Container overlayContent;
private Container rightFloatingOverlayContent;
private Container leftFloatingOverlayContent;
private Container topMostOverlayContent;
[Resolved]
private FrameworkConfigManager frameworkConfig { get; set; }
private ScalingContainer screenContainer;
protected override bool OnExiting()
{
if (ScreenStack.CurrentScreen is Loader)
@ -966,7 +975,7 @@ namespace osu.Game
{
base.UpdateAfterChildren();
screenContainer.Padding = new MarginPadding { Top = ToolbarOffset };
screenOffsetContainer.Padding = new MarginPadding { Top = ToolbarOffset };
overlayContent.Padding = new MarginPadding { Top = ToolbarOffset };
MenuCursorContainer.CanShowCursor = (ScreenStack.CurrentScreen as IOsuScreen)?.CursorVisible ?? false;

View File

@ -0,0 +1,32 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers;
namespace osu.Game.Rulesets.Edit
{
public class ScrollingToolboxGroup : ToolboxGroup
{
protected readonly OsuScrollContainer Scroll;
protected override Container<Drawable> Content { get; }
public ScrollingToolboxGroup(string title, float scrollAreaHeight)
: base(title)
{
base.Content.Add(Scroll = new OsuScrollContainer
{
RelativeSizeAxes = Axes.X,
Height = scrollAreaHeight,
Child = Content = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
},
});
}
}
}

View File

@ -4,6 +4,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Screens.Play.HUD

View File

@ -8,6 +8,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Screens.Play.HUD

View File

@ -13,6 +13,7 @@ using osuTK;
using osuTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
using osu.Game.Skinning;
namespace osu.Game.Screens.Play.HUD
{

View File

@ -4,6 +4,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Skinning;
namespace osu.Game.Screens.Play.HUD
{

View File

@ -13,6 +13,7 @@ using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;

View File

@ -16,12 +16,13 @@ using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play.HUD;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Screens.Play
{
[Cached]
public class HUDOverlay : Container, IKeyBindingHandler<GlobalAction>
public class HUDOverlay : Container, IKeyBindingHandler<GlobalAction>, IDefaultSkinnableTarget
{
public const float FADE_DURATION = 300;

View File

@ -14,7 +14,7 @@ using osu.Framework.Timing;
using osu.Game.Configuration;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play.HUD;
using osu.Game.Skinning;
namespace osu.Game.Screens.Play
{
@ -76,10 +76,6 @@ namespace osu.Game.Screens.Play
{
new SongProgressDisplay
{
Masking = true,
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Children = new Drawable[]
{
info = new SongProgressInfo
@ -187,8 +183,16 @@ namespace osu.Game.Screens.Play
public class SongProgressDisplay : Container, ISkinnableComponent
{
// TODO: move actual implementation into this.
// exists for skin customisation purposes.
public SongProgressDisplay()
{
// TODO: move actual implementation into this.
// exists for skin customisation purposes.
Masking = true;
RelativeSizeAxes = Axes.Both;
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
}
}
}
}

View File

@ -9,7 +9,6 @@ using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
using osu.Game.Screens.Play.HUD;
using osuTK;
namespace osu.Game.Skinning.Editor

View File

@ -6,7 +6,6 @@ using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets.Edit;
using osu.Game.Screens.Edit.Compose.Components;
using osu.Game.Screens.Play.HUD;
namespace osu.Game.Skinning.Editor
{

View File

@ -0,0 +1,162 @@
// 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.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Scoring;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Skinning.Editor
{
public class SkinComponentToolbox : ScrollingToolboxGroup
{
public Action<Type> RequestPlacement;
private const float component_display_scale = 0.8f;
[Cached]
private ScoreProcessor scoreProcessor = new ScoreProcessor
{
Combo = { Value = 727 },
TotalScore = { Value = 1337377 }
};
[Cached(typeof(HealthProcessor))]
private HealthProcessor healthProcessor = new DrainingHealthProcessor(0);
public SkinComponentToolbox(float height)
: base("Components", height)
{
RelativeSizeAxes = Axes.None;
Width = 200;
}
[BackgroundDependencyLoader]
private void load()
{
FillFlowContainer fill;
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)
{
var component = attemptAddComponent(type);
if (component != null)
{
component.RequestPlacement = t => RequestPlacement?.Invoke(t);
fill.Add(component);
}
}
}
private static ToolboxComponentButton attemptAddComponent(Type type)
{
try
{
var instance = (Drawable)Activator.CreateInstance(type);
Debug.Assert(instance != null);
return new ToolboxComponentButton(instance);
}
catch
{
return null;
}
}
private class ToolboxComponentButton : OsuButton
{
private readonly Drawable component;
public Action<Type> RequestPlacement;
private Container innerContainer;
public ToolboxComponentButton(Drawable component)
{
this.component = component;
Enabled.Value = true;
RelativeSizeAxes = Axes.X;
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)
};
AddRange(new Drawable[]
{
new OsuSpriteText
{
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
}
});
// adjust provided component to fit / display in a known state.
component.Anchor = Anchor.Centre;
component.Origin = Anchor.Centre;
}
protected override void LoadComplete()
{
base.LoadComplete();
if (component.RelativeSizeAxes != Axes.None)
{
innerContainer.AutoSizeAxes = Axes.None;
innerContainer.Height = 100;
}
}
protected override bool OnClick(ClickEvent e)
{
RequestPlacement?.Invoke(component.GetType());
return true;
}
}
}
}

View File

@ -1,10 +1,13 @@
// 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;
using osu.Framework.Input.Events;
using osu.Framework.Testing;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
@ -45,6 +48,12 @@ namespace osu.Game.Skinning.Editor
RelativeSizeAxes = Axes.X
},
new SkinBlueprintContainer(target),
new SkinComponentToolbox(600)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RequestPlacement = placeComponent
}
}
};
@ -56,6 +65,15 @@ namespace osu.Game.Skinning.Editor
});
}
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();

View File

@ -21,7 +21,7 @@ namespace osu.Game.Skinning.Editor
private readonly ScalingContainer target;
private SkinEditor skinEditor;
private const float visible_target_scale = 0.8f;
public const float VISIBLE_TARGET_SCALE = 0.8f;
[Resolved]
private OsuColour colours { get; set; }
@ -64,12 +64,14 @@ namespace osu.Game.Skinning.Editor
{
if (visibility.NewValue == Visibility.Visible)
{
target.ScaleTo(visible_target_scale, SkinEditor.TRANSITION_DURATION, Easing.OutQuint);
target.Masking = true;
target.BorderThickness = 5;
target.BorderColour = colours.Yellow;
target.AllowScaling = false;
target.RelativePositionAxes = Axes.Both;
target.ScaleTo(VISIBLE_TARGET_SCALE, SkinEditor.TRANSITION_DURATION, Easing.OutQuint);
target.MoveToX(0.1f, SkinEditor.TRANSITION_DURATION, Easing.OutQuint);
}
else
{
@ -77,6 +79,7 @@ namespace osu.Game.Skinning.Editor
target.AllowScaling = true;
target.ScaleTo(1, SkinEditor.TRANSITION_DURATION, Easing.OutQuint).OnComplete(_ => target.Masking = false);
target.MoveToX(0f, SkinEditor.TRANSITION_DURATION, Easing.OutQuint);
}
}

View File

@ -10,7 +10,6 @@ using osu.Game.Extensions;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
using osu.Game.Screens.Edit.Compose.Components;
using osu.Game.Screens.Play.HUD;
using osuTK;
namespace osu.Game.Skinning.Editor

View File

@ -0,0 +1,12 @@
// 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.
namespace osu.Game.Skinning
{
/// <summary>
/// The default placement location for new <see cref="ISkinnableComponent"/>s.
/// </summary>
public interface IDefaultSkinnableTarget : ISkinnableTarget
{
}
}

View File

@ -3,7 +3,7 @@
using osu.Framework.Graphics;
namespace osu.Game.Screens.Play.HUD
namespace osu.Game.Skinning
{
/// <summary>
/// Denotes a drawable which, as a drawable, can be adjusted via skinning specifications.

View File

@ -0,0 +1,15 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Skinning
{
/// <summary>
/// Denotes a container which can house <see cref="ISkinnableComponent"/>s.
/// </summary>
public interface ISkinnableTarget : IContainerCollection<Drawable>
{
}
}