feat: add keybind mode options
This commit is contained in:
parent
e1e3a39c5c
commit
f70b23a476
|
@ -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),
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
};
|
||||
|
||||
|
|
|
@ -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<KeybindMode>()) {
|
||||
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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue