mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-20 23:07:43 +01:00
Add DalamudAssetManager
This commit is contained in:
parent
01153a2480
commit
a72f407357
17 changed files with 867 additions and 179 deletions
|
|
@ -11,6 +11,7 @@ using Dalamud.Interface.Utility;
|
|||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin.Internal;
|
||||
using Dalamud.Storage.Assets;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
|
||||
|
|
@ -32,7 +33,6 @@ internal sealed class ChangelogWindow : Window, IDisposable
|
|||
";
|
||||
|
||||
private readonly TitleScreenMenuWindow tsmWindow;
|
||||
private readonly IDalamudTextureWrap logoTexture;
|
||||
|
||||
private readonly InOutCubic windowFade = new(TimeSpan.FromSeconds(2.5f))
|
||||
{
|
||||
|
|
@ -47,6 +47,7 @@ internal sealed class ChangelogWindow : Window, IDisposable
|
|||
};
|
||||
|
||||
private IDalamudTextureWrap? apiBumpExplainerTexture;
|
||||
private IDalamudTextureWrap? logoTexture;
|
||||
private GameFontHandle? bannerFont;
|
||||
|
||||
private State state = State.WindowFadeIn;
|
||||
|
|
@ -63,8 +64,6 @@ internal sealed class ChangelogWindow : Window, IDisposable
|
|||
this.tsmWindow = tsmWindow;
|
||||
this.Namespace = "DalamudChangelogWindow";
|
||||
|
||||
this.logoTexture = Service<Branding>.Get().Logo;
|
||||
|
||||
// If we are going to show a changelog, make sure we have the font ready, otherwise it will hitch
|
||||
if (WarrantsChangelog())
|
||||
Service<GameFontManager>.GetAsync().ContinueWith(t => this.MakeFont(t.Result));
|
||||
|
|
@ -188,6 +187,7 @@ internal sealed class ChangelogWindow : Window, IDisposable
|
|||
|
||||
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, Math.Clamp(this.windowFade.EasedPoint.X - 0.5f, 0f, 1f)))
|
||||
{
|
||||
this.logoTexture ??= Service<DalamudAssetManager>.Get().GetDalamudTextureWrap(DalamudAsset.Logo);
|
||||
ImGui.Image(this.logoTexture.ImGuiHandle, logoSize);
|
||||
}
|
||||
}
|
||||
|
|
@ -376,7 +376,6 @@ internal sealed class ChangelogWindow : Window, IDisposable
|
|||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.logoTexture.Dispose();
|
||||
}
|
||||
|
||||
private void MakeFont(GameFontManager gfm) =>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
|
@ -12,8 +11,8 @@ using Dalamud.Networking.Http;
|
|||
using Dalamud.Plugin.Internal;
|
||||
using Dalamud.Plugin.Internal.Types;
|
||||
using Dalamud.Plugin.Internal.Types.Manifest;
|
||||
using Dalamud.Storage.Assets;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiScene;
|
||||
using Serilog;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows;
|
||||
|
|
@ -47,12 +46,6 @@ internal class PluginImageCache : IDisposable, IServiceType
|
|||
private const string MainRepoImageUrl = "https://raw.githubusercontent.com/goatcorp/DalamudPlugins/api6/{0}/{1}/images/{2}";
|
||||
private const string MainRepoDip17ImageUrl = "https://raw.githubusercontent.com/goatcorp/PluginDistD17/main/{0}/{1}/images/{2}";
|
||||
|
||||
[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();
|
||||
|
||||
|
|
@ -64,35 +57,12 @@ internal class PluginImageCache : IDisposable, IServiceType
|
|||
|
||||
private readonly ConcurrentDictionary<string, IDalamudTextureWrap?> pluginIconMap = new();
|
||||
private readonly ConcurrentDictionary<string, IDalamudTextureWrap?[]?> pluginImagesMap = new();
|
||||
|
||||
private readonly Task<IDalamudTextureWrap> emptyTextureTask;
|
||||
private readonly Task<IDalamudTextureWrap> disabledIconTask;
|
||||
private readonly Task<IDalamudTextureWrap> outdatedInstallableIconTask;
|
||||
private readonly Task<IDalamudTextureWrap> defaultIconTask;
|
||||
private readonly Task<IDalamudTextureWrap> troubleIconTask;
|
||||
private readonly Task<IDalamudTextureWrap> updateIconTask;
|
||||
private readonly Task<IDalamudTextureWrap> installedIconTask;
|
||||
private readonly Task<IDalamudTextureWrap> thirdIconTask;
|
||||
private readonly Task<IDalamudTextureWrap> thirdInstalledIconTask;
|
||||
private readonly Task<IDalamudTextureWrap> corePluginIconTask;
|
||||
private readonly DalamudAssetManager dalamudAssetManager;
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
private PluginImageCache(Dalamud dalamud)
|
||||
private PluginImageCache(Dalamud dalamud, DalamudAssetManager dalamudAssetManager)
|
||||
{
|
||||
Task<IDalamudTextureWrap>? TaskWrapIfNonNull(IDalamudTextureWrap? tw) => tw == null ? null : Task.FromResult(tw!);
|
||||
var imwst = Task.Run(() => this.imWithScene);
|
||||
|
||||
this.emptyTextureTask = imwst.ContinueWith(task => task.Result.Manager.LoadImageRaw(new byte[64], 8, 8, 4)!);
|
||||
this.defaultIconTask = imwst.ContinueWith(task => TaskWrapIfNonNull(task.Result.Manager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "defaultIcon.png"))) ?? this.emptyTextureTask).Unwrap();
|
||||
this.disabledIconTask = imwst.ContinueWith(task => TaskWrapIfNonNull(task.Result.Manager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "disabledIcon.png"))) ?? this.emptyTextureTask).Unwrap();
|
||||
this.outdatedInstallableIconTask = imwst.ContinueWith(task => TaskWrapIfNonNull(task.Result.Manager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "outdatedInstallableIcon.png"))) ?? this.emptyTextureTask).Unwrap();
|
||||
this.troubleIconTask = imwst.ContinueWith(task => TaskWrapIfNonNull(task.Result.Manager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "troubleIcon.png"))) ?? this.emptyTextureTask).Unwrap();
|
||||
this.updateIconTask = imwst.ContinueWith(task => TaskWrapIfNonNull(task.Result.Manager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "updateIcon.png"))) ?? this.emptyTextureTask).Unwrap();
|
||||
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(this.branding.LogoSmall)).Unwrap();
|
||||
|
||||
this.dalamudAssetManager = dalamudAssetManager;
|
||||
this.downloadTask = Task.Factory.StartNew(
|
||||
() => this.DownloadTask(8), TaskCreationOptions.LongRunning);
|
||||
this.loadTask = Task.Factory.StartNew(
|
||||
|
|
@ -102,72 +72,62 @@ internal class PluginImageCache : IDisposable, IServiceType
|
|||
/// <summary>
|
||||
/// Gets the fallback empty texture.
|
||||
/// </summary>
|
||||
public IDalamudTextureWrap EmptyTexture => this.emptyTextureTask.IsCompleted
|
||||
? this.emptyTextureTask.Result
|
||||
: this.emptyTextureTask.GetAwaiter().GetResult();
|
||||
public IDalamudTextureWrap EmptyTexture =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.Empty4X4);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the disabled plugin icon.
|
||||
/// </summary>
|
||||
public IDalamudTextureWrap DisabledIcon => this.disabledIconTask.IsCompleted
|
||||
? this.disabledIconTask.Result
|
||||
: this.disabledIconTask.GetAwaiter().GetResult();
|
||||
public IDalamudTextureWrap DisabledIcon =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.DisabledIcon, this.EmptyTexture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the outdated installable plugin icon.
|
||||
/// </summary>
|
||||
public IDalamudTextureWrap OutdatedInstallableIcon => this.outdatedInstallableIconTask.IsCompleted
|
||||
? this.outdatedInstallableIconTask.Result
|
||||
: this.outdatedInstallableIconTask.GetAwaiter().GetResult();
|
||||
public IDalamudTextureWrap OutdatedInstallableIcon =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.OutdatedInstallableIcon, this.EmptyTexture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default plugin icon.
|
||||
/// </summary>
|
||||
public IDalamudTextureWrap DefaultIcon => this.defaultIconTask.IsCompleted
|
||||
? this.defaultIconTask.Result
|
||||
: this.defaultIconTask.GetAwaiter().GetResult();
|
||||
public IDalamudTextureWrap DefaultIcon =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.DefaultIcon, this.EmptyTexture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin trouble icon overlay.
|
||||
/// </summary>
|
||||
public IDalamudTextureWrap TroubleIcon => this.troubleIconTask.IsCompleted
|
||||
? this.troubleIconTask.Result
|
||||
: this.troubleIconTask.GetAwaiter().GetResult();
|
||||
public IDalamudTextureWrap TroubleIcon =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.TroubleIcon, this.EmptyTexture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin update icon overlay.
|
||||
/// </summary>
|
||||
public IDalamudTextureWrap UpdateIcon => this.updateIconTask.IsCompleted
|
||||
? this.updateIconTask.Result
|
||||
: this.updateIconTask.GetAwaiter().GetResult();
|
||||
public IDalamudTextureWrap UpdateIcon =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.UpdateIcon, this.EmptyTexture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin installed icon overlay.
|
||||
/// </summary>
|
||||
public IDalamudTextureWrap InstalledIcon => this.installedIconTask.IsCompleted
|
||||
? this.installedIconTask.Result
|
||||
: this.installedIconTask.GetAwaiter().GetResult();
|
||||
public IDalamudTextureWrap InstalledIcon =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.InstalledIcon, this.EmptyTexture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the third party plugin icon overlay.
|
||||
/// </summary>
|
||||
public IDalamudTextureWrap ThirdIcon => this.thirdIconTask.IsCompleted
|
||||
? this.thirdIconTask.Result
|
||||
: this.thirdIconTask.GetAwaiter().GetResult();
|
||||
public IDalamudTextureWrap ThirdIcon =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.ThirdIcon, this.EmptyTexture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the installed third party plugin icon overlay.
|
||||
/// </summary>
|
||||
public IDalamudTextureWrap ThirdInstalledIcon => this.thirdInstalledIconTask.IsCompleted
|
||||
? this.thirdInstalledIconTask.Result
|
||||
: this.thirdInstalledIconTask.GetAwaiter().GetResult();
|
||||
public IDalamudTextureWrap ThirdInstalledIcon =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.ThirdInstalledIcon, this.EmptyTexture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the core plugin icon.
|
||||
/// </summary>
|
||||
public IDalamudTextureWrap CorePluginIcon => this.corePluginIconTask.IsCompleted
|
||||
? this.corePluginIconTask.Result
|
||||
: this.corePluginIconTask.GetAwaiter().GetResult();
|
||||
public IDalamudTextureWrap CorePluginIcon =>
|
||||
this.dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.LogoSmall, this.EmptyTexture);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
|
|
@ -185,22 +145,6 @@ internal class PluginImageCache : IDisposable, IServiceType
|
|||
this.downloadQueue.Dispose();
|
||||
this.loadQueue.Dispose();
|
||||
|
||||
foreach (var task in new[]
|
||||
{
|
||||
this.defaultIconTask,
|
||||
this.troubleIconTask,
|
||||
this.updateIconTask,
|
||||
this.installedIconTask,
|
||||
this.thirdIconTask,
|
||||
this.thirdInstalledIconTask,
|
||||
this.corePluginIconTask,
|
||||
})
|
||||
{
|
||||
task.Wait();
|
||||
if (task.IsCompletedSuccessfully)
|
||||
task.Result.Dispose();
|
||||
}
|
||||
|
||||
foreach (var icon in this.pluginIconMap.Values)
|
||||
{
|
||||
icon?.Dispose();
|
||||
|
|
@ -319,7 +263,7 @@ internal class PluginImageCache : IDisposable, IServiceType
|
|||
if (bytes == null)
|
||||
return null;
|
||||
|
||||
var interfaceManager = this.imWithScene.Manager;
|
||||
var interfaceManager = (await Service<InterfaceManager.InterfaceManagerWithScene>.GetAsync()).Manager;
|
||||
var framework = await Service<Framework>.GetAsync();
|
||||
|
||||
IDalamudTextureWrap? image;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ using Dalamud.Interface.GameFonts;
|
|||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Plugin.Internal;
|
||||
using Dalamud.Storage.Assets;
|
||||
using Dalamud.Utility;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.UI;
|
||||
using ImGuiNET;
|
||||
|
|
@ -171,19 +172,16 @@ Dalamud is licensed under AGPL v3 or later.
|
|||
Contribute at: https://github.com/goatcorp/Dalamud
|
||||
";
|
||||
|
||||
private readonly IDalamudTextureWrap logoTexture;
|
||||
private readonly Stopwatch creditsThrottler;
|
||||
|
||||
private string creditsText;
|
||||
|
||||
private bool resetNow = false;
|
||||
private IDalamudTextureWrap? logoTexture;
|
||||
private GameFontHandle? thankYouFont;
|
||||
|
||||
public SettingsTabAbout()
|
||||
{
|
||||
var branding = Service<Branding>.Get();
|
||||
|
||||
this.logoTexture = branding.Logo;
|
||||
this.creditsThrottler = new();
|
||||
}
|
||||
|
||||
|
|
@ -251,6 +249,7 @@ Contribute at: https://github.com/goatcorp/Dalamud
|
|||
|
||||
const float imageSize = 190f;
|
||||
ImGui.SameLine((ImGui.GetWindowWidth() / 2) - (imageSize / 2));
|
||||
this.logoTexture ??= Service<DalamudAssetManager>.Get().GetDalamudTextureWrap(DalamudAsset.Logo);
|
||||
ImGui.Image(this.logoTexture.ImGuiHandle, ImGuiHelpers.ScaledVector2(imageSize));
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0, 20f);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
|
|
@ -12,6 +11,7 @@ using Dalamud.Interface.Utility;
|
|||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin.Services;
|
||||
using Dalamud.Storage.Assets;
|
||||
|
||||
using ImGuiNET;
|
||||
|
||||
|
|
@ -46,19 +46,17 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
/// Initializes a new instance of the <see cref="TitleScreenMenuWindow"/> class.
|
||||
/// </summary>
|
||||
/// <param name="clientState">An instance of <see cref="ClientState"/>.</param>
|
||||
/// <param name="dalamud">An instance of <see cref="Dalamud"/>.</param>
|
||||
/// <param name="configuration">An instance of <see cref="DalamudConfiguration"/>.</param>
|
||||
/// <param name="dalamudAssetManager">An instance of <see cref="DalamudAssetManager"/>.</param>
|
||||
/// <param name="framework">An instance of <see cref="Framework"/>.</param>
|
||||
/// <param name="interfaceManager">An instance of <see cref="InterfaceManager"/>.</param>
|
||||
/// <param name="titleScreenMenu">An instance of <see cref="TitleScreenMenu"/>.</param>
|
||||
/// <param name="gameGui">An instance of <see cref="gameGui"/>.</param>
|
||||
public TitleScreenMenuWindow(
|
||||
ClientState clientState,
|
||||
Dalamud dalamud,
|
||||
DalamudConfiguration configuration,
|
||||
DalamudAssetManager dalamudAssetManager,
|
||||
Framework framework,
|
||||
GameGui gameGui,
|
||||
InterfaceManager interfaceManager,
|
||||
TitleScreenMenu titleScreenMenu)
|
||||
: base(
|
||||
"TitleScreenMenuOverlay",
|
||||
|
|
@ -79,9 +77,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
this.PositionCondition = ImGuiCond.Always;
|
||||
this.RespectCloseHotkey = false;
|
||||
|
||||
var shadeTex =
|
||||
interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "tsmShade.png"));
|
||||
this.shadeTexture = shadeTex ?? throw new Exception("Could not load TSM background texture.");
|
||||
this.shadeTexture = dalamudAssetManager.GetDalamudTextureWrap(DalamudAsset.TitleScreenMenuShade);
|
||||
|
||||
framework.Update += this.FrameworkOnUpdate;
|
||||
}
|
||||
|
|
@ -116,7 +112,6 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
this.shadeTexture.Dispose();
|
||||
this.framework.Update -= this.FrameworkOnUpdate;
|
||||
}
|
||||
|
||||
|
|
@ -386,7 +381,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
return isHover;
|
||||
}
|
||||
|
||||
private void FrameworkOnUpdate(IFramework framework)
|
||||
private void FrameworkOnUpdate(IFramework unused)
|
||||
{
|
||||
this.IsOpen = !this.clientState.IsLoggedIn;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue