Fix encapsulation and remove target lookup overhead

This commit is contained in:
Dean Herbert
2021-05-11 11:56:14 +09:00
parent c957293ec3
commit 4769a95b49
5 changed files with 29 additions and 30 deletions

View File

@ -3,6 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Graphics;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.Skinning; using osu.Game.Skinning;
@ -19,6 +20,21 @@ namespace osu.Game.Screens.Play.HUD
Target = target; Target = target;
} }
public void Reload()
{
content = CurrentSkin.GetDrawableComponent(new SkinnableTargetComponent(Target)) as SkinnableTargetWrapper;
ClearInternal();
if (content != null)
LoadComponentAsync(content, AddInternal);
}
public void Add(Drawable drawable)
{
content.Add(drawable);
}
public IEnumerable<SkinnableInfo> CreateSerialisedChildren() => public IEnumerable<SkinnableInfo> CreateSerialisedChildren() =>
content.Select(d => d.CreateSerialisedInformation()); content.Select(d => d.CreateSerialisedInformation());
@ -26,12 +42,7 @@ namespace osu.Game.Screens.Play.HUD
{ {
base.SkinChanged(skin, allowFallback); base.SkinChanged(skin, allowFallback);
content = skin.GetDrawableComponent(new SkinnableTargetComponent(Target)) as SkinnableTargetWrapper; Reload();
ClearInternal();
if (content != null)
LoadComponentAsync(content, AddInternal);
} }
} }
} }

View File

@ -4,8 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Extensions; using osu.Game.Extensions;
@ -23,9 +21,6 @@ namespace osu.Game.Screens.Play.HUD
{ {
public Type Type { get; set; } public Type Type { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public SkinnableTarget? Target { get; set; }
public Vector2 Position { get; set; } public Vector2 Position { get; set; }
public float Rotation { get; set; } public float Rotation { get; set; }
@ -44,10 +39,6 @@ namespace osu.Game.Screens.Play.HUD
{ {
Type = component.GetType(); Type = component.GetType();
ISkinnableTarget target = component.Parent as ISkinnableTarget;
Target = target?.Target;
Position = component.Position; Position = component.Position;
Rotation = component.Rotation; Rotation = component.Rotation;
Scale = component.Scale; Scale = component.Scale;

View File

@ -1,12 +0,0 @@
// 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

@ -8,8 +8,18 @@ namespace osu.Game.Skinning
/// <summary> /// <summary>
/// Denotes a container which can house <see cref="ISkinnableComponent"/>s. /// Denotes a container which can house <see cref="ISkinnableComponent"/>s.
/// </summary> /// </summary>
public interface ISkinnableTarget : IDrawable public interface ISkinnableTarget
{ {
public SkinnableTarget Target { get; } public SkinnableTarget Target { get; }
/// <summary>
/// Reload this target from the current skin.
/// </summary>
public void Reload();
/// <summary>
/// Add the provided item to this target.
/// </summary>
public void Add(Drawable drawable);
} }
} }

View File

@ -331,9 +331,8 @@ namespace osu.Game.Skinning
switch (target.Target) switch (target.Target)
{ {
case SkinnableTarget.MainHUDComponents: case SkinnableTarget.MainHUDComponents:
return new SkinnableTargetWrapper(target.Target) return new SkinnableTargetWrapper
{ {
RelativeSizeAxes = Axes.Both,
Children = new[] Children = new[]
{ {
// TODO: these should fallback to the osu!classic skin. // TODO: these should fallback to the osu!classic skin.