From 30ccf8e416abd74ea28710338a64ca97484f0994 Mon Sep 17 00:00:00 2001 From: Infi Date: Tue, 16 Apr 2024 00:36:30 +0200 Subject: [PATCH] Implement sounds on interaction --- ChatTwo/Configuration.cs | 2 ++ ChatTwo/PayloadHandler.cs | 9 +++++++++ ChatTwo/Resources/Language.Designer.cs | 18 +++++++++++++++++ ChatTwo/Resources/Language.resx | 6 ++++++ ChatTwo/Ui/ChatLogWindow.cs | 28 +++++++++++++++++++++----- ChatTwo/Ui/SettingsTabs/Display.cs | 3 +++ 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index 4cb5ed7..ca97732 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -38,6 +38,7 @@ internal class Configuration : IPluginConfiguration public bool SharedMode; public bool SortAutoTranslate; public bool CollapseDuplicateMessages; + public bool PlaySounds = true; public bool FontsEnabled = true; public ExtraGlyphRanges ExtraGlyphRanges = 0; @@ -83,6 +84,7 @@ internal class Configuration : IPluginConfiguration SharedMode = other.SharedMode; SortAutoTranslate = other.SortAutoTranslate; CollapseDuplicateMessages = other.CollapseDuplicateMessages; + PlaySounds = other.PlaySounds; FontsEnabled = other.FontsEnabled; ExtraGlyphRanges = other.ExtraGlyphRanges; FontSize = other.FontSize; diff --git a/ChatTwo/PayloadHandler.cs b/ChatTwo/PayloadHandler.cs index 1acc902..be86f32 100755 --- a/ChatTwo/PayloadHandler.cs +++ b/ChatTwo/PayloadHandler.cs @@ -13,6 +13,7 @@ using Dalamud.Interface.Internal; using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.Utility; using Dalamud.Utility; +using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Component.GUI; using ImGuiNET; using Lumina.Excel; @@ -40,6 +41,8 @@ public sealed class PayloadHandler { private readonly ExcelSheet TerritorySheet; private readonly ExcelSheet EventItemHelpSheet; + private uint PopupSfx = 1u; + internal PayloadHandler(ChatLogWindow logWindow) { LogWindow = logWindow; @@ -206,6 +209,9 @@ public sealed class PayloadHandler { internal void Click(Chunk chunk, Payload? payload, ImGuiMouseButton button) { + if (LogWindow.Plugin.Config.PlaySounds) + UIModule.PlaySound(PopupSfx); + switch (button) { case ImGuiMouseButton.Left: @@ -408,6 +414,9 @@ public sealed class PayloadHandler { case URIPayload uri: TryOpenURI(uri.Uri); break; + default: + RightClickPayload(chunk, payload); + break; } } diff --git a/ChatTwo/Resources/Language.Designer.cs b/ChatTwo/Resources/Language.Designer.cs index 159d556..b4b4520 100755 --- a/ChatTwo/Resources/Language.Designer.cs +++ b/ChatTwo/Resources/Language.Designer.cs @@ -2183,6 +2183,24 @@ namespace ChatTwo.Resources { } } + /// + /// Looks up a localized string similar to Play sounds on interaction.. + /// + internal static string Options_PlaySounds_Description { + get { + return ResourceManager.GetString("Options_PlaySounds_Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Play sounds. + /// + internal static string Options_PlaySounds_Name { + get { + return ResourceManager.GetString("Options_PlaySounds_Name", resourceCulture); + } + } + /// /// Looks up a localized string similar to Display messages in a more modern style.. /// diff --git a/ChatTwo/Resources/Language.resx b/ChatTwo/Resources/Language.resx index 9cdebcb..bf1eaf5 100644 --- a/ChatTwo/Resources/Language.resx +++ b/ChatTwo/Resources/Language.resx @@ -988,4 +988,10 @@ No dalamud styles available + + Play sounds + + + Play sounds on interaction. + diff --git a/ChatTwo/Ui/ChatLogWindow.cs b/ChatTwo/Ui/ChatLogWindow.cs index 5c5ee1a..6b16e08 100644 --- a/ChatTwo/Ui/ChatLogWindow.cs +++ b/ChatTwo/Ui/ChatLogWindow.cs @@ -17,6 +17,7 @@ using Dalamud.Interface.Style; using Dalamud.Interface.Utility; using Dalamud.Interface.Windowing; using Dalamud.Memory; +using FFXIVClientStructs.FFXIV.Client.UI; using ImGuiNET; using Lumina.Excel.GeneratedSheets; @@ -73,6 +74,10 @@ public sealed class ChatLogWindow : Window, IUiComponent private Dictionary TextCommandChannels { get; } = new(); private HashSet AllCommands { get; } = new(); + private uint ChatOpenSfx = 35u; + private uint ChatCloseSfx = 3u; + private bool PlayedClosingSound = true; + internal ChatLogWindow(Plugin plugin) : base($"{Plugin.PluginName}###chat2") { Plugin = plugin; @@ -195,6 +200,10 @@ public sealed class ChatLogWindow : Window, IUiComponent if (info.Text != null && Chat.Length == 0) Chat = info.Text; + + PlayedClosingSound = false; + if (Plugin.Config.PlaySounds) + UIModule.PlaySound(ChatOpenSfx); } private bool IsValidCommand(string command) @@ -562,11 +571,7 @@ public sealed class ChatLogWindow : Window, IUiComponent ImGui.OpenPopup(ChatChannelPicker); if (activeTab is { Channel: { } } && ImGui.IsItemHovered()) - { - ImGui.BeginTooltip(); - ImGui.TextUnformatted(Language.ChatLog_SwitcherDisabled); - ImGui.EndTooltip(); - } + ImGui.SetTooltip(Language.ChatLog_SwitcherDisabled); if (ImGui.BeginPopup(ChatChannelPicker)) { @@ -687,6 +692,12 @@ public sealed class ChatLogWindow : Window, IUiComponent // Only trigger unfocused if we are currently not calling the auto complete if (!Activate && !ImGui.IsItemActive() && _autoCompleteInfo == null) { + if (Plugin.Config.PlaySounds && !PlayedClosingSound) + { + PlayedClosingSound = true; + UIModule.PlaySound(ChatCloseSfx); + } + if (_tempChannel is InputChannel.Tell) _tellTarget = null; @@ -1332,6 +1343,13 @@ public sealed class ChatLogWindow : Window, IUiComponent private unsafe int Callback(ImGuiInputTextCallbackData* data) { + // We play the opening sound here only if closing sound has been played before + if (Plugin.Config.PlaySounds && PlayedClosingSound) + { + PlayedClosingSound = false; + UIModule.PlaySound(ChatOpenSfx); + } + var ptr = new ImGuiInputTextCallbackDataPtr(data); if (data->EventFlag == ImGuiInputTextFlags.CallbackCompletion) diff --git a/ChatTwo/Ui/SettingsTabs/Display.cs b/ChatTwo/Ui/SettingsTabs/Display.cs index 2bb1b29..8a73122 100755 --- a/ChatTwo/Ui/SettingsTabs/Display.cs +++ b/ChatTwo/Ui/SettingsTabs/Display.cs @@ -17,6 +17,9 @@ internal sealed class Display : ISettingsTab { public void Draw(bool changed) { ImGui.PushTextWrapPos(); + ImGuiUtil.OptionCheckbox(ref Mutable.PlaySounds, Language.Options_PlaySounds_Name, Language.Options_PlaySounds_Description); + ImGui.Spacing(); + ImGuiUtil.OptionCheckbox(ref Mutable.HideChat, Language.Options_HideChat_Name, Language.Options_HideChat_Description); ImGui.Spacing();