diff --git a/Dalamud/Interface/Internal/Branding.cs b/Dalamud/Interface/Internal/Branding.cs new file mode 100644 index 000000000..4162cabeb --- /dev/null +++ b/Dalamud/Interface/Internal/Branding.cs @@ -0,0 +1,58 @@ +using System.IO; + +using Dalamud.IoC.Internal; + +namespace Dalamud.Interface.Internal; + +/// +/// Class containing various textures used by Dalamud windows for branding purposes. +/// +[ServiceManager.EarlyLoadedService] +#pragma warning disable SA1015 +[InherentDependency] // Can't load textures before this +#pragma warning restore SA1015 +internal class Branding : IServiceType, IDisposable +{ + private readonly Dalamud dalamud; + private readonly TextureManager tm; + + /// + /// Initializes a new instance of the class. + /// + /// Dalamud instance. + /// TextureManager instance. + [ServiceManager.ServiceConstructor] + public Branding(Dalamud dalamud, TextureManager tm) + { + this.dalamud = dalamud; + this.tm = tm; + + this.LoadTextures(); + } + + /// + /// Gets a full-size Dalamud logo texture. + /// + public IDalamudTextureWrap Logo { get; private set; } = null!; + + /// + /// Gets a small Dalamud logo texture. + /// + public IDalamudTextureWrap LogoSmall { get; private set; } = null!; + + /// + public void Dispose() + { + this.Logo.Dispose(); + this.LogoSmall.Dispose(); + } + + private void LoadTextures() + { + this.Logo = this.tm.GetTextureFromFile(new FileInfo(Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "logo.png"))) + ?? throw new Exception("Could not load logo."); + + this.LogoSmall = this.tm.GetTextureFromFile(new FileInfo(Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "tsmLogo.png"))) + ?? throw new Exception("Could not load TSM logo."); + } +} diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index 9e4c215b3..a7b1e80b5 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -66,9 +66,6 @@ internal class DalamudInterface : IDisposable, IServiceType private readonly BranchSwitcherWindow branchSwitcherWindow; private readonly HitchSettingsWindow hitchSettingsWindow; - private readonly IDalamudTextureWrap logoTexture; - private readonly IDalamudTextureWrap tsmLogoTexture; - private bool isCreditsDarkening = false; private OutCubic creditsDarkeningAnimation = new(TimeSpan.FromSeconds(10)); @@ -92,7 +89,8 @@ internal class DalamudInterface : IDisposable, IServiceType Dalamud dalamud, DalamudConfiguration configuration, InterfaceManager.InterfaceManagerWithScene interfaceManagerWithScene, - PluginImageCache pluginImageCache) + PluginImageCache pluginImageCache, + Branding branding) { var interfaceManager = interfaceManagerWithScene.Manager; this.WindowSystem = new WindowSystem("DalamudCore"); @@ -136,26 +134,13 @@ internal class DalamudInterface : IDisposable, IServiceType interfaceManager.Draw += this.OnDraw; - var logoTex = - interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "logo.png")); - var tsmLogoTex = - interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "tsmLogo.png")); - - if (logoTex == null || tsmLogoTex == null) - { - throw new Exception("Failed to load logo textures"); - } - - this.logoTexture = logoTex; - this.tsmLogoTexture = tsmLogoTex; - var tsm = Service.Get(); - tsm.AddEntryCore(Loc.Localize("TSMDalamudPlugins", "Plugin Installer"), this.tsmLogoTexture, this.OpenPluginInstaller); - tsm.AddEntryCore(Loc.Localize("TSMDalamudSettings", "Dalamud Settings"), this.tsmLogoTexture, this.OpenSettings); + tsm.AddEntryCore(Loc.Localize("TSMDalamudPlugins", "Plugin Installer"), branding.LogoSmall, this.OpenPluginInstaller); + tsm.AddEntryCore(Loc.Localize("TSMDalamudSettings", "Dalamud Settings"), branding.LogoSmall, this.OpenSettings); if (!configuration.DalamudBetaKind.IsNullOrEmpty()) { - tsm.AddEntryCore(Loc.Localize("TSMDalamudDevMenu", "Developer Menu"), this.tsmLogoTexture, () => this.isImGuiDrawDevMenu = true); + tsm.AddEntryCore(Loc.Localize("TSMDalamudDevMenu", "Developer Menu"), branding.LogoSmall, () => this.isImGuiDrawDevMenu = true); } this.creditsDarkeningAnimation.Point1 = Vector2.Zero; @@ -192,9 +177,6 @@ internal class DalamudInterface : IDisposable, IServiceType this.consoleWindow.Dispose(); this.pluginWindow.Dispose(); this.titleScreenMenuWindow.Dispose(); - - this.logoTexture.Dispose(); - this.tsmLogoTexture.Dispose(); } #region Open diff --git a/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs b/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs index 61010ce0c..cd4618f24 100644 --- a/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs +++ b/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs @@ -49,11 +49,7 @@ Thanks and have fun!"; this.Size = new Vector2(885, 463); this.SizeCondition = ImGuiCond.Appearing; - var interfaceManager = Service.Get(); - var dalamud = Service.Get(); - - this.logoTexture = - interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "logo.png"))!; + this.logoTexture = Service.Get().Logo; } /// diff --git a/Dalamud/Interface/Internal/Windows/PluginImageCache.cs b/Dalamud/Interface/Internal/Windows/PluginImageCache.cs index c334cd4bd..b721b08c3 100644 --- a/Dalamud/Interface/Internal/Windows/PluginImageCache.cs +++ b/Dalamud/Interface/Internal/Windows/PluginImageCache.cs @@ -50,6 +50,9 @@ internal class PluginImageCache : IDisposable, IServiceType [ServiceManager.ServiceDependency] private readonly InterfaceManager.InterfaceManagerWithScene imWithScene = Service.Get(); + [ServiceManager.ServiceDependency] + private readonly Branding branding = Service.Get(); + [ServiceManager.ServiceDependency] private readonly HappyHttpClient happyHttpClient = Service.Get(); @@ -88,7 +91,7 @@ internal class PluginImageCache : IDisposable, IServiceType this.installedIconTask = imwst.ContinueWith(task => TaskWrapIfNonNull(task.Result.Manager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "installedIcon.png"))) ?? this.emptyTextureTask).Unwrap(); this.thirdIconTask = imwst.ContinueWith(task => TaskWrapIfNonNull(task.Result.Manager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "thirdIcon.png"))) ?? this.emptyTextureTask).Unwrap(); this.thirdInstalledIconTask = imwst.ContinueWith(task => TaskWrapIfNonNull(task.Result.Manager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "thirdInstalledIcon.png"))) ?? this.emptyTextureTask).Unwrap(); - this.corePluginIconTask = imwst.ContinueWith(task => TaskWrapIfNonNull(task.Result.Manager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "tsmLogo.png"))) ?? this.emptyTextureTask).Unwrap(); + this.corePluginIconTask = imwst.ContinueWith(task => TaskWrapIfNonNull(this.branding.LogoSmall)).Unwrap(); this.downloadTask = Task.Factory.StartNew( () => this.DownloadTask(8), TaskCreationOptions.LongRunning); diff --git a/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabAbout.cs b/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabAbout.cs index ec9833b78..9b6a32617 100644 --- a/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabAbout.cs +++ b/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabAbout.cs @@ -181,10 +181,9 @@ Contribute at: https://github.com/goatcorp/Dalamud public SettingsTabAbout() { - var dalamud = Service.Get(); - var interfaceManager = Service.Get(); + var branding = Service.Get(); - this.logoTexture = interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "logo.png"))!; + this.logoTexture = branding.Logo; this.creditsThrottler = new(); } diff --git a/Dalamud/ServiceManager.cs b/Dalamud/ServiceManager.cs index 553e0a4af..453fa3530 100644 --- a/Dalamud/ServiceManager.cs +++ b/Dalamud/ServiceManager.cs @@ -16,7 +16,7 @@ using JetBrains.Annotations; namespace Dalamud; // TODO: -// - Unify dependency walking code(load/unload +// - Unify dependency walking code(load/unload) // - Visualize/output .dot or imgui thing /// @@ -122,8 +122,7 @@ internal static class ServiceManager foreach (var serviceType in Assembly.GetExecutingAssembly().GetTypes().Where(x => x.IsAssignableTo(typeof(IServiceType)) && !x.IsInterface && !x.IsAbstract)) { var serviceKind = serviceType.GetServiceKind(); - if (serviceKind is ServiceKind.None) - throw new Exception($"Service<{serviceType.FullName}> did not specify a kind"); + Debug.Assert(serviceKind != ServiceKind.None, $"Service<{serviceType.FullName}> did not specify a kind"); // Let IoC know about the interfaces this service implements serviceContainer.RegisterInterfaces(serviceType); @@ -148,6 +147,11 @@ internal static class ServiceManager if (serviceKind.HasFlag(ServiceKind.ProvidedService)) continue; + Debug.Assert( + serviceKind.HasFlag(ServiceKind.EarlyLoadedService) || + serviceKind.HasFlag(ServiceKind.BlockingEarlyLoadedService), + "At this point, service must be either early loaded or blocking early loaded"); + if (serviceKind.HasFlag(ServiceKind.BlockingEarlyLoadedService)) { blockingEarlyLoadingServices.Add(serviceType);