From 3bacccd216d39f0d6d4643533fe1f70bc8fe1654 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Thu, 14 Apr 2022 19:38:52 +0200 Subject: [PATCH] Add chat messages, include fish statistics in settings window Fixes #1 --- Configuration.cs | 25 +++++++++++++++++ FishNotify.cs | 69 ++++++++++++++++++++++++++++++++++++++--------- FishNotify.csproj | 2 +- 3 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 Configuration.cs diff --git a/Configuration.cs b/Configuration.cs new file mode 100644 index 0000000..c731662 --- /dev/null +++ b/Configuration.cs @@ -0,0 +1,25 @@ +using Dalamud.Configuration; +using Dalamud.Plugin; +using System; + +namespace FishNotify +{ + internal class Configuration : IPluginConfiguration + { + public int Version { get; set; } = 0; + public bool ChatAlerts { get; set; } = false; + + [NonSerialized] + private DalamudPluginInterface pluginInterface = null!; + + public void Initialize(DalamudPluginInterface pluginInterface) + { + this.pluginInterface = pluginInterface; + } + + public void Save() + { + this.pluginInterface.SavePluginConfig(this); + } + } +} diff --git a/FishNotify.cs b/FishNotify.cs index 0eb2352..424a24b 100644 --- a/FishNotify.cs +++ b/FishNotify.cs @@ -1,5 +1,7 @@ using Dalamud.Data; +using Dalamud.Game.Gui; using Dalamud.Game.Network; +using Dalamud.Game.Text.SeStringHandling; using Dalamud.Interface.Colors; using Dalamud.IoC; using Dalamud.Logging; @@ -20,18 +22,27 @@ namespace FishNotify [PluginService] [RequiredVersion("1.0")] - private DalamudPluginInterface PluginInterface { get; set; } + private DalamudPluginInterface PluginInterface { get; set; } = null!; [PluginService] - private GameNetwork Network { get; set; } + private GameNetwork Network { get; set; } = null!; + + [PluginService] + public static ChatGui Chat { get; set; } = null!; + + private Configuration configuration; private bool settingsVisible; private int expectedOpCode = -1; + private uint fishCount = 0; public FishNotifyPlugin() { - Network!.NetworkMessage += OnNetworkMessage; - PluginInterface!.UiBuilder.Draw += OnDrawUI; - PluginInterface!.UiBuilder.OpenConfigUi += OnOpenConfigUi; + configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); + configuration.Initialize(PluginInterface); + + Network.NetworkMessage += OnNetworkMessage; + PluginInterface.UiBuilder.Draw += OnDrawUI; + PluginInterface.UiBuilder.OpenConfigUi += OnOpenConfigUi; var client = new HttpClient(); client.GetStringAsync("https://raw.githubusercontent.com/karashiiro/FFXIVOpcodes/master/opcodes.min.json") @@ -41,7 +52,7 @@ namespace FishNotify public void Dispose() { Network.NetworkMessage -= OnNetworkMessage; - PluginInterface!.UiBuilder.Draw -= OnDrawUI; + PluginInterface.UiBuilder.Draw -= OnDrawUI; PluginInterface.UiBuilder.OpenConfigUi -= OnOpenConfigUi; } @@ -63,7 +74,7 @@ namespace FishNotify return; } - if (!region.Lists.TryGetValue("ServerZoneIpcType", out List serverZoneIpcTypes)) + if (!region.Lists.TryGetValue("ServerZoneIpcType", out List? serverZoneIpcTypes) || serverZoneIpcTypes == null) { PluginLog.Warning("No ServerZoneIpcType in opcode list"); return; @@ -110,17 +121,23 @@ namespace FishNotify case 0x124: // light tug (!) + ++fishCount; Sounds.PlaySound(Resources.Info); + SendChatAlert("light"); break; case 0x125: // medium tug (!!) + ++fishCount; Sounds.PlaySound(Resources.Alert); + SendChatAlert("medium"); break; case 0x126: // heavy tug (!!!) + ++fishCount; Sounds.PlaySound(Resources.Alarm); + SendChatAlert("heavy"); break; default: @@ -129,6 +146,26 @@ namespace FishNotify } } + private void SendChatAlert(string size) + { + if (!configuration.ChatAlerts) + { + return; + } + + SeString message = new SeStringBuilder() + .AddUiForeground(514) + .Append("[FishNotify]") + .AddUiForegroundOff() + .Append($" You hook a fish with a ") + .AddUiForeground(514) + .Append(size) + .AddUiForegroundOff() + .Append(" bite.") + .Build(); + Chat.Print(message); + } + private void OnDrawUI() { if (!settingsVisible) @@ -136,13 +173,21 @@ namespace FishNotify if (ImGui.Begin("FishNotify", ref this.settingsVisible, ImGuiWindowFlags.AlwaysAutoResize)) { + var chatAlerts = configuration.ChatAlerts; + if (ImGui.Checkbox("Show chat message on hooking a fish", ref chatAlerts)) + { + configuration.ChatAlerts = chatAlerts; + configuration.Save(); + } + if (expectedOpCode > -1) - ImGui.TextColored(ImGuiColors.HealerGreen, $"Status: OK, opcode = {expectedOpCode:X}"); + ImGui.TextColored(ImGuiColors.HealerGreen, $"Status: {(fishCount == 0 ? "Unknown (not triggered yet)" : $"OK ({fishCount} fish hooked)")}, opcode = {expectedOpCode:X}"); else ImGui.TextColored(ImGuiColors.DalamudRed, "Status: No opcode :("); } ImGui.End(); } + private void OnOpenConfigUi() { settingsVisible = !settingsVisible; @@ -151,14 +196,14 @@ namespace FishNotify public class OpcodeRegion { - public string Version { get; set; } - public string Region { get; set; } - public Dictionary> Lists { get; set; } + public string? Version { get; set; } + public string? Region { get; set; } + public Dictionary>? Lists { get; set; } } public class OpcodeList { - public string Name { get; set; } + public string? Name { get; set; } public ushort Opcode { get; set; } } } diff --git a/FishNotify.csproj b/FishNotify.csproj index 0e608b1..b1523dd 100644 --- a/FishNotify.csproj +++ b/FishNotify.csproj @@ -3,7 +3,7 @@ - 3.0.0.0 + 3.1.0.0 Plays a sound effect when a fish bites https://github.com/carvelli/Fish-Notify