Permalink
Browse files

reorganise Key enum, so KEY_0 is '0' and KEY_A is 'A'

  • Loading branch information...
UnknownShadow200 committed Feb 10, 2019
1 parent 61d0a87 commit c00eec58fb2c6eb7d7c294edb0de2f7b5e91a5a9
Showing with 102 additions and 102 deletions.
  1. +5 −5 src/Entity.c
  2. +27 −28 src/Input.c
  3. +20 −17 src/Input.h
  4. +18 −18 src/InputHandler.c
  5. +2 −2 src/LWidgets.c
  6. +1 −1 src/Launcher.c
  7. +4 −4 src/Menus.c
  8. +7 −7 src/Screens.c
  9. +5 −5 src/Widgets.c
  10. +13 −15 src/Window.c
@@ -1053,15 +1053,15 @@ bool LocalPlayer_HandlesKey(Key key) {
struct PhysicsComp* physics = &p->Physics;
int maxJumps;

if (key == KeyBind_Get(KEYBIND_RESPAWN)) {
if (key == KeyBinds[KEYBIND_RESPAWN]) {
return LocalPlayer_HandleRespawn();
} else if (key == KeyBind_Get(KEYBIND_SET_SPAWN)) {
} else if (key == KeyBinds[KEYBIND_SET_SPAWN]) {
return LocalPlayer_HandleSetSpawn();
} else if (key == KeyBind_Get(KEYBIND_FLY)) {
} else if (key == KeyBinds[KEYBIND_FLY]) {
return LocalPlayer_HandleFly();
} else if (key == KeyBind_Get(KEYBIND_NOCLIP)) {
} else if (key == KeyBinds[KEYBIND_NOCLIP]) {
return LocalPlayer_HandleNoClip();
} else if (key == KeyBind_Get(KEYBIND_JUMP) && !p->Base.OnGround && !(hacks->Flying || hacks->Noclip)) {
} else if (key == KeyBinds[KEYBIND_JUMP] && !p->Base.OnGround && !(hacks->Flying || hacks->Noclip)) {
maxJumps = hacks->CanDoubleJump && hacks->WOMStyleHacks ? 2 : 0;
maxJumps = max(maxJumps, hacks->MaxJumps - 1);

@@ -25,20 +25,21 @@ bool Key_Pressed[KEY_COUNT];

const char* Key_Names[KEY_COUNT] = {
"None",
"ShiftLeft", "ShiftRight", "ControlLeft", "ControlRight",
"AltLeft", "AltRight", "WinLeft", "WinRight", "Menu",
Key_Function_Names,
"ShiftLeft", "ShiftRight", "ControlLeft", "ControlRight",
"AltLeft", "AltRight", "WinLeft", "WinRight",
"Up", "Down", "Left", "Right",
"Enter", "Escape", "Space", "Tab", "BackSpace", "Insert",
"Delete", "PageUp", "PageDown", "Home", "End", "CapsLock",
"Number0", "Number1", "Number2", "Number3", "Number4",
"Number5", "Number6", "Number7", "Number8", "Number9",
"Insert", "Delete", "Home", "End", "PageUp", "PageDown",
"Menu",
Key_Ascii_Names,
"Enter", "Escape", "Space", "BackSpace", "Tab", "CapsLock",
"ScrollLock", "PrintScreen", "Pause", "NumLock",
"Keypad0", "Keypad1", "Keypad2", "Keypad3", "Keypad4",
"Keypad5", "Keypad6", "Keypad7", "Keypad8", "Keypad9",
"KeypadDivide", "KeypadMultiply", "KeypadSubtract",
"KeypadAdd", "KeypadDecimal", "KeypadEnter",
Key_Ascii_Names,
"Number0", "Number1", "Number2", "Number3", "Number4",
"Number5", "Number6", "Number7", "Number8", "Number9",
"KeypadAdd", "KeypadDecimal", "KeypadEnter",
"Tilde", "Minus", "Plus", "BracketLeft", "BracketRight",
"Semicolon", "Quote", "Comma", "Period", "Slash", "BackSlash",
"XButton1", "XButton2",
@@ -119,17 +120,17 @@ void Mouse_SetPosition(int x, int y) {
/*########################################################################################################################*
*---------------------------------------------------------Keybinds--------------------------------------------------------*
*#########################################################################################################################*/
static Key KeyBind_Keys[KEYBIND_COUNT];
static uint8_t KeyBind_Defaults[KEYBIND_COUNT] = {
KEY_W, KEY_S, KEY_A, KEY_D,
KEY_SPACE, KEY_R, KEY_ENTER, KEY_T,
KEY_B, KEY_F, KEY_ENTER, KEY_TAB,
KEY_LSHIFT, KEY_X, KEY_Z, KEY_Q, KEY_E,
uint8_t KeyBinds[KEYBIND_COUNT];
const uint8_t KeyBind_Defaults[KEYBIND_COUNT] = {
'W', 'S', 'A', 'D',
KEY_SPACE, 'R', KEY_ENTER, 'T',
'B', 'F', KEY_ENTER, KEY_TAB,
KEY_LSHIFT, 'X', 'Z', 'Q', 'E',
KEY_LALT, KEY_F3, KEY_F12, KEY_F11,
KEY_F5, KEY_F1, KEY_F7, KEY_C,
KEY_LCTRL, KEY_NONE, KEY_NONE, KEY_NONE,
KEY_F5, KEY_F1, KEY_F7, 'C',
KEY_LCTRL, 0, 0, 0,
KEY_F6, KEY_LALT, KEY_F8,
KEY_G, KEY_F10, KEY_NONE
'G', KEY_F10, 0
};
const char* KeyBind_Names[KEYBIND_COUNT] = {
"Forward", "Back", "Left", "Right",
@@ -143,9 +144,7 @@ const char* KeyBind_Names[KEYBIND_COUNT] = {
"DropBlock", "IDOverlay", "BreakableLiquids"
};

Key KeyBind_Get(KeyBind binding) { return KeyBind_Keys[binding]; }
Key KeyBind_GetDefault(KeyBind binding) { return KeyBind_Defaults[binding]; }
bool KeyBind_IsPressed(KeyBind binding) { return Key_Pressed[KeyBind_Keys[binding]]; }
bool KeyBind_IsPressed(KeyBind binding) { return Key_Pressed[KeyBinds[binding]]; }

void KeyBind_Load(void) {
String name; char nameBuffer[STRING_SIZE + 1];
@@ -159,7 +158,7 @@ void KeyBind_Load(void) {
name.buffer[name.length] = '\0';

mapping = Options_GetEnum(name.buffer, KeyBind_Defaults[i], Key_Names, KEY_COUNT);
if (mapping != KEY_ESCAPE) KeyBind_Keys[i] = mapping;
if (mapping != KEY_ESCAPE) KeyBinds[i] = mapping;
}
}

@@ -173,20 +172,20 @@ void KeyBind_Save(void) {
name.length = 0;
String_Format1(&name, "key-%c", KeyBind_Names[i]);

value = String_FromReadonly(Key_Names[KeyBind_Keys[i]]);
value = String_FromReadonly(Key_Names[KeyBinds[i]]);
Options_SetString(&name, &value);
}
}

void KeyBind_Set(KeyBind binding, Key key) {
KeyBind_Keys[binding] = key;
KeyBinds[binding] = key;
KeyBind_Save();
}

void KeyBind_Init(void) {
int i;
for (i = 0; i < KEYBIND_COUNT; i++) {
KeyBind_Keys[i] = KeyBind_Defaults[i];
KeyBinds[i] = KeyBind_Defaults[i];
}
KeyBind_Load();
}
@@ -196,10 +195,10 @@ void KeyBind_Init(void) {
*---------------------------------------------------------Hotkeys---------------------------------------------------------*
*#########################################################################################################################*/
const uint8_t Hotkeys_LWJGL[256] = {
0, KEY_ESCAPE, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0, KEY_MINUS, KEY_PLUS, KEY_BACKSPACE, KEY_TAB,
KEY_Q, KEY_W, KEY_E, KEY_R, KEY_T, KEY_Y, KEY_U, KEY_I, KEY_O, KEY_P, KEY_LBRACKET, KEY_RBRACKET, KEY_ENTER, KEY_LCTRL, KEY_A, KEY_S,
KEY_D, KEY_F, KEY_G, KEY_H, KEY_J, KEY_K, KEY_L, KEY_SEMICOLON, KEY_QUOTE, KEY_TILDE, KEY_LSHIFT, KEY_BACKSLASH, KEY_Z, KEY_X, KEY_C, KEY_V,
KEY_B, KEY_N, KEY_M, KEY_COMMA, KEY_PERIOD, KEY_SLASH, KEY_RSHIFT, 0, KEY_LALT, KEY_SPACE, KEY_CAPSLOCK, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
0, KEY_ESCAPE, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', KEY_MINUS, KEY_PLUS, KEY_BACKSPACE, KEY_TAB,
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', KEY_LBRACKET, KEY_RBRACKET, KEY_ENTER, KEY_LCTRL, 'A', 'S',
'D', 'F', 'G', 'H', 'J', 'K', 'L', KEY_SEMICOLON, KEY_QUOTE, KEY_TILDE, KEY_LSHIFT, KEY_BACKSLASH, 'Z', 'X', 'C', 'V',
'B', 'N', 'M', KEY_COMMA, KEY_PERIOD, KEY_SLASH, KEY_RSHIFT, 0, KEY_LALT, KEY_SPACE, KEY_CAPSLOCK, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_NUMLOCK, KEY_SCROLLLOCK, KEY_KP7, KEY_KP8, KEY_KP9, KEY_KP_MINUS, KEY_KP4, KEY_KP5, KEY_KP6, KEY_KP_PLUS, KEY_KP1,
KEY_KP2, KEY_KP3, KEY_KP0, KEY_KP_DECIMAL, 0, 0, 0, KEY_F11, KEY_F12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17, KEY_F18, 0, 0, 0, 0, 0, 0,
@@ -33,32 +33,34 @@
typedef enum Key_ {
KEY_NONE, /* Unrecognised key */

KEY_LSHIFT, KEY_RSHIFT, KEY_LCTRL, KEY_RCTRL,
KEY_LALT, KEY_RALT, KEY_LWIN, KEY_RWIN, KEY_MENU,

KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10,
KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10,
KEY_F11, KEY_F12, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20,
KEY_F21, KEY_F22, KEY_F23, KEY_F24, KEY_F25, KEY_F26, KEY_F27, KEY_F28, KEY_F29, KEY_F30,
KEY_F31, KEY_F32, KEY_F33, KEY_F34, KEY_F35,

KEY_LSHIFT, KEY_RSHIFT, KEY_LCTRL, KEY_RCTRL,
KEY_LALT, KEY_RALT, KEY_LWIN, KEY_RWIN,

KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT,

KEY_ENTER, KEY_ESCAPE, KEY_SPACE, KEY_TAB, KEY_BACKSPACE, KEY_INSERT,
KEY_DELETE, KEY_PAGEUP, KEY_PAGEDOWN, KEY_HOME, KEY_END, KEY_CAPSLOCK,
KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, /* same as 0-9 */

KEY_INSERT, KEY_DELETE, KEY_HOME, KEY_END, KEY_PAGEUP, KEY_PAGEDOWN,
KEY_MENU,

KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T,
KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, /* same as A-Z */

KEY_ENTER, KEY_ESCAPE, KEY_SPACE, KEY_BACKSPACE, KEY_TAB, KEY_CAPSLOCK,
KEY_SCROLLLOCK, KEY_PRINTSCREEN, KEY_PAUSE, KEY_NUMLOCK,

KEY_KP0, KEY_KP1, KEY_KP2, KEY_KP3, KEY_KP4,
KEY_KP5, KEY_KP6, KEY_KP7, KEY_KP8, KEY_KP9,
KEY_KP_DIVIDE, KEY_KP_MULTIPLY, KEY_KP_MINUS,
KEY_KP_PLUS, KEY_KP_DECIMAL, KEY_KP_ENTER,

KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T,
KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z,

KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,

KEY_TILDE, KEY_MINUS, KEY_PLUS, KEY_LBRACKET, KEY_RBRACKET,
KEY_SEMICOLON, KEY_QUOTE, KEY_COMMA, KEY_PERIOD, KEY_SLASH, KEY_BACKSLASH,

@@ -120,10 +122,11 @@ typedef enum KeyBind_ {
KEYBIND_COUNT
} KeyBind;

/* Gets the key that is bound to the the given key binding. */
Key KeyBind_Get(KeyBind binding);
/* Gets the default key that the given key binding is bound to */
Key KeyBind_GetDefault(KeyBind binding);
/* The keys that are bound to each key binding. */
extern uint8_t KeyBinds[KEYBIND_COUNT];
/* Default key that each key binding is bound to */
extern const uint8_t KeyBind_Defaults[KEYBIND_COUNT];

/* Gets whether the key bound to the given key binding is pressed. */
bool KeyBind_IsPressed(KeyBind binding);
/* Set the key that the given key binding is bound to. (also updates options list) */
@@ -76,7 +76,7 @@ static bool InputHandler_IsShutdown(Key key) {

/* On OSX, Cmd+Q should also terminate the process */
#ifdef CC_BUILD_OSX
return key == KEY_Q && Key_IsWinPressed();
return key == 'Q' && Key_IsWinPressed();
#else
return false;
#endif
@@ -143,33 +143,33 @@ static bool InputHandler_DoFovZoom(float deltaPrecise) {
}

static bool InputHandler_HandleNonClassicKey(Key key) {
if (key == KeyBind_Get(KEYBIND_HIDE_GUI)) {
if (key == KeyBinds[KEYBIND_HIDE_GUI]) {
Game_HideGui = !Game_HideGui;
} else if (key == KeyBind_Get(KEYBIND_SMOOTH_CAMERA)) {
} else if (key == KeyBinds[KEYBIND_SMOOTH_CAMERA]) {
InputHandler_Toggle(key, &Camera.Smooth,
" &eSmooth camera is &aenabled",
" &eSmooth camera is &cdisabled");
} else if (key == KeyBind_Get(KEYBIND_AXIS_LINES)) {
} else if (key == KeyBinds[KEYBIND_AXIS_LINES]) {
InputHandler_Toggle(key, &Game_ShowAxisLines,
" &eAxis lines (&4X&e, &2Y&e, &1Z&e) now show",
" &eAxis lines no longer show");
} else if (key == KeyBind_Get(KEYBIND_AUTOROTATE)) {
} else if (key == KeyBinds[KEYBIND_AUTOROTATE]) {
InputHandler_Toggle(key, &AutoRotate_Enabled,
" &eAuto rotate is &aenabled",
" &eAuto rotate is &cdisabled");
} else if (key == KeyBind_Get(KEYBIND_THIRD_PERSON)) {
} else if (key == KeyBinds[KEYBIND_THIRD_PERSON]) {
Camera_CycleActive();
} else if (key == KeyBind_Get(KEYBIND_DROP_BLOCK)) {
} else if (key == KeyBinds[KEYBIND_DROP_BLOCK]) {
if (Inventory_CheckChangeSelected() && Inventory_SelectedBlock != BLOCK_AIR) {
/* Don't assign SelectedIndex directly, because we don't want held block
switching positions if they already have air in their inventory hotbar. */
Inventory_Set(Inventory.SelectedIndex, BLOCK_AIR);
Event_RaiseVoid(&UserEvents.HeldBlockChanged);
}
} else if (key == KeyBind_Get(KEYBIND_IDOVERLAY)) {
} else if (key == KeyBinds[KEYBIND_IDOVERLAY]) {
if (Gui_OverlaysCount) return true;
Gui_ShowOverlay(TexIdsOverlay_MakeInstance(), false);
} else if (key == KeyBind_Get(KEYBIND_BREAK_LIQUIDS)) {
} else if (key == KeyBinds[KEYBIND_BREAK_LIQUIDS]) {
InputHandler_Toggle(key, &Game_BreakableLiquids,
" &eBreakable liquids is &aenabled",
" &eBreakable liquids is &cdisabled");
@@ -182,15 +182,15 @@ static bool InputHandler_HandleNonClassicKey(Key key) {
static bool InputHandler_HandleCoreKey(Key key) {
struct Screen* active = Gui_GetActiveScreen();

if (key == KeyBind_Get(KEYBIND_HIDE_FPS)) {
if (key == KeyBinds[KEYBIND_HIDE_FPS]) {
Gui_ShowFPS = !Gui_ShowFPS;
} else if (key == KeyBind_Get(KEYBIND_FULLSCREEN)) {
} else if (key == KeyBinds[KEYBIND_FULLSCREEN]) {
int state = Window_GetWindowState();
if (state != WINDOW_STATE_MAXIMISED) {
bool fullscreen = state == WINDOW_STATE_FULLSCREEN;
Window_SetWindowState(fullscreen ? WINDOW_STATE_NORMAL : WINDOW_STATE_FULLSCREEN);
}
} else if (key == KeyBind_Get(KEYBIND_FOG)) {
} else if (key == KeyBinds[KEYBIND_FOG]) {
short* viewDists = Gui_ClassicMenu ? classicViewDists : normViewDists;
int count = Gui_ClassicMenu ? Array_Elems(classicViewDists) : Array_Elems(normViewDists);

@@ -202,7 +202,7 @@ static bool InputHandler_HandleCoreKey(Key key) {
} else if ((key == KEY_ESCAPE || key == KEY_PAUSE) && !active->HandlesAllInput) {
Gui_FreeActive();
Gui_SetActive(PauseScreen_MakeInstance());
} else if (key == KeyBind_Get(KEYBIND_INVENTORY) && active == Gui_HUD) {
} else if (key == KeyBinds[KEYBIND_INVENTORY] && active == Gui_HUD) {
Gui_FreeActive();
Gui_SetActive(InventoryScreen_MakeInstance());
} else if (key == KEY_F5 && Game_ClassicMode) {
@@ -438,9 +438,9 @@ static void InputHandler_MouseUp(void* obj, int button) {
}

static bool InputHandler_SimulateMouse(Key key, bool pressed) {
Key left = KeyBind_Get(KEYBIND_MOUSE_LEFT);
Key middle = KeyBind_Get(KEYBIND_MOUSE_MIDDLE);
Key right = KeyBind_Get(KEYBIND_MOUSE_RIGHT);
Key left = KeyBinds[KEYBIND_MOUSE_LEFT];
Key middle = KeyBinds[KEYBIND_MOUSE_MIDDLE];
Key right = KeyBinds[KEYBIND_MOUSE_RIGHT];
MouseButton btn;
if (!(key == left || key == middle || key == right)) return false;

@@ -462,7 +462,7 @@ static void InputHandler_KeyDown(void* obj, int key, bool was) {
if (InputHandler_IsShutdown(key)) {
/* TODO: Do we need a separate exit function in Game class? */
Window_Close(); return;
} else if (key == KeyBind_Get(KEYBIND_SCREENSHOT) && !was) {
} else if (key == KeyBinds[KEYBIND_SCREENSHOT] && !was) {
Game_ScreenshotRequested = true; return;
} else if (Elem_HandlesKeyDown(active, key, was)) { return; }

@@ -489,7 +489,7 @@ static void InputHandler_KeyUp(void* obj, int key) {
struct Screen* active;
if (InputHandler_SimulateMouse(key, false)) return;

if (key == KeyBind_Get(KEYBIND_ZOOM_SCROLL)) {
if (key == KeyBinds[KEYBIND_ZOOM_SCROLL]) {
InputHandler_SetFOV(Game_DefaultFov, false);
}

@@ -397,9 +397,9 @@ static void LInput_KeyDown(void* widget, Key key, bool was) {
LWidget_Redraw(w);
} else if (key == KEY_DELETE && LInput_Delete(w)) {
LWidget_Redraw(w);
} else if (key == KEY_C && Key_IsControlPressed()) {
} else if (key == 'C' && Key_IsControlPressed()) {
if (w->Text.length) Window_SetClipboardText(&w->Text);
} else if (key == KEY_V && Key_IsControlPressed()) {
} else if (key == 'V' && Key_IsControlPressed()) {
if (LInput_CopyFromClipboard(w)) LWidget_Redraw(w);
} else if (key == KEY_ESCAPE) {
if (LInput_Clear(w)) LWidget_Redraw(w);
@@ -115,7 +115,7 @@ static bool Launcher_IsShutdown(int key) {

/* On OSX, Cmd+Q should also terminate the process */
#ifdef CC_BUILD_OSX
return key == KEY_Q && Key_IsWinPressed();
return key == 'Q' && Key_IsWinPressed();
#else
return false;
#endif
@@ -1598,7 +1598,7 @@ struct Screen* LoadLevelScreen_MakeInstance(void) {
*#########################################################################################################################*/
static struct KeyBindingsScreen KeyBindingsScreen_Instance;
static void KeyBindingsScreen_GetText(struct KeyBindingsScreen* s, int i, String* text) {
Key key = KeyBind_Get(s->Binds[i]);
Key key = KeyBinds[s->Binds[i]];
String_Format2(text, "%c: %c", s->Descs[i], Key_Names[key]);
}

@@ -1676,7 +1676,7 @@ static bool KeyBindingsScreen_KeyDown(void* screen, Key key, bool was) {

if (s->CurI == -1) return MenuScreen_KeyDown(s, key, was);
bind = s->Binds[s->CurI];
if (key == KEY_ESCAPE) key = KeyBind_GetDefault(bind);
if (key == KEY_ESCAPE) key = KeyBind_Defaults[bind];

KeyBind_Set(bind, key);
String_InitArray(text, textBuffer);
@@ -1699,7 +1699,7 @@ static bool KeyBindingsScreen_MouseDown(void* screen, int x, int y, MouseButton
/* Reset a key binding */
if ((s->CurI == -1 || s->CurI == i) && i < s->BindsCount) {
s->CurI = i;
Elem_HandlesKeyDown(s, KeyBind_GetDefault(s->Binds[i]), false);
Elem_HandlesKeyDown(s, KeyBind_Defaults[s->Binds[i]], false);
}
return true;
}
@@ -3057,7 +3057,7 @@ static void TexIdsOverlay_Render(void* screen, double delta) {
static bool TexIdsOverlay_KeyDown(void* screen, Key key, bool was) {
struct Screen* active = Gui_GetUnderlyingScreen();

if (key == KeyBind_Get(KEYBIND_IDOVERLAY) || key == KEY_ESCAPE) {
if (key == KeyBinds[KEYBIND_IDOVERLAY] || key == KEY_ESCAPE) {
Gui_FreeOverlay(screen); return true;
}
return Elem_HandlesKeyDown(active, key, was);
Oops, something went wrong.

0 comments on commit c00eec5

Please sign in to comment.