Skip to content

Commit

Permalink
Add Open/Close SFX to Window (#1298)
Browse files Browse the repository at this point in the history
Co-authored-by: goat <[email protected]>
  • Loading branch information
MidoriKami and goaaats committed Jul 5, 2023
1 parent 2cf3b93 commit e52f769
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Dalamud/Configuration/Internal/DalamudConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
public bool IsDocking { get; set; }

/// <summary>
/// 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.
/// </summary>
public bool EnablePluginUISoundEffects { get; set; }

/// <summary>
/// Gets or sets a value indicating whether viewports should always be disabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>(
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<bool>(
Loc.Localize("DalamudSettingToggleGamepadNavigation", "Control plugins via gamepad"),
Expand Down
22 changes: 22 additions & 0 deletions Dalamud/Interface/Windowing/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Dalamud.Configuration.Internal;
using Dalamud.Game.ClientState.Keys;
using FFXIVClientStructs.FFXIV.Client.UI;
using ImGuiNET;

namespace Dalamud.Interface.Windowing;
Expand All @@ -16,6 +17,7 @@ public abstract class Window
private bool internalLastIsOpen = false;
private bool internalIsOpen = false;
private bool nextFrameBringToFront = false;
private DalamudConfiguration Configuration;

/// <summary>
/// Initializes a new instance of the <see cref="Window"/> class.
Expand All @@ -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<DalamudConfiguration>.Get();
}

/// <summary>
Expand All @@ -55,6 +58,21 @@ protected Window(string name, ImGuiWindowFlags flags = ImGuiWindowFlags.None, bo
/// </summary>
public bool RespectCloseHotkey { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether this window should not generate sound effects when opening and closing.
/// </summary>
public bool DisableWindowSounds { get; set; } = false;

/// <summary>
/// Gets or sets a value representing the sound effect id to be played when the window is opened.
/// </summary>
public uint OnOpenSfxId { get; set; } = 23u;

/// <summary>
/// Gets or sets a value representing the sound effect id to be played when the window is closed.
/// </summary>
public uint OnCloseSfxId { get; set; } = 24u;

/// <summary>
/// Gets or sets the position of this window.
/// </summary>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit e52f769

Please sign in to comment.