From e52f7696ba77c4032d8e9d1f3719769c936eb29e Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Wed, 5 Jul 2023 14:21:49 -0700
Subject: [PATCH] Add Open/Close SFX to Window (#1298)
Co-authored-by: goat <16760685+goaaats@users.noreply.github.com>
---
.../Internal/DalamudConfiguration.cs | 6 +++++
.../Windows/Settings/Tabs/SettingsTabLook.cs | 6 +++++
Dalamud/Interface/Windowing/Window.cs | 22 +++++++++++++++++++
3 files changed, 34 insertions(+)
diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs
index d192ab676..39c53c3cb 100644
--- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs
+++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs
@@ -207,6 +207,12 @@ internal sealed class DalamudConfiguration : IServiceType
/// Gets or sets a value indicating whether or not docking should be globally enabled in ImGui.
///
public bool IsDocking { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether or not plugin user interfaces should trigger sound effects.
+ /// This setting is effected by the in-game "System Sounds" option and volume.
+ ///
+ public bool EnablePluginUISoundEffects { get; set; }
///
/// Gets or sets a value indicating whether viewports should always be disabled.
diff --git a/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabLook.cs b/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabLook.cs
index 13adccffd..3e801a8c3 100644
--- a/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabLook.cs
+++ b/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabLook.cs
@@ -101,6 +101,12 @@ public class SettingsTabLook : SettingsTab
Loc.Localize("DalamudSettingToggleDockingHint", "This will allow you to fuse and tab plugin windows."),
c => c.IsDocking,
(v, c) => c.IsDocking = v),
+
+ new SettingsEntry(
+ Loc.Localize("DalamudSettingEnablePluginUISoundEffects", "Enable sound effects for plugin windows"),
+ Loc.Localize("DalamudSettingEnablePluginUISoundEffectsHint", "This will allow you to enable or disable sound effects generated by plugin user interfaces.\nThis is affected by your in-game `System Sounds` volume settings."),
+ c => c.EnablePluginUISoundEffects,
+ (v, c) => c.EnablePluginUISoundEffects = v),
new SettingsEntry(
Loc.Localize("DalamudSettingToggleGamepadNavigation", "Control plugins via gamepad"),
diff --git a/Dalamud/Interface/Windowing/Window.cs b/Dalamud/Interface/Windowing/Window.cs
index 2a8beb639..3bf987690 100644
--- a/Dalamud/Interface/Windowing/Window.cs
+++ b/Dalamud/Interface/Windowing/Window.cs
@@ -2,6 +2,7 @@
using Dalamud.Configuration.Internal;
using Dalamud.Game.ClientState.Keys;
+using FFXIVClientStructs.FFXIV.Client.UI;
using ImGuiNET;
namespace Dalamud.Interface.Windowing;
@@ -16,6 +17,7 @@ public abstract class Window
private bool internalLastIsOpen = false;
private bool internalIsOpen = false;
private bool nextFrameBringToFront = false;
+ private DalamudConfiguration Configuration;
///
/// Initializes a new instance of the class.
@@ -31,6 +33,7 @@ protected Window(string name, ImGuiWindowFlags flags = ImGuiWindowFlags.None, bo
this.WindowName = name;
this.Flags = flags;
this.ForceMainWindow = forceMainWindow;
+ this.Configuration = Service.Get();
}
///
@@ -55,6 +58,21 @@ protected Window(string name, ImGuiWindowFlags flags = ImGuiWindowFlags.None, bo
///
public bool RespectCloseHotkey { get; set; } = true;
+ ///
+ /// Gets or sets a value indicating whether this window should not generate sound effects when opening and closing.
+ ///
+ public bool DisableWindowSounds { get; set; } = false;
+
+ ///
+ /// Gets or sets a value representing the sound effect id to be played when the window is opened.
+ ///
+ public uint OnOpenSfxId { get; set; } = 23u;
+
+ ///
+ /// Gets or sets a value representing the sound effect id to be played when the window is closed.
+ ///
+ public uint OnCloseSfxId { get; set; } = 24u;
+
///
/// Gets or sets the position of this window.
///
@@ -219,6 +237,8 @@ internal void DrawInternal()
this.OnClose();
this.IsFocused = false;
+
+ if (this.Configuration.EnablePluginUISoundEffects && !this.DisableWindowSounds) UIModule.PlaySound(this.OnCloseSfxId, 0, 0, 0);
}
return;
@@ -243,6 +263,8 @@ internal void DrawInternal()
{
this.internalLastIsOpen = this.internalIsOpen;
this.OnOpen();
+
+ if (this.Configuration.EnablePluginUISoundEffects && !this.DisableWindowSounds) UIModule.PlaySound(this.OnOpenSfxId, 0, 0, 0);
}
var wasFocused = this.IsFocused;