1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-19 17:00:17 +08:00

Add basic database setup for skins

This commit is contained in:
Dean Herbert
2018-01-25 16:57:48 +09:00
Unverified
parent 22192c4569
commit 669d62027c
8 changed files with 143 additions and 9 deletions
@@ -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) });
}
}
}
+4
View File
@@ -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<byte[]>(Resources, @"Textures"))));
var skinManager = new SkinManager { CurrentSkin = { Value = new LegacySkin("Andromeda", Host.Storage) } };
dependencies.Cache(skinManager);
dependencies.CacheAs(this);
dependencies.Cache(LocalConfig);
+14
View File
@@ -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;
}
}
+38
View File
@@ -0,0 +1,38 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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),
};
}
}
}
+19
View File
@@ -0,0 +1,19 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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;
}
}
}
+12
View File
@@ -0,0 +1,12 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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<Skin> CurrentSkin = new Bindable<Skin>(new DefaultSkin());
}
}
+48
View File
@@ -0,0 +1,48 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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<Drawable>
{
public SkinnableComponent(string name, Func<string,Drawable> defaultImplementation)
: base(name, defaultImplementation)
{
RelativeSizeAxes = Axes.Both;
}
}
public class SkinnableComponent<T> : CompositeDrawable
where T : Drawable
{
private Bindable<Skin> skin;
protected Func<string,T> CreateDefault;
public string ComponentName { get; set; }
public SkinnableComponent(string name, Func<string,T> 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);
}
}
}
+5
View File
@@ -843,6 +843,11 @@
<Compile Include="Screens\Tournament\Teams\DrawingsTeam.cs" />
<Compile Include="Screens\Tournament\Teams\ITeamList.cs" />
<Compile Include="Screens\Tournament\Teams\StorageBackedTeamList.cs" />
<Compile Include="Skinning\DefaultSkin.cs" />
<Compile Include="Skinning\LegacySkin.cs" />
<Compile Include="Skinning\Skin.cs" />
<Compile Include="Skinning\SkinManager.cs" />
<Compile Include="Skinning\SkinnableComponent.cs" />
<Compile Include="Storyboards\CommandLoop.cs" />
<Compile Include="Storyboards\CommandTimeline.cs" />
<Compile Include="Storyboards\CommandTimelineGroup.cs" />