From 847483566161b4b0437a05956ec3a3afd1cdf9d0 Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 1 May 2021 23:06:28 -0400 Subject: [PATCH] feat: show pf description in chat after joining --- BetterPartyFinder/BetterPartyFinder.csproj | 10 +++---- BetterPartyFinder/Commands.cs | 2 +- BetterPartyFinder/Configuration.cs | 1 + BetterPartyFinder/JoinHandler.cs | 35 ++++++++++++++++++++++ BetterPartyFinder/Plugin.cs | 8 +++-- BetterPartyFinder/PluginUi.cs | 8 +++++ 6 files changed, 56 insertions(+), 8 deletions(-) create mode 100755 BetterPartyFinder/JoinHandler.cs diff --git a/BetterPartyFinder/BetterPartyFinder.csproj b/BetterPartyFinder/BetterPartyFinder.csproj index b16858d..5643c70 100755 --- a/BetterPartyFinder/BetterPartyFinder.csproj +++ b/BetterPartyFinder/BetterPartyFinder.csproj @@ -9,7 +9,7 @@ - $(AppData)\XIVLauncher\addon\Hooks\5.2.4.3\Dalamud.dll + $(AppData)\XIVLauncher\addon\Hooks\dev\Dalamud.dll False @@ -35,10 +35,10 @@ - - - - + + + + diff --git a/BetterPartyFinder/Commands.cs b/BetterPartyFinder/Commands.cs index d69c9aa..e162ba4 100755 --- a/BetterPartyFinder/Commands.cs +++ b/BetterPartyFinder/Commands.cs @@ -28,7 +28,7 @@ namespace BetterPartyFinder { } private void OnCommand(string command, string args) { - if (args == "c" || args == "config") { + if (args is "c" or "config") { this.Plugin.Ui.SettingsVisible = !this.Plugin.Ui.SettingsVisible; } else { this.Plugin.Ui.Visible = !this.Plugin.Ui.Visible; diff --git a/BetterPartyFinder/Configuration.cs b/BetterPartyFinder/Configuration.cs index 0b8fbde..969c4e8 100755 --- a/BetterPartyFinder/Configuration.cs +++ b/BetterPartyFinder/Configuration.cs @@ -15,6 +15,7 @@ namespace BetterPartyFinder { public bool ShowWhenPfOpen { get; set; } public WindowSide WindowSide { get; set; } = WindowSide.Left; + public bool ShowDescriptionOnJoin { get; set; } = true; internal static Configuration? Load(Plugin plugin) { return (Configuration?) plugin.Interface.GetPluginConfig(); diff --git a/BetterPartyFinder/JoinHandler.cs b/BetterPartyFinder/JoinHandler.cs new file mode 100755 index 0000000..f2135a8 --- /dev/null +++ b/BetterPartyFinder/JoinHandler.cs @@ -0,0 +1,35 @@ +using System; +using Dalamud.Game.Internal.Gui.Structs; +using Dalamud.Game.Text; +using Dalamud.Game.Text.SeStringHandling; + +namespace BetterPartyFinder { + public class JoinHandler : IDisposable { + private Plugin Plugin { get; } + + internal JoinHandler(Plugin plugin) { + this.Plugin = plugin; + + this.Plugin.Common.Functions.PartyFinder.JoinParty += this.OnJoin; + } + + public void Dispose() { + this.Plugin.Common.Functions.PartyFinder.JoinParty -= this.OnJoin; + } + + private void OnJoin(PartyFinderListing listing) { + if (!this.Plugin.Config.ShowDescriptionOnJoin) { + return; + } + + SeString msg = "Party description: "; + msg.Payloads.AddRange(listing.Description.Payloads); + + this.Plugin.Interface.Framework.Gui.Chat.PrintChat(new XivChatEntry { + Name = "Better Party Finder", + Type = XivChatType.SystemMessage, + MessageBytes = msg.Encode(), + }); + } + } +} diff --git a/BetterPartyFinder/Plugin.cs b/BetterPartyFinder/Plugin.cs index e8c4cdd..9911025 100755 --- a/BetterPartyFinder/Plugin.cs +++ b/BetterPartyFinder/Plugin.cs @@ -2,15 +2,17 @@ using XivCommon; namespace BetterPartyFinder { + // ReSharper disable once ClassNeverInstantiated.Global public class Plugin : IDalamudPlugin { public string Name => "Better Party Finder"; internal DalamudPluginInterface Interface { get; private set; } = null!; internal Configuration Config { get; private set; } = null!; private Filter Filter { get; set; } = null!; - internal PluginUi Ui { get; set; } = null!; + internal PluginUi Ui { get; private set; } = null!; private Commands Commands { get; set; } = null!; - internal XivCommonBase Common { get; set; } = null!; + internal XivCommonBase Common { get; private set; } = null!; + private JoinHandler JoinHandler { get; set; } = null!; public void Initialize(DalamudPluginInterface pluginInterface) { this.Interface = pluginInterface; @@ -20,6 +22,7 @@ namespace BetterPartyFinder { this.Common = new XivCommonBase(this.Interface, Hooks.PartyFinder); this.Filter = new Filter(this); + this.JoinHandler = new JoinHandler(this); this.Ui = new PluginUi(this); this.Commands = new Commands(this); @@ -30,6 +33,7 @@ namespace BetterPartyFinder { public void Dispose() { this.Commands.Dispose(); this.Ui.Dispose(); + this.JoinHandler.Dispose(); this.Filter.Dispose(); this.Common.Dispose(); } diff --git a/BetterPartyFinder/PluginUi.cs b/BetterPartyFinder/PluginUi.cs index b4a38fa..8e1910c 100755 --- a/BetterPartyFinder/PluginUi.cs +++ b/BetterPartyFinder/PluginUi.cs @@ -114,6 +114,14 @@ namespace BetterPartyFinder { this.Plugin.Config.Save(); } + ImGui.Separator(); + + var showDesc = this.Plugin.Config.ShowDescriptionOnJoin; + if (ImGui.Checkbox("Show PF description in chat after joining", ref showDesc)) { + this.Plugin.Config.ShowDescriptionOnJoin = showDesc; + this.Plugin.Config.Save(); + } + ImGui.End(); }