Add server settings to config UI

This commit is contained in:
Liza 2024-02-18 10:34:16 +01:00
parent d15b852cb3
commit 5670ef060d
Signed by: liza
GPG Key ID: 7199F8D727D55F67
3 changed files with 111 additions and 67 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<Version>0.2</Version> <Version>0.3</Version>
<LangVersion>11.0</LangVersion> <LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

View File

@ -84,13 +84,13 @@ public class InfluxPlugin : IDalamudPlugin
private void ProcessCommand(string command, string arguments) private void ProcessCommand(string command, string arguments)
{ {
if (arguments == "c" || arguments == "config") if (arguments == "gil")
_configurationWindow.Toggle();
else
{ {
UpdateStatistics(); UpdateStatistics();
_statisticsWindow.IsOpen = true; _statisticsWindow.IsOpen = true;
} }
else
_configurationWindow.Toggle();
} }
private void UpdateStatistics() private void UpdateStatistics()

View File

@ -1,5 +1,6 @@
using System.Linq; using System.Linq;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
@ -24,23 +25,68 @@ internal sealed class ConfigurationWindow : Window
public override void Draw() public override void Draw()
{ {
if (ImGui.BeginTabBar("InfluxConfigTabs")) using var tabBar = ImRaii.TabBar("InfluxConfigTabs");
if (tabBar)
{ {
DrawConnectionSettings();
DrawIncludedCharacters(); 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() private void DrawIncludedCharacters()
{ {
if (ImGui.BeginTabItem("Included Characters")) using var tabItem = ImRaii.TabItem("Included Characters");
{ if (!tabItem)
return;
if (_clientState is { IsLoggedIn: true, LocalContentId: > 0 }) if (_clientState is { IsLoggedIn: true, LocalContentId: > 0 })
{ {
string worldName = _clientState.LocalPlayer?.HomeWorld.GameData?.Name ?? "??"; string worldName = _clientState.LocalPlayer?.HomeWorld.GameData?.Name ?? "??";
ImGui.TextWrapped( ImGui.TextWrapped(
$"Current Character: {_clientState.LocalPlayer?.Name} @ {worldName} ({_clientState.LocalContentId:X})"); $"Current Character: {_clientState.LocalPlayer?.Name} @ {worldName} ({_clientState.LocalContentId:X})");
ImGui.Indent(30); ImGui.Indent(30);
if (_configuration.IncludedCharacters.Any(x => x.LocalContentId == _clientState.LocalContentId)) if (_configuration.IncludedCharacters.Any(x => x.LocalContentId == _clientState.LocalContentId))
{ {
@ -56,7 +102,6 @@ internal sealed class ConfigurationWindow : Window
{ {
ImGui.TextColored(ImGuiColors.DalamudRed, ImGui.TextColored(ImGuiColors.DalamudRed,
"This character is currently excluded."); "This character is currently excluded.");
if (ImGui.Button("Include current character")) if (ImGui.Button("Include current character"))
{ {
_configuration.IncludedCharacters.Add(new Configuration.CharacterInfo _configuration.IncludedCharacters.Add(new Configuration.CharacterInfo
@ -86,9 +131,11 @@ internal sealed class ConfigurationWindow : Window
} }
else else
{ {
foreach (var world in _configuration.IncludedCharacters.OrderBy(x => x.CachedWorldName).ThenBy(x => x.LocalContentId).GroupBy(x => x.CachedWorldName)) 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.CollapsingHeader($"{world.Key} ({world.Count()})",
ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.Bullet);
ImGui.Indent(30); ImGui.Indent(30);
foreach (var characterInfo in world) foreach (var characterInfo in world)
{ {
@ -99,9 +146,6 @@ internal sealed class ConfigurationWindow : Window
ImGui.Unindent(30); ImGui.Unindent(30);
} }
} }
ImGui.EndTabItem();
}
} }
private void Save() private void Save()