feat: add player filtering
This commit is contained in:
parent
6c80ef1f0b
commit
6fcc6d9694
|
@ -50,6 +50,8 @@ namespace BetterPartyFinder {
|
||||||
public uint? MinItemLevel { get; set; }
|
public uint? MinItemLevel { get; set; }
|
||||||
public uint? MaxItemLevel { get; set; }
|
public uint? MaxItemLevel { get; set; }
|
||||||
|
|
||||||
|
public HashSet<PlayerInfo> Players { get; set; } = new();
|
||||||
|
|
||||||
internal bool this[SearchAreaFlags flags] {
|
internal bool this[SearchAreaFlags flags] {
|
||||||
get => (this.SearchArea & flags) > 0;
|
get => (this.SearchArea & flags) > 0;
|
||||||
set {
|
set {
|
||||||
|
@ -109,6 +111,7 @@ namespace BetterPartyFinder {
|
||||||
var categories = this.Categories.ToHashSet();
|
var categories = this.Categories.ToHashSet();
|
||||||
var duties = this.Duties.ToHashSet();
|
var duties = this.Duties.ToHashSet();
|
||||||
var jobs = this.Jobs.ToList();
|
var jobs = this.Jobs.ToList();
|
||||||
|
var players = this.Players.Select(info => info.Clone()).ToHashSet();
|
||||||
|
|
||||||
return new ConfigurationFilter {
|
return new ConfigurationFilter {
|
||||||
Categories = categories,
|
Categories = categories,
|
||||||
|
@ -124,6 +127,7 @@ namespace BetterPartyFinder {
|
||||||
MaxItemLevel = this.MaxItemLevel,
|
MaxItemLevel = this.MaxItemLevel,
|
||||||
MinItemLevel = this.MinItemLevel,
|
MinItemLevel = this.MinItemLevel,
|
||||||
AllowHugeItemLevel = this.AllowHugeItemLevel,
|
AllowHugeItemLevel = this.AllowHugeItemLevel,
|
||||||
|
Players = players,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +140,42 @@ namespace BetterPartyFinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class PlayerInfo {
|
||||||
|
public string Name { get; }
|
||||||
|
public uint World { get; }
|
||||||
|
|
||||||
|
public PlayerInfo(string name, uint world) {
|
||||||
|
this.Name = name;
|
||||||
|
this.World = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal PlayerInfo Clone() {
|
||||||
|
return new(this.Name, this.World);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool Equals(PlayerInfo other) {
|
||||||
|
return this.Name == other.Name && this.World == other.World;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj) {
|
||||||
|
if (ReferenceEquals(null, obj)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ReferenceEquals(this, obj)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj.GetType() == this.GetType() && this.Equals((PlayerInfo) obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode() {
|
||||||
|
unchecked {
|
||||||
|
return (this.Name.GetHashCode() * 397) ^ (int) this.World;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public enum ListMode {
|
public enum ListMode {
|
||||||
Whitelist,
|
Whitelist,
|
||||||
Blacklist,
|
Blacklist,
|
||||||
|
|
|
@ -140,6 +140,13 @@ namespace BetterPartyFinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// filter based on player
|
||||||
|
if (filter.Players.Count > 0) {
|
||||||
|
if (filter.Players.Any(info => info.Name == listing.Name && info.World == listing.HomeWorld.Value.RowId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -283,6 +283,8 @@ namespace BetterPartyFinder {
|
||||||
|
|
||||||
this.DrawRestrictionsTab(filter);
|
this.DrawRestrictionsTab(filter);
|
||||||
|
|
||||||
|
this.DrawPlayersTab(filter);
|
||||||
|
|
||||||
ImGui.EndTabBar();
|
ImGui.EndTabBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,6 +581,65 @@ namespace BetterPartyFinder {
|
||||||
|
|
||||||
ImGui.EndTabItem();
|
ImGui.EndTabItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int _selectedWorld;
|
||||||
|
private string _playerName = string.Empty;
|
||||||
|
|
||||||
|
private void DrawPlayersTab(ConfigurationFilter filter) {
|
||||||
|
var player = this.Plugin.Interface.ClientState.LocalPlayer;
|
||||||
|
|
||||||
|
if (player == null || !ImGui.BeginTabItem("Players")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.PushItemWidth(ImGui.GetWindowWidth() / 3f);
|
||||||
|
|
||||||
|
ImGui.InputText("###player-name", ref this._playerName, 64);
|
||||||
|
|
||||||
|
ImGui.SameLine();
|
||||||
|
|
||||||
|
var worlds = Util.WorldsOnDataCentre(this.Plugin.Interface.Data, player)
|
||||||
|
.OrderBy(world => world.Name.RawString)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var worldNames = worlds
|
||||||
|
.Select(world => world.Name.ToString())
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
if (ImGui.Combo("###player-world", ref this._selectedWorld, worldNames, worldNames.Length)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.PopItemWidth();
|
||||||
|
|
||||||
|
ImGui.SameLine();
|
||||||
|
|
||||||
|
if (IconButton(FontAwesomeIcon.Plus, "add-player")) {
|
||||||
|
var name = this._playerName.Trim();
|
||||||
|
if (name.Length != 0) {
|
||||||
|
var world = worlds[this._selectedWorld];
|
||||||
|
filter.Players.Add(new PlayerInfo(name, world.RowId));
|
||||||
|
this.Plugin.Config.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerInfo? deleting = null;
|
||||||
|
|
||||||
|
foreach (var info in filter.Players) {
|
||||||
|
var world = this.Plugin.Interface.Data.GetExcelSheet<World>().GetRow(info.World);
|
||||||
|
ImGui.TextUnformatted($"{info.Name}@{world?.Name}");
|
||||||
|
ImGui.SameLine();
|
||||||
|
if (IconButton(FontAwesomeIcon.Trash, $"delete-player-{info.GetHashCode()}")) {
|
||||||
|
deleting = info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deleting != null) {
|
||||||
|
filter.Players.Remove(deleting);
|
||||||
|
this.Plugin.Config.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndTabItem();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum UiCategory {
|
public enum UiCategory {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using System.Globalization;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Dalamud.Data;
|
using Dalamud.Data;
|
||||||
|
using Dalamud.Game.ClientState.Actors.Types;
|
||||||
using Lumina.Excel.GeneratedSheets;
|
using Lumina.Excel.GeneratedSheets;
|
||||||
|
|
||||||
namespace BetterPartyFinder {
|
namespace BetterPartyFinder {
|
||||||
|
@ -25,5 +27,11 @@ namespace BetterPartyFinder {
|
||||||
internal static bool ContainsIgnoreCase(this string haystack, string needle) {
|
internal static bool ContainsIgnoreCase(this string haystack, string needle) {
|
||||||
return CultureInfo.InvariantCulture.CompareInfo.IndexOf(haystack, needle, CompareOptions.IgnoreCase) >= 0;
|
return CultureInfo.InvariantCulture.CompareInfo.IndexOf(haystack, needle, CompareOptions.IgnoreCase) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static IEnumerable<World> WorldsOnDataCentre(DataManager data, PlayerCharacter character) {
|
||||||
|
var dcRow = character.HomeWorld.GameData.DataCenter.Row;
|
||||||
|
return data.GetExcelSheet<World>()
|
||||||
|
.Where(world => world.IsPublic && world.DataCenter.Row == dcRow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue