Files
HellionChat/HellionChat/Ui/Components/Settings/Tabs/GeneralTab.cs
T

113 lines
3.4 KiB
C#

using Dalamud.Bindings.ImGui;
using HellionChat.Util;
namespace HellionChat.Ui.Components.Settings.Tabs;
internal sealed class GeneralTab
{
private readonly Plugin _plugin;
public GeneralTab(Plugin plugin)
{
_plugin = plugin;
}
public void Draw()
{
if (ImGui.CollapsingHeader("Behavior", ImGuiTreeNodeFlags.DefaultOpen))
{
DrawToggle(
"Reduce motion (no theme crossfade)",
() => Plugin.Config.ReduceMotion,
v => Plugin.Config.ReduceMotion = v
);
DrawToggle(
"Print changelog on update",
() => Plugin.Config.PrintChangelog,
v => Plugin.Config.PrintChangelog = v
);
}
if (ImGui.CollapsingHeader("Keybinds", ImGuiTreeNodeFlags.DefaultOpen))
{
ImGui.TextDisabled("Click a button, then press the key combination. Esc clears.");
DrawKeybind(
"Cycle to next chat tab",
"ChatTabForwardKeybind",
() => Plugin.Config.ChatTabForward,
v => Plugin.Config.ChatTabForward = v
);
DrawKeybind(
"Cycle to previous chat tab",
"ChatTabBackwardKeybind",
() => Plugin.Config.ChatTabBackward,
v => Plugin.Config.ChatTabBackward = v
);
}
if (ImGui.CollapsingHeader("Notifications", ImGuiTreeNodeFlags.DefaultOpen))
{
DrawToggle(
"Show novice network",
() => Plugin.Config.ShowNoviceNetwork,
v => Plugin.Config.ShowNoviceNetwork = v
);
}
if (ImGui.CollapsingHeader("Volumes", ImGuiTreeNodeFlags.DefaultOpen))
{
DrawSlider(
"Custom sound volume",
() => Plugin.Config.CustomSoundVolume,
v => Plugin.Config.CustomSoundVolume = v,
0f,
1f
);
}
}
private void DrawToggle(string label, Func<bool> get, Action<bool> set)
{
var current = get();
if (ImGui.Checkbox(label, ref current))
{
set(current);
_plugin.SaveConfig();
}
}
private void DrawSlider(string label, Func<float> get, Action<float> set, float min, float max)
{
var current = get();
ImGui.SetNextItemWidth(200);
if (ImGui.SliderFloat(label, ref current, min, max, "%.2f"))
{
set(current);
_plugin.SaveConfig();
}
}
// Wires the already-present ImGuiUtil.KeybindInput capture widget (dead/unwired
// since the v1.6.0 rewrite) back into the settings, so ChatTabForward/Backward
// are bindable again. ConfigKeyBind is a reference type, so a capture (new
// instance) or an Esc-clear (null) changes the reference — persist only then.
private void DrawKeybind(
string label,
string id,
Func<ConfigKeyBind?> get,
Action<ConfigKeyBind?> set
)
{
ImGui.TextUnformatted(label);
ImGui.SetNextItemWidth(-1);
var keybind = get();
var before = keybind;
ImGuiUtil.KeybindInput(id, ref keybind);
if (!ReferenceEquals(before, keybind))
{
set(keybind);
_plugin.SaveConfig();
}
}
}