feat: add prettier timestamps

This commit is contained in:
Anna 2022-01-14 18:22:38 -05:00
parent 5ce2cd607d
commit 8a110bdd30
3 changed files with 39 additions and 6 deletions

View File

@ -9,6 +9,7 @@ internal class Configuration : IPluginConfiguration {
public bool HideChat = true; public bool HideChat = true;
public bool NativeItemTooltips = true; public bool NativeItemTooltips = true;
public bool PrettierTimestamps = true;
public bool SidebarTabView; public bool SidebarTabView;
public float FontSize = 17f; public float FontSize = 17f;
public Dictionary<ChatType, uint> ChatColours = new(); public Dictionary<ChatType, uint> ChatColours = new();

View File

@ -172,6 +172,16 @@ internal sealed class ChatLog : IUiComponent {
private void DrawMessageLog(Tab tab, float childHeight, bool switchedTab) { private void DrawMessageLog(Tab tab, float childHeight, bool switchedTab) {
if (ImGui.BeginChild("##chat2-messages", new Vector2(-1, childHeight))) { if (ImGui.BeginChild("##chat2-messages", new Vector2(-1, childHeight))) {
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero); ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero);
var table = tab.DisplayTimestamp && this.Ui.Plugin.Config.PrettierTimestamps;
if (table) {
if (!ImGui.BeginTable("timestamp-table", 2, ImGuiTableFlags.PreciseWidths)) {
goto EndChild;
}
ImGui.TableSetupColumn("timestamps", ImGuiTableColumnFlags.WidthFixed);
ImGui.TableSetupColumn("messages", ImGuiTableColumnFlags.WidthStretch);
}
// var clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper()); // var clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper());
// int numMessages; // int numMessages;
@ -184,11 +194,20 @@ internal sealed class ChatLog : IUiComponent {
if (tab.DisplayTimestamp) { if (tab.DisplayTimestamp) {
var timestamp = message.Date.ToLocalTime().ToString("t"); var timestamp = message.Date.ToLocalTime().ToString("t");
if (table) {
ImGui.TableNextColumn();
ImGui.TextUnformatted(timestamp);
} else {
this.DrawChunk(new TextChunk(null, null, $"[{timestamp}]") { this.DrawChunk(new TextChunk(null, null, $"[{timestamp}]") {
Foreground = 0xFFFFFFFF, Foreground = 0xFFFFFFFF,
}); });
ImGui.SameLine(); ImGui.SameLine();
} }
}
if (table) {
ImGui.TableNextColumn();
}
if (message.Sender.Count > 0) { if (message.Sender.Count > 0) {
this.DrawChunks(message.Sender, true, this.PayloadHandler); this.DrawChunks(message.Sender, true, this.PayloadHandler);
@ -220,10 +239,15 @@ internal sealed class ChatLog : IUiComponent {
// ImGui.SetScrollFromPosY(itemPosY - ImGui.GetWindowPos().Y); // ImGui.SetScrollFromPosY(itemPosY - ImGui.GetWindowPos().Y);
ImGui.SetScrollHereY(1f); ImGui.SetScrollHereY(1f);
} }
}
this.PayloadHandler.Draw(); this.PayloadHandler.Draw();
if (table) {
ImGui.EndTable();
}
}
EndChild:
ImGui.EndChild(); ImGui.EndChild();
} }
@ -421,6 +445,10 @@ internal sealed class ChatLog : IUiComponent {
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero); ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero);
try { try {
for (var i = 0; i < chunks.Count; i++) { for (var i = 0; i < chunks.Count; i++) {
if (chunks[i] is TextChunk text && string.IsNullOrEmpty(text.Content)) {
continue;
}
this.DrawChunk(chunks[i], wrap, handler); this.DrawChunk(chunks[i], wrap, handler);
if (i < chunks.Count - 1) { if (i < chunks.Count - 1) {

View File

@ -13,6 +13,7 @@ internal sealed class Settings : IUiComponent {
private bool _hideChat; private bool _hideChat;
private bool _nativeItemTooltips; private bool _nativeItemTooltips;
private bool _sidebarTabView; private bool _sidebarTabView;
private bool _prettierTimestamps;
private float _fontSize; private float _fontSize;
private Dictionary<ChatType, uint> _chatColours = new(); private Dictionary<ChatType, uint> _chatColours = new();
private List<Tab> _tabs = new(); private List<Tab> _tabs = new();
@ -37,6 +38,7 @@ internal sealed class Settings : IUiComponent {
this._hideChat = config.HideChat; this._hideChat = config.HideChat;
this._nativeItemTooltips = config.NativeItemTooltips; this._nativeItemTooltips = config.NativeItemTooltips;
this._sidebarTabView = config.SidebarTabView; this._sidebarTabView = config.SidebarTabView;
this._prettierTimestamps = config.PrettierTimestamps;
this._fontSize = config.FontSize; this._fontSize = config.FontSize;
this._chatColours = config.ChatColours.ToDictionary(entry => entry.Key, entry => entry.Value); this._chatColours = config.ChatColours.ToDictionary(entry => entry.Key, entry => entry.Value);
this._tabs = config.Tabs.Select(tab => tab.Clone()).ToList(); this._tabs = config.Tabs.Select(tab => tab.Clone()).ToList();
@ -65,6 +67,7 @@ internal sealed class Settings : IUiComponent {
ImGui.Checkbox("Hide chat", ref this._hideChat); ImGui.Checkbox("Hide chat", ref this._hideChat);
ImGui.Checkbox("Show native item tooltips", ref this._nativeItemTooltips); ImGui.Checkbox("Show native item tooltips", ref this._nativeItemTooltips);
ImGui.Checkbox("Show tabs in a sidebar", ref this._sidebarTabView); ImGui.Checkbox("Show tabs in a sidebar", ref this._sidebarTabView);
ImGui.Checkbox("Use modern timestamp layout", ref this._prettierTimestamps);
ImGui.DragFloat("Font size", ref this._fontSize, .0125f, 12f, 36f, "%.1f"); ImGui.DragFloat("Font size", ref this._fontSize, .0125f, 12f, 36f, "%.1f");
if (ImGui.TreeNodeEx("Chat colours")) { if (ImGui.TreeNodeEx("Chat colours")) {
@ -206,6 +209,7 @@ internal sealed class Settings : IUiComponent {
config.HideChat = this._hideChat; config.HideChat = this._hideChat;
config.NativeItemTooltips = this._nativeItemTooltips; config.NativeItemTooltips = this._nativeItemTooltips;
config.SidebarTabView = this._sidebarTabView; config.SidebarTabView = this._sidebarTabView;
config.PrettierTimestamps = this._prettierTimestamps;
config.FontSize = this._fontSize; config.FontSize = this._fontSize;
config.ChatColours = this._chatColours; config.ChatColours = this._chatColours;
config.Tabs = this._tabs; config.Tabs = this._tabs;