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? MaxItemLevel { get; set; }
|
||||
|
||||
public HashSet<PlayerInfo> Players { get; set; } = new();
|
||||
|
||||
internal bool this[SearchAreaFlags flags] {
|
||||
get => (this.SearchArea & flags) > 0;
|
||||
set {
|
||||
|
@ -109,6 +111,7 @@ namespace BetterPartyFinder {
|
|||
var categories = this.Categories.ToHashSet();
|
||||
var duties = this.Duties.ToHashSet();
|
||||
var jobs = this.Jobs.ToList();
|
||||
var players = this.Players.Select(info => info.Clone()).ToHashSet();
|
||||
|
||||
return new ConfigurationFilter {
|
||||
Categories = categories,
|
||||
|
@ -124,6 +127,7 @@ namespace BetterPartyFinder {
|
|||
MaxItemLevel = this.MaxItemLevel,
|
||||
MinItemLevel = this.MinItemLevel,
|
||||
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 {
|
||||
Whitelist,
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -283,6 +283,8 @@ namespace BetterPartyFinder {
|
|||
|
||||
this.DrawRestrictionsTab(filter);
|
||||
|
||||
this.DrawPlayersTab(filter);
|
||||
|
||||
ImGui.EndTabBar();
|
||||
}
|
||||
|
||||
|
@ -579,6 +581,65 @@ namespace BetterPartyFinder {
|
|||
|
||||
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 {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Dalamud.Data;
|
||||
using Dalamud.Game.ClientState.Actors.Types;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
|
||||
namespace BetterPartyFinder {
|
||||
|
@ -25,5 +27,11 @@ namespace BetterPartyFinder {
|
|||
internal static bool ContainsIgnoreCase(this string haystack, string needle) {
|
||||
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