InputPreview prototype
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>1.24.4</Version>
|
<Version>1.25.0</Version>
|
||||||
<TargetFramework>net8.0-windows</TargetFramework>
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|||||||
@@ -112,6 +112,11 @@ internal class Message
|
|||||||
chunk.Message = this;
|
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()
|
private int GenerateHash()
|
||||||
{
|
{
|
||||||
return SortCode.GetHashCode()
|
return SortCode.GetHashCode()
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
public readonly WindowSystem WindowSystem = new(PluginName);
|
public readonly WindowSystem WindowSystem = new(PluginName);
|
||||||
public SettingsWindow SettingsWindow { get; }
|
public SettingsWindow SettingsWindow { get; }
|
||||||
public ChatLogWindow ChatLogWindow { get; }
|
public ChatLogWindow ChatLogWindow { get; }
|
||||||
|
public InputPreview InputPreview { get; }
|
||||||
public CommandHelpWindow CommandHelpWindow { get; }
|
public CommandHelpWindow CommandHelpWindow { get; }
|
||||||
public SeStringDebugger SeStringDebugger { get; }
|
public SeStringDebugger SeStringDebugger { get; }
|
||||||
public DebuggerWindow DebuggerWindow { get; }
|
public DebuggerWindow DebuggerWindow { get; }
|
||||||
@@ -88,12 +89,14 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
|
|
||||||
ChatLogWindow = new ChatLogWindow(this);
|
ChatLogWindow = new ChatLogWindow(this);
|
||||||
SettingsWindow = new SettingsWindow(this);
|
SettingsWindow = new SettingsWindow(this);
|
||||||
|
InputPreview = new InputPreview(ChatLogWindow);
|
||||||
CommandHelpWindow = new CommandHelpWindow(ChatLogWindow);
|
CommandHelpWindow = new CommandHelpWindow(ChatLogWindow);
|
||||||
SeStringDebugger = new SeStringDebugger(this);
|
SeStringDebugger = new SeStringDebugger(this);
|
||||||
DebuggerWindow = new DebuggerWindow(this);
|
DebuggerWindow = new DebuggerWindow(this);
|
||||||
|
|
||||||
WindowSystem.AddWindow(ChatLogWindow);
|
WindowSystem.AddWindow(ChatLogWindow);
|
||||||
WindowSystem.AddWindow(SettingsWindow);
|
WindowSystem.AddWindow(SettingsWindow);
|
||||||
|
WindowSystem.AddWindow(InputPreview);
|
||||||
WindowSystem.AddWindow(CommandHelpWindow);
|
WindowSystem.AddWindow(CommandHelpWindow);
|
||||||
WindowSystem.AddWindow(SeStringDebugger);
|
WindowSystem.AddWindow(SeStringDebugger);
|
||||||
WindowSystem.AddWindow(DebuggerWindow);
|
WindowSystem.AddWindow(DebuggerWindow);
|
||||||
@@ -150,6 +153,7 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
WindowSystem?.RemoveAllWindows();
|
WindowSystem?.RemoveAllWindows();
|
||||||
ChatLogWindow?.Dispose();
|
ChatLogWindow?.Dispose();
|
||||||
SettingsWindow?.Dispose();
|
SettingsWindow?.Dispose();
|
||||||
|
DebuggerWindow?.Dispose();
|
||||||
SeStringDebugger?.Dispose();
|
SeStringDebugger?.Dispose();
|
||||||
LegacyMessageImporterWindow?.Dispose();
|
LegacyMessageImporterWindow?.Dispose();
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ public sealed class ChatLogWindow : Window
|
|||||||
|
|
||||||
public int CursorPos;
|
public int CursorPos;
|
||||||
|
|
||||||
|
public float PosYAboveInput { get; private set; }
|
||||||
public Vector2 LastWindowPos { get; private set; } = Vector2.Zero;
|
public Vector2 LastWindowPos { get; private set; } = Vector2.Zero;
|
||||||
public Vector2 LastWindowSize { 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)
|
if (currentTab > -1 && currentTab < Plugin.Config.Tabs.Count)
|
||||||
activeTab = Plugin.Config.Tabs[currentTab];
|
activeTab = Plugin.Config.Tabs[currentTab];
|
||||||
|
|
||||||
|
PosYAboveInput = ImGui.GetCursorPosY();
|
||||||
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
|
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
|
||||||
{
|
{
|
||||||
if (TellTarget != null)
|
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)
|
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
|
try
|
||||||
{
|
{
|
||||||
tab.MessagesMutex.Wait();
|
tab.MessagesMutex.Wait();
|
||||||
@@ -975,7 +971,6 @@ public sealed class ChatLogWindow : Window
|
|||||||
prevMessage.Height.TryGetValue(tab.Identifier, out var prevHeight);
|
prevMessage.Height.TryGetValue(tab.Identifier, out var prevHeight);
|
||||||
if (prevHeight == null || (prevMessage.IsVisible.TryGetValue(tab.Identifier, out var prevVisible) && prevVisible))
|
if (prevHeight == null || (prevMessage.IsVisible.TryGetValue(tab.Identifier, out var prevVisible) && prevVisible))
|
||||||
{
|
{
|
||||||
Plugin.DebuggerWindow.HeightCalculationsInside++;
|
|
||||||
var newHeight = ImGui.GetCursorPosY() - lastPosY;
|
var newHeight = ImGui.GetCursorPosY() - lastPosY;
|
||||||
|
|
||||||
// Remove the padding from the bottom of the previous row and the top of the current row.
|
// 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 has rendered once
|
||||||
// message isn't visible, so render dummy
|
// message isn't visible, so render dummy
|
||||||
message.Height.TryGetValue(tab.Identifier, out var height);
|
message.Height.TryGetValue(tab.Identifier, out var height);
|
||||||
if (height == null)
|
|
||||||
Plugin.DebuggerWindow.HeightNull++;
|
|
||||||
message.IsVisible.TryGetValue(tab.Identifier, out var visible);
|
message.IsVisible.TryGetValue(tab.Identifier, out var visible);
|
||||||
if (height != null && !visible)
|
if (height != null && !visible)
|
||||||
{
|
{
|
||||||
Plugin.DebuggerWindow.InvisibleMessages++;
|
|
||||||
var beforeDummy = ImGui.GetCursorPos();
|
var beforeDummy = ImGui.GetCursorPos();
|
||||||
|
|
||||||
// skip to the message column for vis test
|
// skip to the message column for vis test
|
||||||
@@ -1057,11 +1049,7 @@ public sealed class ChatLogWindow : Window
|
|||||||
else
|
else
|
||||||
DrawChunks(message.Content, true, handler, lineWidth);
|
DrawChunks(message.Content, true, handler, lineWidth);
|
||||||
|
|
||||||
var vis = ImGui.IsItemVisible();
|
message.IsVisible[tab.Identifier] = ImGui.IsItemVisible();
|
||||||
if (!vis)
|
|
||||||
Plugin.DebuggerWindow.InvisibleAfter++;
|
|
||||||
|
|
||||||
message.IsVisible[tab.Identifier] = vis;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
@@ -11,11 +11,6 @@ public class DebuggerWindow : Window
|
|||||||
private readonly Plugin Plugin;
|
private readonly Plugin Plugin;
|
||||||
private readonly ChatLogWindow ChatLogWindow;
|
private readonly ChatLogWindow ChatLogWindow;
|
||||||
|
|
||||||
public int InvisibleMessages;
|
|
||||||
public int InvisibleAfter;
|
|
||||||
public int HeightNull;
|
|
||||||
public int HeightCalculationsInside;
|
|
||||||
|
|
||||||
public DebuggerWindow(Plugin plugin) : base($"Debugger###chat2-debugger")
|
public DebuggerWindow(Plugin plugin) : base($"Debugger###chat2-debugger")
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
@@ -55,11 +50,5 @@ public class DebuggerWindow : Window
|
|||||||
ImGui.TextUnformatted($"Hovered Item: {ChatLogWindow.PayloadHandler._hoveredItem}");
|
ImGui.TextUnformatted($"Hovered Item: {ChatLogWindow.PayloadHandler._hoveredItem}");
|
||||||
ImGui.TextUnformatted($"Hover Counter: {ChatLogWindow.PayloadHandler._hoverCounter}");
|
ImGui.TextUnformatted($"Hover Counter: {ChatLogWindow.PayloadHandler._hoverCounter}");
|
||||||
ImGui.TextUnformatted($"Last Hover Counter: {ChatLogWindow.PayloadHandler._lastHoverCounter}");
|
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