qstbak/Questionable/Questionable.Windows.ConfigComponents/NotificationConfigComponent.cs
2025-12-24 05:01:16 +10:00

98 lines
2.9 KiB
C#

using System;
using System.Linq;
using System.Numerics;
using Dalamud.Bindings.ImGui;
using Dalamud.Game.Text;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Plugin;
using Dalamud.Utility;
namespace Questionable.Windows.ConfigComponents;
internal sealed class NotificationConfigComponent : ConfigComponent
{
private readonly XivChatType[] _xivChatTypes;
private readonly string[] _chatTypeNames;
private string _chatChannelSearchText = string.Empty;
private bool _chatChannelComboJustOpened;
public NotificationConfigComponent(IDalamudPluginInterface pluginInterface, Configuration configuration)
: base(pluginInterface, configuration)
{
_xivChatTypes = (from x in Enum.GetValues<XivChatType>()
where x != XivChatType.StandardEmote
select x).ToArray();
_chatTypeNames = _xivChatTypes.Select((XivChatType t) => t.GetAttribute<XivChatTypeInfoAttribute>()?.FancyName ?? t.ToString()).ToArray();
}
public override void DrawTab()
{
using ImRaii.IEndObject endObject = ImRaii.TabItem("Notifications###Notifications");
if (!endObject)
{
return;
}
bool v = base.Configuration.Notifications.Enabled;
if (ImGui.Checkbox("Enable notifications when manual interaction is required", ref v))
{
base.Configuration.Notifications.Enabled = v;
Save();
}
using (ImRaii.Disabled(!base.Configuration.Notifications.Enabled))
{
using (ImRaii.PushIndent())
{
int num = Array.IndexOf(_xivChatTypes, base.Configuration.Notifications.ChatType);
if (num == -1)
{
num = 0;
}
string text = ((num >= 0 && num < _chatTypeNames.Length) ? _chatTypeNames[num] : "Unknown");
if (ImGui.BeginCombo("Chat channel", text, ImGuiComboFlags.HeightLarge))
{
if (!_chatChannelComboJustOpened)
{
ImGui.SetKeyboardFocusHere();
_chatChannelComboJustOpened = true;
}
ImGui.SetNextItemWidth(-1f);
ImGui.InputTextWithHint("##ChatChannelSearch", "Search chat channels...", ref _chatChannelSearchText, 256);
ImGui.Separator();
using (ImRaii.IEndObject endObject2 = ImRaii.Child("##ChatChannelScrollArea", new Vector2(0f, 300f), border: false))
{
if (endObject2)
{
string value = _chatChannelSearchText.ToUpperInvariant();
for (int i = 0; i < _chatTypeNames.Length; i++)
{
if (string.IsNullOrEmpty(_chatChannelSearchText) || _chatTypeNames[i].ToUpperInvariant().Contains(value, StringComparison.Ordinal))
{
bool flag = i == num;
if (ImGui.Selectable(_chatTypeNames[i], flag))
{
base.Configuration.Notifications.ChatType = _xivChatTypes[i];
Save();
_chatChannelSearchText = string.Empty;
ImGui.CloseCurrentPopup();
}
if (flag)
{
ImGui.SetItemDefaultFocus();
}
}
}
}
}
ImGui.EndCombo();
}
else
{
_chatChannelComboJustOpened = false;
}
}
}
}
}