1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 03:22:57 +08:00

Add HexaconIcons lookup to allow usage with SpriteIcon

This commit is contained in:
Dean Herbert 2023-11-24 12:45:55 +09:00
parent 537b0ae870
commit 95c00f9666
No known key found for this signature in database
4 changed files with 116 additions and 2 deletions

View File

@ -0,0 +1,112 @@
// 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.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Text;
namespace osu.Game.Graphics
{
public static class HexaconsIcons
{
public const string FONT_NAME = "Icons/Hexacons";
public static IconUsage Editor => get(HexaconsMapping.editor);
private static IconUsage get(HexaconsMapping icon)
{
return new IconUsage((char)icon, FONT_NAME);
}
// Basically just converting to something we can use in a `char` lookup for FontStore/GlyphStore compatibility.
// Names should match filenames in resources.
private enum HexaconsMapping
{
beatmap_packs,
beatmap,
calendar,
chart,
community,
contests,
devtools,
download,
editor,
featured_artist,
home,
messaging,
music,
news,
notification,
profile,
rankings,
search,
settings,
social,
store,
tournament,
wiki,
}
public class HexaconsStore : ITextureStore, ITexturedGlyphLookupStore
{
private readonly TextureStore textures;
public HexaconsStore(TextureStore textures)
{
this.textures = textures;
}
public void Dispose()
{
textures.Dispose();
}
public ITexturedCharacterGlyph? Get(string? fontName, char character)
{
if (fontName == FONT_NAME)
return new Glyph(textures.Get($"{fontName}/{((HexaconsMapping)character).ToString().Replace("_", "-")}"));
return null;
}
public Task<ITexturedCharacterGlyph?> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character));
public Texture? Get(string name, WrapMode wrapModeS, WrapMode wrapModeT) => null;
public Texture Get(string name) => throw new NotImplementedException();
public Task<Texture> GetAsync(string name, CancellationToken cancellationToken = default) => throw new NotImplementedException();
public Stream GetStream(string name) => throw new NotImplementedException();
public IEnumerable<string> GetAvailableResources() => throw new NotImplementedException();
public Task<Texture?> GetAsync(string name, WrapMode wrapModeS, WrapMode wrapModeT, CancellationToken cancellationToken = default) => throw new NotImplementedException();
public class Glyph : ITexturedCharacterGlyph
{
public float XOffset => default;
public float YOffset => default;
public float XAdvance => default;
public float Baseline => default;
public char Character => default;
public float GetKerning<T>(T lastGlyph) where T : ICharacterGlyph => throw new NotImplementedException();
public Texture Texture { get; }
public float Width => Texture.Width;
public float Height => Texture.Height;
public Glyph(Texture texture)
{
Texture = texture;
}
}
}
}
}

View File

@ -477,6 +477,8 @@ namespace osu.Game
AddFont(Resources, @"Fonts/Venera/Venera-Light"); AddFont(Resources, @"Fonts/Venera/Venera-Light");
AddFont(Resources, @"Fonts/Venera/Venera-Bold"); AddFont(Resources, @"Fonts/Venera/Venera-Bold");
AddFont(Resources, @"Fonts/Venera/Venera-Black"); AddFont(Resources, @"Fonts/Venera/Venera-Black");
Fonts.AddStore(new HexaconsIcons.HexaconsStore(Textures));
} }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>

View File

@ -155,7 +155,7 @@ namespace osu.Game.Screens.Play.HUD
this.getLookup = getLookup; this.getLookup = getLookup;
} }
public ITexturedCharacterGlyph? Get(string fontName, char character) public ITexturedCharacterGlyph? Get(string? fontName, char character)
{ {
string lookup = getLookup(character); string lookup = getLookup(character);
var texture = textures.Get($"Gameplay/Fonts/{fontName}-{lookup}"); var texture = textures.Get($"Gameplay/Fonts/{fontName}-{lookup}");

View File

@ -63,7 +63,7 @@ namespace osu.Game.Skinning
this.maxSize = maxSize; this.maxSize = maxSize;
} }
public ITexturedCharacterGlyph? Get(string fontName, char character) public ITexturedCharacterGlyph? Get(string? fontName, char character)
{ {
string lookup = getLookupName(character); string lookup = getLookupName(character);