248 lines
8.1 KiB
C#
248 lines
8.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using Dalamud.Bindings.ImGui;
|
|
using Dalamud.Interface;
|
|
using Dalamud.Interface.Components;
|
|
using Dalamud.Interface.Utility.Raii;
|
|
using Dalamud.Plugin;
|
|
using Questionable.Controller;
|
|
using Questionable.Functions;
|
|
using Questionable.Model;
|
|
using Questionable.Model.Questing;
|
|
using Questionable.Windows.QuestComponents;
|
|
using Questionable.Windows.Utils;
|
|
|
|
namespace Questionable.Windows.ConfigComponents;
|
|
|
|
internal sealed class BlacklistConfigComponent : ConfigComponent
|
|
{
|
|
private readonly IDalamudPluginInterface _pluginInterface;
|
|
|
|
private readonly QuestSelector _questSelector;
|
|
|
|
private readonly QuestRegistry _questRegistry;
|
|
|
|
private readonly QuestFunctions _questFunctions;
|
|
|
|
private readonly QuestTooltipComponent _questTooltipComponent;
|
|
|
|
private readonly UiUtils _uiUtils;
|
|
|
|
public BlacklistConfigComponent(IDalamudPluginInterface pluginInterface, QuestSelector questSelector, QuestFunctions questFunctions, QuestRegistry questRegistry, QuestTooltipComponent questTooltipComponent, UiUtils uiUtils, Configuration configuration)
|
|
: base(pluginInterface, configuration)
|
|
{
|
|
BlacklistConfigComponent blacklistConfigComponent = this;
|
|
_pluginInterface = pluginInterface;
|
|
_questSelector = questSelector;
|
|
_questRegistry = questRegistry;
|
|
_questFunctions = questFunctions;
|
|
_questTooltipComponent = questTooltipComponent;
|
|
_uiUtils = uiUtils;
|
|
_questSelector.SuggestionPredicate = (Quest quest) => !configuration.General.BlacklistedQuests.Contains(quest.Id);
|
|
_questSelector.DefaultPredicate = (Quest quest) => !quest.Root.Disabled && questFunctions.IsQuestAccepted(quest.Id);
|
|
_questSelector.QuestSelected = delegate(Quest quest)
|
|
{
|
|
configuration.General.BlacklistedQuests.Add(quest.Id);
|
|
blacklistConfigComponent.Save();
|
|
};
|
|
}
|
|
|
|
public override void DrawTab()
|
|
{
|
|
using ImRaii.IEndObject endObject = ImRaii.TabItem("Blacklist###QuestBlacklist");
|
|
if (!endObject)
|
|
{
|
|
return;
|
|
}
|
|
ImGui.TextWrapped("Blacklisted quests will never be automatically picked up or executed by Questionable.");
|
|
ImGui.TextWrapped("Use this to permanently skip specific quests you don't want to do.");
|
|
ImGui.Separator();
|
|
DrawCurrentlyAcceptedQuests();
|
|
HashSet<ElementId> blacklistedQuests = base.Configuration.General.BlacklistedQuests;
|
|
ImU8String text = new ImU8String(22, 1);
|
|
text.AppendLiteral("Blacklisted Quests (");
|
|
text.AppendFormatted(blacklistedQuests.Count);
|
|
text.AppendLiteral("):");
|
|
ImGui.Text(text);
|
|
using (ImRaii.IEndObject endObject2 = ImRaii.Child("BlacklistedQuestsList", new Vector2(-1f, 200f), border: true))
|
|
{
|
|
if (endObject2)
|
|
{
|
|
if (blacklistedQuests.Count > 0)
|
|
{
|
|
ElementId elementId = null;
|
|
int num = 0;
|
|
foreach (ElementId item in blacklistedQuests.OrderBy((ElementId x) => x.ToString()))
|
|
{
|
|
if (!_questRegistry.TryGetQuest(item, out Quest quest))
|
|
{
|
|
ImU8String id = new ImU8String(5, 1);
|
|
id.AppendLiteral("Quest");
|
|
id.AppendFormatted(item);
|
|
using (ImRaii.PushId(id))
|
|
{
|
|
ImGui.AlignTextToFramePadding();
|
|
Vector4 col = new Vector4(0.7f, 0.7f, 0.7f, 1f);
|
|
ImU8String text2 = new ImU8String(16, 1);
|
|
text2.AppendLiteral("Unknown Quest (");
|
|
text2.AppendFormatted(item);
|
|
text2.AppendLiteral(")");
|
|
ImGui.TextColored(in col, text2);
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.CalcTextSize(FontAwesomeIcon.Times.ToIconString()).X - ImGui.GetStyle().FramePadding.X * 2f);
|
|
if (ImGuiComponents.IconButton($"##Remove{num}", FontAwesomeIcon.Times))
|
|
{
|
|
elementId = item;
|
|
}
|
|
}
|
|
num++;
|
|
continue;
|
|
}
|
|
ImU8String id2 = new ImU8String(5, 1);
|
|
id2.AppendLiteral("Quest");
|
|
id2.AppendFormatted(item);
|
|
using (ImRaii.PushId(id2))
|
|
{
|
|
(Vector4, FontAwesomeIcon, string) questStyle = _uiUtils.GetQuestStyle(item);
|
|
bool flag;
|
|
using (_pluginInterface.UiBuilder.IconFontFixedWidthHandle.Push())
|
|
{
|
|
ImGui.AlignTextToFramePadding();
|
|
ImGui.TextColored(in questStyle.Item1, questStyle.Item2.ToIconString());
|
|
flag = ImGui.IsItemHovered();
|
|
}
|
|
ImGui.SameLine();
|
|
ImGui.AlignTextToFramePadding();
|
|
ImGui.TextUnformatted(quest.Info.Name);
|
|
flag |= ImGui.IsItemHovered();
|
|
if (flag)
|
|
{
|
|
_questTooltipComponent.Draw(quest.Info);
|
|
}
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.CalcTextSize(FontAwesomeIcon.Times.ToIconString()).X - ImGui.GetStyle().FramePadding.X * 2f);
|
|
if (ImGuiComponents.IconButton($"##Remove{num}", FontAwesomeIcon.Times))
|
|
{
|
|
elementId = item;
|
|
}
|
|
if (ImGui.IsItemHovered())
|
|
{
|
|
ImGui.SetTooltip("Remove from blacklist");
|
|
}
|
|
}
|
|
num++;
|
|
}
|
|
if (elementId != null)
|
|
{
|
|
base.Configuration.General.BlacklistedQuests.Remove(elementId);
|
|
Save();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.7f, 0.7f, 0.7f, 1f));
|
|
ImGui.TextWrapped("No quests blacklisted. Use the dropdown above or add from currently accepted quests.");
|
|
ImGui.PopStyleColor();
|
|
}
|
|
}
|
|
}
|
|
_questSelector.DrawSelection();
|
|
if (blacklistedQuests.Count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
using (ImRaii.Disabled(!ImGui.IsKeyDown(ImGuiKey.ModCtrl)))
|
|
{
|
|
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Trash, "Clear All"))
|
|
{
|
|
base.Configuration.General.BlacklistedQuests.Clear();
|
|
Save();
|
|
}
|
|
}
|
|
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
|
|
{
|
|
ImGui.SetTooltip("Hold CTRL to enable this button.");
|
|
}
|
|
}
|
|
|
|
private void DrawCurrentlyAcceptedQuests()
|
|
{
|
|
List<Quest> currentlyAcceptedQuests = GetCurrentlyAcceptedQuests();
|
|
ImGui.Text("Currently Accepted Quests:");
|
|
using (ImRaii.IEndObject endObject = ImRaii.Child("AcceptedQuestsList", new Vector2(-1f, 100f), border: true))
|
|
{
|
|
if (endObject)
|
|
{
|
|
if (currentlyAcceptedQuests.Count > 0)
|
|
{
|
|
foreach (Quest item in currentlyAcceptedQuests)
|
|
{
|
|
ImU8String id = new ImU8String(13, 1);
|
|
id.AppendLiteral("AcceptedQuest");
|
|
id.AppendFormatted(item.Id);
|
|
using (ImRaii.PushId(id))
|
|
{
|
|
(Vector4, FontAwesomeIcon, string) questStyle = _uiUtils.GetQuestStyle(item.Id);
|
|
bool flag = false;
|
|
bool flag2 = base.Configuration.General.BlacklistedQuests.Contains(item.Id);
|
|
using (_pluginInterface.UiBuilder.IconFontFixedWidthHandle.Push())
|
|
{
|
|
ImGui.AlignTextToFramePadding();
|
|
ImGui.TextColored(flag2 ? new Vector4(0.5f, 0.5f, 0.5f, 1f) : questStyle.Item1, questStyle.Item2.ToIconString());
|
|
flag = ImGui.IsItemHovered();
|
|
}
|
|
ImGui.SameLine();
|
|
ImGui.AlignTextToFramePadding();
|
|
ImGui.TextColored(flag2 ? new Vector4(0.7f, 0.7f, 0.7f, 1f) : new Vector4(1f, 1f, 1f, 1f), item.Info.Name);
|
|
if (flag | ImGui.IsItemHovered())
|
|
{
|
|
_questTooltipComponent.Draw(item.Info);
|
|
}
|
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.CalcTextSize(FontAwesomeIcon.Ban.ToIconString()).X - ImGui.GetStyle().FramePadding.X * 2f);
|
|
using (ImRaii.Disabled(flag2))
|
|
{
|
|
if (ImGuiComponents.IconButton($"##Blacklist{item.Id}", FontAwesomeIcon.Ban))
|
|
{
|
|
base.Configuration.General.BlacklistedQuests.Add(item.Id);
|
|
Save();
|
|
}
|
|
}
|
|
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
|
|
{
|
|
ImGui.SetTooltip(flag2 ? "Quest already blacklisted" : "Add this quest to blacklist");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.7f, 0.7f, 0.7f, 1f));
|
|
ImGui.TextWrapped("No quests currently accepted");
|
|
ImGui.PopStyleColor();
|
|
}
|
|
}
|
|
}
|
|
ImGui.Spacing();
|
|
}
|
|
|
|
private List<Quest> GetCurrentlyAcceptedQuests()
|
|
{
|
|
List<Quest> list = new List<Quest>();
|
|
try
|
|
{
|
|
foreach (Quest allQuest in _questRegistry.AllQuests)
|
|
{
|
|
if (_questFunctions.IsQuestAccepted(allQuest.Id))
|
|
{
|
|
list.Add(allQuest);
|
|
}
|
|
}
|
|
list.Sort((Quest a, Quest b) => string.Compare(a.Info.Name, b.Info.Name, StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
catch (Exception)
|
|
{
|
|
list.Clear();
|
|
}
|
|
return list;
|
|
}
|
|
}
|