2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2018-08-27 08:05:58 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2018-04-13 09:19:50 +00: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 07:27:11 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
|
{
|
|
|
|
|
public class LegacySkin : Skin
|
|
|
|
|
{
|
|
|
|
|
protected TextureStore Textures;
|
|
|
|
|
|
|
|
|
|
protected SampleManager Samples;
|
|
|
|
|
|
|
|
|
|
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
|
|
|
|
|
: this(skin, new LegacySkinResourceStore<SkinFileInfo>(skin, storage), audioManager, "skin.ini")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-28 04:31:40 +00:00
|
|
|
|
protected LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager, string filename)
|
|
|
|
|
: base(skin)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Stream stream = storage.GetStream(filename);
|
|
|
|
|
if (stream != null)
|
|
|
|
|
using (StreamReader reader = new StreamReader(stream))
|
|
|
|
|
Configuration = new LegacySkinDecoder().Decode(reader);
|
|
|
|
|
else
|
|
|
|
|
Configuration = new SkinConfiguration();
|
|
|
|
|
|
|
|
|
|
Samples = audioManager.GetSampleManager(storage);
|
2018-09-07 09:56:08 +00:00
|
|
|
|
Textures = new TextureStore(new TextureLoaderStore(storage));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Drawable GetDrawableComponent(string componentName)
|
|
|
|
|
{
|
|
|
|
|
switch (componentName)
|
|
|
|
|
{
|
|
|
|
|
case "Play/Miss":
|
|
|
|
|
componentName = "hit0";
|
|
|
|
|
break;
|
|
|
|
|
case "Play/Meh":
|
|
|
|
|
componentName = "hit50";
|
|
|
|
|
break;
|
|
|
|
|
case "Play/Good":
|
|
|
|
|
componentName = "hit100";
|
|
|
|
|
break;
|
|
|
|
|
case "Play/Great":
|
|
|
|
|
componentName = "hit300";
|
|
|
|
|
break;
|
2018-09-27 07:27:11 +00:00
|
|
|
|
case "Play/osu/number-text":
|
2019-02-15 12:03:06 +00: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 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 06:29:22 +00:00
|
|
|
|
var texture = GetTexture(componentName);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-27 07:27:11 +00:00
|
|
|
|
if (texture == null)
|
|
|
|
|
return null;
|
2018-09-27 06:29:22 +00:00
|
|
|
|
|
|
|
|
|
return new Sprite { Texture = texture };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Texture GetTexture(string componentName)
|
|
|
|
|
{
|
|
|
|
|
float ratio = 2;
|
|
|
|
|
|
|
|
|
|
var texture = Textures.Get($"{componentName}@2x");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
if (texture == null)
|
|
|
|
|
{
|
2018-09-27 06:29:22 +00:00
|
|
|
|
ratio = 1;
|
|
|
|
|
texture = Textures.Get(componentName);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 06:29:22 +00:00
|
|
|
|
if (texture != null)
|
|
|
|
|
texture.ScaleAdjust = ratio / 0.72f; // brings sizing roughly in-line with stable
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-27 06:29:22 +00:00
|
|
|
|
return texture;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override SampleChannel GetSample(string sampleName) => Samples.Get(sampleName);
|
|
|
|
|
|
2018-09-27 07:27:11 +00:00
|
|
|
|
private bool hasFont(string fontName) => GetTexture($"{fontName}-0") != null;
|
|
|
|
|
|
2018-04-13 09:19:50 +00: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 05:20:37 +00:00
|
|
|
|
var legacyName = filename.StartsWith("Gameplay/taiko/") ? "taiko-" + lastPiece : lastPiece;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-01-05 16:35:33 +00:00
|
|
|
|
var file = source.Files.Find(f =>
|
2019-01-21 05:20:37 +00:00
|
|
|
|
string.Equals(hasExtension ? f.Filename : Path.ChangeExtension(f.Filename, null), legacyName, StringComparison.InvariantCultureIgnoreCase));
|
2018-04-13 09:19:50 +00: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);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-27 08:05:58 +00:00
|
|
|
|
byte[] IResourceStore<byte[]>.Get(string name) => GetAsync(name).Result;
|
|
|
|
|
|
2018-08-29 11:57:48 +00:00
|
|
|
|
public Task<byte[]> GetAsync(string name)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
string path = getPathForFile(name);
|
2018-08-29 11:57:48 +00:00
|
|
|
|
return path == null ? Task.FromResult<byte[]>(null) : underlyingStore.GetAsync(path);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2018-04-21 09:15:27 +00: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 09:19:50 +00:00
|
|
|
|
}
|
2018-09-27 07:27:11 +00: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 08:33:27 +00:00
|
|
|
|
// Approximate value that brings character sizing roughly in-line with stable
|
2018-09-27 07:27:11 +00:00
|
|
|
|
float ratio = 36;
|
|
|
|
|
|
|
|
|
|
var texture = textures.Get($"{textureName}@2x");
|
|
|
|
|
if (texture == null)
|
|
|
|
|
{
|
|
|
|
|
ratio = 18;
|
|
|
|
|
texture = textures.Get(textureName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (texture != null)
|
|
|
|
|
texture.ScaleAdjust = ratio;
|
|
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|