- Migrate DB to v2 (Channel)
- Add channel selection to DBViewer
This commit is contained in:
+65
-8
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
using ChatTwo.Code;
|
||||
using ChatTwo.Resources;
|
||||
using ChatTwo.Util;
|
||||
using Dalamud.Interface;
|
||||
@@ -24,10 +25,11 @@ public class DbViewer : Window
|
||||
private int CurrentPage = 1;
|
||||
private string SimpleSearchTerm = "";
|
||||
private bool OnlyCurrentCharacter = true;
|
||||
private readonly Dictionary<ChatType, ChatSource> ChatCodes;
|
||||
|
||||
private bool IsProcessing;
|
||||
private long ProcessingStart = Environment.TickCount64;
|
||||
private (DateTime Min, DateTime Max, int Page, bool Local) LastProcessed;
|
||||
private (DateTime Min, DateTime Max, int Page, bool Local, int ChannelCount) LastProcessed;
|
||||
|
||||
private string MinDateString = "";
|
||||
private string MaxDateString = "";
|
||||
@@ -42,11 +44,12 @@ public class DbViewer : Window
|
||||
public DbViewer(Plugin plugin) : base("DBViewer###chat2-dbviewer")
|
||||
{
|
||||
Plugin = plugin;
|
||||
ChatCodes = TabsUtil.MostlyPlayer;
|
||||
|
||||
DateFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
|
||||
DateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern;
|
||||
|
||||
LastProcessed = (AfterDate, BeforeDate, CurrentPage, OnlyCurrentCharacter);
|
||||
LastProcessed = (AfterDate, BeforeDate, CurrentPage, OnlyCurrentCharacter, ChatCodes.Count);
|
||||
DateReset();
|
||||
|
||||
SizeConstraints = new WindowSizeConstraints
|
||||
@@ -88,6 +91,8 @@ public class DbViewer : Window
|
||||
if (ImGuiUtil.IconButton(FontAwesomeIcon.Recycle))
|
||||
DateReset();
|
||||
ImGuiUtil.DrawArrows(ref CurrentPage, 1, totalPages, spacing);
|
||||
ImGui.SameLine(0, spacing);
|
||||
ChannelSelection();
|
||||
|
||||
var skipText = Language.DbViewer_CharacterOption;
|
||||
var textLength = ImGui.GetTextLineHeight() + ImGui.CalcTextSize(skipText).X + ImGui.GetStyle().ItemInnerSpacing.X + ImGui.GetStyle().FramePadding.X * 2;
|
||||
@@ -107,7 +112,7 @@ public class DbViewer : Window
|
||||
if (DateWidget.Validate(MinimalDate, ref AfterDate, ref BeforeDate))
|
||||
DateRefresh();
|
||||
|
||||
if (!IsProcessing && LastProcessed != (AfterDate, BeforeDate, CurrentPage, OnlyCurrentCharacter))
|
||||
if (!IsProcessing && LastProcessed != (AfterDate, BeforeDate, CurrentPage, OnlyCurrentCharacter, ChatCodes.Count))
|
||||
{
|
||||
// Page hasn't changed, so we reset it back to 1
|
||||
if (LastProcessed.Page == CurrentPage)
|
||||
@@ -116,17 +121,18 @@ public class DbViewer : Window
|
||||
AdjustDates();
|
||||
IsProcessing = true;
|
||||
ProcessingStart = Environment.TickCount64 + 1_000; // + 1 second
|
||||
LastProcessed = (AfterDate, BeforeDate, CurrentPage, OnlyCurrentCharacter);
|
||||
LastProcessed = (AfterDate, BeforeDate, CurrentPage, OnlyCurrentCharacter, ChatCodes.Count);
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
ulong? character = OnlyCurrentCharacter ? Plugin.ClientState.LocalContentId : null;
|
||||
var channels = ChatCodes.Select(c => (uint) c.Key).ToArray();
|
||||
|
||||
// We only want to fetch count if this is the first page
|
||||
if (CurrentPage == 1)
|
||||
Count = Plugin.MessageManager.Store.CountDateRange(AfterDate, BeforeDate, character);
|
||||
Messages = Plugin.MessageManager.Store.GetDateRange(AfterDate, BeforeDate, character, CurrentPage - 1).ToArray();
|
||||
Count = Plugin.MessageManager.Store.CountDateRange(AfterDate, BeforeDate, channels, character);
|
||||
Messages = Plugin.MessageManager.Store.GetDateRange(AfterDate, BeforeDate, channels, character, CurrentPage - 1).ToArray();
|
||||
|
||||
Filter();
|
||||
}
|
||||
@@ -153,11 +159,13 @@ public class DbViewer : Window
|
||||
if (!child.Success)
|
||||
return;
|
||||
|
||||
using var table = ImRaii.Table("##messageHistory", 3, ImGuiTableFlags.Borders | ImGuiTableFlags.RowBg | ImGuiTableFlags.Resizable);
|
||||
using var table = ImRaii.Table("##messageHistory", 4, ImGuiTableFlags.Borders | ImGuiTableFlags.RowBg | ImGuiTableFlags.Resizable);
|
||||
if (!table.Success)
|
||||
return;
|
||||
|
||||
ImGui.TableSetupColumn(Language.DbViewer_TableField_Date, ImGuiTableColumnFlags.WidthFixed);
|
||||
var columnWidth = ImGui.CalcTextSize(Language.DbViewer_TableField_Type);
|
||||
ImGui.TableSetupColumn(Language.DbViewer_TableField_Date, ImGuiTableColumnFlags.WidthFixed | ImGuiTableColumnFlags.NoResize);
|
||||
ImGui.TableSetupColumn(Language.DbViewer_TableField_Type, ImGuiTableColumnFlags.WidthFixed | ImGuiTableColumnFlags.NoResize, columnWidth.X);
|
||||
ImGui.TableSetupColumn(Language.DbViewer_TableField_Sender);
|
||||
ImGui.TableSetupColumn(Language.DbViewer_TableField_Content);
|
||||
|
||||
@@ -167,6 +175,14 @@ public class DbViewer : Window
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted(message.Date.ToLocalTime().ToString(DateTimeFormat));
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
var pos = ImGui.GetCursorPos();
|
||||
ImGuiUtil.CenterText($"{message.Code.Raw}");
|
||||
ImGui.SetCursorPos(pos);
|
||||
ImGui.Dummy(columnWidth);
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(message.Code.Type.Name());
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
Plugin.ChatLogWindow.DrawChunks(message.Sender);
|
||||
|
||||
@@ -175,6 +191,47 @@ public class DbViewer : Window
|
||||
}
|
||||
}
|
||||
|
||||
private void ChannelSelection()
|
||||
{
|
||||
const string addTabPopup = "add-channel-popup";
|
||||
|
||||
if (ImGui.Button("Channels"))
|
||||
ImGui.OpenPopup(addTabPopup);
|
||||
|
||||
using var popup = ImRaii.Popup(addTabPopup);
|
||||
if (!popup.Success)
|
||||
return;
|
||||
|
||||
using var channelNode = ImRaii.TreeNode(Language.Options_Tabs_Channels);
|
||||
if (!channelNode.Success)
|
||||
return;
|
||||
|
||||
foreach (var (header, types) in ChatTypeExt.SortOrder)
|
||||
{
|
||||
using var headerNode = ImRaii.TreeNode(header);
|
||||
if (!headerNode.Success)
|
||||
continue;
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (type.IsGm())
|
||||
continue;
|
||||
|
||||
var enabled = ChatCodes.ContainsKey(type);
|
||||
if (ImGui.Checkbox($"##{type.Name()}", ref enabled))
|
||||
{
|
||||
if (enabled)
|
||||
ChatCodes[type] = ChatSourceExt.All;
|
||||
else
|
||||
ChatCodes.Remove(type);
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted(type.Name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Filter()
|
||||
{
|
||||
if (SimpleSearchTerm == "")
|
||||
|
||||
Reference in New Issue
Block a user