diff options
| author | Pinapelz <yukais@pinapelz.com> | 2024-09-15 02:22:37 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2024-09-15 02:22:37 -0700 |
| commit | bbb1b64dea7d1fdbb6192997cb0d771aa108dca2 (patch) | |
| tree | afa0c5e0de8664dfd038bca5a8e992e999ed5510 | |
| parent | d00b782c7fa6b4b4e68754293a3236e35ed7ff90 (diff) | |
add configuration window and user input table
| -rw-r--r-- | DiscordToXIV/Configuration.cs | 9 | ||||
| -rw-r--r-- | DiscordToXIV/Windows/ConfigWindow.cs | 118 |
2 files changed, 111 insertions, 16 deletions
diff --git a/DiscordToXIV/Configuration.cs b/DiscordToXIV/Configuration.cs index 82d14e3..b4b763b 100644 --- a/DiscordToXIV/Configuration.cs +++ b/DiscordToXIV/Configuration.cs @@ -1,4 +1,5 @@ -using Dalamud.Configuration; +using System.Collections.Generic; +using Dalamud.Configuration; using Dalamud.Plugin; using System; @@ -8,11 +9,9 @@ namespace DiscordToXIV; public class Configuration : IPluginConfiguration { public int Version { get; set; } = 0; + public Dictionary<string, string> ChannelMappings { get; set; } = new Dictionary<string, string>(); + public bool HideUsernameWhenNicknameExists { get; set; } = false; - public bool IsConfigWindowMovable { get; set; } = true; - public bool SomePropertyToBeSavedAndWithADefault { get; set; } = true; - - // the below exist just to make saving less cumbersome public void Save() { Plugin.PluginInterface.SavePluginConfig(this); diff --git a/DiscordToXIV/Windows/ConfigWindow.cs b/DiscordToXIV/Windows/ConfigWindow.cs index d386fc3..fe2195a 100644 --- a/DiscordToXIV/Windows/ConfigWindow.cs +++ b/DiscordToXIV/Windows/ConfigWindow.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Numerics; using Dalamud.Interface.Windowing; using ImGuiNET; @@ -10,29 +11,124 @@ public class ConfigWindow : Window, IDisposable { private Configuration Configuration; - public ConfigWindow(Plugin plugin) : base("A Wonderful Configuration Window###With a constant ID") + public ConfigWindow(Plugin plugin) : base("DiscordToXIV Config###DiscordToXIVConfig") { - Size = new Vector2(232, 90); - SizeCondition = ImGuiCond.Always; Configuration = plugin.Configuration; } public void Dispose() { } +public override void Draw() +{ + // Existing code for checkboxes... + + ImGui.Spacing(); - public override void Draw() + if (ImGui.BeginTable("ChannelMappingsTable", 3, ImGuiTableFlags.Borders | ImGuiTableFlags.RowBg)) { - var configValue = Configuration.SomePropertyToBeSavedAndWithADefault; - if (ImGui.Checkbox("Random Config Bool", ref configValue)) + ImGui.TableSetupColumn("Channel ID"); + ImGui.TableSetupColumn("Channel Name"); + ImGui.TableSetupColumn("Actions", ImGuiTableColumnFlags.WidthFixed, 60); + ImGui.TableHeadersRow(); + + string keyToRemove = null; + int index = 0; + + var keys = new List<string>(Configuration.ChannelMappings.Keys); + + foreach (var key in keys) { - Configuration.SomePropertyToBeSavedAndWithADefault = configValue; - Configuration.Save(); + ImGui.TableNextRow(); + ImGui.TableNextColumn(); + + // Declare variables at the top of the loop + string channelId = key; + string channelName = Configuration.ChannelMappings[key]; + + // Input for Channel ID + ImGui.SetNextItemWidth(-1); + if (ImGui.InputText($"##ChannelID_{index}", ref channelId, 256)) + { + channelId = channelId.Trim(); + + if (string.IsNullOrEmpty(channelId)) + { + ImGui.TextColored(new Vector4(1, 0, 0, 1), "Channel ID cannot be empty"); + } + else if (channelId != key && Configuration.ChannelMappings.ContainsKey(channelId)) + { + ImGui.TextColored(new Vector4(1, 0, 0, 1), "Channel ID already exists"); + } + else + { + // Update the key in the dictionary + Configuration.ChannelMappings.Remove(key); + Configuration.ChannelMappings[channelId] = channelName; + Configuration.Save(); + break; // Exit the loop to avoid enumeration issues + } + } + + ImGui.TableNextColumn(); + + // Input for Channel Name + ImGui.SetNextItemWidth(-1); + if (ImGui.InputText($"##ChannelName_{index}", ref channelName, 256)) + { + channelName = channelName.Trim(); + if (string.IsNullOrEmpty(channelName)) + { + ImGui.TextColored(new Vector4(1, 0, 0, 1), "Channel Name cannot be empty"); + } + else + { + Configuration.ChannelMappings[channelId] = channelName; + Configuration.Save(); + } + } + + ImGui.TableNextColumn(); + + // Delete button + if (ImGui.Button($"Delete##{index}")) + { + keyToRemove = key; + } + + index++; } - var movable = Configuration.IsConfigWindowMovable; - if (ImGui.Checkbox("Movable Config Window", ref movable)) + if (keyToRemove != null) { - Configuration.IsConfigWindowMovable = movable; + Configuration.ChannelMappings.Remove(keyToRemove); Configuration.Save(); } + + ImGui.EndTable(); + } + + if (ImGui.Button("Add New Mapping")) + { + int newIndex = 1; + string newKey = "NewChannelID_" + newIndex; + while (Configuration.ChannelMappings.ContainsKey(newKey)) + { + newIndex++; + newKey = "NewChannelID_" + newIndex; + } + + Configuration.ChannelMappings.Add(newKey, "ChannelName"); + Configuration.Save(); + } + + ImGui.Separator(); + + var hideUsernameWhenNicknameExists = Configuration.HideUsernameWhenNicknameExists; + if (ImGui.Checkbox("Hide username when nickname exists", ref hideUsernameWhenNicknameExists)) + { + Configuration.HideUsernameWhenNicknameExists = hideUsernameWhenNicknameExists; + Configuration.Save(); } } + +} + |
