Skip to content

Commit

Permalink
allow using enum for registering keybinds
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniMacaroni committed Oct 30, 2023
1 parent 024788b commit 3adace8
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
12 changes: 12 additions & 0 deletions RedLoader/Preferences/ConfigCategory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using RedLoader.Preferences;

namespace RedLoader
{
Expand Down Expand Up @@ -70,6 +71,17 @@ public ConfigEntry<T> CreateEntry<T>(string identifier, T default_value, string

return entry;
}

public KeybindConfigEntry CreateKeybindEntry(string identifier, EInputKey input_key, string display_name = null,
string description = null, bool is_hidden = false, bool dont_save_default = false, Preferences.ValueValidator validator = null,
string oldIdentifier = null)
{
var keyName = input_key.ToString();
if (keyName.StartsWith("alpha"))
keyName = keyName.Substring(5);

return CreateKeybindEntry(identifier, keyName, display_name, description, is_hidden, dont_save_default, validator, oldIdentifier);
}

public KeybindConfigEntry CreateKeybindEntry(string identifier, string key_name, string display_name = null,
string description = null, bool is_hidden = false, bool dont_save_default = false, Preferences.ValueValidator validator = null, string oldIdentifier = null)
Expand Down
121 changes: 121 additions & 0 deletions RedLoader/Preferences/EInputKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// ReSharper disable InconsistentNaming
namespace RedLoader.Preferences;

public enum EInputKey
{
anyKey,
escape,
space,
enter,
tab,
backquote,
quote,
semicolon,
comma,
period,
slash,
backslash,
leftBracket,
rightBracket,
minus,
equals,
upArrow,
downArrow,
leftArrow,
rightArrow,
a,
b,
c,
d,
e,
f,
g,
h,
i,
j,
k,
l,
m,
n,
o,
p,
q,
r,
s,
t,
u,
v,
w,
x,
y,
z,
alpha1,
alpha2,
alpha3,
alpha4,
alpha5,
alpha6,
alpha7,
alpha8,
alpha9,
alpha0,
leftShift,
rightShift,
shift,
leftAlt,
rightAlt,
alt,
leftCtrl,
rightCtrl,
ctrl,
leftMeta,
rightMeta,
contextMenu,
backspace,
pageDown,
pageUp,
home,
end,
insert,
delete,
capsLock,
numLock,
printScreen,
scrollLock,
pause,
numpadEnter,
numpadDivide,
numpadMultiply,
numpadPlus,
numpadMinus,
numpadPeriod,
numpadEquals,
numpad1,
numpad2,
numpad3,
numpad4,
numpad5,
numpad6,
numpad7,
numpad8,
numpad9,
numpad0,
f1,
f2,
f3,
f4,
f5,
f6,
f7,
f8,
f9,
f10,
f11,
f12,
OEM1,
OEM2,
OEM3,
OEM4,
OEM5,
IMESelected,
}

0 comments on commit 3adace8

Please sign in to comment.