Skip to content

Commit

Permalink
title screen menu: some visual fixes
Browse files Browse the repository at this point in the history
Use SeStringRenderer to render menu entries
Clamp alpha values to avoid flickering
  • Loading branch information
goaaats committed Dec 29, 2024
1 parent c79b1cd commit 2e77e90
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Dalamud.Game.Gui;
using Dalamud.Game.Text;
using Dalamud.Interface.Animation.EasingFunctions;
using Dalamud.Interface.ImGuiSeStringRenderer;
using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.ManagedFontAtlas.Internals;
using Dalamud.Interface.Textures.TextureWraps;
Expand Down Expand Up @@ -50,19 +51,19 @@ internal class TitleScreenMenuWindow : Window, IDisposable
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();

private readonly IConsoleVariable<bool> showTsm;

private InOutCubic? fadeOutEasing;

private State state = State.Hide;

private int lastLoadedPluginCount = -1;

/// <summary>
/// Initializes a new instance of the <see cref="TitleScreenMenuWindow"/> class.
/// </summary>
Expand Down Expand Up @@ -91,7 +92,7 @@ public TitleScreenMenuWindow(
ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoNavFocus)
{
this.showTsm = consoleManager.AddVariable("dalamud.show_tsm", "Show the Title Screen Menu", true);

this.clientState = clientState;
this.configuration = configuration;
this.gameGui = gameGui;
Expand Down Expand Up @@ -124,7 +125,7 @@ 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));
Expand All @@ -136,7 +137,7 @@ private enum State
Show,
FadeOut,
}

/// <summary>
/// Gets or sets a value indicating whether drawing is allowed.
/// </summary>
Expand Down Expand Up @@ -165,7 +166,7 @@ public override void Draw()
{
if (!this.AllowDrawing || !this.showTsm.Value)
return;

var scale = ImGui.GetIO().FontGlobalScale;
var entries = this.titleScreenMenu.PluginEntries;

Expand All @@ -174,7 +175,7 @@ public override void Draw()
ImGuiHoveredFlags.AllowWhenBlockedByActiveItem);

Service<InterfaceManager>.Get().OverrideGameCursor = !hovered;

switch (this.state)
{
case State.Show:
Expand Down Expand Up @@ -251,7 +252,7 @@ public override void Draw()

this.fadeOutEasing.Update();

using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.Value))
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)Math.Max(this.fadeOutEasing.Value, 0)))
{
var i = 0;
foreach (var entry in entries)
Expand Down Expand Up @@ -392,21 +393,14 @@ private bool DrawEntry(

if (overrideAlpha)
{
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, showText ? (float)logoEasing.Value : 0f);
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, showText ? (float)Math.Min(logoEasing.Value, 1) : 0f);
}

// Drop shadow
using (ImRaii.PushColor(ImGuiCol.Text, 0xFF000000))
{
for (int i = 0, to = (int)Math.Ceiling(1 * scale); i < to; i++)
{
ImGui.SetCursorPos(new Vector2(cursor.X, cursor.Y + i));
ImGui.Text(entry.Name);
}
}

ImGui.SetCursorPos(cursor);
ImGui.Text(entry.Name);
var renderStyle = default(SeStringDrawParams);
renderStyle.FontSize = TargetFontSizePx;
ImGuiHelpers.CompileSeStringWrapped($"<edge(1)><shadow(1)>{entry.Name}<shadow(0)><edge(0)>", renderStyle);

if (overrideAlpha)
{
Expand Down Expand Up @@ -439,7 +433,7 @@ private unsafe void OnVersionStringDraw(AddonEvent ev, AddonArgs args)

var addon = (AtkUnitBase*)drawArgs.Addon;
var textNode = addon->GetTextNodeById(3);

// look and feel init. should be harmless to set.
textNode->TextFlags |= (byte)TextFlags.MultiLine;
textNode->AlignmentType = AlignmentType.TopLeft;
Expand Down

0 comments on commit 2e77e90

Please sign in to comment.