feat: add category filtering

This commit is contained in:
Anna 2021-01-14 12:00:15 -05:00
parent 48dc71b04a
commit 297402843e
3 changed files with 135 additions and 7 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Configuration;
namespace BetterPartyFinder {
@ -22,11 +23,18 @@ namespace BetterPartyFinder {
public class ConfigurationFilter {
public string Name { get; set; } = "<unnamed preset>";
public ListMode ListMode { get; set; } = ListMode.Blacklist;
public List<uint> Duties { get; set; } = new();
public ListMode DutiesMode { get; set; } = ListMode.Blacklist;
public HashSet<uint> Duties { get; set; } = new();
public HashSet<UiCategory> Categories { get; set; } = Enum.GetValues(typeof(UiCategory))
.Cast<UiCategory>()
.ToHashSet();
public List<JobFlags> Jobs { get; set; } = new();
// default to true because that's the PF's default
// use nosol if trying to avoid spam
public bool AllowHugeItemLevel { get; set; } = true;
public uint? MinItemLevel { get; set; }
public uint? MaxItemLevel { get; set; }

View File

@ -1,4 +1,5 @@
using System;
using System.Linq;
namespace BetterPartyFinder {
public class Filter : IDisposable {
@ -30,7 +31,7 @@ namespace BetterPartyFinder {
if (filter.Duties.Count > 0 && listing.DutyType == DutyType.Normal) {
var inList = filter.Duties.Contains(listing.RawDuty);
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (filter.ListMode) {
switch (filter.DutiesMode) {
case ListMode.Blacklist when inList:
case ListMode.Whitelist when !inList:
return false;
@ -46,6 +47,11 @@ namespace BetterPartyFinder {
return false;
}
// filter based on category (slow)
if (!filter.Categories.Any(category => category.ListingMatches(this.Plugin.Interface.Data, listing))) {
return false;
}
return true;
}

View File

@ -1,7 +1,7 @@
using System;
using System.Drawing;
using System.Linq;
using System.Numerics;
using Dalamud.Data;
using Dalamud.Interface;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
@ -169,7 +169,21 @@ namespace BetterPartyFinder {
return;
}
ImGui.TextUnformatted("Nothing here yet");
foreach (var category in (UiCategory[]) Enum.GetValues(typeof(UiCategory))) {
var selected = filter.Categories.Contains(category);
if (!ImGui.Selectable(category.Name(this.Plugin.Interface.Data), ref selected)) {
continue;
}
if (selected) {
filter.Categories.Add(category);
} else {
filter.Categories.Remove(category);
}
this.Plugin.Config.Save();
}
ImGui.EndTabItem();
}
@ -183,11 +197,11 @@ namespace BetterPartyFinder {
"Show ONLY these duties",
"Do NOT show these duties",
};
var listModeIdx = filter.ListMode == ListMode.Blacklist ? 1 : 0;
var listModeIdx = filter.DutiesMode == ListMode.Blacklist ? 1 : 0;
ImGui.TextUnformatted("List mode");
ImGui.PushItemWidth(-1);
if (ImGui.Combo("###list-mode", ref listModeIdx, listModeStrings, listModeStrings.Length)) {
filter.ListMode = listModeIdx == 0 ? ListMode.Whitelist : ListMode.Blacklist;
filter.DutiesMode = listModeIdx == 0 ? ListMode.Whitelist : ListMode.Blacklist;
this.Plugin.Config.Save();
}
@ -296,4 +310,104 @@ namespace BetterPartyFinder {
ImGui.EndTabItem();
}
}
public enum UiCategory {
None,
DutyRoulette,
Dungeons,
Guildhests,
Trials,
Raids,
HighEndDuty,
Pvp,
QuestBattles,
Fates,
TreasureHunt,
TheHunt,
GatheringForays,
DeepDungeons,
AdventuringForays,
}
internal static class UiCategoryExt {
internal static string? Name(this UiCategory category, DataManager data) {
var ct = data.GetExcelSheet<ContentType>();
var addon = data.GetExcelSheet<Addon>();
return category switch {
UiCategory.None => addon.GetRow(1_562).Text.ToString(), // best guess
UiCategory.DutyRoulette => ct.GetRow((uint) ContentType2.DutyRoulette).Name.ToString(),
UiCategory.Dungeons => ct.GetRow((uint) ContentType2.Dungeons).Name.ToString(),
UiCategory.Guildhests => ct.GetRow((uint) ContentType2.Guildhests).Name.ToString(),
UiCategory.Trials => ct.GetRow((uint) ContentType2.Trials).Name.ToString(),
UiCategory.Raids => ct.GetRow((uint) ContentType2.Raids).Name.ToString(),
UiCategory.HighEndDuty => addon.GetRow(10_822).Text.ToString(), // best guess
UiCategory.Pvp => ct.GetRow((uint) ContentType2.Pvp).Name.ToString(),
UiCategory.QuestBattles => ct.GetRow((uint) ContentType2.QuestBattles).Name.ToString(),
UiCategory.Fates => ct.GetRow((uint) ContentType2.Fates).Name.ToString(),
UiCategory.TreasureHunt => ct.GetRow((uint) ContentType2.TreasureHunt).Name.ToString(),
UiCategory.TheHunt => addon.GetRow(8_613).Text.ToString(),
UiCategory.GatheringForays => addon.GetRow(2_306).Text.ToString(),
UiCategory.DeepDungeons => ct.GetRow((uint) ContentType2.DeepDungeons).Name.ToString(),
UiCategory.AdventuringForays => addon.GetRow(2_307).Text.ToString(),
_ => null,
};
}
internal static bool ListingMatches(this UiCategory category, DataManager data, PartyFinderListing listing) {
var cr = data.GetExcelSheet<ContentRoulette>();
var isDuty = listing.Category == Category.Duty;
var isNormal = listing.DutyType == DutyType.Normal;
var isOther = listing.DutyType == DutyType.Other;
var isNormalDuty = isNormal && isDuty;
return category switch {
UiCategory.None => isOther && isDuty && listing.RawDuty == 0,
UiCategory.DutyRoulette => listing.DutyType == DutyType.Roulette && isDuty && !cr.GetRow(listing.RawDuty).Unknown10,
UiCategory.Dungeons => isNormalDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Dungeons,
UiCategory.Guildhests => isNormalDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Guildhests,
UiCategory.Trials => isNormalDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Trials,
UiCategory.Raids => isNormalDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Raids,
UiCategory.HighEndDuty => isNormalDuty && listing.Duty.Value.HighEndDuty,
UiCategory.Pvp => listing.DutyType == DutyType.Roulette && isDuty && cr.GetRow(listing.RawDuty).Unknown10
|| isNormalDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Pvp,
UiCategory.QuestBattles => isOther && listing.Category == Category.QuestBattles,
UiCategory.Fates => isOther && listing.Category == Category.Fates,
UiCategory.TreasureHunt => isOther && listing.Category == Category.TreasureHunt,
UiCategory.TheHunt => isOther && listing.Category == Category.TheHunt,
UiCategory.GatheringForays => isNormal && listing.Category == Category.GatheringForays,
UiCategory.DeepDungeons => isOther && listing.Category == Category.DeepDungeons,
UiCategory.AdventuringForays => isNormal && listing.Category == Category.AdventuringForays,
_ => false,
};
}
private enum ContentType2 {
DutyRoulette = 1,
Dungeons = 2,
Guildhests = 3,
Trials = 4,
Raids = 5,
Pvp = 6,
QuestBattles = 7,
Fates = 8,
TreasureHunt = 9,
Levequests = 10,
GrandCompany = 11,
Companions = 12,
BeastTribeQuests = 13,
OverallCompletion = 14,
PlayerCommendation = 15,
DisciplesOfTheLand = 16,
DisciplesOfTheHand = 17,
RetainerVentures = 18,
GoldSaucer = 19,
DeepDungeons = 21,
WondrousTails = 24,
CustomDeliveries = 25,
Eureka = 26,
UltimateRaids = 28,
}
}
}