ChatTwo/ChatTwo/Plugin.cs

167 lines
4.8 KiB
C#
Raw Normal View History

2022-02-15 18:02:46 +00:00
using System.Diagnostics;
2022-02-13 09:36:08 +00:00
using System.Globalization;
2022-06-23 22:51:12 +00:00
using ChatTwo.Ipc;
using ChatTwo.Resources;
2022-06-12 14:29:29 +00:00
using ChatTwo.Util;
2021-12-30 02:53:44 +00:00
using Dalamud.Game.ClientState.Objects;
2021-12-29 19:31:45 +00:00
using Dalamud.IoC;
using Dalamud.Plugin;
2023-10-03 06:59:51 +00:00
using Dalamud.Plugin.Services;
2021-12-29 19:31:45 +00:00
using XivCommon;
namespace ChatTwo;
// ReSharper disable once ClassNeverInstantiated.Global
public sealed class Plugin : IDalamudPlugin {
internal const string PluginName = "Chat 2";
2023-10-03 06:59:51 +00:00
internal static string Name => PluginName;
[PluginService]
internal static IPluginLog Log { get; private set; }
2021-12-29 19:31:45 +00:00
[PluginService]
internal DalamudPluginInterface Interface { get; init; }
[PluginService]
2023-10-03 06:59:51 +00:00
internal IChatGui ChatGui { get; init; }
[PluginService]
internal IClientState ClientState { get; init; }
[PluginService]
internal ICommandManager CommandManager { get; init; }
[PluginService]
internal ICondition Condition { get; init; }
2021-12-29 19:31:45 +00:00
[PluginService]
2023-10-03 06:59:51 +00:00
internal IDataManager DataManager { get; init; }
2021-12-30 02:53:44 +00:00
2021-12-29 19:31:45 +00:00
[PluginService]
2023-10-03 06:59:51 +00:00
internal IFramework Framework { get; init; }
2021-12-29 19:31:45 +00:00
2022-02-01 05:20:20 +00:00
[PluginService]
2023-10-03 06:59:51 +00:00
internal IGameGui GameGui { get; init; }
2022-02-01 05:20:20 +00:00
2021-12-29 19:31:45 +00:00
[PluginService]
2023-10-03 06:59:51 +00:00
internal IKeyState KeyState { get; init; }
2021-12-29 19:31:45 +00:00
[PluginService]
2023-10-03 06:59:51 +00:00
internal IObjectTable ObjectTable { get; init; }
2021-12-29 19:31:45 +00:00
2021-12-30 02:53:44 +00:00
[PluginService]
2023-10-03 06:59:51 +00:00
internal IPartyList PartyList { get; init; }
2022-01-31 04:45:07 +00:00
[PluginService]
2023-10-03 06:59:51 +00:00
internal ITargetManager TargetManager { get; init; }
2021-12-30 02:53:44 +00:00
[PluginService]
2023-10-03 06:59:51 +00:00
internal ITextureProvider TextureProvider { get; init; }
2021-12-30 02:53:44 +00:00
[PluginService]
2023-10-03 06:59:51 +00:00
internal IGameInteropProvider GameInteropProvider { get; init; }
2021-12-30 02:53:44 +00:00
[PluginService]
2023-10-03 06:59:51 +00:00
internal IGameConfig GameConfig { get; init; }
2021-12-30 02:53:44 +00:00
2021-12-29 19:31:45 +00:00
internal Configuration Config { get; }
2022-02-15 21:57:15 +00:00
internal Commands Commands { get; }
2021-12-29 19:31:45 +00:00
internal XivCommonBase Common { get; }
internal TextureCache TextureCache { get; }
internal GameFunctions.GameFunctions Functions { get; }
2021-12-29 19:31:45 +00:00
internal Store Store { get; }
2022-02-13 19:08:59 +00:00
internal IpcManager Ipc { get; }
2022-06-23 22:51:12 +00:00
internal ExtraChat ExtraChat { get; }
2021-12-29 19:31:45 +00:00
internal PluginUi Ui { get; }
2022-02-05 04:31:36 +00:00
internal int DeferredSaveFrames = -1;
2022-02-13 09:36:08 +00:00
internal DateTime GameStarted { get; }
2021-12-29 19:31:45 +00:00
#pragma warning disable CS8618
public Plugin() {
2022-02-13 09:36:08 +00:00
this.GameStarted = Process.GetCurrentProcess().StartTime.ToUniversalTime();
2022-02-08 20:23:00 +00:00
this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration();
2022-02-03 21:15:27 +00:00
this.Config.Migrate();
2022-02-08 20:23:00 +00:00
2022-06-12 14:29:29 +00:00
if (this.Config.Tabs.Count == 0) {
this.Config.Tabs.Add(TabsUtil.VanillaGeneral);
}
2022-02-08 20:23:00 +00:00
this.LanguageChanged(this.Interface.UiLanguage);
2022-02-15 21:57:15 +00:00
this.Commands = new Commands(this);
2023-10-03 21:34:10 +00:00
this.Common = new XivCommonBase(this.Interface);
2023-10-03 06:59:51 +00:00
this.TextureCache = new TextureCache(this.TextureProvider!);
this.Functions = new GameFunctions.GameFunctions(this);
2021-12-29 19:31:45 +00:00
this.Store = new Store(this);
2022-02-13 19:08:59 +00:00
this.Ipc = new IpcManager(this.Interface);
2022-06-23 22:51:12 +00:00
this.ExtraChat = new ExtraChat(this);
2021-12-29 19:31:45 +00:00
this.Ui = new PluginUi(this);
2022-02-15 21:57:15 +00:00
// let all the other components register, then initialise commands
this.Commands.Initialise();
2022-02-13 09:36:08 +00:00
if (this.Interface.Reason is not PluginLoadReason.Boot) {
this.Store.FilterAllTabs(false);
}
2021-12-29 19:31:45 +00:00
this.Framework!.Update += this.FrameworkUpdate;
2022-02-08 20:23:00 +00:00
this.Interface.LanguageChanged += this.LanguageChanged;
2021-12-29 19:31:45 +00:00
}
#pragma warning restore CS8618
public void Dispose() {
2022-02-08 20:23:00 +00:00
this.Interface.LanguageChanged -= this.LanguageChanged;
2021-12-29 19:31:45 +00:00
this.Framework.Update -= this.FrameworkUpdate;
GameFunctions.GameFunctions.SetChatInteractable(true);
2021-12-29 19:31:45 +00:00
this.Ui.Dispose();
2022-06-23 22:51:12 +00:00
this.ExtraChat.Dispose();
2022-02-13 19:08:59 +00:00
this.Ipc.Dispose();
2021-12-29 19:31:45 +00:00
this.Store.Dispose();
this.Functions.Dispose();
this.TextureCache.Dispose();
2021-12-29 19:31:45 +00:00
this.Common.Dispose();
2022-02-15 21:57:15 +00:00
this.Commands.Dispose();
2021-12-29 19:31:45 +00:00
}
internal void SaveConfig() {
this.Interface.SavePluginConfig(this.Config);
}
2022-02-08 20:23:00 +00:00
internal void LanguageChanged(string langCode) {
var info = this.Config.LanguageOverride is LanguageOverride.None
? new CultureInfo(langCode)
: new CultureInfo(this.Config.LanguageOverride.Code());
Language.Culture = info;
}
2021-12-29 19:31:45 +00:00
private static readonly string[] ChatAddonNames = {
"ChatLog",
"ChatLogPanel_0",
"ChatLogPanel_1",
"ChatLogPanel_2",
"ChatLogPanel_3",
};
2023-10-03 06:59:51 +00:00
private void FrameworkUpdate(IFramework framework) {
2022-02-05 04:31:36 +00:00
if (this.DeferredSaveFrames >= 0 && this.DeferredSaveFrames-- == 0) {
this.SaveConfig();
}
2021-12-29 19:31:45 +00:00
if (!this.Config.HideChat) {
return;
}
2021-12-30 02:53:44 +00:00
2021-12-29 19:31:45 +00:00
foreach (var name in ChatAddonNames) {
if (GameFunctions.GameFunctions.IsAddonInteractable(name)) {
GameFunctions.GameFunctions.SetAddonInteractable(name, false);
2021-12-29 19:31:45 +00:00
}
}
}
}