// 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.Configuration; 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 Bindable 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(SkinManager skinManager) { skin = skinManager.CurrentSkin.GetBoundCopy(); skin.ValueChanged += skin => SkinChanged(skin, allowDefaultFallback || skin.SkinInfo == SkinInfo.Default); } protected override void LoadAsyncComplete() { base.LoadAsyncComplete(); skin.TriggerChange(); } /// /// 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(Skin skin, bool allowFallback) { } } }