feat: add Chat 2 context menus

This commit is contained in:
Anna 2022-07-10 14:24:35 -04:00
parent fa832ee0e4
commit eefa7f5d64
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,59 @@
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Plugin.Ipc;
using ImGuiNET;
namespace ExtraChat.Integrations;
internal class ChatTwo : IDisposable {
private Plugin Plugin { get; }
private ICallGateSubscriber<string> Register { get; }
private ICallGateSubscriber<string, object?> Unregister { get; }
private ICallGateSubscriber<object?> Available { get; }
private ICallGateSubscriber<string, PlayerPayload?, ulong, Payload?, SeString?, SeString?, object?> Invoke { get; }
private string? _id;
internal ChatTwo(Plugin plugin) {
this.Plugin = plugin;
this.Register = this.Plugin.Interface.GetIpcSubscriber<string>("ChatTwo.Register");
this.Unregister = this.Plugin.Interface.GetIpcSubscriber<string, object?>("ChatTwo.Unregister");
this.Invoke = this.Plugin.Interface.GetIpcSubscriber<string, PlayerPayload?, ulong, Payload?, SeString?, SeString?, object?>("ChatTwo.Invoke");
this.Available = this.Plugin.Interface.GetIpcSubscriber<object?>("ChatTwo.Available");
this.Available.Subscribe(this.DoRegister);
this.DoRegister();
this.Invoke.Subscribe(this.Integration);
}
public void Dispose() {
if (this._id != null) {
this.Unregister.InvokeAction(this._id);
this._id = null;
}
this.Invoke.Unsubscribe(this.Integration);
this.Available.Unsubscribe(this.DoRegister);
}
private void DoRegister() {
this._id = this.Register.InvokeFunc();
}
private void Integration(string id, PlayerPayload? sender, ulong contentId, Payload? payload, SeString? senderString, SeString? content) {
if (id != this._id) {
return;
}
if (payload is not PlayerPayload player) {
return;
}
if (ImGui.Selectable("Invite to ExtraChat Linkshell")) {
this.Plugin.PluginUi.InviteInfo = (player.PlayerName, (ushort) player.World.RowId);
}
}
}

View File

@ -12,6 +12,7 @@ using Dalamud.Game.Text;
using Dalamud.Interface.Internal.Notifications;
using Dalamud.IoC;
using Dalamud.Plugin;
using ExtraChat.Integrations;
using ExtraChat.Ui;
using ExtraChat.Util;
@ -62,6 +63,7 @@ public class Plugin : IDalamudPlugin {
internal DalamudContextMenuBase ContextMenu { get; }
internal GameFunctions GameFunctions { get; }
internal Ipc Ipc { get; }
private IDisposable[] Integrations { get; }
private PlayerCharacter? _localPlayer;
private readonly Mutex _localPlayerLock = new();
@ -91,6 +93,10 @@ public class Plugin : IDalamudPlugin {
this.GameFunctions = new GameFunctions(this);
this.Ipc = new Ipc(this);
this.Integrations = new IDisposable[] {
new ChatTwo(this),
};
this.Framework!.Update += this.FrameworkUpdate;
this.ContextMenu.Functions.ContextMenu.OnOpenGameObjectContextMenu += this.OnOpenGameObjectContextMenu;
}
@ -101,6 +107,11 @@ public class Plugin : IDalamudPlugin {
this.ContextMenu.Functions.ContextMenu.OnOpenGameObjectContextMenu -= this.OnOpenGameObjectContextMenu;
this.Framework.Update -= this.FrameworkUpdate;
this._localPlayerLock.Dispose();
foreach (var integration in this.Integrations) {
integration.Dispose();
}
this.Ipc.Dispose();
this.GameFunctions.Dispose();
this.PluginUi.Dispose();