1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 16:12:57 +08:00

Place new skin components at the centre of the screen by default

This commit is contained in:
Dean Herbert 2021-05-12 14:11:40 +09:00
parent 96d4011de2
commit 42e6795251
2 changed files with 16 additions and 2 deletions

View File

@ -166,10 +166,22 @@ namespace osu.Game.Skinning.Editor
private void placeComponent(Type type)
{
var targetContainer = getTarget(SkinnableTarget.MainHUDComponents);
if (targetContainer == null)
return;
if (!(Activator.CreateInstance(type) is ISkinnableComponent component))
throw new InvalidOperationException("Attempted to instantiate a component for placement which was not an {typeof(ISkinnableComponent)}.");
getTarget(SkinnableTarget.MainHUDComponents)?.Add(component);
var drawableComponent = (Drawable)component;
// give newly added components a sane starting location.
drawableComponent.Origin = Anchor.TopCentre;
drawableComponent.Anchor = Anchor.TopCentre;
drawableComponent.Y = targetContainer.DrawSize.Y / 2;
targetContainer.Add(component);
SelectedComponents.Clear();
SelectedComponents.Add(component);

View File

@ -1,12 +1,14 @@
// 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;
namespace osu.Game.Skinning
{
/// <summary>
/// Denotes a container which can house <see cref="ISkinnableComponent"/>s.
/// </summary>
public interface ISkinnableTarget
public interface ISkinnableTarget : IDrawable
{
public SkinnableTarget Target { get; }