Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Dalamud Version to the Title Screen #1939

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Dalamud/Interface/Internal/DalamudInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -103,7 +104,8 @@ private DalamudInterface(
ClientState clientState,
TitleScreenMenu titleScreenMenu,
GameGui gameGui,
ConsoleManager consoleManager)
ConsoleManager consoleManager,
AddonLifecycle addonLifecycle)
{
this.dalamud = dalamud;
this.configuration = configuration;
Expand All @@ -129,7 +131,8 @@ private DalamudInterface(
framework,
gameGui,
titleScreenMenu,
consoleManager) { IsOpen = false };
consoleManager,
addonLifecycle) { IsOpen = false };
this.changelogWindow = new ChangelogWindow(
this.titleScreenMenuWindow,
fontAtlasFactory,
Expand Down
58 changes: 55 additions & 3 deletions Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
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;
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;
Expand All @@ -39,7 +48,8 @@ internal class TitleScreenMenuWindow : Window, IDisposable
private readonly IFontAtlas privateAtlas;
private readonly Lazy<IFontHandle> myFontHandle;
private readonly Lazy<IDalamudTextureWrap> shadeTexture;

private readonly AddonLifecycleEventListener versionStringListener;

private readonly Dictionary<Guid, InOutCubic> shadeEasings = new();
private readonly Dictionary<Guid, InOutQuint> moveEasings = new();
private readonly Dictionary<Guid, InOutCubic> logoEasings = new();
Expand All @@ -49,7 +59,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
private InOutCubic? fadeOutEasing;

private State state = State.Hide;

/// <summary>
/// Initializes a new instance of the <see cref="TitleScreenMenuWindow"/> class.
/// </summary>
Expand All @@ -61,6 +71,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
/// <param name="titleScreenMenu">An instance of <see cref="TitleScreenMenu"/>.</param>
/// <param name="gameGui">An instance of <see cref="GameGui"/>.</param>
/// <param name="consoleManager">An instance of <see cref="ConsoleManager"/>.</param>
/// <param name="addonLifecycle">An instance of <see cref="AddonLifecycle"/>.</param>
public TitleScreenMenuWindow(
ClientState clientState,
DalamudConfiguration configuration,
Expand All @@ -69,7 +80,8 @@ public TitleScreenMenuWindow(
Framework framework,
GameGui gameGui,
TitleScreenMenu titleScreenMenu,
ConsoleManager consoleManager)
ConsoleManager consoleManager,
AddonLifecycle addonLifecycle)
: base(
"TitleScreenMenuOverlay",
ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoScrollbar |
Expand Down Expand Up @@ -109,6 +121,10 @@ public TitleScreenMenuWindow(

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
Expand Down Expand Up @@ -414,5 +430,41 @@ private void FrameworkOnUpdate(IFramework unused)
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<PluginManager>.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();
}
Loading