2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
2019-05-31 13:33:18 +08:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2018-08-27 16:05:58 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Framework.IO.Stores;
|
|
|
|
|
using osu.Game.Database;
|
2018-09-27 15:27:11 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
|
{
|
|
|
|
|
public class LegacySkin : Skin
|
|
|
|
|
{
|
|
|
|
|
protected TextureStore Textures;
|
|
|
|
|
|
2019-05-28 22:54:42 +08:00
|
|
|
|
protected IResourceStore<SampleChannel> Samples;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
|
|
|
|
|
: this(skin, new LegacySkinResourceStore<SkinFileInfo>(skin, storage), audioManager, "skin.ini")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-28 12:31:40 +08:00
|
|
|
|
protected LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager, string filename)
|
|
|
|
|
: base(skin)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Stream stream = storage.GetStream(filename);
|
|
|
|
|
if (stream != null)
|
|
|
|
|
using (StreamReader reader = new StreamReader(stream))
|
|
|
|
|
Configuration = new LegacySkinDecoder().Decode(reader);
|
|
|
|
|
else
|
|
|
|
|
Configuration = new SkinConfiguration();
|
|
|
|
|
|
2019-05-28 16:06:01 +08:00
|
|
|
|
Samples = audioManager.GetSampleStore(storage);
|
2018-09-07 17:56:08 +08:00
|
|
|
|
Textures = new TextureStore(new TextureLoaderStore(storage));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 22:54:42 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
Textures?.Dispose();
|
|
|
|
|
Samples?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public override Drawable GetDrawableComponent(string componentName)
|
|
|
|
|
{
|
|
|
|
|
switch (componentName)
|
|
|
|
|
{
|
|
|
|
|
case "Play/Miss":
|
|
|
|
|
componentName = "hit0";
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case "Play/Meh":
|
|
|
|
|
componentName = "hit50";
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case "Play/Good":
|
|
|
|
|
componentName = "hit100";
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case "Play/Great":
|
|
|
|
|
componentName = "hit300";
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-09-27 15:27:11 +08:00
|
|
|
|
case "Play/osu/number-text":
|
2019-02-15 20:03:06 +08:00
|
|
|
|
return !hasFont(Configuration.HitCircleFont)
|
|
|
|
|
? null
|
|
|
|
|
: new LegacySpriteText(Textures, Configuration.HitCircleFont)
|
|
|
|
|
{
|
|
|
|
|
Scale = new Vector2(0.96f),
|
|
|
|
|
// Spacing value was reverse-engineered from the ratio of the rendered sprite size in the visual inspector vs the actual texture size
|
|
|
|
|
Spacing = new Vector2(-Configuration.HitCircleOverlap * 0.89f, 0)
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 14:29:22 +08:00
|
|
|
|
var texture = GetTexture(componentName);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-09-27 15:27:11 +08:00
|
|
|
|
if (texture == null)
|
|
|
|
|
return null;
|
2018-09-27 14:29:22 +08:00
|
|
|
|
|
|
|
|
|
return new Sprite { Texture = texture };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Texture GetTexture(string componentName)
|
|
|
|
|
{
|
|
|
|
|
float ratio = 2;
|
|
|
|
|
|
|
|
|
|
var texture = Textures.Get($"{componentName}@2x");
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (texture == null)
|
|
|
|
|
{
|
2018-09-27 14:29:22 +08:00
|
|
|
|
ratio = 1;
|
|
|
|
|
texture = Textures.Get(componentName);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 14:29:22 +08:00
|
|
|
|
if (texture != null)
|
|
|
|
|
texture.ScaleAdjust = ratio / 0.72f; // brings sizing roughly in-line with stable
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-09-27 14:29:22 +08:00
|
|
|
|
return texture;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override SampleChannel GetSample(string sampleName) => Samples.Get(sampleName);
|
|
|
|
|
|
2018-09-27 15:27:11 +08:00
|
|
|
|
private bool hasFont(string fontName) => GetTexture($"{fontName}-0") != null;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
protected class LegacySkinResourceStore<T> : IResourceStore<byte[]>
|
|
|
|
|
where T : INamedFileInfo
|
|
|
|
|
{
|
|
|
|
|
private readonly IHasFiles<T> source;
|
|
|
|
|
private readonly IResourceStore<byte[]> underlyingStore;
|
|
|
|
|
|
|
|
|
|
private string getPathForFile(string filename)
|
|
|
|
|
{
|
|
|
|
|
bool hasExtension = filename.Contains('.');
|
|
|
|
|
|
|
|
|
|
string lastPiece = filename.Split('/').Last();
|
2019-01-21 13:20:37 +08:00
|
|
|
|
var legacyName = filename.StartsWith("Gameplay/taiko/") ? "taiko-" + lastPiece : lastPiece;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-01-06 00:35:33 +08:00
|
|
|
|
var file = source.Files.Find(f =>
|
2019-01-21 13:20:37 +08:00
|
|
|
|
string.Equals(hasExtension ? f.Filename : Path.ChangeExtension(f.Filename, null), legacyName, StringComparison.InvariantCultureIgnoreCase));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return file?.FileInfo.StoragePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LegacySkinResourceStore(IHasFiles<T> source, IResourceStore<byte[]> underlyingStore)
|
|
|
|
|
{
|
|
|
|
|
this.source = source;
|
|
|
|
|
this.underlyingStore = underlyingStore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Stream GetStream(string name)
|
|
|
|
|
{
|
|
|
|
|
string path = getPathForFile(name);
|
|
|
|
|
return path == null ? null : underlyingStore.GetStream(path);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 13:33:18 +08:00
|
|
|
|
public IEnumerable<string> GetAvailableResources() => source.Files.Select(f => f.Filename);
|
|
|
|
|
|
2018-08-27 16:05:58 +08:00
|
|
|
|
byte[] IResourceStore<byte[]>.Get(string name) => GetAsync(name).Result;
|
|
|
|
|
|
2018-08-29 19:57:48 +08:00
|
|
|
|
public Task<byte[]> GetAsync(string name)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
string path = getPathForFile(name);
|
2018-08-29 19:57:48 +08:00
|
|
|
|
return path == null ? Task.FromResult<byte[]>(null) : underlyingStore.GetAsync(path);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-04-21 17:15:27 +08:00
|
|
|
|
|
|
|
|
|
#region IDisposable Support
|
|
|
|
|
|
|
|
|
|
private bool isDisposed;
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (!isDisposed)
|
|
|
|
|
{
|
|
|
|
|
isDisposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~LegacySkinResourceStore()
|
|
|
|
|
{
|
|
|
|
|
Dispose(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-09-27 15:27:11 +08:00
|
|
|
|
|
|
|
|
|
private class LegacySpriteText : OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
private readonly TextureStore textures;
|
|
|
|
|
private readonly string font;
|
|
|
|
|
|
|
|
|
|
public LegacySpriteText(TextureStore textures, string font)
|
|
|
|
|
{
|
|
|
|
|
this.textures = textures;
|
|
|
|
|
this.font = font;
|
|
|
|
|
|
|
|
|
|
Shadow = false;
|
|
|
|
|
UseFullGlyphHeight = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Texture GetTextureForCharacter(char c)
|
|
|
|
|
{
|
|
|
|
|
string textureName = $"{font}-{c}";
|
|
|
|
|
|
2018-09-27 16:33:27 +08:00
|
|
|
|
// Approximate value that brings character sizing roughly in-line with stable
|
2018-09-27 15:27:11 +08:00
|
|
|
|
float ratio = 36;
|
|
|
|
|
|
|
|
|
|
var texture = textures.Get($"{textureName}@2x");
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-09-27 15:27:11 +08:00
|
|
|
|
if (texture == null)
|
|
|
|
|
{
|
|
|
|
|
ratio = 18;
|
|
|
|
|
texture = textures.Get(textureName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (texture != null)
|
|
|
|
|
texture.ScaleAdjust = ratio;
|
|
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|