139 lines
4.7 KiB
C#
139 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Dalamud.Bindings.ImGui;
|
|
using Dalamud.Game.Text;
|
|
using Dalamud.Interface;
|
|
using Dalamud.Interface.Utility.Raii;
|
|
using Dalamud.Plugin;
|
|
using Questionable.Model.Questing;
|
|
using Questionable.Windows.Utils;
|
|
|
|
namespace Questionable.Windows.ConfigComponents;
|
|
|
|
internal abstract class ConfigComponent
|
|
{
|
|
protected const string DutyClipboardSeparator = ";";
|
|
|
|
protected const string DutyWhitelistPrefix = "+";
|
|
|
|
protected const string DutyBlacklistPrefix = "-";
|
|
|
|
private const string ModePrefix = "M:";
|
|
|
|
protected readonly string[] SupportedCfcOptions = new string[3] { "Enabled (Default)", "Enabled", "Disabled" };
|
|
|
|
protected readonly string[] UnsupportedCfcOptions = new string[3] { "Disabled (Default)", "Enabled", "Disabled" };
|
|
|
|
private readonly IDalamudPluginInterface _pluginInterface;
|
|
|
|
protected Configuration Configuration { get; }
|
|
|
|
protected ConfigComponent(IDalamudPluginInterface pluginInterface, Configuration configuration)
|
|
{
|
|
_pluginInterface = pluginInterface;
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public abstract void DrawTab();
|
|
|
|
protected void Save()
|
|
{
|
|
_pluginInterface.SavePluginConfig(Configuration);
|
|
}
|
|
|
|
protected static string FormatLevel(int level, bool includePrefix = true)
|
|
{
|
|
if (level == 0)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
return $"{(includePrefix ? SeIconChar.LevelEn.ToIconString() : string.Empty)}{FormatLevel(level / 10, includePrefix: false)}{((SeIconChar)(57440 + level % 10)).ToIconChar()}";
|
|
}
|
|
|
|
protected static void DrawNotes(bool enabledByDefault, IEnumerable<string> notes)
|
|
{
|
|
using ImRaii.ColorDisposable colorDisposable = new ImRaii.ColorDisposable();
|
|
colorDisposable.Push(ImGuiCol.TextDisabled, (!enabledByDefault) ? UiThemeUtils.StatusActive : UiThemeUtils.StatusAvailableComplete);
|
|
ImGui.SameLine();
|
|
using (ImRaii.PushFont(UiBuilder.IconFont))
|
|
{
|
|
if (!enabledByDefault)
|
|
{
|
|
ImGui.TextDisabled(FontAwesomeIcon.ExclamationTriangle.ToIconString());
|
|
}
|
|
else
|
|
{
|
|
ImGui.TextDisabled(FontAwesomeIcon.InfoCircle.ToIconString());
|
|
}
|
|
}
|
|
if (!ImGui.IsItemHovered())
|
|
{
|
|
return;
|
|
}
|
|
using (ImRaii.Tooltip())
|
|
{
|
|
ImGui.TextColored(in UiThemeUtils.StatusActive, "While testing, the following issues have been found:");
|
|
foreach (string note in notes)
|
|
{
|
|
ImGui.BulletText(note);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void DrawClipboardButtons(string clipboardPrefix, HashSet<uint> whitelistedIds, HashSet<uint> blacklistedIds, Dictionary<uint, EDutyMode>? modeOverrides = null)
|
|
{
|
|
using (ImRaii.Disabled(whitelistedIds.Count + blacklistedIds.Count + (modeOverrides?.Count ?? 0) == 0))
|
|
{
|
|
if (UiThemeUtils.IconTextButton(FontAwesomeIcon.Copy, "Export to clipboard"))
|
|
{
|
|
IEnumerable<string> first = whitelistedIds.Select((uint x) => $"{"+"}{x}");
|
|
IEnumerable<string> second = blacklistedIds.Select((uint x) => $"{"-"}{x}");
|
|
IEnumerable<string> enumerable = first.Concat(second);
|
|
if (modeOverrides != null)
|
|
{
|
|
enumerable = enumerable.Concat(modeOverrides.Select((KeyValuePair<uint, EDutyMode> x) => $"{"M:"}{x.Key}:{x.Value}"));
|
|
}
|
|
ImGui.SetClipboardText(clipboardPrefix + Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Join(";", enumerable))));
|
|
}
|
|
}
|
|
ImGui.SameLine();
|
|
string text = ThrottledClipboard.GetText();
|
|
using (ImRaii.Disabled(string.IsNullOrEmpty(text) || !text.StartsWith(clipboardPrefix, StringComparison.InvariantCulture)))
|
|
{
|
|
if (!UiThemeUtils.IconTextButton(FontAwesomeIcon.Paste, "Import from Clipboard"))
|
|
{
|
|
return;
|
|
}
|
|
text = text.Substring(clipboardPrefix.Length);
|
|
string text2 = Encoding.UTF8.GetString(Convert.FromBase64String(text));
|
|
whitelistedIds.Clear();
|
|
blacklistedIds.Clear();
|
|
modeOverrides?.Clear();
|
|
string[] array = text2.Split(";");
|
|
foreach (string text3 in array)
|
|
{
|
|
if (text3.StartsWith("+", StringComparison.InvariantCulture) && uint.TryParse(text3.AsSpan("+".Length), CultureInfo.InvariantCulture, out var result))
|
|
{
|
|
whitelistedIds.Add(result);
|
|
}
|
|
if (text3.StartsWith("-", StringComparison.InvariantCulture) && uint.TryParse(text3.AsSpan("-".Length), CultureInfo.InvariantCulture, out var result2))
|
|
{
|
|
blacklistedIds.Add(result2);
|
|
}
|
|
if (modeOverrides != null && text3.StartsWith("M:", StringComparison.InvariantCulture))
|
|
{
|
|
ReadOnlySpan<char> span = text3.AsSpan("M:".Length);
|
|
int num2 = span.IndexOf(':');
|
|
if (num2 > 0 && uint.TryParse(span.Slice(0, num2), CultureInfo.InvariantCulture, out var result3) && int.TryParse(span.Slice(num2 + 1), CultureInfo.InvariantCulture, out var result4) && Enum.IsDefined(typeof(EDutyMode), result4))
|
|
{
|
|
modeOverrides[result3] = (EDutyMode)result4;
|
|
}
|
|
}
|
|
}
|
|
Save();
|
|
}
|
|
}
|
|
}
|