From b34a855a926313c80432a8d5be1563cd1577c1b0 Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 15 Jan 2022 14:27:56 -0500 Subject: [PATCH] feat: add new settings ui Also add window display options. --- ChatTwo/Configuration.cs | 17 +++ ChatTwo/PayloadHandler.cs | 2 +- ChatTwo/Ui/ChatLog.cs | 17 ++- ChatTwo/Ui/Settings.cs | 185 ++++-------------------- ChatTwo/Ui/SettingsTabs/ChatColours.cs | 34 +++++ ChatTwo/Ui/SettingsTabs/Display.cs | 29 ++++ ChatTwo/Ui/SettingsTabs/ISettingsTab.cs | 6 + ChatTwo/Ui/SettingsTabs/Tabs.cs | 105 ++++++++++++++ 8 files changed, 239 insertions(+), 156 deletions(-) create mode 100755 ChatTwo/Ui/SettingsTabs/ChatColours.cs create mode 100755 ChatTwo/Ui/SettingsTabs/Display.cs create mode 100755 ChatTwo/Ui/SettingsTabs/ISettingsTab.cs create mode 100755 ChatTwo/Ui/SettingsTabs/Tabs.cs diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index 7371056..246d77d 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -12,9 +12,26 @@ internal class Configuration : IPluginConfiguration { public bool PrettierTimestamps = true; public bool MoreCompactPretty; public bool SidebarTabView; + public bool CanMove = true; + public bool CanResize = true; + public bool ShowTitleBar; public float FontSize = 17f; public Dictionary ChatColours = new(); public List Tabs = new(); + + internal void UpdateFrom(Configuration other) { + this.HideChat = other.HideChat; + this.NativeItemTooltips = other.NativeItemTooltips; + this.PrettierTimestamps = other.PrettierTimestamps; + this.MoreCompactPretty = other.MoreCompactPretty; + this.SidebarTabView = other.SidebarTabView; + this.CanMove = other.CanMove; + this.CanResize = other.CanResize; + this.ShowTitleBar = other.ShowTitleBar; + this.FontSize = other.FontSize; + this.ChatColours = other.ChatColours.ToDictionary(entry => entry.Key, entry => entry.Value); + this.Tabs = other.Tabs.Select(t => t.Clone()).ToList(); + } } [Serializable] diff --git a/ChatTwo/PayloadHandler.cs b/ChatTwo/PayloadHandler.cs index 82902cb..06a31bc 100755 --- a/ChatTwo/PayloadHandler.cs +++ b/ChatTwo/PayloadHandler.cs @@ -87,7 +87,7 @@ internal sealed class PayloadHandler { internal void Hover(Payload payload) { var hoverSize = 250f * ImGuiHelpers.GlobalScale; - + switch (payload) { case StatusPayload status: { this.DoHover(() => this.HoverStatus(status), hoverSize); diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index d4cc229..ac71347 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -65,7 +65,20 @@ internal sealed class ChatLog : IUiComponent { } public unsafe void Draw() { - if (!ImGui.Begin($"{this.Ui.Plugin.Name}##chat", ImGuiWindowFlags.NoTitleBar)) { + var flags = ImGuiWindowFlags.None; + if (!this.Ui.Plugin.Config.CanMove) { + flags |= ImGuiWindowFlags.NoMove; + } + + if (!this.Ui.Plugin.Config.CanResize) { + flags |= ImGuiWindowFlags.NoResize; + } + + if (!this.Ui.Plugin.Config.ShowTitleBar) { + flags |= ImGuiWindowFlags.NoTitleBar; + } + + if (!ImGui.Begin($"{this.Ui.Plugin.Name}##chat", flags)) { ImGui.End(); return; } @@ -180,7 +193,7 @@ internal sealed class ChatLog : IUiComponent { ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, padding); } - + if (table) { if (!ImGui.BeginTable("timestamp-table", 2, ImGuiTableFlags.PreciseWidths)) { goto EndChild; diff --git a/ChatTwo/Ui/Settings.cs b/ChatTwo/Ui/Settings.cs index d226bbd..a4bcd1c 100755 --- a/ChatTwo/Ui/Settings.cs +++ b/ChatTwo/Ui/Settings.cs @@ -1,8 +1,6 @@ using System.Numerics; -using ChatTwo.Code; -using ChatTwo.Util; +using ChatTwo.Ui.SettingsTabs; using Dalamud.Game.Command; -using Dalamud.Interface; using ImGuiNET; namespace ChatTwo.Ui; @@ -10,17 +8,19 @@ namespace ChatTwo.Ui; internal sealed class Settings : IUiComponent { private PluginUi Ui { get; } - private bool _hideChat; - private bool _nativeItemTooltips; - private bool _sidebarTabView; - private bool _prettierTimestamps; - private bool _moreCompactPretty; - private float _fontSize; - private Dictionary _chatColours = new(); - private List _tabs = new(); + private Configuration Mutable { get; } + private List Tabs { get; } internal Settings(PluginUi ui) { this.Ui = ui; + this.Mutable = new Configuration(); + + this.Tabs = new List { + new Display(this.Mutable), + new ChatColours(this.Mutable), + new Tabs(this.Mutable), + }; + this.Ui.Plugin.CommandManager.AddHandler("/chat2", new CommandInfo(this.Command) { HelpMessage = "Toggle the Chat 2 settings", }); @@ -35,15 +35,7 @@ internal sealed class Settings : IUiComponent { } private void Initialise() { - var config = this.Ui.Plugin.Config; - this._hideChat = config.HideChat; - this._nativeItemTooltips = config.NativeItemTooltips; - this._sidebarTabView = config.SidebarTabView; - this._prettierTimestamps = config.PrettierTimestamps; - this._moreCompactPretty = config.MoreCompactPretty; - this._fontSize = config.FontSize; - this._chatColours = config.ChatColours.ToDictionary(entry => entry.Key, entry => entry.Value); - this._tabs = config.Tabs.Select(tab => tab.Clone()).ToList(); + this.Mutable.UpdateFrom(this.Ui.Plugin.Config); } public void Draw() { @@ -60,132 +52,26 @@ internal sealed class Settings : IUiComponent { this.Initialise(); } - var height = ImGui.GetContentRegionAvail().Y - - ImGui.GetStyle().FramePadding.Y * 2 - - ImGui.GetStyle().ItemSpacing.Y - - ImGui.GetStyle().ItemInnerSpacing.Y * 2 - - ImGui.CalcTextSize("A").Y; - if (ImGui.BeginChild("##chat2-settings", new Vector2(-1, height))) { - ImGui.Checkbox("Hide chat", ref this._hideChat); - ImGui.Checkbox("Show native item tooltips", ref this._nativeItemTooltips); - ImGui.Checkbox("Show tabs in a sidebar", ref this._sidebarTabView); - ImGui.Checkbox("Use modern timestamp layout", ref this._prettierTimestamps); - - if (this._prettierTimestamps) { - ImGui.Checkbox("More compact modern layout", ref this._moreCompactPretty); - } - - ImGui.DragFloat("Font size", ref this._fontSize, .0125f, 12f, 36f, "%.1f"); - - if (ImGui.TreeNodeEx("Chat colours")) { - foreach (var type in Enum.GetValues()) { - if (ImGui.Button($"Default##{type}")) { - this._chatColours.Remove(type); - } - - ImGui.SameLine(); - - var vec = this._chatColours.TryGetValue(type, out var colour) - ? ColourUtil.RgbaToVector3(colour) - : ColourUtil.RgbaToVector3(type.DefaultColour() ?? 0); - if (ImGui.ColorEdit3(type.Name(), ref vec, ImGuiColorEditFlags.NoInputs)) { - this._chatColours[type] = ColourUtil.Vector3ToRgba(vec); - } + if (ImGui.BeginTabBar("settings-tabs")) { + foreach (var settingsTab in this.Tabs) { + if (!ImGui.BeginTabItem(settingsTab.Name)) { + continue; } - ImGui.TreePop(); + var height = ImGui.GetContentRegionAvail().Y + - ImGui.GetStyle().FramePadding.Y * 2 + - ImGui.GetStyle().ItemSpacing.Y + - ImGui.GetStyle().ItemInnerSpacing.Y * 2 + - ImGui.CalcTextSize("A").Y; + if (ImGui.BeginChild("##chat2-settings", new Vector2(-1, height))) { + settingsTab.Draw(); + ImGui.EndChild(); + } + + ImGui.EndTabItem(); } - if (ImGui.TreeNodeEx("Tabs")) { - if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: "Add")) { - this._tabs.Add(new Tab()); - } - - var toRemove = -1; - for (var i = 0; i < this._tabs.Count; i++) { - var tab = this._tabs[i]; - - if (ImGui.TreeNodeEx($"{tab.Name}###tab-{i}")) { - ImGui.PushID($"tab-{i}"); - - if (ImGuiUtil.IconButton(FontAwesomeIcon.TrashAlt, tooltip: "Delete")) { - toRemove = i; - } - - ImGui.SameLine(); - - if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowUp, tooltip: "Move up") && i > 0) { - (this._tabs[i - 1], this._tabs[i]) = (this._tabs[i], this._tabs[i - 1]); - } - - ImGui.SameLine(); - - if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowDown, tooltip: "Move down") && i < this._tabs.Count - 1) { - (this._tabs[i + 1], this._tabs[i]) = (this._tabs[i], this._tabs[i + 1]); - } - - ImGui.InputText("Name", ref tab.Name, 512, ImGuiInputTextFlags.EnterReturnsTrue); - ImGui.Checkbox("Show unread count", ref tab.DisplayUnread); - ImGui.Checkbox("Show timestamps", ref tab.DisplayTimestamp); - - var input = tab.Channel?.ToChatType().Name() ?? ""; - if (ImGui.BeginCombo("Input channel", input)) { - if (ImGui.Selectable("", tab.Channel == null)) { - tab.Channel = null; - } - - foreach (var channel in Enum.GetValues()) { - if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) { - tab.Channel = channel; - } - } - - ImGui.EndCombo(); - } - - if (ImGui.TreeNodeEx("Channels")) { - foreach (var type in Enum.GetValues()) { - var enabled = tab.ChatCodes.ContainsKey(type); - if (ImGui.Checkbox($"##{type.Name()}-{i}", ref enabled)) { - if (enabled) { - tab.ChatCodes[type] = ChatSourceExt.All; - } else { - tab.ChatCodes.Remove(type); - } - } - - ImGui.SameLine(); - - if (ImGui.TreeNodeEx($"{type.Name()}##{i}")) { - tab.ChatCodes.TryGetValue(type, out var sourcesEnum); - var sources = (uint) sourcesEnum; - - foreach (var source in Enum.GetValues()) { - if (ImGui.CheckboxFlags(source.ToString(), ref sources, (uint) source)) { - tab.ChatCodes[type] = (ChatSource) sources; - } - } - - ImGui.TreePop(); - } - } - - - ImGui.TreePop(); - } - - ImGui.TreePop(); - - ImGui.PopID(); - } - } - - if (toRemove > -1) { - this._tabs.RemoveAt(toRemove); - } - } - - ImGui.EndChild(); + ImGui.EndTabBar(); } ImGui.Separator(); @@ -210,17 +96,10 @@ internal sealed class Settings : IUiComponent { if (save) { var config = this.Ui.Plugin.Config; - var hideChatChanged = this._hideChat != this.Ui.Plugin.Config.HideChat; - var fontSizeChanged = Math.Abs(this._fontSize - this.Ui.Plugin.Config.FontSize) > float.Epsilon; + var hideChatChanged = this.Mutable.HideChat != this.Ui.Plugin.Config.HideChat; + var fontSizeChanged = Math.Abs(this.Mutable.FontSize - this.Ui.Plugin.Config.FontSize) > float.Epsilon; - config.HideChat = this._hideChat; - config.NativeItemTooltips = this._nativeItemTooltips; - config.SidebarTabView = this._sidebarTabView; - config.PrettierTimestamps = this._prettierTimestamps; - config.MoreCompactPretty = this._moreCompactPretty; - config.FontSize = this._fontSize; - config.ChatColours = this._chatColours; - config.Tabs = this._tabs; + config.UpdateFrom(this.Mutable); this.Ui.Plugin.SaveConfig(); @@ -230,7 +109,7 @@ internal sealed class Settings : IUiComponent { this.Ui.Plugin.Interface.UiBuilder.RebuildFonts(); } - if (!this._hideChat && hideChatChanged) { + if (!this.Mutable.HideChat && hideChatChanged) { GameFunctions.GameFunctions.SetChatInteractable(true); } diff --git a/ChatTwo/Ui/SettingsTabs/ChatColours.cs b/ChatTwo/Ui/SettingsTabs/ChatColours.cs new file mode 100755 index 0000000..93f3f8a --- /dev/null +++ b/ChatTwo/Ui/SettingsTabs/ChatColours.cs @@ -0,0 +1,34 @@ +using ChatTwo.Code; +using ChatTwo.Util; +using ImGuiNET; + +namespace ChatTwo.Ui.SettingsTabs; + +internal sealed class ChatColours : ISettingsTab { + private Configuration Mutable { get; } + + public string Name => "Chat colours"; + + internal ChatColours(Configuration mutable) { + this.Mutable = mutable; + } + + public void Draw() { + foreach (var type in Enum.GetValues()) { + if (ImGui.Button($"Default##{type}")) { + this.Mutable.ChatColours.Remove(type); + } + + ImGui.SameLine(); + + var vec = this.Mutable.ChatColours.TryGetValue(type, out var colour) + ? ColourUtil.RgbaToVector3(colour) + : ColourUtil.RgbaToVector3(type.DefaultColour() ?? 0); + if (ImGui.ColorEdit3(type.Name(), ref vec, ImGuiColorEditFlags.NoInputs)) { + this.Mutable.ChatColours[type] = ColourUtil.Vector3ToRgba(vec); + } + } + + ImGui.TreePop(); + } +} diff --git a/ChatTwo/Ui/SettingsTabs/Display.cs b/ChatTwo/Ui/SettingsTabs/Display.cs new file mode 100755 index 0000000..32c7b9b --- /dev/null +++ b/ChatTwo/Ui/SettingsTabs/Display.cs @@ -0,0 +1,29 @@ +using ImGuiNET; + +namespace ChatTwo.Ui.SettingsTabs; + +internal sealed class Display : ISettingsTab { + private Configuration Mutable { get; } + + public string Name => "Display"; + + internal Display(Configuration mutable) { + this.Mutable = mutable; + } + + public void Draw() { + ImGui.Checkbox("Hide chat", ref this.Mutable.HideChat); + ImGui.Checkbox("Show native item tooltips", ref this.Mutable.NativeItemTooltips); + ImGui.Checkbox("Show tabs in a sidebar", ref this.Mutable.SidebarTabView); + ImGui.Checkbox("Use modern timestamp layout", ref this.Mutable.PrettierTimestamps); + + if (this.Mutable.PrettierTimestamps) { + ImGui.Checkbox("More compact modern layout", ref this.Mutable.MoreCompactPretty); + } + + ImGui.DragFloat("Font size", ref this.Mutable.FontSize, .0125f, 12f, 36f, "%.1f"); + ImGui.Checkbox("Allow moving main window", ref this.Mutable.CanMove); + ImGui.Checkbox("Allow resizing main window", ref this.Mutable.CanResize); + ImGui.Checkbox("Show title bar for main window", ref this.Mutable.ShowTitleBar); + } +} diff --git a/ChatTwo/Ui/SettingsTabs/ISettingsTab.cs b/ChatTwo/Ui/SettingsTabs/ISettingsTab.cs new file mode 100755 index 0000000..f62573d --- /dev/null +++ b/ChatTwo/Ui/SettingsTabs/ISettingsTab.cs @@ -0,0 +1,6 @@ +namespace ChatTwo.Ui.SettingsTabs; + +internal interface ISettingsTab { + string Name { get; } + void Draw(); +} diff --git a/ChatTwo/Ui/SettingsTabs/Tabs.cs b/ChatTwo/Ui/SettingsTabs/Tabs.cs new file mode 100755 index 0000000..20cd44f --- /dev/null +++ b/ChatTwo/Ui/SettingsTabs/Tabs.cs @@ -0,0 +1,105 @@ +using ChatTwo.Code; +using ChatTwo.Util; +using Dalamud.Interface; +using ImGuiNET; + +namespace ChatTwo.Ui.SettingsTabs; + +internal sealed class Tabs : ISettingsTab { + private Configuration Mutable { get; } + + public string Name => "Tabs"; + + internal Tabs(Configuration mutable) { + this.Mutable = mutable; + } + + public void Draw() { + if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: "Add")) { + this.Mutable.Tabs.Add(new Tab()); + } + + var toRemove = -1; + for (var i = 0; i < this.Mutable.Tabs.Count; i++) { + var tab = this.Mutable.Tabs[i]; + + if (ImGui.TreeNodeEx($"{tab.Name}###tab-{i}")) { + ImGui.PushID($"tab-{i}"); + + if (ImGuiUtil.IconButton(FontAwesomeIcon.TrashAlt, tooltip: "Delete")) { + toRemove = i; + } + + ImGui.SameLine(); + + if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowUp, tooltip: "Move up") && i > 0) { + (this.Mutable.Tabs[i - 1], this.Mutable.Tabs[i]) = (this.Mutable.Tabs[i], this.Mutable.Tabs[i - 1]); + } + + ImGui.SameLine(); + + if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowDown, tooltip: "Move down") && i < this.Mutable.Tabs.Count - 1) { + (this.Mutable.Tabs[i + 1], this.Mutable.Tabs[i]) = (this.Mutable.Tabs[i], this.Mutable.Tabs[i + 1]); + } + + ImGui.InputText("Name", ref tab.Name, 512, ImGuiInputTextFlags.EnterReturnsTrue); + ImGui.Checkbox("Show unread count", ref tab.DisplayUnread); + ImGui.Checkbox("Show timestamps", ref tab.DisplayTimestamp); + + var input = tab.Channel?.ToChatType().Name() ?? ""; + if (ImGui.BeginCombo("Input channel", input)) { + if (ImGui.Selectable("", tab.Channel == null)) { + tab.Channel = null; + } + + foreach (var channel in Enum.GetValues()) { + if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) { + tab.Channel = channel; + } + } + + ImGui.EndCombo(); + } + + if (ImGui.TreeNodeEx("Channels")) { + foreach (var type in Enum.GetValues()) { + var enabled = tab.ChatCodes.ContainsKey(type); + if (ImGui.Checkbox($"##{type.Name()}-{i}", ref enabled)) { + if (enabled) { + tab.ChatCodes[type] = ChatSourceExt.All; + } else { + tab.ChatCodes.Remove(type); + } + } + + ImGui.SameLine(); + + if (ImGui.TreeNodeEx($"{type.Name()}##{i}")) { + tab.ChatCodes.TryGetValue(type, out var sourcesEnum); + var sources = (uint) sourcesEnum; + + foreach (var source in Enum.GetValues()) { + if (ImGui.CheckboxFlags(source.ToString(), ref sources, (uint) source)) { + tab.ChatCodes[type] = (ChatSource) sources; + } + } + + ImGui.TreePop(); + } + } + + + ImGui.TreePop(); + } + + ImGui.TreePop(); + + ImGui.PopID(); + } + } + + if (toRemove > -1) { + this.Mutable.Tabs.RemoveAt(toRemove); + } + } +}