From 3396fba470d3d9bb4a1ab7ae4ab19fbf1e6c6dee Mon Sep 17 00:00:00 2001 From: Viktor Dvorak Date: Fri, 23 Jan 2026 11:45:38 +0100 Subject: [PATCH 1/4] feature: added keybind to toggle autoplay --- SpeechMod/Keybinds/ToggleAutoPlay.cs | 68 ++++++++++++++++++++++++++++ SpeechMod/Localization/enGB.json | 56 +++++++++++++---------- SpeechMod/Main.cs | 2 +- 3 files changed, 100 insertions(+), 26 deletions(-) create mode 100644 SpeechMod/Keybinds/ToggleAutoPlay.cs diff --git a/SpeechMod/Keybinds/ToggleAutoPlay.cs b/SpeechMod/Keybinds/ToggleAutoPlay.cs new file mode 100644 index 0000000..b0b9f4e --- /dev/null +++ b/SpeechMod/Keybinds/ToggleAutoPlay.cs @@ -0,0 +1,68 @@ +using HarmonyLib; +using Kingmaker; +using Kingmaker.Localization; +using Kingmaker.UI.MVVM._PCView.Common; +using SpeechMod.Configuration.Settings; +using System; + +#if DEBUG +using UnityEngine; +#endif + +namespace SpeechMod.Keybinds; + +public class ToggleAutoPlay() : ModHotkeySettingEntry(_key, _title, _tooltip, _defaultValue) +{ + private const string _key = "autoplay.toggle"; + private const string _title = "Toggle autoplay"; + private const string _tooltip = "Toggles autoplay on and off."; + private const string _defaultValue = "%A;;All;false"; + private const string BIND_NAME = $"{Constants.SETTINGS_PREFIX}.newcontrols.ui.{_key}"; + + public override SettingStatus TryEnable() => TryEnableAndPatch(typeof(Patches)); + + [HarmonyPatch] + private static class Patches + { + private static string _ToggleAutoPlayOffText = "SpeechMod: Autoplay toggled OFF!"; + private static string _ToggleAutoPlayOnText = "SpeechMod: Autoplay toggled ON!"; + private static IDisposable _disposableBinding; + + [HarmonyPatch(typeof(CommonPCView), nameof(CommonPCView.BindViewImplementation))] + [HarmonyPostfix] + private static void Add(CommonPCView __instance) + { +#if DEBUG + Debug.Log($"{nameof(CommonPCView)}_{nameof(CommonPCView.BindViewImplementation)}_Postfix : {BIND_NAME}"); +#endif + var autoPlayOffText = LocalizationManager.CurrentPack!.GetText("osmodium.speechmod.feature.autoplay.toggle.notification.off", false); + if (string.IsNullOrWhiteSpace(autoPlayOffText)) + _ToggleAutoPlayOffText = autoPlayOffText; + + var autoPlayOnText = LocalizationManager.CurrentPack!.GetText("osmodium.speechmod.feature.autoplay.toggle.notification.on", false); + if (string.IsNullOrWhiteSpace(autoPlayOnText)) + _ToggleAutoPlayOnText = autoPlayOnText; + + if (Game.Instance.Keyboard.m_Bindings.Exists(binding => binding.Name.Equals(BIND_NAME))) + { +#if DEBUG + Debug.Log($"Binding {BIND_NAME} already exists! Disposing of binding..."); +#endif + _disposableBinding.Dispose(); + } + + _disposableBinding = Game.Instance!.Keyboard!.Bind(BIND_NAME, delegate { ToggleAutoPlay(__instance); }); + __instance?.AddDisposable(_disposableBinding); + } + + private static void ToggleAutoPlay(CommonPCView instance) + { + Main.Settings.AutoPlay = !Main.Settings.AutoPlay; + + if (instance.m_WarningsText != null && Main.Settings!.ShowNotificationOnPlaybackStop) + { + instance.m_WarningsText?.Show(Main.Settings.AutoPlay ? _ToggleAutoPlayOnText : _ToggleAutoPlayOffText); + } + } + } +} \ No newline at end of file diff --git a/SpeechMod/Localization/enGB.json b/SpeechMod/Localization/enGB.json index 4d7d3e1..1172e66 100644 --- a/SpeechMod/Localization/enGB.json +++ b/SpeechMod/Localization/enGB.json @@ -1,28 +1,34 @@ { - "Strings": { - "osmodium.speechmod.group.main": { - "Text": "Speech Mod" - }, - "osmodium.speechmod.feature.playback.stop.description": { - "Text": "Stop playback" - }, - "osmodium.speechmod.feature.playback.stop.tooltip-description": { - "Text": "Stops playback of SpeechMod TTS when it is playing." - }, - "osmodium.speechmod.feature.playback.stop.notification": { - "Text": "SpeechMod: Playback stopped!" - }, - "osmodium.speechmod.feature.barks.toggle.description": { - "Text": "Toggle barks" - }, - "osmodium.speechmod.feature.barks.toggle.tooltip-description": { - "Text": "Toggles playback of barks ON and OFF.\nBarks are the small text boxes above characters heads when they speak." - }, - "osmodium.speechmod.feature.barks.toggle.notification.off": { - "Text": "SpeechMod: Barks toggled OFF!" - }, - "osmodium.speechmod.feature.barks.toggle.notification.on": { - "Text": "SpeechMod: Barks toggled ON!" - } + "Strings": { + "osmodium.speechmod.group.main": { + "Text": "Speech Mod" + }, + "osmodium.speechmod.feature.playback.stop.description": { + "Text": "Stop playback" + }, + "osmodium.speechmod.feature.playback.stop.tooltip-description": { + "Text": "Stops playback of SpeechMod TTS when it is playing." + }, + "osmodium.speechmod.feature.playback.stop.notification": { + "Text": "SpeechMod: Playback stopped!" + }, + "osmodium.speechmod.feature.barks.toggle.description": { + "Text": "Toggle barks" + }, + "osmodium.speechmod.feature.barks.toggle.tooltip-description": { + "Text": "Toggles playback of barks ON and OFF.\nBarks are the small text boxes above characters heads when they speak." + }, + "osmodium.speechmod.feature.barks.toggle.notification.off": { + "Text": "SpeechMod: Barks toggled OFF!" + }, + "osmodium.speechmod.feature.barks.toggle.notification.on": { + "Text": "SpeechMod: Barks toggled ON!" + }, + "osmodium.speechmod.feature.autoplay.toggle.notification.off": { + "Text": "SpeechMod: Autoplay toggled OFF!" + }, + "osmodium.speechmod.feature.autoplay.toggle.notification.on": { + "Text": "SpeechMod: Autoplay toggled ON!" } + } } \ No newline at end of file diff --git a/SpeechMod/Main.cs b/SpeechMod/Main.cs index a803af0..66fba7e 100644 --- a/SpeechMod/Main.cs +++ b/SpeechMod/Main.cs @@ -80,7 +80,7 @@ private static void SetUpSettings() if (ModConfigurationManager.Instance.GroupedSettings.TryGetValue("main", out _)) return; - ModConfigurationManager.Instance.GroupedSettings.Add("main", [new PlaybackStop(), new ToggleBarks()]); + ModConfigurationManager.Instance.GroupedSettings.Add("main", [new PlaybackStop(), new ToggleBarks(), new ToggleAutoPlay()]); } private static bool SetAvailableVoices() From 4f4a51d4f5198b7a9084a98fa8574f74efc1f692 Mon Sep 17 00:00:00 2001 From: Viktor Dvorak Date: Fri, 23 Jan 2026 11:55:41 +0100 Subject: [PATCH 2/4] missing localization added --- SpeechMod/Localization/enGB.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/SpeechMod/Localization/enGB.json b/SpeechMod/Localization/enGB.json index 1172e66..7e5d77b 100644 --- a/SpeechMod/Localization/enGB.json +++ b/SpeechMod/Localization/enGB.json @@ -24,11 +24,17 @@ "osmodium.speechmod.feature.barks.toggle.notification.on": { "Text": "SpeechMod: Barks toggled ON!" }, + "osmodium.speechmod.feature.autoplay.toggle.description": { + "Text": "Toggle Auto play dialog" + }, + "osmodium.speechmod.feature.autoplay.toggle.tooltip-description": { + "Text": "Toggles Auto play dialog ON and OFF." + }, "osmodium.speechmod.feature.autoplay.toggle.notification.off": { - "Text": "SpeechMod: Autoplay toggled OFF!" + "Text": "SpeechMod: Auto play dialog toggled OFF!" }, "osmodium.speechmod.feature.autoplay.toggle.notification.on": { - "Text": "SpeechMod: Autoplay toggled ON!" + "Text": "SpeechMod: Auto play dialog toggled ON!" } } } \ No newline at end of file From 2f0257e7f2e1c1cdc27727975a0f9d9758746551 Mon Sep 17 00:00:00 2001 From: Viktor Dvorak Date: Fri, 23 Jan 2026 12:02:31 +0100 Subject: [PATCH 3/4] changed keybind to CTRL+T --- SpeechMod/Keybinds/ToggleAutoPlay.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpeechMod/Keybinds/ToggleAutoPlay.cs b/SpeechMod/Keybinds/ToggleAutoPlay.cs index b0b9f4e..3134d40 100644 --- a/SpeechMod/Keybinds/ToggleAutoPlay.cs +++ b/SpeechMod/Keybinds/ToggleAutoPlay.cs @@ -16,7 +16,7 @@ public class ToggleAutoPlay() : ModHotkeySettingEntry(_key, _title, _tooltip, _d private const string _key = "autoplay.toggle"; private const string _title = "Toggle autoplay"; private const string _tooltip = "Toggles autoplay on and off."; - private const string _defaultValue = "%A;;All;false"; + private const string _defaultValue = "%T;;All;false"; private const string BIND_NAME = $"{Constants.SETTINGS_PREFIX}.newcontrols.ui.{_key}"; public override SettingStatus TryEnable() => TryEnableAndPatch(typeof(Patches)); From 105813a48e456789bb3a0bc6f81d402b9843c9de Mon Sep 17 00:00:00 2001 From: Viktor Dvorak Date: Fri, 23 Jan 2026 12:29:42 +0100 Subject: [PATCH 4/4] fix localization fallback logic --- SpeechMod/Keybinds/ToggleAutoPlay.cs | 4 ++-- SpeechMod/Keybinds/ToggleBarks.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SpeechMod/Keybinds/ToggleAutoPlay.cs b/SpeechMod/Keybinds/ToggleAutoPlay.cs index 3134d40..2bb74c8 100644 --- a/SpeechMod/Keybinds/ToggleAutoPlay.cs +++ b/SpeechMod/Keybinds/ToggleAutoPlay.cs @@ -36,11 +36,11 @@ private static void Add(CommonPCView __instance) Debug.Log($"{nameof(CommonPCView)}_{nameof(CommonPCView.BindViewImplementation)}_Postfix : {BIND_NAME}"); #endif var autoPlayOffText = LocalizationManager.CurrentPack!.GetText("osmodium.speechmod.feature.autoplay.toggle.notification.off", false); - if (string.IsNullOrWhiteSpace(autoPlayOffText)) + if (!string.IsNullOrWhiteSpace(autoPlayOffText)) _ToggleAutoPlayOffText = autoPlayOffText; var autoPlayOnText = LocalizationManager.CurrentPack!.GetText("osmodium.speechmod.feature.autoplay.toggle.notification.on", false); - if (string.IsNullOrWhiteSpace(autoPlayOnText)) + if (!string.IsNullOrWhiteSpace(autoPlayOnText)) _ToggleAutoPlayOnText = autoPlayOnText; if (Game.Instance.Keyboard.m_Bindings.Exists(binding => binding.Name.Equals(BIND_NAME))) diff --git a/SpeechMod/Keybinds/ToggleBarks.cs b/SpeechMod/Keybinds/ToggleBarks.cs index c02ffd7..62dcc89 100644 --- a/SpeechMod/Keybinds/ToggleBarks.cs +++ b/SpeechMod/Keybinds/ToggleBarks.cs @@ -36,11 +36,11 @@ private static void Add(CommonPCView __instance) Debug.Log($"{nameof(CommonPCView)}_{nameof(CommonPCView.BindViewImplementation)}_Postfix : {BIND_NAME}"); #endif var barksOffText = LocalizationManager.CurrentPack!.GetText("osmodium.speechmod.feature.barks.toggle.notification.off", false); - if (string.IsNullOrWhiteSpace(barksOffText)) + if (!string.IsNullOrWhiteSpace(barksOffText)) _ToggleBarksOffText = barksOffText; var barksOnText = LocalizationManager.CurrentPack!.GetText("osmodium.speechmod.feature.barks.toggle.notification.on", false); - if (string.IsNullOrWhiteSpace(barksOnText)) + if (!string.IsNullOrWhiteSpace(barksOnText)) _ToggleBarksOnText = barksOnText; if (Game.Instance.Keyboard.m_Bindings.Exists(binding => binding.Name.Equals(BIND_NAME)))