diff --git a/WhoSaidWhatNow/Objects/ChatEntry.cs b/WhoSaidWhatNow/Objects/ChatEntry.cs index 549f0a1..e1e8727 100644 --- a/WhoSaidWhatNow/Objects/ChatEntry.cs +++ b/WhoSaidWhatNow/Objects/ChatEntry.cs @@ -26,7 +26,7 @@ public string CreateMessage(string tag) { string time = this.Time.ToShortTimeString(); string sender = this.Sender.Name + "" + this.Sender.Server; - string msg = this.Message; + string msg = this.Message.Trim(); return $"[{time}]" + String.Format(tag, sender, msg); } diff --git a/WhoSaidWhatNow/Plugin.cs b/WhoSaidWhatNow/Plugin.cs index 343cc96..60bbda3 100644 --- a/WhoSaidWhatNow/Plugin.cs +++ b/WhoSaidWhatNow/Plugin.cs @@ -4,6 +4,7 @@ using Dalamud.Game.ClientState.Objects; using Dalamud.Game.Command; using Dalamud.Game.Gui; +using Dalamud.Interface.ImGuiFileDialog; using Dalamud.Interface.Windowing; using Dalamud.IoC; using Dalamud.Plugin; @@ -61,6 +62,8 @@ public sealed class Plugin : IDalamudPlugin [RequiredVersion("1.0")] public static ObjectTable ObjectTable { get; private set; } = null!; + public FileDialogManager FileDialogManager { get; set; } = null!; + internal ChatListener ChatListener { get; private set; } = null!; public PlayerService PlayerService { get; set; } = null!; @@ -77,6 +80,7 @@ public Plugin() // setup UI this.MainWindow = new MainWindow(this); this.ConfigWindow = new ConfigWindow(this); + this.FileDialogManager = new FileDialogManager(); this.WindowSystem = new WindowSystem("WhoSaidWhatNow"); this.WindowSystem.AddWindow(this.ConfigWindow); @@ -84,6 +88,7 @@ public Plugin() PluginInterface.UiBuilder.Draw += DrawUI; PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI; + PluginInterface.UiBuilder.Draw += FileDialogManager.Draw; // add events/listeners Plugin.ClientState.Login += OnLogin; @@ -96,6 +101,7 @@ public Plugin() { HelpMessage = "Open main window" }); + } //TODO: make sure we're disposing of everything we need to appropriately @@ -104,6 +110,7 @@ public void Dispose() ChatListener.Dispose(); PluginInterface.UiBuilder.Draw -= DrawUI; PluginInterface.UiBuilder.OpenConfigUi -= DrawConfigUI; + PluginInterface.UiBuilder.Draw -= FileDialogManager.Draw; WindowSystem.RemoveAllWindows(); CommandManager.RemoveHandler(COMMAND); Plugin.ClientState.Login -= OnLogin; diff --git a/WhoSaidWhatNow/Services/FileService.cs b/WhoSaidWhatNow/Services/FileService.cs new file mode 100644 index 0000000..ce86aa2 --- /dev/null +++ b/WhoSaidWhatNow/Services/FileService.cs @@ -0,0 +1,111 @@ +using Dalamud.DrunkenToad; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using WhoSaidWhatNow.Objects; + +namespace WhoSaidWhatNow.Services +{ + public class FileService + { + /// + /// OpenFileDialog for individual + /// + /// the plugin + /// player name + public static void OpenFileDialog(Plugin plugin, string playerName) + { + plugin.FileDialogManager.SaveFileDialog("Save log...", "Text File{.txt}", + Regex.Replace(playerName, "[^a-zA-Z0-9]", String.Empty) + "-" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", + ".txt", (isOk, selectedFile) => + { + if (isOk) + { + FileService.SaveIndividualLog(selectedFile); + } + }); + } + + /// + /// OpenFileDialog for groups + /// + /// the plugin + /// KeyValuePair string for group name, Dictionary for contents of group + public static void OpenFileDialog(Plugin plugin, KeyValuePair PLAYERS)> group) + { + plugin.FileDialogManager.SaveFileDialog("Save log...", "Text File{.txt}", + Regex.Replace(group.Key, "[^a-zA-Z0-9]", String.Empty) + "-" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", + ".txt", (isOk, selectedFile) => + { + if (isOk) + { + FileService.SaveGroupLog(selectedFile, group.Value.PLAYERS); + } + }); + } + + /// + /// Save individual character log to file + /// + /// file path passed from save file dialog + public static void SaveIndividualLog(string path) + { + try + { + using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, false)) + { + foreach (var c in from KeyValuePair c in Plugin.ChatEntries + where Plugin.Config.ChannelToggles[c.Value.Type] == true && c.Value.Sender.Name.Contains(Plugin.SelectedPlayer.Name) + select c) + { + string tag = Plugin.Config.Formats[c.Value.Type]; + file.WriteLine(c.Value.CreateMessage(tag)); + } + ChatGuiExtensions.PluginPrint(Plugin.ChatGui, "Successfully saved log: " + path); + } + } + catch + { + ChatGuiExtensions.PluginPrint(Plugin.ChatGui, "Failed to save log."); + } + } + + + /// + /// Save group log to file + /// + /// file path passed from save file dialog + /// passed dictionary of players + public static void SaveGroupLog(string path, Dictionary players) + { + try + { + using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, false)) + { + foreach (var c in Plugin.ChatEntries) + { + // if we are displaying this type of message; + if (Plugin.Config.ChannelToggles[c.Value.Type] == true) + { + // and if the player is among the tracked; + var p = Plugin.Players.Find(p => c.Value.Sender.Name.Contains(p.Name)); + if (players[p!]) + { + string tag = Plugin.Config.Formats[c.Value.Type]; + file.WriteLine(c.Value.CreateMessage(tag)); + } + } + } + + ChatGuiExtensions.PluginPrint(Plugin.ChatGui, "Successfully saved log: " + path); + } + } + catch + { + ChatGuiExtensions.PluginPrint(Plugin.ChatGui, "Failed to save log."); + } + } + + } +} diff --git a/WhoSaidWhatNow/WhoSaidWhatNow.json b/WhoSaidWhatNow/WhoSaidWhatNow.json index 0824524..ec129bd 100644 --- a/WhoSaidWhatNow/WhoSaidWhatNow.json +++ b/WhoSaidWhatNow/WhoSaidWhatNow.json @@ -4,8 +4,8 @@ "Punchline": "Per character chat history plugin.", "Description": "Per character chat history plugin, evolution of Maia-Everett/dalamud-snooper.\n Main command /whowhat", "InternalName": "WhoSaidWhatNow", - "AssemblyVersion": "0.1.1", - "TestingAssemblyVersion": "0.1.1", + "AssemblyVersion": "0.2.1", + "TestingAssemblyVersion": "0.2.1", "ApplicableVersion": "any", "RepoUrl": "https://github.com/perappu/WhoSaidWhatNow", "DalamudApiLevel": 8, diff --git a/WhoSaidWhatNow/Windows/MainWindow.cs b/WhoSaidWhatNow/Windows/MainWindow.cs index 90f9f21..f22326f 100644 --- a/WhoSaidWhatNow/Windows/MainWindow.cs +++ b/WhoSaidWhatNow/Windows/MainWindow.cs @@ -138,7 +138,7 @@ public void AddPlayerSelectable(Player player) { ImGui.BeginGroup(); - if (ImGui.Selectable("###WhoSaidWhatNow_Player_Selectable_" + player.Name, true, ImGuiSelectableFlags.None)) + if (ImGui.Selectable("###WhoSaidWhatNow_Player_Selectable_" + player.Name, player.Name.Equals(Plugin.SelectedPlayer?.Name), ImGuiSelectableFlags.None)) { ToggleWindowOpen(player); } @@ -185,10 +185,10 @@ public override void Draw() //INDIVIDUAL TAB ImGui.BeginTabBar("###WhoSaidWhatNow_Tab_Bar"); - var individual = new TabIndividual(this); + var individual = new TabIndividual(this, plugin); //GROUP TAB - var groups = new TabGroups(this); + var groups = new TabGroups(this, plugin); ImGui.EndTabBar(); diff --git a/WhoSaidWhatNow/Windows/TabGroups.cs b/WhoSaidWhatNow/Windows/TabGroups.cs index 47ff959..7584091 100644 --- a/WhoSaidWhatNow/Windows/TabGroups.cs +++ b/WhoSaidWhatNow/Windows/TabGroups.cs @@ -6,16 +6,16 @@ using WhoSaidWhatNow; using WhoSaidWhatNow.Windows; using System.Linq; - +using System.Text.RegularExpressions; +using WhoSaidWhatNow.Services; public class TabGroups { private static int counter = 1; - public TabGroups(MainWindow main) + public TabGroups(MainWindow main, Plugin plugin) { - if (ImGui.BeginTabItem("Groups")) { main.toggleWindow(true); @@ -55,7 +55,25 @@ public TabGroups(MainWindow main) ImGui.SameLine(); // construct chatlog. - ImGui.BeginChild(MainWindow.ID_PANEL_RIGHT, new Vector2(0, 0), true); + ImGui.BeginChild(MainWindow.ID_PANEL_RIGHT, new Vector2(0, 0), true, ImGuiWindowFlags.MenuBar); + + // add menu bar with chat log button + if (ImGui.BeginMenuBar()) + { + //push font to make our menus with FA icons + ImGui.PushFont(UiBuilder.IconFont); + if (ImGui.MenuItem(FontAwesomeIcon.Save.ToIconString())) + { + FileService.OpenFileDialog(plugin, g); + } + ImGui.PopFont(); + if (ImGui.IsItemHovered()) + { + ImGui.SetTooltip("Save log to .txt file"); + } + ImGui.EndMenuBar(); + } + ImGui.EndChild(); ImGui.BeginChild(MainWindow.ID_PANEL_RIGHT); diff --git a/WhoSaidWhatNow/Windows/TabIndividual.cs b/WhoSaidWhatNow/Windows/TabIndividual.cs index a3eee36..e2c4efd 100644 --- a/WhoSaidWhatNow/Windows/TabIndividual.cs +++ b/WhoSaidWhatNow/Windows/TabIndividual.cs @@ -1,11 +1,11 @@ using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Interface; -using Dalamud.Logging; using ImGuiNET; using System; using System.Collections.Generic; using System.Linq; using System.Numerics; +using System.Text.RegularExpressions; using WhoSaidWhatNow.Objects; using WhoSaidWhatNow.Services; @@ -13,7 +13,7 @@ namespace WhoSaidWhatNow.Windows; public class TabIndividual { - public TabIndividual(MainWindow mainWindow) + public TabIndividual(MainWindow mainWindow, Plugin plugin) { if (ImGui.BeginTabItem("Individual")) @@ -32,31 +32,65 @@ public TabIndividual(MainWindow mainWindow) if (ImGui.BeginMenuBar()) { ImGui.BeginDisabled(!(Plugin.TargetManager.Target != null && Plugin.TargetManager.Target.ObjectKind == ObjectKind.Player)); - if (ImGui.MenuItem("Add Target")) + //push font to make our menus with FA icons + ImGui.PushFont(UiBuilder.IconFont); + if (ImGui.MenuItem(FontAwesomeIcon.UserPlus.ToIconString())) { PlayerService.AddPlayer(Plugin.TargetManager.Target); } + ImGui.PopFont(); + if (ImGui.IsItemHovered()) + { + ImGui.SetTooltip("Add currently targeted player"); + } + ImGui.EndDisabled(); if (Plugin.SelectedPlayer is not null) { ImGui.BeginDisabled(Plugin.SelectedPlayer.RemoveDisabled); - if (ImGui.MenuItem("Remove Target")) + ImGui.PushFont(UiBuilder.IconFont); + if (ImGui.MenuItem(FontAwesomeIcon.UserMinus.ToIconString())) { mainWindow.RemovePlayer(); } + ImGui.PopFont(); + if (ImGui.IsItemHovered()) + { + ImGui.SetTooltip("Remove currently opened player"); + } ImGui.EndDisabled(); } - - ImGui.EndMenuBar(); + ImGui.EndMenuBar(); } - + ImGui.EndChild(); ImGui.SameLine(); - ImGui.BeginChild(MainWindow.ID_PANEL_RIGHT, new Vector2(0, 0), true); + + //initialize right window with menu bar + ImGui.BeginChild(MainWindow.ID_PANEL_RIGHT, new Vector2(0, 0), true, ImGuiWindowFlags.MenuBar); + + if (ImGui.BeginMenuBar()) + { + //push font to make our menus with FA icons + ImGui.PushFont(UiBuilder.IconFont); + if (ImGui.MenuItem(FontAwesomeIcon.Save.ToIconString())) + { + FileService.OpenFileDialog(plugin, Plugin.SelectedPlayer.Name); + + } + ImGui.PopFont(); + + if (ImGui.IsItemHovered()) + { + ImGui.SetTooltip("Save log to .txt file"); + } + ImGui.EndMenuBar(); + } ImGui.EndChild(); + - //Populating selectable list + //Reopen left window, populate selectable list foreach (var p in Plugin.Players) { ImGui.BeginChild(MainWindow.ID_PANEL_LEFT); @@ -64,9 +98,10 @@ public TabIndividual(MainWindow mainWindow) ImGui.EndChild(); } - // Build the chat log + // Reopen right window, build the chat log // it's worth noting all of this stuff stays in memory and is only hidden when it's "closed" ImGui.BeginChild(MainWindow.ID_PANEL_RIGHT); + ImGui.BeginGroup(); if (Plugin.SelectedPlayer is not null)