chore: move all dalamud logo textures into special service

This commit is contained in:
goat 2023-10-01 21:35:21 +02:00
parent 2bdb837577
commit 263771c082
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
6 changed files with 77 additions and 35 deletions

View file

@ -0,0 +1,58 @@
using System.IO;
using Dalamud.IoC.Internal;
namespace Dalamud.Interface.Internal;
/// <summary>
/// Class containing various textures used by Dalamud windows for branding purposes.
/// </summary>
[ServiceManager.EarlyLoadedService]
#pragma warning disable SA1015
[InherentDependency<InterfaceManager.InterfaceManagerWithScene>] // Can't load textures before this
#pragma warning restore SA1015
internal class Branding : IServiceType, IDisposable
{
private readonly Dalamud dalamud;
private readonly TextureManager tm;
/// <summary>
/// Initializes a new instance of the <see cref="Branding"/> class.
/// </summary>
/// <param name="dalamud">Dalamud instance.</param>
/// <param name="tm">TextureManager instance.</param>
[ServiceManager.ServiceConstructor]
public Branding(Dalamud dalamud, TextureManager tm)
{
this.dalamud = dalamud;
this.tm = tm;
this.LoadTextures();
}
/// <summary>
/// Gets a full-size Dalamud logo texture.
/// </summary>
public IDalamudTextureWrap Logo { get; private set; } = null!;
/// <summary>
/// Gets a small Dalamud logo texture.
/// </summary>
public IDalamudTextureWrap LogoSmall { get; private set; } = null!;
/// <inheritdoc/>
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.");
}
}

View file

@ -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<TitleScreenMenu>.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

View file

@ -49,11 +49,7 @@ Thanks and have fun!";
this.Size = new Vector2(885, 463);
this.SizeCondition = ImGuiCond.Appearing;
var interfaceManager = Service<InterfaceManager>.Get();
var dalamud = Service<Dalamud>.Get();
this.logoTexture =
interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "logo.png"))!;
this.logoTexture = Service<Branding>.Get().Logo;
}
/// <inheritdoc/>

View file

@ -50,6 +50,9 @@ internal class PluginImageCache : IDisposable, IServiceType
[ServiceManager.ServiceDependency]
private readonly InterfaceManager.InterfaceManagerWithScene imWithScene = Service<InterfaceManager.InterfaceManagerWithScene>.Get();
[ServiceManager.ServiceDependency]
private readonly Branding branding = Service<Branding>.Get();
[ServiceManager.ServiceDependency]
private readonly HappyHttpClient happyHttpClient = Service<HappyHttpClient>.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);

View file

@ -181,10 +181,9 @@ Contribute at: https://github.com/goatcorp/Dalamud
public SettingsTabAbout()
{
var dalamud = Service<Dalamud>.Get();
var interfaceManager = Service<InterfaceManager>.Get();
var branding = Service<Branding>.Get();
this.logoTexture = interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "logo.png"))!;
this.logoTexture = branding.Logo;
this.creditsThrottler = new();
}

View file

@ -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
/// <summary>
@ -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);