feat: add ExtraChat channel filtering

This commit is contained in:
Anna 2022-08-27 13:26:21 -04:00
parent 03ac04a690
commit cfa57ae11a
6 changed files with 1400 additions and 2067 deletions

View File

@ -2,6 +2,7 @@ using ChatTwo.Code;
using ChatTwo.Resources;
using ChatTwo.Ui;
using Dalamud.Configuration;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Logging;
using ImGuiNET;
@ -147,6 +148,8 @@ internal static class UnreadModeExt {
internal class Tab {
public string Name = Language.Tab_DefaultName;
public Dictionary<ChatType, ChatSource> ChatCodes = new();
public bool ExtraChatAll;
public HashSet<Guid> ExtraChatChannels = new();
[Obsolete("Use UnreadMode instead")]
public bool DisplayUnread = true;
@ -172,7 +175,18 @@ internal class Tab {
}
internal bool Matches(Message message) {
return message.Code.Type.IsGm() || this.ChatCodes.TryGetValue(message.Code.Type, out var sources) && (message.Code.Source is 0 or (ChatSource) 1 || sources.HasFlag(message.Code.Source));
var extraChatChannel = Guid.Empty;
if (message.ContentSource.Payloads.Count > 0 && message.ContentSource.Payloads[0] is RawPayload raw) {
// this does an encode and clone every time it's accessed, so cache
var data = raw.Data;
if (data[1] == 0x27 && data[2] == 19 && data[3] == 0x20) {
extraChatChannel = new Guid(data[4..]);
}
}
return message.Code.Type.IsGm()
|| (extraChatChannel != Guid.Empty && (this.ExtraChatAll || this.ExtraChatChannels.Contains(extraChatChannel)))
|| this.ChatCodes.TryGetValue(message.Code.Type, out var sources) && (message.Code.Source is 0 or (ChatSource) 1 || sources.HasFlag(message.Code.Source));
}
internal void AddMessage(Message message, bool unread = true) {
@ -199,6 +213,8 @@ internal class Tab {
return new Tab {
Name = this.Name,
ChatCodes = this.ChatCodes.ToDictionary(entry => entry.Key, entry => entry.Value),
ExtraChatAll = this.ExtraChatAll,
ExtraChatChannels = this.ExtraChatChannels.ToHashSet(),
#pragma warning disable CS0618
DisplayUnread = this.DisplayUnread,
#pragma warning restore CS0618
@ -258,8 +274,10 @@ internal enum LanguageOverride {
French,
German,
Greek,
// Italian,
Japanese,
// Korean,
// Norwegian,
PortugueseBrazil,

View File

@ -14,30 +14,34 @@ internal sealed class ExtraChat : IDisposable {
private ICallGateSubscriber<OverrideInfo, object> OverrideChannelGate { get; }
private ICallGateSubscriber<Dictionary<string, uint>, Dictionary<string, uint>> ChannelCommandColoursGate { get; }
private ICallGateSubscriber<Dictionary<Guid, string>, Dictionary<Guid, string>> ChannelNamesGate { get; }
internal (string, uint)? ChannelOverride { get; set; }
private Dictionary<string, uint> ChannelCommandColoursInternal { get; set; } = new();
internal IReadOnlyDictionary<string, uint> ChannelCommandColours => this.ChannelCommandColoursInternal;
private Dictionary<Guid, string> ChannelNamesInternal { get; set; } = new();
internal IReadOnlyDictionary<Guid, string> ChannelNames => this.ChannelNamesInternal;
internal ExtraChat(Plugin plugin) {
this.Plugin = plugin;
this.OverrideChannelGate = this.Plugin.Interface.GetIpcSubscriber<OverrideInfo, object>("ExtraChat.OverrideChannelColour");
this.ChannelCommandColoursGate = this.Plugin.Interface.GetIpcSubscriber<Dictionary<string, uint>, Dictionary<string, uint>>("ExtraChat.ChannelCommandColours");
this.ChannelNamesGate = this.Plugin.Interface.GetIpcSubscriber<Dictionary<Guid, string>, Dictionary<Guid, string>>("ExtraChat.ChannelNames");
this.OverrideChannelGate.Subscribe(this.OnOverrideChannel);
this.ChannelCommandColoursGate.Subscribe(this.OnChannelCommandColours);
this.ChannelNamesGate.Subscribe(this.OnChannelNames);
try {
this.ChannelCommandColoursInternal = this.ChannelCommandColoursGate.InvokeFunc(null!);
this.ChannelNamesInternal = this.ChannelNamesGate.InvokeFunc(null!);
} catch (Exception) {
// no-op
}
}
private void OnChannelCommandColours(Dictionary<string, uint> obj) {
this.ChannelCommandColoursInternal = obj;
}
public void Dispose() {
this.OverrideChannelGate.Unsubscribe(this.OnOverrideChannel);
}
@ -50,4 +54,12 @@ internal sealed class ExtraChat : IDisposable {
this.ChannelOverride = (info.Channel, info.Rgba);
}
private void OnChannelCommandColours(Dictionary<string, uint> obj) {
this.ChannelCommandColoursInternal = obj;
}
private void OnChannelNames(Dictionary<Guid, string> obj) {
this.ChannelNamesInternal = obj;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -845,4 +845,10 @@
<data name="Options_CollapseDuplicateMessages_Description" xml:space="preserve">
<value>Replace consecutive duplicate messages with a counter appended to the first instance of the message.</value>
</data>
<data name="Options_Tabs_ExtraChatChannels" xml:space="preserve">
<value>ExtraChat channels</value>
</data>
<data name="Options_Tabs_ExtraChatAll" xml:space="preserve">
<value>All</value>
</data>
</root>

View File

@ -24,7 +24,7 @@ internal sealed class Settings : IUiComponent {
new Display(this.Mutable),
new Ui.SettingsTabs.Fonts(this.Mutable),
new ChatColours(this.Mutable, this.Ui.Plugin),
new Tabs(this.Mutable),
new Tabs(this.Ui.Plugin, this.Mutable),
new Database(this.Mutable, this.Ui.Plugin.Store),
new Miscellaneous(this.Mutable),
new About(),

View File

@ -7,13 +7,15 @@ using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
internal sealed class Tabs : ISettingsTab {
private Plugin Plugin { get; }
private Configuration Mutable { get; }
public string Name => Language.Options_Tabs_Tab + "###tabs-tabs";
private int _toOpen = -2;
internal Tabs(Configuration mutable) {
internal Tabs(Plugin plugin, Configuration mutable) {
this.Plugin = plugin;
this.Mutable = mutable;
}
@ -158,6 +160,27 @@ internal sealed class Tabs : ISettingsTab {
ImGui.TreePop();
}
if (this.Plugin.ExtraChat.ChannelNames.Count > 0 && ImGui.TreeNodeEx(Language.Options_Tabs_ExtraChatChannels)) {
ImGui.Checkbox(Language.Options_Tabs_ExtraChatAll, ref tab.ExtraChatAll);
ImGui.Separator();
foreach (var (id, name) in this.Plugin.ExtraChat.ChannelNames) {
var enabled = tab.ExtraChatChannels.Contains(id);
if (!ImGui.Checkbox($"{name}##ec-{id}", ref enabled)) {
continue;
}
if (enabled) {
tab.ExtraChatChannels.Add(id);
} else {
tab.ExtraChatChannels.Remove(id);
}
}
ImGui.TreePop();
}
ImGui.TreePop();
ImGui.PopID();