// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Allocation; using osu.Framework.Graphics.Containers; namespace osu.Game.Skinning { /// /// A drawable which has a callback when the skin changes. /// public abstract class SkinReloadableDrawable : CompositeDrawable { private ISkinSource skin; /// /// Whether fallback to default skin should be allowed if the custom skin is missing this resource. /// private readonly bool allowDefaultFallback; /// /// Create a new /// /// Whether fallback to default skin should be allowed if the custom skin is missing this resource. protected SkinReloadableDrawable(bool fallback = true) { allowDefaultFallback = fallback; } [BackgroundDependencyLoader] private void load(ISkinSource source) { skin = source; skin.SourceChanged += onChange; } private void onChange() => SkinChanged(skin, allowDefaultFallback); protected override void LoadAsyncComplete() { base.LoadAsyncComplete(); onChange(); } /// /// Called when a change is made to the skin. /// /// The new skin. /// Whether fallback to default skin should be allowed if the custom skin is missing this resource. protected virtual void SkinChanged(ISkinSource skin, bool allowFallback) { } } }