diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index 9c7bf65..743069f 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -22,6 +22,7 @@ internal class Configuration : IPluginConfiguration { public bool ShowNoviceNetwork; public bool SidebarTabView; public CommandHelpSide CommandHelpSide = CommandHelpSide.None; + public KeybindMode KeybindMode = KeybindMode.Strict; public bool CanMove = true; public bool CanResize = true; public bool ShowTitleBar; @@ -47,6 +48,7 @@ internal class Configuration : IPluginConfiguration { this.ShowNoviceNetwork = other.ShowNoviceNetwork; this.SidebarTabView = other.SidebarTabView; this.CommandHelpSide = other.CommandHelpSide; + this.KeybindMode = other.KeybindMode; this.CanMove = other.CanMove; this.CanResize = other.CanResize; this.ShowTitleBar = other.ShowTitleBar; @@ -191,3 +193,17 @@ internal static class CommandHelpSideExt { _ => throw new ArgumentOutOfRangeException(nameof(side), side, null), }; } + +[Serializable] +internal enum KeybindMode { + Flexible, + Strict, +} + +internal static class KeybindModeExt { + internal static string Name(this KeybindMode mode) => mode switch { + KeybindMode.Flexible => Language.KeybindMode_Flexible_Name, + KeybindMode.Strict => Language.KeybindMode_Strict_Name, + _ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null), + }; + diff --git a/ChatTwo/GameFunctions/Chat.cs b/ChatTwo/GameFunctions/Chat.cs index 138e521..d679f66 100755 --- a/ChatTwo/GameFunctions/Chat.cs +++ b/ChatTwo/GameFunctions/Chat.cs @@ -367,7 +367,12 @@ internal sealed unsafe class Chat : IDisposable { return; } - if (!modifierState.HasFlag(modifier)) { + var modifierPressed = this.Plugin.Config.KeybindMode switch { + KeybindMode.Strict => modifier == modifierState, + KeybindMode.Flexible => modifierState.HasFlag(modifier), + _ => false, + }; + if (!modifierPressed) { return; } diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index f43db8c..228b047 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -221,7 +221,12 @@ internal sealed class ChatLog : IUiComponent { } void Intercept(VirtualKey key, ModifierFlag modifier) { - if (!ImGui.IsKeyPressed((int) key) || !modifierState.HasFlag(modifier) || modifier == 0 && modifiersOnly) { + var modifierPressed = this.Ui.Plugin.Config.KeybindMode switch { + KeybindMode.Strict => modifier == modifierState, + KeybindMode.Flexible => modifierState.HasFlag(modifier), + _ => false, + }; + if (!ImGui.IsKeyPressed((int) key) || !modifierPressed || modifier == 0 && modifiersOnly) { return; } diff --git a/ChatTwo/Ui/Settings.cs b/ChatTwo/Ui/Settings.cs index a7c3914..f0de410 100755 --- a/ChatTwo/Ui/Settings.cs +++ b/ChatTwo/Ui/Settings.cs @@ -24,6 +24,7 @@ internal sealed class Settings : IUiComponent { new Ui.SettingsTabs.Fonts(this.Mutable), new ChatColours(this.Mutable, this.Ui.Plugin), new Tabs(this.Mutable), + new Miscellaneous(this.Mutable), new About(), }; diff --git a/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs b/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs new file mode 100755 index 0000000..346b07f --- /dev/null +++ b/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs @@ -0,0 +1,36 @@ +using ChatTwo.Resources; +using ChatTwo.Util; +using ImGuiNET; + +namespace ChatTwo.Ui.SettingsTabs; + +internal sealed class Miscellaneous : ISettingsTab { + private Configuration Mutable { get; } + + public string Name => Language.Options_Miscellaneous_Tab + "###tabs-miscellaneous"; + + public Miscellaneous(Configuration mutable) { + this.Mutable = mutable; + } + + public void Draw() { + if (ImGui.BeginCombo(Language.Options_KeybindMode_Name, this.Mutable.KeybindMode.Name())) { + foreach (var mode in Enum.GetValues()) { + if (ImGui.Selectable(mode.Name(), this.Mutable.KeybindMode == mode)) { + this.Mutable.KeybindMode = mode; + } + + if (ImGui.IsItemHovered()) { + ImGui.BeginTooltip(); + ImGui.TextUnformatted(mode.Tooltip()); + ImGui.EndTooltip(); + } + } + + ImGui.EndCombo(); + } + + ImGuiUtil.HelpText(string.Format(Language.Options_KeybindMode_Description, Plugin.PluginName)); + ImGui.Spacing(); + } +}