feat: add extrachat ipc

This commit is contained in:
Anna 2022-06-23 18:51:12 -04:00
parent 8b0650282a
commit 737011c6f8
3 changed files with 33 additions and 0 deletions

27
ChatTwo/Ipc/ExtraChat.cs Normal file
View File

@ -0,0 +1,27 @@
using Dalamud.Plugin.Ipc;
namespace ChatTwo.Ipc;
internal sealed class ExtraChat : IDisposable {
private Plugin Plugin { get; }
private ICallGateSubscriber<string?, object> OverrideChannelGate { get; }
internal string? ChannelOverride { get; set; }
internal ExtraChat(Plugin plugin) {
this.Plugin = plugin;
this.OverrideChannelGate = this.Plugin.Interface.GetIpcSubscriber<string?, object>("ExtraChat.OverrideChannel");
this.OverrideChannelGate.Subscribe(this.OnOverrideChannel);
}
public void Dispose() {
this.OverrideChannelGate.Unsubscribe(this.OnOverrideChannel);
}
private void OnOverrideChannel(string? channel) {
this.ChannelOverride = channel;
}
}

View File

@ -1,5 +1,6 @@
using System.Diagnostics;
using System.Globalization;
using ChatTwo.Ipc;
using ChatTwo.Resources;
using ChatTwo.Util;
using Dalamud.Data;
@ -66,6 +67,7 @@ public sealed class Plugin : IDalamudPlugin {
internal GameFunctions.GameFunctions Functions { get; }
internal Store Store { get; }
internal IpcManager Ipc { get; }
internal ExtraChat ExtraChat { get; }
internal PluginUi Ui { get; }
internal int DeferredSaveFrames = -1;
@ -91,6 +93,7 @@ public sealed class Plugin : IDalamudPlugin {
this.Functions = new GameFunctions.GameFunctions(this);
this.Store = new Store(this);
this.Ipc = new IpcManager(this.Interface);
this.ExtraChat = new ExtraChat(this);
this.Ui = new PluginUi(this);
// let all the other components register, then initialise commands
@ -111,6 +114,7 @@ public sealed class Plugin : IDalamudPlugin {
GameFunctions.GameFunctions.SetChatInteractable(true);
this.Ui.Dispose();
this.ExtraChat.Dispose();
this.Ipc.Dispose();
this.Store.Dispose();
this.Functions.Dispose();

View File

@ -470,6 +470,8 @@ internal sealed class ChatLog : IUiComponent {
}
} else if (activeTab is { Channel: { } channel }) {
ImGui.TextUnformatted(channel.ToChatType().Name());
} else if (this.Ui.Plugin.ExtraChat.ChannelOverride is { } overriden) {
ImGui.TextUnformatted(overriden);
} else {
this.DrawChunks(this.Ui.Plugin.Functions.Chat.Channel.name);
}