feat: add battle talk filtering
This commit is contained in:
parent
d11848ff7c
commit
10e6b5ecc3
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin;
|
||||
using XivCommon;
|
||||
|
||||
namespace BurntToast {
|
||||
public class BurntToast : IDalamudPlugin {
|
||||
|
@ -8,6 +8,7 @@ namespace BurntToast {
|
|||
internal DalamudPluginInterface Interface { get; private set; } = null!;
|
||||
internal Configuration Config { get; private set; } = null!;
|
||||
internal PluginUi Ui { get; private set; } = null!;
|
||||
internal XivCommonBase Common { get; private set; } = null!;
|
||||
private Commands Commands { get; set; } = null!;
|
||||
private Filter Filter { get; set; } = null!;
|
||||
|
||||
|
@ -19,11 +20,13 @@ namespace BurntToast {
|
|||
|
||||
this.Ui = new PluginUi(this);
|
||||
this.Commands = new Commands(this);
|
||||
this.Common = new XivCommonBase(this.Interface, Hooks.BattleTalk);
|
||||
this.Filter = new Filter(this);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
this.Filter.Dispose();
|
||||
this.Common.Dispose();
|
||||
this.Commands.Dispose();
|
||||
this.Ui.Dispose();
|
||||
}
|
||||
|
|
|
@ -10,22 +10,25 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Dalamud, Version=5.2.4.5, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\..\Dalamud\bin\Dalamud.dll</HintPath>
|
||||
<Reference Include="Dalamud">
|
||||
<HintPath>D:\code\Dalamud\bin\Dalamud.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="ImGui.NET, Version=1.72.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\..\Dalamud\bin\ImGui.NET.dll</HintPath>
|
||||
<Reference Include="ImGui.NET">
|
||||
<HintPath>D:\code\Dalamud\bin\ImGui.NET.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="ImGuiScene, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\..\Dalamud\bin\ImGuiScene.dll</HintPath>
|
||||
<Reference Include="ImGuiScene">
|
||||
<HintPath>D:\code\Dalamud\bin\ImGuiScene.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DalamudPackager" Version="1.2.1" />
|
||||
<PackageReference Include="DalamudPackager" Version="1.2.1"/>
|
||||
<PackageReference Include="Fody" Version="6.5.1" PrivateAssets="all"/>
|
||||
<PackageReference Include="ILMerge.Fody" Version="1.16.0" PrivateAssets="all"/>
|
||||
<PackageReference Include="XivCommon" Version="1.1.2"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using Dalamud.Configuration;
|
||||
|
||||
namespace BurntToast {
|
||||
[Serializable]
|
||||
public class Configuration : IPluginConfiguration {
|
||||
private BurntToast Plugin { get; set; } = null!;
|
||||
|
||||
public int Version { get; set; } = 1;
|
||||
|
||||
public List<Regex> Patterns { get; set; } = new List<Regex>();
|
||||
public List<Regex> Patterns { get; set; } = new();
|
||||
|
||||
public List<BattleTalkPattern> BattleTalkPatterns { get; set; } = new();
|
||||
|
||||
internal void Initialise(BurntToast plugin) {
|
||||
this.Plugin = plugin;
|
||||
|
@ -18,4 +22,15 @@ namespace BurntToast {
|
|||
this.Plugin.Interface.SavePluginConfig(this);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class BattleTalkPattern {
|
||||
public Regex Pattern { get; set; }
|
||||
public bool ShowMessage { get; set; }
|
||||
|
||||
public BattleTalkPattern(Regex pattern, bool showMessage) {
|
||||
this.Pattern = pattern;
|
||||
this.ShowMessage = showMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Dalamud.Game.Internal.Gui.Toast;
|
||||
using Dalamud.Game.Text;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using XivCommon.Functions;
|
||||
|
||||
namespace BurntToast {
|
||||
public class Filter : IDisposable {
|
||||
|
@ -13,14 +15,20 @@ namespace BurntToast {
|
|||
this.Plugin.Interface.Framework.Gui.Toast.OnToast += this.OnToast;
|
||||
this.Plugin.Interface.Framework.Gui.Toast.OnQuestToast += this.OnQuestToast;
|
||||
this.Plugin.Interface.Framework.Gui.Toast.OnErrorToast += this.OnErrorToast;
|
||||
this.Plugin.Common.Functions.BattleTalk.OnBattleTalk += this.OnBattleTalk;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
this.Plugin.Common.Functions.BattleTalk.OnBattleTalk -= this.OnBattleTalk;
|
||||
this.Plugin.Interface.Framework.Gui.Toast.OnErrorToast -= this.OnErrorToast;
|
||||
this.Plugin.Interface.Framework.Gui.Toast.OnQuestToast -= this.OnQuestToast;
|
||||
this.Plugin.Interface.Framework.Gui.Toast.OnToast -= this.OnToast;
|
||||
}
|
||||
|
||||
private bool AnyMatches(string text) {
|
||||
return this.Plugin.Config.Patterns.Any(regex => regex.IsMatch(text));
|
||||
}
|
||||
|
||||
private void OnToast(ref SeString message, ref ToastOptions options, ref bool isHandled) {
|
||||
this.DoFilter(message, ref isHandled);
|
||||
}
|
||||
|
@ -38,10 +46,31 @@ namespace BurntToast {
|
|||
return;
|
||||
}
|
||||
|
||||
var text = message.TextValue;
|
||||
if (this.Plugin.Config.Patterns.Any(regex => regex.IsMatch(text))) {
|
||||
if (this.AnyMatches(message.TextValue)) {
|
||||
isHandled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBattleTalk(ref SeString sender, ref SeString message, ref BattleTalkOptions options, ref bool isHandled) {
|
||||
if (isHandled) {
|
||||
return;
|
||||
}
|
||||
|
||||
var text = message.TextValue;
|
||||
var pattern = this.Plugin.Config.BattleTalkPatterns.Find(pattern => pattern.Pattern.IsMatch(text));
|
||||
if (pattern == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
isHandled = true;
|
||||
|
||||
if (pattern.ShowMessage) {
|
||||
this.Plugin.Interface.Framework.Gui.Chat.PrintChat(new XivChatEntry {
|
||||
Type = (XivChatType) 68,
|
||||
Name = sender.TextValue,
|
||||
MessageBytes = message.Encode(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<ILMerge/>
|
||||
</Weavers>
|
|
@ -46,6 +46,28 @@ namespace BurntToast {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!ImGui.BeginTabBar("burnt-toast-tabs")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabItem("Toasts")) {
|
||||
this.DrawToastTab();
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabItem("Battle talk")) {
|
||||
this.DrawBattleTalkTab();
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
ImGui.EndTabBar();
|
||||
|
||||
|
||||
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
private void DrawToastTab() {
|
||||
ImGui.PushTextWrapPos();
|
||||
ImGui.TextUnformatted("Add regular expressions to filter below. Any toast matching a regular expression on the list will be hidden.");
|
||||
ImGui.PopTextWrapPos();
|
||||
|
@ -96,8 +118,66 @@ namespace BurntToast {
|
|||
if (toRemove != null) {
|
||||
this.Plugin.Config.Patterns.RemoveAt(toRemove.Value);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.End();
|
||||
private void DrawBattleTalkTab() {
|
||||
ImGui.PushTextWrapPos();
|
||||
ImGui.TextUnformatted("Add regular expressions to filter below. Any battle talk matching a regular expression on the list will be hidden.");
|
||||
ImGui.PopTextWrapPos();
|
||||
|
||||
if (ImGui.Button("Add")) {
|
||||
this.Plugin.Config.BattleTalkPatterns.Add(new BattleTalkPattern(new Regex(""), true));
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
int? toRemove = null;
|
||||
|
||||
for (var i = 0; i < this.Plugin.Config.BattleTalkPatterns.Count; i++) {
|
||||
var pattern = this.Plugin.Config.BattleTalkPatterns[i];
|
||||
var patternText = pattern.Pattern.ToString();
|
||||
var textResult = ImGui.InputText($"##pattern-{i}", ref patternText, 250);
|
||||
|
||||
ImGui.SameLine();
|
||||
var show = pattern.ShowMessage;
|
||||
if (ImGui.Checkbox("Show in chat", ref show)) {
|
||||
pattern.ShowMessage = show;
|
||||
this.Plugin.Config.Save();
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button($"Delete##{i}")) {
|
||||
toRemove = i;
|
||||
}
|
||||
|
||||
if (!textResult) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(patternText)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Regex? regex = null;
|
||||
try {
|
||||
regex = new Regex(patternText, RegexOptions.Compiled);
|
||||
} catch (ArgumentException) {
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0f, 0f, 1f));
|
||||
ImGui.TextUnformatted("Invalid regular expression.");
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
||||
if (regex == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pattern.Pattern = regex;
|
||||
this.Plugin.Config.Save();
|
||||
}
|
||||
|
||||
if (toRemove != null) {
|
||||
this.Plugin.Config.BattleTalkPatterns.RemoveAt(toRemove.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue