Don't encode the preview message every frame
This commit is contained in:
@@ -67,7 +67,9 @@ public sealed class ChatLogWindow : Window
|
|||||||
private int AutoCompleteSelection;
|
private int AutoCompleteSelection;
|
||||||
private bool AutoCompleteShouldScroll;
|
private bool AutoCompleteShouldScroll;
|
||||||
|
|
||||||
|
private int LastLength;
|
||||||
private float PreviewHeight;
|
private float PreviewHeight;
|
||||||
|
private Message? PreviewMessage;
|
||||||
|
|
||||||
public int CursorPos;
|
public int CursorPos;
|
||||||
|
|
||||||
@@ -518,16 +520,19 @@ public sealed class ChatLogWindow : Window
|
|||||||
WasDocked = ImGui.IsWindowDocked();
|
WasDocked = ImGui.IsWindowDocked();
|
||||||
|
|
||||||
// We Predraw this once to get the actual height :HideThePain:
|
// We Predraw this once to get the actual height :HideThePain:
|
||||||
// TODO: I hate this predraw thing
|
|
||||||
PreviewHeight = 0;
|
PreviewHeight = 0;
|
||||||
Message? predrawnMessage = null;
|
|
||||||
if (Plugin.Config.PreviewPosition is PreviewPosition.Inside && !string.IsNullOrEmpty(Chat))
|
if (Plugin.Config.PreviewPosition is PreviewPosition.Inside && !string.IsNullOrEmpty(Chat))
|
||||||
{
|
{
|
||||||
var bytes = Encoding.UTF8.GetBytes(Chat.Trim());
|
if (PreviewMessage == null || LastLength != Chat.Length)
|
||||||
AutoTranslate.ReplaceWithPayload(Plugin.DataManager, ref bytes);
|
{
|
||||||
|
LastLength = Chat.Length;
|
||||||
|
|
||||||
var chunks = ChunkUtil.ToChunks(SeString.Parse(bytes), ChunkSource.Content, ChatType.Say).ToList();
|
var bytes = Encoding.UTF8.GetBytes(Chat.Trim());
|
||||||
predrawnMessage = Message.FakeMessage(chunks, new ChatCode((ushort) XivChatType.Say));
|
AutoTranslate.ReplaceWithPayload(Plugin.DataManager, ref bytes);
|
||||||
|
|
||||||
|
var chunks = ChunkUtil.ToChunks(SeString.Parse(bytes), ChunkSource.Content, ChatType.Say).ToList();
|
||||||
|
PreviewMessage = Message.FakeMessage(chunks, new ChatCode((ushort)XivChatType.Say));
|
||||||
|
}
|
||||||
|
|
||||||
var pos = ImGui.GetCursorPos();
|
var pos = ImGui.GetCursorPos();
|
||||||
ImGui.SetCursorPos(new Vector2(-500, -500));
|
ImGui.SetCursorPos(new Vector2(-500, -500));
|
||||||
@@ -535,13 +540,18 @@ public sealed class ChatLogWindow : Window
|
|||||||
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
|
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
|
||||||
{
|
{
|
||||||
ImGui.TextUnformatted(Language.Options_Preview_Header);
|
ImGui.TextUnformatted(Language.Options_Preview_Header);
|
||||||
DrawChunks(predrawnMessage.Content);
|
DrawChunks(PreviewMessage.Content);
|
||||||
}
|
}
|
||||||
var after = ImGui.GetCursorPosY();
|
var after = ImGui.GetCursorPosY();
|
||||||
ImGui.SetCursorPos(pos);
|
ImGui.SetCursorPos(pos);
|
||||||
|
|
||||||
PreviewHeight = after - before;
|
PreviewHeight = after - before;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LastLength = 0;
|
||||||
|
PreviewMessage = null;
|
||||||
|
}
|
||||||
|
|
||||||
var currentTab = Plugin.Config.SidebarTabView ? DrawTabSidebar() : DrawTabBar();
|
var currentTab = Plugin.Config.SidebarTabView ? DrawTabSidebar() : DrawTabBar();
|
||||||
|
|
||||||
@@ -549,12 +559,12 @@ 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];
|
||||||
|
|
||||||
if (predrawnMessage != null)
|
if (PreviewMessage != null)
|
||||||
{
|
{
|
||||||
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
|
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
|
||||||
{
|
{
|
||||||
ImGui.TextUnformatted("Text Preview:");
|
ImGui.TextUnformatted("Text Preview:");
|
||||||
DrawChunks(predrawnMessage.Content);
|
DrawChunks(PreviewMessage.Content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user