Expose a method to reload a `SkinnableTargetContainer` from provided info

This commit is contained in:
Dean Herbert 2023-02-03 18:53:09 +09:00
parent 3345e34544
commit 2f30306ea2
2 changed files with 27 additions and 5 deletions

View File

@ -36,6 +36,11 @@ public interface ISkinnableTarget : IDrawable
/// </summary>
void Reload();
/// <summary>
/// Reload this target from the provided skinnable information.
/// </summary>
public void Reload(SkinnableInfo[] skinnableInfo);
/// <summary>
/// Add a new skinnable component to this target.
/// </summary>

View File

@ -2,10 +2,12 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Screens.Play.HUD;
namespace osu.Game.Skinning
{
@ -30,16 +32,31 @@ public SkinnableTargetContainer(GlobalSkinComponentLookup.LookupType target)
Target = target;
}
/// <summary>
/// Reload all components in this container from the current skin.
/// </summary>
public void Reload()
public void Reload(SkinnableInfo[] skinnableInfo)
{
var drawables = new List<Drawable>();
foreach (var i in skinnableInfo)
drawables.Add(i.CreateInstance());
Reload(new SkinnableTargetComponentsContainer
{
Children = drawables,
});
}
public void Reload() => Reload(CurrentSkin.GetDrawableComponent(new GlobalSkinComponentLookup(Target)) as SkinnableTargetComponentsContainer);
public void Reload(SkinnableTargetComponentsContainer? componentsContainer)
{
ClearInternal();
components.Clear();
ComponentsLoaded = false;
content = CurrentSkin.GetDrawableComponent(new GlobalSkinComponentLookup(Target)) as SkinnableTargetComponentsContainer;
if (componentsContainer == null)
return;
content = componentsContainer;
cancellationSource?.Cancel();
cancellationSource = null;