diff --git a/BetterPartyFinder/Configuration.cs b/BetterPartyFinder/Configuration.cs index 48b20da..f97e178 100755 --- a/BetterPartyFinder/Configuration.cs +++ b/BetterPartyFinder/Configuration.cs @@ -50,6 +50,8 @@ namespace BetterPartyFinder { public uint? MinItemLevel { get; set; } public uint? MaxItemLevel { get; set; } + public HashSet 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, diff --git a/BetterPartyFinder/Filter.cs b/BetterPartyFinder/Filter.cs index 27fcfe7..054565d 100755 --- a/BetterPartyFinder/Filter.cs +++ b/BetterPartyFinder/Filter.cs @@ -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; } diff --git a/BetterPartyFinder/PluginUi.cs b/BetterPartyFinder/PluginUi.cs index 109d177..9b2942e 100755 --- a/BetterPartyFinder/PluginUi.cs +++ b/BetterPartyFinder/PluginUi.cs @@ -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().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 { diff --git a/BetterPartyFinder/Util.cs b/BetterPartyFinder/Util.cs index 8748526..71948de 100755 --- a/BetterPartyFinder/Util.cs +++ b/BetterPartyFinder/Util.cs @@ -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 WorldsOnDataCentre(DataManager data, PlayerCharacter character) { + var dcRow = character.HomeWorld.GameData.DataCenter.Row; + return data.GetExcelSheet() + .Where(world => world.IsPublic && world.DataCenter.Row == dcRow); + } } }