feat: add chat database

This commit is contained in:
Anna
2022-02-13 04:36:08 -05:00
parent 18c311ace5
commit 9b7b84a58d
25 changed files with 476 additions and 95 deletions
+19 -9
View File
@@ -53,14 +53,28 @@ internal sealed class ChatLog : IUiComponent {
this._fontIcon = this.Ui.Plugin.DataManager.GetImGuiTexture("common/font/fonticon_ps5.tex");
this.Ui.Plugin.Functions.Chat.Activated += this.Activated;
this.Ui.Plugin.ClientState.Login += this.Login;
this.Ui.Plugin.ClientState.Logout += this.Logout;
}
public void Dispose() {
this.Ui.Plugin.ClientState.Logout -= this.Logout;
this.Ui.Plugin.ClientState.Login -= this.Login;
this.Ui.Plugin.Functions.Chat.Activated -= this.Activated;
this._fontIcon?.Dispose();
this.Ui.Plugin.CommandManager.RemoveHandler("/clearlog2");
}
private void Logout(object? sender, EventArgs e) {
foreach (var tab in this.Ui.Plugin.Config.Tabs) {
tab.Clear();
}
}
private void Login(object? sender, EventArgs e) {
this.Ui.Plugin.Store.FilterAllTabs(false);
}
private void Activated(ChatActivatedArgs args) {
this.Activate = true;
if (args.AddIfNotPresent != null && !this.Chat.Contains(args.AddIfNotPresent)) {
@@ -126,10 +140,6 @@ internal sealed class ChatLog : IUiComponent {
private void ClearLog(string command, string arguments) {
switch (arguments) {
case "all":
using (var messages = this.Ui.Plugin.Store.GetMessages()) {
messages.Messages.Clear();
}
foreach (var tab in this.Ui.Plugin.Config.Tabs) {
tab.Clear();
}
@@ -374,10 +384,10 @@ internal sealed class ChatLog : IUiComponent {
?.RawString ?? "???";
this.DrawChunks(new Chunk[] {
new TextChunk(null, null, "Tell "),
new TextChunk(null, null, this._tellTarget.Name),
new IconChunk(null, null, BitmapFontIcon.CrossWorld),
new TextChunk(null, null, world),
new TextChunk(ChunkSource.None, null, "Tell "),
new TextChunk(ChunkSource.None, null, this._tellTarget.Name),
new IconChunk(ChunkSource.None, null, BitmapFontIcon.CrossWorld),
new TextChunk(ChunkSource.None, null, world),
});
} else if (this._tempChannel != null) {
if (this._tempChannel.Value.IsLinkshell()) {
@@ -626,7 +636,7 @@ internal sealed class ChatLog : IUiComponent {
if (table) {
ImGui.TextUnformatted(timestamp);
} else {
this.DrawChunk(new TextChunk(null, null, $"[{timestamp}]") {
this.DrawChunk(new TextChunk(ChunkSource.None, null, $"[{timestamp}]") {
Foreground = 0xFFFFFFFF,
});
ImGui.SameLine();
+1 -1
View File
@@ -50,7 +50,7 @@ internal class CommandHelp {
return;
}
this.Log.DrawChunks(ChunkUtil.ToChunks(this.Command.Description.ToDalamudString(), null).ToList());
this.Log.DrawChunks(ChunkUtil.ToChunks(this.Command.Description.ToDalamudString(), ChunkSource.None, null).ToList());
ImGui.End();
}
+4 -1
View File
@@ -26,6 +26,7 @@ internal sealed class Settings : IUiComponent {
new Ui.SettingsTabs.Fonts(this.Mutable),
new ChatColours(this.Mutable, this.Ui.Plugin),
new Tabs(this.Mutable),
new Database(this.Mutable, this.Ui.Plugin.Store),
new Miscellaneous(this.Mutable),
new About(),
};
@@ -70,9 +71,11 @@ internal sealed class Settings : IUiComponent {
ImGui.TableNextColumn();
var changed = false;
for (var i = 0; i < this.Tabs.Count; i++) {
if (ImGui.Selectable($"{this.Tabs[i].Name}###tab-{i}", this._currentTab == i)) {
this._currentTab = i;
changed = true;
}
}
@@ -84,7 +87,7 @@ internal sealed class Settings : IUiComponent {
- ImGui.GetStyle().ItemInnerSpacing.Y * 2
- ImGui.CalcTextSize("A").Y;
if (ImGui.BeginChild("##chat2-settings", new Vector2(-1, height))) {
this.Tabs[this._currentTab].Draw();
this.Tabs[this._currentTab].Draw(changed);
ImGui.EndChild();
}
+1 -1
View File
@@ -29,7 +29,7 @@ internal sealed class About : ISettingsTab {
this._translators.Sort((a, b) => string.Compare(a.ToLowerInvariant(), b.ToLowerInvariant(), StringComparison.Ordinal));
}
public void Draw() {
public void Draw(bool changed) {
ImGui.PushTextWrapPos();
ImGui.TextUnformatted(string.Format(Language.Options_About_Opening, Plugin.PluginName));
+1 -1
View File
@@ -32,7 +32,7 @@ internal sealed class ChatColours : ISettingsTab {
#endif
}
public void Draw() {
public void Draw(bool changed) {
foreach (var (_, types) in ChatTypeExt.SortOrder) {
foreach (var type in types) {
if (ImGuiUtil.IconButton(FontAwesomeIcon.UndoAlt, $"{type}", Language.Options_ChatColours_Reset)) {
+60
View File
@@ -0,0 +1,60 @@
using ChatTwo.Resources;
using ChatTwo.Util;
using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
internal sealed class Database : ISettingsTab {
private Configuration Mutable { get; }
private Store Store { get; }
public string Name => Language.Options_Database_Tab + "###tabs-database";
internal Database(Configuration mutable, Store store) {
this.Store = store;
this.Mutable = mutable;
}
private bool _showAdvanced;
public void Draw(bool changed) {
if (changed) {
this._showAdvanced = ImGui.GetIO().KeyShift;
}
ImGuiUtil.OptionCheckbox(ref this.Mutable.DatabaseBattleMessages, Language.Options_DatabaseBattleMessages_Name, Language.Options_DatabaseBattleMessages_Description);
ImGui.Spacing();
if (ImGuiUtil.OptionCheckbox(ref this.Mutable.LoadPreviousSession, Language.Options_LoadPreviousSession_Name, Language.Options_LoadPreviousSession_Description)) {
if (this.Mutable.LoadPreviousSession) {
this.Mutable.FilterIncludePreviousSessions = true;
}
}
ImGui.Spacing();
if (ImGuiUtil.OptionCheckbox(ref this.Mutable.FilterIncludePreviousSessions, Language.Options_FilterIncludePreviousSessions_Name, Language.Options_FilterIncludePreviousSessions_Description)) {
if (!this.Mutable.FilterIncludePreviousSessions) {
this.Mutable.LoadPreviousSession = false;
}
}
ImGui.Spacing();
if (this._showAdvanced && ImGui.TreeNodeEx("Advanced")) {
ImGui.PushTextWrapPos();
ImGuiUtil.WarningText("Do not click these buttons unless you know what you're doing.");
if (ImGui.Button("Checkpoint")) {
this.Store.Database.Checkpoint();
}
if (ImGui.Button("Rebuild")) {
this.Store.Database.Rebuild();
}
ImGui.PopTextWrapPos();
ImGui.TreePop();
}
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ internal sealed class Display : ISettingsTab {
this.Mutable = mutable;
}
public void Draw() {
public void Draw(bool changed) {
ImGui.PushTextWrapPos();
ImGuiUtil.OptionCheckbox(ref this.Mutable.HideChat, Language.Options_HideChat_Name, Language.Options_HideChat_Description);
+2 -2
View File
@@ -21,8 +21,8 @@ public class Fonts : ISettingsTab {
this.JpFonts = Ui.Fonts.GetJpFonts();
}
public void Draw() {
if (ImGui.IsWindowAppearing()) {
public void Draw(bool changed) {
if (changed) {
this.UpdateFonts();
}
+1 -1
View File
@@ -2,5 +2,5 @@
internal interface ISettingsTab {
string Name { get; }
void Draw();
void Draw(bool changed);
}
+1 -1
View File
@@ -13,7 +13,7 @@ internal sealed class Miscellaneous : ISettingsTab {
this.Mutable = mutable;
}
public void Draw() {
public void Draw(bool changed) {
if (ImGuiUtil.BeginComboVertical(Language.Options_Language_Name, this.Mutable.LanguageOverride.Name())) {
foreach (var language in Enum.GetValues<LanguageOverride>()) {
if (ImGui.Selectable(language.Name())) {
+1 -1
View File
@@ -17,7 +17,7 @@ internal sealed class Tabs : ISettingsTab {
this.Mutable = mutable;
}
public void Draw() {
public void Draw(bool changed) {
const string addTabPopup = "add-tab-popup";
if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: Language.Options_Tabs_Add)) {