From 42e67952517e43eef66f688099bd5490efe6ea36 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 12 May 2021 14:11:40 +0900 Subject: [PATCH] Place new skin components at the centre of the screen by default --- osu.Game/Skinning/Editor/SkinEditor.cs | 14 +++++++++++++- osu.Game/Skinning/ISkinnableTarget.cs | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/osu.Game/Skinning/Editor/SkinEditor.cs b/osu.Game/Skinning/Editor/SkinEditor.cs index b32d117a92..4e38caa806 100644 --- a/osu.Game/Skinning/Editor/SkinEditor.cs +++ b/osu.Game/Skinning/Editor/SkinEditor.cs @@ -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); diff --git a/osu.Game/Skinning/ISkinnableTarget.cs b/osu.Game/Skinning/ISkinnableTarget.cs index 4d97b42e8e..4f6e3e66c3 100644 --- a/osu.Game/Skinning/ISkinnableTarget.cs +++ b/osu.Game/Skinning/ISkinnableTarget.cs @@ -1,12 +1,14 @@ // Copyright (c) ppy Pty Ltd . 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 { /// /// Denotes a container which can house s. /// - public interface ISkinnableTarget + public interface ISkinnableTarget : IDrawable { public SkinnableTarget Target { get; }