Add server settings to config UI

master v0.3
Liza 2024-02-18 10:34:16 +01:00
parent d15b852cb3
commit 4a9e626815
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,83 +25,126 @@ 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)
if (_clientState is { IsLoggedIn: true, LocalContentId: > 0 }) return;
{
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")) 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() ?? "??",
LocalContentId = _clientState.LocalContentId, CachedWorldName = worldName,
CachedPlayerName = _clientState.LocalPlayer?.Name.ToString() ?? "??", });
CachedWorldName = worldName, Save();
}); }
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); 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();
} }
} }