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);