mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-20 23:07:43 +01:00
Better Service dependency handling (#1535)
This commit is contained in:
parent
fcebd15077
commit
b66be84b93
25 changed files with 415 additions and 197 deletions
|
|
@ -67,7 +67,7 @@ internal sealed class ChangelogWindow : Window, IDisposable
|
|||
|
||||
// If we are going to show a changelog, make sure we have the font ready, otherwise it will hitch
|
||||
if (WarrantsChangelog())
|
||||
this.MakeFont();
|
||||
Service<GameFontManager>.GetAsync().ContinueWith(t => this.MakeFont(t.Result));
|
||||
}
|
||||
|
||||
private enum State
|
||||
|
|
@ -98,7 +98,7 @@ internal sealed class ChangelogWindow : Window, IDisposable
|
|||
Service<DalamudInterface>.Get().SetCreditsDarkeningAnimation(true);
|
||||
this.tsmWindow.AllowDrawing = false;
|
||||
|
||||
this.MakeFont();
|
||||
this.MakeFont(Service<GameFontManager>.Get());
|
||||
|
||||
this.state = State.WindowFadeIn;
|
||||
this.windowFade.Reset();
|
||||
|
|
@ -379,12 +379,6 @@ internal sealed class ChangelogWindow : Window, IDisposable
|
|||
this.logoTexture.Dispose();
|
||||
}
|
||||
|
||||
private void MakeFont()
|
||||
{
|
||||
if (this.bannerFont == null)
|
||||
{
|
||||
var gfm = Service<GameFontManager>.Get();
|
||||
this.bannerFont = gfm.NewFontRef(new GameFontStyle(GameFontFamilyAndSize.MiedingerMid18));
|
||||
}
|
||||
}
|
||||
private void MakeFont(GameFontManager gfm) =>
|
||||
this.bannerFont ??= gfm.NewFontRef(new GameFontStyle(GameFontFamilyAndSize.MiedingerMid18));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,11 +56,10 @@ internal class ConsoleWindow : Window, IDisposable
|
|||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ConsoleWindow"/> class.
|
||||
/// </summary>
|
||||
public ConsoleWindow()
|
||||
/// <param name="configuration">An instance of <see cref="DalamudConfiguration"/>.</param>
|
||||
public ConsoleWindow(DalamudConfiguration configuration)
|
||||
: base("Dalamud Console", ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
|
||||
{
|
||||
var configuration = Service<DalamudConfiguration>.Get();
|
||||
|
||||
this.autoScroll = configuration.LogAutoScroll;
|
||||
this.autoOpen = configuration.LogOpenAtStartup;
|
||||
SerilogEventSink.Instance.LogLine += this.OnLogLine;
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
private string[] testerImagePaths = new string[5];
|
||||
private string testerIconPath = string.Empty;
|
||||
|
||||
private IDalamudTextureWrap?[] testerImages;
|
||||
private IDalamudTextureWrap?[]? testerImages;
|
||||
private IDalamudTextureWrap? testerIcon;
|
||||
|
||||
private bool testerError = false;
|
||||
|
|
@ -132,9 +132,10 @@ internal class PluginInstallerWindow : Window, IDisposable
|
|||
/// Initializes a new instance of the <see cref="PluginInstallerWindow"/> class.
|
||||
/// </summary>
|
||||
/// <param name="imageCache">An instance of <see cref="PluginImageCache"/> class.</param>
|
||||
public PluginInstallerWindow(PluginImageCache imageCache)
|
||||
/// <param name="configuration">An instance of <see cref="DalamudConfiguration"/>.</param>
|
||||
public PluginInstallerWindow(PluginImageCache imageCache, DalamudConfiguration configuration)
|
||||
: base(
|
||||
Locs.WindowTitle + (Service<DalamudConfiguration>.Get().DoPluginTest ? Locs.WindowTitleMod_Testing : string.Empty) + "###XlPluginInstaller",
|
||||
Locs.WindowTitle + (configuration.DoPluginTest ? Locs.WindowTitleMod_Testing : string.Empty) + "###XlPluginInstaller",
|
||||
ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar)
|
||||
{
|
||||
this.IsOpen = true;
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ using Dalamud.Interface.Utility;
|
|||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin.Services;
|
||||
|
||||
using ImGuiNET;
|
||||
using ImGuiScene;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows;
|
||||
|
||||
|
|
@ -25,6 +25,12 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
private const float TargetFontSizePt = 18f;
|
||||
private const float TargetFontSizePx = TargetFontSizePt * 4 / 3;
|
||||
|
||||
private readonly ClientState clientState;
|
||||
private readonly DalamudConfiguration configuration;
|
||||
private readonly Framework framework;
|
||||
private readonly GameGui gameGui;
|
||||
private readonly TitleScreenMenu titleScreenMenu;
|
||||
|
||||
private readonly IDalamudTextureWrap shadeTexture;
|
||||
|
||||
private readonly Dictionary<Guid, InOutCubic> shadeEasings = new();
|
||||
|
|
@ -39,12 +45,32 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TitleScreenMenuWindow"/> class.
|
||||
/// </summary>
|
||||
public TitleScreenMenuWindow()
|
||||
/// <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="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,
|
||||
Framework framework,
|
||||
GameGui gameGui,
|
||||
InterfaceManager interfaceManager,
|
||||
TitleScreenMenu titleScreenMenu)
|
||||
: base(
|
||||
"TitleScreenMenuOverlay",
|
||||
ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoScrollbar |
|
||||
ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoNavFocus)
|
||||
{
|
||||
this.clientState = clientState;
|
||||
this.configuration = configuration;
|
||||
this.framework = framework;
|
||||
this.gameGui = gameGui;
|
||||
this.titleScreenMenu = titleScreenMenu;
|
||||
|
||||
this.IsOpen = true;
|
||||
this.DisableWindowSounds = true;
|
||||
this.ForceMainWindow = true;
|
||||
|
|
@ -53,17 +79,13 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
this.PositionCondition = ImGuiCond.Always;
|
||||
this.RespectCloseHotkey = false;
|
||||
|
||||
var dalamud = Service<Dalamud>.Get();
|
||||
var interfaceManager = Service<InterfaceManager>.Get();
|
||||
|
||||
var shadeTex =
|
||||
interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "tsmShade.png"));
|
||||
this.shadeTexture = shadeTex ?? throw new Exception("Could not load TSM background texture.");
|
||||
|
||||
var framework = Service<Framework>.Get();
|
||||
framework.Update += this.FrameworkOnUpdate;
|
||||
}
|
||||
|
||||
|
||||
private enum State
|
||||
{
|
||||
Hide,
|
||||
|
|
@ -95,8 +117,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
public void Dispose()
|
||||
{
|
||||
this.shadeTexture.Dispose();
|
||||
var framework = Service<Framework>.Get();
|
||||
framework.Update -= this.FrameworkOnUpdate;
|
||||
this.framework.Update -= this.FrameworkOnUpdate;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
@ -106,9 +127,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
return;
|
||||
|
||||
var scale = ImGui.GetIO().FontGlobalScale;
|
||||
var entries = Service<TitleScreenMenu>.Get().Entries
|
||||
.OrderByDescending(x => x.IsInternal)
|
||||
.ToList();
|
||||
var entries = this.titleScreenMenu.Entries.OrderByDescending(x => x.IsInternal).ToList();
|
||||
|
||||
switch (this.state)
|
||||
{
|
||||
|
|
@ -369,17 +388,14 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
|
||||
private void FrameworkOnUpdate(IFramework framework)
|
||||
{
|
||||
var clientState = Service<ClientState>.Get();
|
||||
this.IsOpen = !clientState.IsLoggedIn;
|
||||
this.IsOpen = !this.clientState.IsLoggedIn;
|
||||
|
||||
var configuration = Service<DalamudConfiguration>.Get();
|
||||
if (!configuration.ShowTsm)
|
||||
if (!this.configuration.ShowTsm)
|
||||
this.IsOpen = false;
|
||||
|
||||
var gameGui = Service<GameGui>.Get();
|
||||
var charaSelect = gameGui.GetAddonByName("CharaSelect", 1);
|
||||
var charaMake = gameGui.GetAddonByName("CharaMake", 1);
|
||||
var titleDcWorldMap = gameGui.GetAddonByName("TitleDCWorldMap", 1);
|
||||
var charaSelect = this.gameGui.GetAddonByName("CharaSelect", 1);
|
||||
var charaMake = this.gameGui.GetAddonByName("CharaMake", 1);
|
||||
var titleDcWorldMap = this.gameGui.GetAddonByName("TitleDCWorldMap", 1);
|
||||
if (charaMake != IntPtr.Zero || charaSelect != IntPtr.Zero || titleDcWorldMap != IntPtr.Zero)
|
||||
this.IsOpen = false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue