65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Dalamud.Bindings.ImGui;
|
|
using Questionable.Controller;
|
|
using Questionable.Model;
|
|
using Questionable.Model.Questing;
|
|
|
|
namespace Questionable.Windows.Utils;
|
|
|
|
internal sealed class QuestSelector(QuestRegistry questRegistry)
|
|
{
|
|
private string _searchString = string.Empty;
|
|
|
|
public Predicate<Quest>? SuggestionPredicate { private get; set; }
|
|
|
|
public Predicate<Quest>? DefaultPredicate { private get; set; }
|
|
|
|
public Action<Quest>? QuestSelected { private get; set; }
|
|
|
|
public void DrawSelection()
|
|
{
|
|
if (QuestSelected == null)
|
|
{
|
|
throw new InvalidOperationException("QuestSelected action must be set before drawing the quest selector.");
|
|
}
|
|
ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X);
|
|
if (ImGui.BeginCombo("##QuestSelection", "Add Quest...", ImGuiComboFlags.HeightLarge))
|
|
{
|
|
ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X);
|
|
bool flag = ImGui.InputTextWithHint("", "Filter...", ref _searchString, 256, ImGuiInputTextFlags.AutoSelectAll | ImGuiInputTextFlags.EnterReturnsTrue);
|
|
IEnumerable<Quest> enumerable;
|
|
if (!string.IsNullOrEmpty(_searchString))
|
|
{
|
|
enumerable = Enumerable.Where(predicate: (!ElementId.TryFromString(_searchString, out ElementId elementId)) ? new Func<Quest, bool>(DefaultPredicate) : ((Func<Quest, bool>)((Quest x) => DefaultPredicate(x) || x.Id == elementId)), source: questRegistry.AllQuests.Where(delegate(Quest x)
|
|
{
|
|
ElementId id = x.Id;
|
|
return !(id is SatisfactionSupplyNpcId) && !(id is AlliedSocietyDailyId);
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
enumerable = questRegistry.AllQuests.Where((Quest x) => this.DefaultPredicate?.Invoke(x) ?? true);
|
|
}
|
|
foreach (Quest item in enumerable)
|
|
{
|
|
if ((SuggestionPredicate == null || SuggestionPredicate(item)) && (ImGui.Selectable(item.Info.Name) || flag))
|
|
{
|
|
QuestSelected(item);
|
|
if (flag)
|
|
{
|
|
ImGui.CloseCurrentPopup();
|
|
flag = false;
|
|
}
|
|
}
|
|
}
|
|
ImGui.EndCombo();
|
|
}
|
|
ImGui.Spacing();
|
|
bool DefaultPredicate(Quest x)
|
|
{
|
|
return x.Info.Name.Contains(_searchString, StringComparison.CurrentCultureIgnoreCase);
|
|
}
|
|
}
|
|
}
|