From 3435c346b66ac4d341789482adb31412b75ccea9 Mon Sep 17 00:00:00 2001 From: KazWolfe Date: Mon, 4 Nov 2024 08:18:31 -0800 Subject: [PATCH] feat: Add Dalamud Version to the Title Screen (#1939) --- .../Interface/Internal/DalamudInterface.cs | 7 ++- .../Internal/Windows/TitleScreenMenuWindow.cs | 58 ++++++++++++++++++- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index 793dfddd9..96395ac26 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; using CheapLoc; using Dalamud.Configuration.Internal; using Dalamud.Console; +using Dalamud.Game.Addon.Lifecycle; using Dalamud.Game.ClientState; using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Keys; @@ -103,7 +104,8 @@ internal class DalamudInterface : IInternalDisposableService ClientState clientState, TitleScreenMenu titleScreenMenu, GameGui gameGui, - ConsoleManager consoleManager) + ConsoleManager consoleManager, + AddonLifecycle addonLifecycle) { this.dalamud = dalamud; this.configuration = configuration; @@ -129,7 +131,8 @@ internal class DalamudInterface : IInternalDisposableService framework, gameGui, titleScreenMenu, - consoleManager) { IsOpen = false }; + consoleManager, + addonLifecycle) { IsOpen = false }; this.changelogWindow = new ChangelogWindow( this.titleScreenMenuWindow, fontAtlasFactory, diff --git a/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs b/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs index c22dc76d3..588153b85 100644 --- a/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs +++ b/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs @@ -5,8 +5,12 @@ using System.Numerics; using Dalamud.Configuration.Internal; using Dalamud.Console; using Dalamud.Game; +using Dalamud.Game.Addon.Lifecycle; +using Dalamud.Game.Addon.Lifecycle.AddonArgTypes; using Dalamud.Game.ClientState; using Dalamud.Game.Gui; +using Dalamud.Game.Text; +using Dalamud.Game.Text.SeStringHandling; using Dalamud.Interface.Animation.EasingFunctions; using Dalamud.Interface.ManagedFontAtlas; using Dalamud.Interface.ManagedFontAtlas.Internals; @@ -14,10 +18,15 @@ using Dalamud.Interface.Textures.TextureWraps; using Dalamud.Interface.Utility; using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Windowing; +using Dalamud.Plugin.Internal; +using Dalamud.Plugin.Internal.Types; using Dalamud.Plugin.Services; using Dalamud.Storage.Assets; +using Dalamud.Support; using Dalamud.Utility; +using FFXIVClientStructs.FFXIV.Component.GUI; + using ImGuiNET; namespace Dalamud.Interface.Internal.Windows; @@ -39,7 +48,8 @@ internal class TitleScreenMenuWindow : Window, IDisposable private readonly IFontAtlas privateAtlas; private readonly Lazy myFontHandle; private readonly Lazy shadeTexture; - + private readonly AddonLifecycleEventListener versionStringListener; + private readonly Dictionary shadeEasings = new(); private readonly Dictionary moveEasings = new(); private readonly Dictionary logoEasings = new(); @@ -49,7 +59,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable private InOutCubic? fadeOutEasing; private State state = State.Hide; - + /// /// Initializes a new instance of the class. /// @@ -61,6 +71,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable /// An instance of . /// An instance of . /// An instance of . + /// An instance of . public TitleScreenMenuWindow( ClientState clientState, DalamudConfiguration configuration, @@ -69,7 +80,8 @@ internal class TitleScreenMenuWindow : Window, IDisposable Framework framework, GameGui gameGui, TitleScreenMenu titleScreenMenu, - ConsoleManager consoleManager) + ConsoleManager consoleManager, + AddonLifecycle addonLifecycle) : base( "TitleScreenMenuOverlay", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoScrollbar | @@ -109,6 +121,10 @@ internal class TitleScreenMenuWindow : Window, IDisposable framework.Update += this.FrameworkOnUpdate; this.scopedFinalizer.Add(() => framework.Update -= this.FrameworkOnUpdate); + + this.versionStringListener = new AddonLifecycleEventListener(AddonEvent.PreDraw, "_TitleRevision", this.OnVersionStringDraw); + addonLifecycle.RegisterListener(this.versionStringListener); + this.scopedFinalizer.Add(() => addonLifecycle.UnregisterListener(this.versionStringListener)); } private enum State @@ -414,5 +430,41 @@ internal class TitleScreenMenuWindow : Window, IDisposable this.IsOpen = false; } + private unsafe void OnVersionStringDraw(AddonEvent ev, AddonArgs args) + { + if (args is not AddonDrawArgs setupArgs) return; + + var addon = (AtkUnitBase*)setupArgs.Addon; + var textNode = addon->GetTextNodeById(3); + + // look and feel init. should be harmless to set. + textNode->TextFlags |= (byte)TextFlags.MultiLine; + textNode->AlignmentType = AlignmentType.TopLeft; + + if (!this.configuration.ShowTsm || !this.showTsm.Value) + { + textNode->NodeText.SetString(addon->AtkValues[1].String); + return; + } + + var pm = Service.GetNullable(); + + var pluginCount = pm?.InstalledPlugins.Count(c => c.State == PluginState.Loaded) ?? 0; + + var titleVersionText = new SeStringBuilder() + .AddText(addon->AtkValues[1].GetValueAsString()) + .AddText("\n\n") + .AddUiForeground(SeIconChar.BoxedLetterD.ToIconString(), 539) + .AddUiForeground(561) + .AddText($" Dalamud: {Util.GetScmVersion()}") + .AddText($" - {pluginCount} {(pluginCount != 1 ? "plugins" : "plugin")} loaded") + .AddUiForegroundOff(); + + if (pm?.SafeMode ?? false) + titleVersionText.AddUiForeground(" [SAFE MODE]", 17); + + textNode->NodeText.SetString(titleVersionText.Build().EncodeWithNullTerminator()); + } + private void TitleScreenMenuEntryListChange() => this.privateAtlas.BuildFontsAsync(); }