From 5670ef060dba56da2e76984743e5ee0ba2092960 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sun, 18 Feb 2024 10:34:16 +0100 Subject: [PATCH] Add server settings to config UI --- Influx/Influx.csproj | 2 +- Influx/InfluxPlugin.cs | 6 +- Influx/Windows/ConfigurationWindow.cs | 170 ++++++++++++++++---------- 3 files changed, 111 insertions(+), 67 deletions(-) diff --git a/Influx/Influx.csproj b/Influx/Influx.csproj index f0ef35e..927e2c0 100644 --- a/Influx/Influx.csproj +++ b/Influx/Influx.csproj @@ -1,7 +1,7 @@ net7.0-windows - 0.2 + 0.3 11.0 enable true diff --git a/Influx/InfluxPlugin.cs b/Influx/InfluxPlugin.cs index e31a072..f61792c 100644 --- a/Influx/InfluxPlugin.cs +++ b/Influx/InfluxPlugin.cs @@ -84,13 +84,13 @@ public class InfluxPlugin : IDalamudPlugin private void ProcessCommand(string command, string arguments) { - if (arguments == "c" || arguments == "config") - _configurationWindow.Toggle(); - else + if (arguments == "gil") { UpdateStatistics(); _statisticsWindow.IsOpen = true; } + else + _configurationWindow.Toggle(); } private void UpdateStatistics() diff --git a/Influx/Windows/ConfigurationWindow.cs b/Influx/Windows/ConfigurationWindow.cs index 9d2343c..b614dc0 100644 --- a/Influx/Windows/ConfigurationWindow.cs +++ b/Influx/Windows/ConfigurationWindow.cs @@ -1,5 +1,6 @@ using System.Linq; using Dalamud.Interface.Colors; +using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Windowing; using Dalamud.Plugin; using Dalamud.Plugin.Services; @@ -24,83 +25,126 @@ internal sealed class ConfigurationWindow : Window public override void Draw() { - if (ImGui.BeginTabBar("InfluxConfigTabs")) + using var tabBar = ImRaii.TabBar("InfluxConfigTabs"); + if (tabBar) { + DrawConnectionSettings(); DrawIncludedCharacters(); + } + } - ImGui.EndTabBar(); + private void DrawConnectionSettings() + { + using var tabItem = ImRaii.TabItem("Connection Settings"); + if (!tabItem) + return; + + bool enabled = _configuration.Server.Enabled; + if (ImGui.Checkbox("Enable Server Connection", ref enabled)) + { + _configuration.Server.Enabled = enabled; + Save(); + } + + string server = _configuration.Server.Server; + if (ImGui.InputText("InfluxDB URL", ref server, 128)) + { + _configuration.Server.Server = server; + Save(); + } + + string token = _configuration.Server.Token; + if (ImGui.InputText("Token", ref token, 128, ImGuiInputTextFlags.Password)) + { + _configuration.Server.Token = token; + Save(); + } + + string organization = _configuration.Server.Organization; + if (ImGui.InputText("Organization", ref organization, 128)) + { + _configuration.Server.Organization = organization; + Save(); + } + + string bucket = _configuration.Server.Bucket; + if (ImGui.InputText("Bucket", ref bucket, 128)) + { + _configuration.Server.Bucket = bucket; + Save(); } } private void DrawIncludedCharacters() { - if (ImGui.BeginTabItem("Included Characters")) - { - if (_clientState is { IsLoggedIn: true, LocalContentId: > 0 }) - { - string worldName = _clientState.LocalPlayer?.HomeWorld.GameData?.Name ?? "??"; - ImGui.TextWrapped( - $"Current Character: {_clientState.LocalPlayer?.Name} @ {worldName} ({_clientState.LocalContentId:X})"); - ImGui.Indent(30); - if (_configuration.IncludedCharacters.Any(x => x.LocalContentId == _clientState.LocalContentId)) - { - ImGui.TextColored(ImGuiColors.HealerGreen, "This character is currently included."); - if (ImGui.Button("Remove inclusion")) - { - _configuration.IncludedCharacters.RemoveAll( - c => c.LocalContentId == _clientState.LocalContentId); - Save(); - } - } - else - { - ImGui.TextColored(ImGuiColors.DalamudRed, - "This character is currently excluded."); + using var tabItem = ImRaii.TabItem("Included Characters"); + if (!tabItem) + return; - if (ImGui.Button("Include current character")) + if (_clientState is { IsLoggedIn: true, LocalContentId: > 0 }) + { + string worldName = _clientState.LocalPlayer?.HomeWorld.GameData?.Name ?? "??"; + ImGui.TextWrapped( + $"Current Character: {_clientState.LocalPlayer?.Name} @ {worldName} ({_clientState.LocalContentId:X})"); + + ImGui.Indent(30); + if (_configuration.IncludedCharacters.Any(x => x.LocalContentId == _clientState.LocalContentId)) + { + ImGui.TextColored(ImGuiColors.HealerGreen, "This character is currently included."); + if (ImGui.Button("Remove inclusion")) + { + _configuration.IncludedCharacters.RemoveAll( + c => c.LocalContentId == _clientState.LocalContentId); + Save(); + } + } + else + { + ImGui.TextColored(ImGuiColors.DalamudRed, + "This character is currently excluded."); + if (ImGui.Button("Include current character")) + { + _configuration.IncludedCharacters.Add(new Configuration.CharacterInfo { - _configuration.IncludedCharacters.Add(new Configuration.CharacterInfo - { - LocalContentId = _clientState.LocalContentId, - CachedPlayerName = _clientState.LocalPlayer?.Name.ToString() ?? "??", - CachedWorldName = worldName, - }); - Save(); - } + LocalContentId = _clientState.LocalContentId, + CachedPlayerName = _clientState.LocalPlayer?.Name.ToString() ?? "??", + CachedWorldName = worldName, + }); + Save(); + } + } + + ImGui.Unindent(30); + } + else + { + ImGui.TextColored(ImGuiColors.DalamudRed, "You are not logged in."); + } + + ImGui.Separator(); + ImGui.TextWrapped("Characters that are included:"); + ImGui.Spacing(); + + if (_configuration.IncludedCharacters.Count == 0) + { + ImGui.TextColored(ImGuiColors.DalamudGrey, "No included characters."); + } + else + { + foreach (var world in _configuration.IncludedCharacters.OrderBy(x => x.CachedWorldName) + .ThenBy(x => x.LocalContentId).GroupBy(x => x.CachedWorldName)) + { + ImGui.CollapsingHeader($"{world.Key} ({world.Count()})", + ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.Bullet); + ImGui.Indent(30); + foreach (var characterInfo in world) + { + ImGui.Selectable( + $"{characterInfo.CachedPlayerName} @ {characterInfo.CachedWorldName} ({characterInfo.LocalContentId:X})"); } ImGui.Unindent(30); } - else - { - ImGui.TextColored(ImGuiColors.DalamudRed, "You are not logged in."); - } - - ImGui.Separator(); - ImGui.TextWrapped("Characters that are included:"); - ImGui.Spacing(); - - if (_configuration.IncludedCharacters.Count == 0) - { - ImGui.TextColored(ImGuiColors.DalamudGrey, "No included characters."); - } - else - { - foreach (var world in _configuration.IncludedCharacters.OrderBy(x => x.CachedWorldName).ThenBy(x => x.LocalContentId).GroupBy(x => x.CachedWorldName)) - { - ImGui.CollapsingHeader($"{world.Key} ({world.Count()})", ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.Bullet); - ImGui.Indent(30); - foreach (var characterInfo in world) - { - ImGui.Selectable( - $"{characterInfo.CachedPlayerName} @ {characterInfo.CachedWorldName} ({characterInfo.LocalContentId:X})"); - } - - ImGui.Unindent(30); - } - } - - ImGui.EndTabItem(); } }