diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs index 61e9027157..f109d9ccc7 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs @@ -6,30 +6,24 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; +using osu.Game.Skinning; namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces { public class ApproachCircle : Container { - private readonly Sprite approachCircle; - public ApproachCircle() { Anchor = Anchor.Centre; Origin = Anchor.Centre; - AutoSizeAxes = Axes.Both; - - Children = new Drawable[] - { - approachCircle = new Sprite() - }; + RelativeSizeAxes = Axes.Both; } [BackgroundDependencyLoader] private void load(TextureStore textures) { - approachCircle.Texture = textures.Get(@"Play/osu/approachcircle"); + Child = new SkinnableComponent("Play/osu/approachcircle", name => new Sprite { Texture = textures.Get(name) }); } } } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 505577416d..e45fd64cd1 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -27,6 +27,7 @@ using osu.Game.Input.Bindings; using osu.Game.IO; using osu.Game.Rulesets; using osu.Game.Rulesets.Scoring; +using osu.Game.Skinning; namespace osu.Game { @@ -95,6 +96,9 @@ namespace osu.Game dependencies.Cache(new LargeTextureStore(new RawTextureLoaderStore(new NamespacedResourceStore(Resources, @"Textures")))); + var skinManager = new SkinManager { CurrentSkin = { Value = new LegacySkin("Andromeda", Host.Storage) } }; + dependencies.Cache(skinManager); + dependencies.CacheAs(this); dependencies.Cache(LocalConfig); diff --git a/osu.Game/Skinning/DefaultSkin.cs b/osu.Game/Skinning/DefaultSkin.cs new file mode 100644 index 0000000000..819c52e946 --- /dev/null +++ b/osu.Game/Skinning/DefaultSkin.cs @@ -0,0 +1,14 @@ +using osu.Framework.Graphics; + +namespace osu.Game.Skinning +{ + public class DefaultSkin : Skin + { + public DefaultSkin() + : base("Default") + { + } + + public override Drawable GetComponent(string componentName) => null; + } +} diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs new file mode 100644 index 0000000000..d1d0be467a --- /dev/null +++ b/osu.Game/Skinning/LegacySkin.cs @@ -0,0 +1,38 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Linq; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Framework.IO.Stores; +using osu.Framework.Platform; + +namespace osu.Game.Skinning +{ + public class LegacySkin : Skin + { + private readonly TextureStore textures; + + public LegacySkin(string name, Storage storage) + : base(name) + { + textures = new TextureStore(new RawTextureLoaderStore(new StorageBackedResourceStore(storage.GetStorageForDirectory($"skins/{name}")))); + } + + public override Drawable GetComponent(string componentName) + { + var legacyComponentName = componentName.Split('/').Last(); + + var texture = textures.Get(legacyComponentName); + if (texture == null) return null; + + return new Sprite + { + RelativeSizeAxes = Axes.Both, + FillMode = FillMode.Fit, + Texture = textures.Get(legacyComponentName), + }; + } + } +} diff --git a/osu.Game/Skinning/Skin.cs b/osu.Game/Skinning/Skin.cs new file mode 100644 index 0000000000..a815401036 --- /dev/null +++ b/osu.Game/Skinning/Skin.cs @@ -0,0 +1,19 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; + +namespace osu.Game.Skinning +{ + public abstract class Skin + { + public string Name { get; } + + public abstract Drawable GetComponent(string componentName); + + protected Skin(string name) + { + Name = name; + } + } +} diff --git a/osu.Game/Skinning/SkinManager.cs b/osu.Game/Skinning/SkinManager.cs new file mode 100644 index 0000000000..0200217e68 --- /dev/null +++ b/osu.Game/Skinning/SkinManager.cs @@ -0,0 +1,12 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Configuration; + +namespace osu.Game.Skinning +{ + public class SkinManager + { + public Bindable CurrentSkin = new Bindable(new DefaultSkin()); + } +} diff --git a/osu.Game/Skinning/SkinnableComponent.cs b/osu.Game/Skinning/SkinnableComponent.cs new file mode 100644 index 0000000000..64a133d4ac --- /dev/null +++ b/osu.Game/Skinning/SkinnableComponent.cs @@ -0,0 +1,48 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; + +namespace osu.Game.Skinning +{ + public class SkinnableComponent : SkinnableComponent + { + public SkinnableComponent(string name, Func defaultImplementation) + : base(name, defaultImplementation) + { + RelativeSizeAxes = Axes.Both; + } + } + + public class SkinnableComponent : CompositeDrawable + where T : Drawable + { + private Bindable skin; + protected Func CreateDefault; + + public string ComponentName { get; set; } + + public SkinnableComponent(string name, Func defaultImplementation) + { + ComponentName = name; + CreateDefault = defaultImplementation; + } + + [BackgroundDependencyLoader] + private void load(SkinManager skinManager) + { + skin = skinManager.CurrentSkin.GetBoundCopy(); + skin.ValueChanged += updateComponent; + skin.TriggerChange(); + } + + private void updateComponent(Skin skin) + { + InternalChild = skin.GetComponent(ComponentName) ?? CreateDefault(Name); + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 02801eb81f..7d46400a16 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -843,6 +843,11 @@ + + + + +