diff --git a/osu.Game.Rulesets.Karaoke.Tests/Resources/TestResources.cs b/osu.Game.Rulesets.Karaoke.Tests/Resources/TestResources.cs index 78bbdfe28..f7ed4dab7 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Resources/TestResources.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Resources/TestResources.cs @@ -5,6 +5,8 @@ using NUnit.Framework; using osu.Framework.Audio; using osu.Framework.Audio.Track; +using osu.Framework.Graphics.Rendering; +using osu.Framework.Graphics.Rendering.Dummy; using osu.Framework.Graphics.Textures; using osu.Framework.IO.Stores; using osu.Game.Database; @@ -44,6 +46,8 @@ public static string GetTestLrcForImport(string name) public static IStorageResourceProvider CreateSkinStorageResourceProvider(string skinName = "special-skin") => new TestStorageResourceProvider(skinName); +#nullable disable + private class TestStorageResourceProvider : IStorageResourceProvider { public TestStorageResourceProvider(string skinName) @@ -51,12 +55,16 @@ public TestStorageResourceProvider(string skinName) Files = Resources = new NamespacedResourceStore(new DllResourceStore(GetType().Assembly), $"Resources/{skinName}"); } - public IResourceStore? CreateTextureLoaderStore(IResourceStore underlyingStore) => null; + public IRenderer Renderer => new DummyRenderer(); - public AudioManager? AudioManager => null; + public AudioManager AudioManager => null; public IResourceStore Files { get; } public IResourceStore Resources { get; } - public RealmAccess? RealmAccess => null; + public RealmAccess RealmAccess => null; + + public IResourceStore CreateTextureLoaderStore(IResourceStore underlyingStore) => null; } + +#nullable enable } } diff --git a/osu.Game.Rulesets.Karaoke.Tests/Screens/TestManageFontPreview.cs b/osu.Game.Rulesets.Karaoke.Tests/Screens/TestManageFontPreview.cs index c3bc1f515..d2326b460 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Screens/TestManageFontPreview.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Screens/TestManageFontPreview.cs @@ -33,7 +33,7 @@ public TestManageFontPreview() private void load(GameHost host) { var resources = new KaraokeRuleset().CreateResourceStore(); - var textureStore = new TextureStore(host.CreateTextureLoaderStore(new NamespacedResourceStore(resources, @"Textures"))); + var textureStore = new TextureStore(host.Renderer, host.CreateTextureLoaderStore(new NamespacedResourceStore(resources, @"Textures"))); Dependencies.CacheAs(textureStore); Add(new ManageFontPreview diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Shapes/RightTriangle.cs b/osu.Game.Rulesets.Karaoke/Graphics/Shapes/RightTriangle.cs index 1bcff7d18..158025bd3 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Shapes/RightTriangle.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Shapes/RightTriangle.cs @@ -1,15 +1,12 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; +using osu.Framework.Allocation; using osu.Framework.Graphics; -using osu.Framework.Graphics.OpenGL; -using osu.Framework.Graphics.OpenGL.Vertices; using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.Rendering; using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Textures; using osuTK; namespace osu.Game.Rulesets.Karaoke.Graphics.Shapes @@ -21,7 +18,15 @@ public class RightTriangle : Sprite /// public RightTriangle() { - Texture = Texture.WhitePixel; + // Setting the texture would normally set a size of (1, 1), but since the texture is set from BDL it needs to be set here instead. + // RelativeSizeAxes may not behave as expected if this is not done. + Size = Vector2.One; + } + + [BackgroundDependencyLoader] + private void load(IRenderer renderer) + { + Texture ??= renderer.WhitePixel; } public override RectangleF BoundingBox => toTriangle(ToParentSpace(LayoutRectangle), RightAngleDirection).AABBFloat; @@ -70,20 +75,26 @@ public override void ApplyState() rightAngleDirection = Source.RightAngleDirection; } - protected override void Blit(Action vertexAction) + protected override void Blit(IRenderer renderer) { - DrawTriangle(Texture, toTriangle(ScreenSpaceDrawQuad, rightAngleDirection), DrawColourInfo.Colour, null, null, + if (DrawRectangle.Width == 0 || DrawRectangle.Height == 0) + return; + + renderer.DrawTriangle(Texture, toTriangle(ScreenSpaceDrawQuad, rightAngleDirection), DrawColourInfo.Colour, null, null, new Vector2(InflationAmount.X / DrawRectangle.Width, InflationAmount.Y / DrawRectangle.Height), TextureCoords); } - protected override void BlitOpaqueInterior(Action vertexAction) + protected override void BlitOpaqueInterior(IRenderer renderer) { + if (DrawRectangle.Width == 0 || DrawRectangle.Height == 0) + return; + var triangle = toTriangle(ConservativeScreenSpaceDrawQuad, rightAngleDirection); - if (GLWrapper.IsMaskingActive) - DrawClipped(ref triangle, Texture, DrawColourInfo.Colour, vertexAction: vertexAction); + if (renderer.IsMaskingActive) + renderer.DrawClipped(ref triangle, Texture, DrawColourInfo.Colour); else - DrawTriangle(Texture, triangle, DrawColourInfo.Colour, vertexAction: vertexAction); + renderer.DrawTriangle(Texture, triangle, DrawColourInfo.Colour); } } } diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs index 10624d0a2..e808230c0 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs @@ -9,6 +9,7 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Rendering; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.IO.Stores; @@ -198,12 +199,12 @@ public FontSelector() } [BackgroundDependencyLoader] - private void load(FontManager fontManager) + private void load(FontManager fontManager, IRenderer renderer) { fonts.BindTo(fontManager.Fonts); // create local font store and import those files - localFontStore = new KaraokeLocalFontStore(fontManager); + localFontStore = new KaraokeLocalFontStore(fontManager, renderer); fontStore.AddStore(localFontStore); Current.BindValueChanged(e => diff --git a/osu.Game.Rulesets.Karaoke/IO/Stores/KaraokeLocalFontStore.cs b/osu.Game.Rulesets.Karaoke/IO/Stores/KaraokeLocalFontStore.cs index f02e6f527..71c991dac 100644 --- a/osu.Game.Rulesets.Karaoke/IO/Stores/KaraokeLocalFontStore.cs +++ b/osu.Game.Rulesets.Karaoke/IO/Stores/KaraokeLocalFontStore.cs @@ -4,6 +4,7 @@ #nullable disable using System.Collections.Generic; +using osu.Framework.Graphics.Rendering; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.IO.Stores; @@ -15,19 +16,18 @@ namespace osu.Game.Rulesets.Karaoke.IO.Stores public class KaraokeLocalFontStore : FontStore { private readonly Dictionary> fontInfos = new(); - private readonly IResourceStore store; private readonly FontManager fontManager; /// /// Construct a font store to be added to a parent font store via . /// /// font manager. + /// The renderer to create textures with. /// The texture source. /// The raw pixel height of the font. Can be used to apply a global scale or metric to font usages. - public KaraokeLocalFontStore(FontManager fontManager, IResourceStore store = null, float scaleAdjust = 100) - : base(store, scaleAdjust) + public KaraokeLocalFontStore(FontManager fontManager, IRenderer renderer, IResourceStore store = null, float scaleAdjust = 100) + : base(renderer, store, scaleAdjust) { - this.store = store; this.fontManager = fontManager; } diff --git a/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs b/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs index 54e5cff02..16be786b6 100644 --- a/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs +++ b/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs @@ -5,8 +5,10 @@ using System; using System.Collections.Generic; +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Rendering; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.Input.Bindings; @@ -158,27 +160,7 @@ public override IEnumerable GetModsFor(ModType type) => _ => Array.Empty() }; - public override Drawable CreateIcon() => new Container - { - AutoSizeAxes = Axes.Both, - Children = new Drawable[] - { - new Sprite - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Scale = new Vector2(0.9f), - Texture = new TextureStore(new TextureLoaderStore(CreateResourceStore()), false).Get("Textures/logo"), - }, - new SpriteIcon - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Scale = new Vector2(45f), - Icon = FontAwesome.Regular.Circle, - }, - } - }; + public override Drawable CreateIcon() => new KaraokeIcon(this); public override IResourceStore CreateResourceStore() { @@ -312,5 +294,38 @@ public KaraokeRuleset() // it's a tricky way for loading customized karaoke beatmap. RulesetInfo.OnlineID = 111; } + + private class KaraokeIcon : CompositeDrawable + { + private readonly KaraokeRuleset ruleset; + + public KaraokeIcon(KaraokeRuleset ruleset) + { + this.ruleset = ruleset; + AutoSizeAxes = Axes.Both; + } + + [BackgroundDependencyLoader] + private void load(IRenderer renderer) + { + InternalChildren = new Drawable[] + { + new Sprite + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(0.9f), + Texture = new TextureStore(renderer, new TextureLoaderStore(ruleset.CreateResourceStore()), false).Get("Textures/logo"), + }, + new SpriteIcon + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(45f), + Icon = FontAwesome.Regular.Circle, + }, + }; + } + } } } diff --git a/osu.Game.Rulesets.Karaoke/Screens/Settings/Previews/Gameplay/LyricPreview.cs b/osu.Game.Rulesets.Karaoke/Screens/Settings/Previews/Gameplay/LyricPreview.cs index 37faa8bce..868ec3724 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Settings/Previews/Gameplay/LyricPreview.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Settings/Previews/Gameplay/LyricPreview.cs @@ -8,6 +8,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Rendering; using osu.Framework.Graphics.Sprites; using osu.Framework.IO.Stores; using osu.Game.Rulesets.Karaoke.Configuration; @@ -74,10 +75,10 @@ void addFont(FontUsage fontUsage) } [BackgroundDependencyLoader] - private void load(FontManager fontManager, KaraokeRulesetConfigManager config) + private void load(FontManager fontManager, IRenderer renderer, KaraokeRulesetConfigManager config) { // create local font store and import those files - localFontStore = new KaraokeLocalFontStore(fontManager); + localFontStore = new KaraokeLocalFontStore(fontManager, renderer); fontStore.AddStore(localFontStore); // fonts diff --git a/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkin.cs b/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkin.cs index 941cefb33..77e24a5cf 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkin.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkin.cs @@ -114,7 +114,7 @@ protected JsonSerializerSettings CreateJsonSerializerSettings(params JsonConvert } public override ISample? GetSample(ISampleInfo sampleInfo) - => sampleInfo.LookupNames.Select(lookup => resources?.AudioManager.Samples.Get(lookup)).FirstOrDefault(sample => sample != null); + => sampleInfo.LookupNames.Select(lookup => resources?.AudioManager?.Samples.Get(lookup)).FirstOrDefault(sample => sample != null); public override Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => null; diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs index 91870864d..ecf5976e2 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs @@ -6,6 +6,8 @@ using osu.Framework.Audio; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Rendering; +using osu.Framework.Graphics.Rendering.Dummy; using osu.Framework.Graphics.Textures; using osu.Framework.IO.Stores; using osu.Game.Beatmaps; @@ -101,6 +103,8 @@ public TempLegacySkin(SkinInfo skin) } } +#nullable disable + private class InternalSkinStorageResourceProvider : IStorageResourceProvider { public InternalSkinStorageResourceProvider(string skinName) @@ -109,12 +113,15 @@ public InternalSkinStorageResourceProvider(string skinName) Files = Resources = new NamespacedResourceStore(store, $"Skin/{skinName}"); } - public IResourceStore? CreateTextureLoaderStore(IResourceStore underlyingStore) => null; + public IRenderer Renderer => new DummyRenderer(); - public AudioManager? AudioManager => null; + public AudioManager AudioManager => null; public IResourceStore Files { get; } public IResourceStore Resources { get; } - public RealmAccess? RealmAccess => null; + public RealmAccess RealmAccess => null; + public IResourceStore CreateTextureLoaderStore(IResourceStore underlyingStore) => null; } + +#nullable enable } } diff --git a/osu.Game.Rulesets.Karaoke/UI/KaraokePlayfieldAdjustmentContainer.cs b/osu.Game.Rulesets.Karaoke/UI/KaraokePlayfieldAdjustmentContainer.cs index 92228534b..07baaf163 100644 --- a/osu.Game.Rulesets.Karaoke/UI/KaraokePlayfieldAdjustmentContainer.cs +++ b/osu.Game.Rulesets.Karaoke/UI/KaraokePlayfieldAdjustmentContainer.cs @@ -5,6 +5,7 @@ using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Graphics.Rendering; using osu.Framework.Graphics.Sprites; using osu.Framework.IO.Stores; using osu.Game.Rulesets.Karaoke.Configuration; @@ -26,7 +27,7 @@ public class KaraokePlayfieldAdjustmentContainer : PlayfieldAdjustmentContainer private KaraokeLocalFontStore localFontStore; [BackgroundDependencyLoader] - private void load(FontManager fontManager, KaraokeRulesetConfigManager manager) + private void load( FontManager fontManager, IRenderer renderer, KaraokeRulesetConfigManager manager) { // get all font usage which wants to import. var targetImportFonts = new[] @@ -46,7 +47,7 @@ private void load(FontManager fontManager, KaraokeRulesetConfigManager manager) return; // create local font store and import those files - localFontStore = new KaraokeLocalFontStore(fontManager); + localFontStore = new KaraokeLocalFontStore(fontManager, renderer); fontStore.AddStore(localFontStore); foreach (var fontInfo in fontInfos) diff --git a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj index 0a3f12443..9caf8a3a8 100644 --- a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj +++ b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj @@ -12,13 +12,13 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - +