InputPreview prototype
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Version>1.24.4</Version>
|
||||
<Version>1.25.0</Version>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
@@ -112,6 +112,11 @@ internal class Message
|
||||
chunk.Message = this;
|
||||
}
|
||||
|
||||
internal static Message FakeMessage(List<Chunk> content, ChatCode code)
|
||||
{
|
||||
return new Message(0, 0, code, [], content, new SeString(), new SeString());
|
||||
}
|
||||
|
||||
private int GenerateHash()
|
||||
{
|
||||
return SortCode.GetHashCode()
|
||||
|
||||
@@ -45,6 +45,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
public readonly WindowSystem WindowSystem = new(PluginName);
|
||||
public SettingsWindow SettingsWindow { get; }
|
||||
public ChatLogWindow ChatLogWindow { get; }
|
||||
public InputPreview InputPreview { get; }
|
||||
public CommandHelpWindow CommandHelpWindow { get; }
|
||||
public SeStringDebugger SeStringDebugger { get; }
|
||||
public DebuggerWindow DebuggerWindow { get; }
|
||||
@@ -88,12 +89,14 @@ public sealed class Plugin : IDalamudPlugin
|
||||
|
||||
ChatLogWindow = new ChatLogWindow(this);
|
||||
SettingsWindow = new SettingsWindow(this);
|
||||
InputPreview = new InputPreview(ChatLogWindow);
|
||||
CommandHelpWindow = new CommandHelpWindow(ChatLogWindow);
|
||||
SeStringDebugger = new SeStringDebugger(this);
|
||||
DebuggerWindow = new DebuggerWindow(this);
|
||||
|
||||
WindowSystem.AddWindow(ChatLogWindow);
|
||||
WindowSystem.AddWindow(SettingsWindow);
|
||||
WindowSystem.AddWindow(InputPreview);
|
||||
WindowSystem.AddWindow(CommandHelpWindow);
|
||||
WindowSystem.AddWindow(SeStringDebugger);
|
||||
WindowSystem.AddWindow(DebuggerWindow);
|
||||
@@ -150,6 +153,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
WindowSystem?.RemoveAllWindows();
|
||||
ChatLogWindow?.Dispose();
|
||||
SettingsWindow?.Dispose();
|
||||
DebuggerWindow?.Dispose();
|
||||
SeStringDebugger?.Dispose();
|
||||
LegacyMessageImporterWindow?.Dispose();
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ public sealed class ChatLogWindow : Window
|
||||
|
||||
public int CursorPos;
|
||||
|
||||
public float PosYAboveInput { get; private set; }
|
||||
public Vector2 LastWindowPos { get; private set; } = Vector2.Zero;
|
||||
public Vector2 LastWindowSize { get; private set; } = Vector2.Zero;
|
||||
|
||||
@@ -517,6 +518,7 @@ public sealed class ChatLogWindow : Window
|
||||
if (currentTab > -1 && currentTab < Plugin.Config.Tabs.Count)
|
||||
activeTab = Plugin.Config.Tabs[currentTab];
|
||||
|
||||
PosYAboveInput = ImGui.GetCursorPosY();
|
||||
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
|
||||
{
|
||||
if (TellTarget != null)
|
||||
@@ -896,12 +898,6 @@ public sealed class ChatLogWindow : Window
|
||||
|
||||
private void DrawMessages(Tab tab, PayloadHandler handler, bool isTable, bool moreCompact = false, float oldCellPaddingY = 0)
|
||||
{
|
||||
// TODO Remove when the temp fix is replaced with a perm one
|
||||
Plugin.DebuggerWindow.InvisibleMessages = 0;
|
||||
Plugin.DebuggerWindow.InvisibleAfter = 0;
|
||||
Plugin.DebuggerWindow.HeightNull = 0;
|
||||
Plugin.DebuggerWindow.HeightCalculationsInside = 0;
|
||||
|
||||
try
|
||||
{
|
||||
tab.MessagesMutex.Wait();
|
||||
@@ -975,7 +971,6 @@ public sealed class ChatLogWindow : Window
|
||||
prevMessage.Height.TryGetValue(tab.Identifier, out var prevHeight);
|
||||
if (prevHeight == null || (prevMessage.IsVisible.TryGetValue(tab.Identifier, out var prevVisible) && prevVisible))
|
||||
{
|
||||
Plugin.DebuggerWindow.HeightCalculationsInside++;
|
||||
var newHeight = ImGui.GetCursorPosY() - lastPosY;
|
||||
|
||||
// Remove the padding from the bottom of the previous row and the top of the current row.
|
||||
@@ -991,12 +986,9 @@ public sealed class ChatLogWindow : Window
|
||||
// message has rendered once
|
||||
// message isn't visible, so render dummy
|
||||
message.Height.TryGetValue(tab.Identifier, out var height);
|
||||
if (height == null)
|
||||
Plugin.DebuggerWindow.HeightNull++;
|
||||
message.IsVisible.TryGetValue(tab.Identifier, out var visible);
|
||||
if (height != null && !visible)
|
||||
{
|
||||
Plugin.DebuggerWindow.InvisibleMessages++;
|
||||
var beforeDummy = ImGui.GetCursorPos();
|
||||
|
||||
// skip to the message column for vis test
|
||||
@@ -1057,11 +1049,7 @@ public sealed class ChatLogWindow : Window
|
||||
else
|
||||
DrawChunks(message.Content, true, handler, lineWidth);
|
||||
|
||||
var vis = ImGui.IsItemVisible();
|
||||
if (!vis)
|
||||
Plugin.DebuggerWindow.InvisibleAfter++;
|
||||
|
||||
message.IsVisible[tab.Identifier] = vis;
|
||||
message.IsVisible[tab.Identifier] = ImGui.IsItemVisible();
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -11,11 +11,6 @@ public class DebuggerWindow : Window
|
||||
private readonly Plugin Plugin;
|
||||
private readonly ChatLogWindow ChatLogWindow;
|
||||
|
||||
public int InvisibleMessages;
|
||||
public int InvisibleAfter;
|
||||
public int HeightNull;
|
||||
public int HeightCalculationsInside;
|
||||
|
||||
public DebuggerWindow(Plugin plugin) : base($"Debugger###chat2-debugger")
|
||||
{
|
||||
Plugin = plugin;
|
||||
@@ -55,11 +50,5 @@ public class DebuggerWindow : Window
|
||||
ImGui.TextUnformatted($"Hovered Item: {ChatLogWindow.PayloadHandler._hoveredItem}");
|
||||
ImGui.TextUnformatted($"Hover Counter: {ChatLogWindow.PayloadHandler._hoverCounter}");
|
||||
ImGui.TextUnformatted($"Last Hover Counter: {ChatLogWindow.PayloadHandler._lastHoverCounter}");
|
||||
ImGui.NewLine();
|
||||
ImGui.NewLine();
|
||||
ImGui.TextUnformatted($"Invisible Messages: {InvisibleMessages}");
|
||||
ImGui.TextUnformatted($"Invisible After: {InvisibleAfter}");
|
||||
ImGui.TextUnformatted($"Height was null: {HeightNull}");
|
||||
ImGui.TextUnformatted($"Actual Height Calculations {HeightCalculationsInside}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using System.Text;
|
||||
using ChatTwo.Code;
|
||||
using ChatTwo.Util;
|
||||
using Dalamud.Game.Text;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace ChatTwo.Ui;
|
||||
|
||||
public class InputPreview : Window
|
||||
{
|
||||
private ChatLogWindow LogWindow { get; }
|
||||
|
||||
private float Height;
|
||||
private float AppliedHeight;
|
||||
|
||||
internal InputPreview(ChatLogWindow logWindow) : base("##chat2-inputpreview")
|
||||
{
|
||||
LogWindow = logWindow;
|
||||
|
||||
Flags = ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoMove |
|
||||
ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.AlwaysAutoResize;
|
||||
|
||||
RespectCloseHotkey = false;
|
||||
DisableWindowSounds = true;
|
||||
IsOpen = true;
|
||||
}
|
||||
|
||||
public override void PreDraw()
|
||||
{
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
// Sizes don't use much precision
|
||||
if (AppliedHeight == Height)
|
||||
return;
|
||||
|
||||
AppliedHeight = Height;
|
||||
|
||||
var width = LogWindow.LastWindowSize.X;
|
||||
var pos = LogWindow.LastWindowPos;
|
||||
|
||||
Size = LogWindow.LastWindowSize with { X = width };
|
||||
|
||||
Position = pos with { Y = pos.Y - Height };
|
||||
PositionCondition = ImGuiCond.Always;
|
||||
}
|
||||
|
||||
public override bool DrawConditions()
|
||||
{
|
||||
return !string.IsNullOrEmpty(LogWindow.Chat);
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
var content = LogWindow.Chat.Trim();
|
||||
var bytes = Encoding.UTF8.GetBytes(content);
|
||||
AutoTranslate.ReplaceWithPayload(Plugin.DataManager, ref bytes);
|
||||
|
||||
var seString = SeString.Parse(bytes);
|
||||
var chunks = ChunkUtil.ToChunks(seString, ChunkSource.Content, ChatType.Say).ToList();
|
||||
var encodedChunks = Message.FakeMessage(chunks, new ChatCode((ushort) XivChatType.Say));
|
||||
|
||||
var before = ImGui.GetCursorPosY();
|
||||
LogWindow.DrawChunks(encodedChunks.Content);
|
||||
var after = ImGui.GetCursorPosY();
|
||||
|
||||
Height = after - before + ImGui.GetStyle().WindowPadding.Y;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user