feat: add names to filters

This commit is contained in:
Anna 2021-05-08 14:51:53 -04:00
parent 85a9d74293
commit 83b7c58389
6 changed files with 55 additions and 11 deletions

View File

@ -5,7 +5,7 @@ using Dalamud.Configuration;
using Dalamud.Plugin;
using DotNet.Globbing;
namespace SoundFilter {
namespace SoundFilter.Config {
[Serializable]
internal class Configuration : IPluginConfiguration {
public int Version { get; set; } = 1;
@ -16,7 +16,7 @@ namespace SoundFilter {
public bool Enabled = true;
public bool ShowLog;
public uint LogEntries = 250;
public Dictionary<string, bool> Filtered { get; set; } = new();
public Dictionary<string, CustomFilter> Filtered { get; set; } = new();
internal IReadOnlyDictionary<Glob, bool> Globs {
get {
@ -30,7 +30,7 @@ namespace SoundFilter {
this.CachedGlobs[entry.Key] = glob;
return glob;
},
entry => entry.Value
entry => entry.Value.Enabled
);
}
}

View File

@ -0,0 +1,9 @@
using System;
namespace SoundFilter.Config {
[Serializable]
internal class CustomFilter {
public string Name = "Unnamed filter";
public bool Enabled = true;
}
}

View File

@ -96,6 +96,24 @@ namespace SoundFilter.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Filter name.
/// </summary>
internal static string SettingsAddFilterName {
get {
return ResourceManager.GetString("SettingsAddFilterName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sound path to filter.
/// </summary>
internal static string SettingsAddPathToFilter {
get {
return ResourceManager.GetString("SettingsAddPathToFilter", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enable sound filter.
/// </summary>

View File

@ -39,4 +39,10 @@
<data name="LoadWarning" xml:space="preserve">
<value>Due to the way FFXIV's resource loading works, {0} has to hear a sound once before it can filter it after a fresh install or update. Restart your game after installing or updating if this is a problem for you.</value>
</data>
<data name="SettingsAddFilterName" xml:space="preserve">
<value>Filter name</value>
</data>
<data name="SettingsAddPathToFilter" xml:space="preserve">
<value>Sound path to filter</value>
</data>
</root>

View File

@ -3,6 +3,7 @@ using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Plugin;
using SoundFilter.Config;
using SoundFilter.Resources;
using SoundFilter.Ui;

View File

@ -1,8 +1,8 @@
using System;
using System.Linq;
using Dalamud.Interface;
using DotNet.Globbing;
using ImGuiNET;
using SoundFilter.Config;
using SoundFilter.Resources;
namespace SoundFilter.Ui {
@ -10,6 +10,7 @@ namespace SoundFilter.Ui {
private SoundFilterPlugin Plugin { get; }
private bool _showWindow;
private string _filterName = string.Empty;
private string _soundPath = string.Empty;
internal Settings(SoundFilterPlugin plugin) {
@ -52,18 +53,25 @@ namespace SoundFilter.Ui {
ImGui.Separator();
ImGui.TextUnformatted("Sound path to filter");
ImGui.TextUnformatted(Language.SettingsAddFilterName);
ImGui.InputText("##sound-filter-name", ref this._filterName, 255);
ImGui.TextUnformatted(Language.SettingsAddPathToFilter);
ImGui.InputText("##sound-path", ref this._soundPath, 255);
ImGui.SameLine();
if (Util.IconButton(FontAwesomeIcon.Plus, "add") && !string.IsNullOrWhiteSpace(this._soundPath)) {
this.Plugin.Config.Filtered[this._soundPath] = true;
if (Util.IconButton(FontAwesomeIcon.Plus, "add") && !string.IsNullOrWhiteSpace(this._soundPath) && !string.IsNullOrWhiteSpace(this._filterName)) {
this.Plugin.Config.Filtered[this._soundPath] = new CustomFilter {
Name = this._filterName,
Enabled = true,
};
shouldSave = true;
}
ImGui.Separator();
if (ImGui.BeginChild("filtered-sounds")) {
foreach (var entry in this.Plugin.Config.Filtered.ToList()) {
var glob = entry.Key;
var enabled = entry.Value;
if (Util.IconButton(FontAwesomeIcon.Trash, $"delete-{glob}")) {
this.Plugin.Config.Filtered.Remove(glob);
@ -72,9 +80,11 @@ namespace SoundFilter.Ui {
ImGui.SameLine();
if (ImGui.Checkbox(glob, ref enabled)) {
this.Plugin.Config.Filtered[glob] = enabled;
shouldSave = true;
shouldSave |= ImGui.Checkbox(entry.Value.Name, ref entry.Value.Enabled);
if (ImGui.IsItemHovered()) {
ImGui.BeginTooltip();
ImGui.TextUnformatted(glob);
ImGui.EndTooltip();
}
}