diff --git a/src/Entity.c b/src/Entity.c index fe7f17d79..c662c1fb9 100644 --- a/src/Entity.c +++ b/src/Entity.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); diff --git a/src/Input.c b/src/Input.c index 63f1be4f1..a2e8be3bb 100644 --- a/src/Input.c +++ b/src/Input.c @@ -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, diff --git a/src/Input.h b/src/Input.h index 3cdf8dd1a..8dde2f224 100644 --- a/src/Input.h +++ b/src/Input.h @@ -33,18 +33,27 @@ 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, @@ -52,13 +61,6 @@ typedef enum Key_ { 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) */ diff --git a/src/InputHandler.c b/src/InputHandler.c index 9df4fe750..04eb490a0 100644 --- a/src/InputHandler.c +++ b/src/InputHandler.c @@ -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); } diff --git a/src/LWidgets.c b/src/LWidgets.c index 8b8f8f29b..72f874f22 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -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); diff --git a/src/Launcher.c b/src/Launcher.c index a236b4194..c15fde207 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -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 diff --git a/src/Menus.c b/src/Menus.c index 63bee07f1..1f00931f4 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -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); diff --git a/src/Screens.c b/src/Screens.c index 170a4667c..d9c428cd5 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -179,7 +179,7 @@ static bool InventoryScreen_KeyDown(void* screen, Key key, bool was) { if (key == KEY_ESCAPE) { Gui_CloseActive(); - } else if (key == KeyBind_Get(KEYBIND_INVENTORY) && s->ReleasedInv) { + } else if (key == KeyBinds[KEYBIND_INVENTORY] && s->ReleasedInv) { Gui_CloseActive(); } else if (key == KEY_ENTER && table->SelectedIndex != -1) { Inventory_SetSelectedBlock(table->Elements[table->SelectedIndex]); @@ -197,7 +197,7 @@ static bool InventoryScreen_KeyUp(void* screen, Key key) { struct InventoryScreen* s = screen; struct HUDScreen* hud; - if (key == KeyBind_Get(KEYBIND_INVENTORY)) { + if (key == KeyBinds[KEYBIND_INVENTORY]) { s->ReleasedInv = true; return true; } @@ -913,7 +913,7 @@ static bool ChatScreen_KeyDown(void* screen, Key key, bool was) { s->SuppressNextPress = false; /* Handle text input bar */ if (s->HandlesAllInput) { - if (key == KeyBind_Get(KEYBIND_SEND_CHAT) || key == KEY_KP_ENTER || key == KEY_ESCAPE) { + if (key == KeyBinds[KEYBIND_SEND_CHAT] || key == KEY_KP_ENTER || key == KEY_ESCAPE) { ChatScreen_SetHandlesAllInput(s, false); if (key == KEY_ESCAPE) InputWidget_Clear(&s->Input.Base); @@ -940,7 +940,7 @@ static bool ChatScreen_KeyDown(void* screen, Key key, bool was) { return key < KEY_F1 || key > KEY_F35; } - if (key == KeyBind_Get(KEYBIND_CHAT)) { + if (key == KeyBinds[KEYBIND_CHAT]) { ChatScreen_OpenInput(s, &String_Empty); } else if (key == KEY_SLASH) { ChatScreen_OpenInput(s, &slash); @@ -954,7 +954,7 @@ static bool ChatScreen_KeyUp(void* screen, Key key) { struct ChatScreen* s = screen; if (!s->HandlesAllInput) return false; - if (Server.SupportsFullCP437 && key == KeyBind_Get(KEYBIND_EXT_INPUT)) { + if (Server.SupportsFullCP437 && key == KeyBinds[KEYBIND_EXT_INPUT]) { if (!Window_Focused) return true; SpecialInputWidget_SetActive(&s->AltText, !s->AltText.Active); } @@ -1247,7 +1247,7 @@ static bool HUDScreen_KeyPress(void* screen, char keyChar) { static bool HUDScreen_KeyDown(void* screen, Key key, bool was) { struct HUDScreen* s = screen; - Key playerListKey = KeyBind_Get(KEYBIND_PLAYER_LIST); + Key playerListKey = KeyBinds[KEYBIND_PLAYER_LIST]; bool handles = playerListKey != KEY_TAB || !Gui_TabAutocomplete || !s->Chat->HandlesAllInput; if (key == playerListKey && handles) { @@ -1263,7 +1263,7 @@ static bool HUDScreen_KeyDown(void* screen, Key key, bool was) { static bool HUDScreen_KeyUp(void* screen, Key key) { struct HUDScreen* s = screen; - if (key == KeyBind_Get(KEYBIND_PLAYER_LIST) && s->ShowingList) { + if (key == KeyBinds[KEYBIND_PLAYER_LIST] && s->ShowingList) { s->ShowingList = false; s->WasShowingList = false; Elem_TryFree(&s->PlayerList); diff --git a/src/Widgets.c b/src/Widgets.c index eb20ab015..538ec7213 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -415,9 +415,9 @@ static void HotbarWidget_Render(void* widget, double delta) { static bool HotbarWidget_KeyDown(void* widget, Key key, bool was) { struct HotbarWidget* w = widget; int index; - if (key < KEY_1 || key > KEY_9) return false; + if (key < '1' || key > '9') return false; - index = key - KEY_1; + index = key - '1'; if (KeyBind_IsPressed(KEYBIND_HOTBAR_SWITCH)) { /* Pick from first to ninth row */ Inventory_SetHotbarIndex(index); @@ -436,7 +436,7 @@ static bool HotbarWidget_KeyUp(void* widget, Key key) { a) user presses alt then number b) user presses alt We only do case b) if case a) did not happen */ - if (key != KeyBind_Get(KEYBIND_HOTBAR_SWITCH)) return false; + if (key != KeyBinds[KEYBIND_HOTBAR_SWITCH]) return false; if (w->AltHandled) { w->AltHandled = false; return true; } /* handled already */ /* Don't switch hotbar when alt+tab */ @@ -1158,7 +1158,7 @@ static bool InputWidget_OtherKey(struct InputWidget* w, Key key) { maxChars = w->GetMaxLines() * INPUTWIDGET_LEN; if (!InputWidget_ControlDown()) return false; - if (key == KEY_V && w->Text.length < maxChars) { + if (key == 'V' && w->Text.length < maxChars) { String_InitArray(text, textBuffer); Window_GetClipboardText(&text); @@ -1168,7 +1168,7 @@ static bool InputWidget_OtherKey(struct InputWidget* w, Key key) { if (!text.length) return true; InputWidget_AppendString(w, &text); return true; - } else if (key == KEY_C) { + } else if (key == 'C') { if (!w->Text.length) return true; Window_SetClipboardText(&w->Text); return true; diff --git a/src/Window.c b/src/Window.c index ae03edc2c..c2678161c 100644 --- a/src/Window.c +++ b/src/Window.c @@ -63,9 +63,9 @@ static uint8_t key_map[14 * 16] = { 0, 0, 0, 0, 0, 0, 0, 0, KEY_BACKSPACE, KEY_TAB, 0, 0, 0, KEY_ENTER, 0, 0, 0, 0, 0, KEY_PAUSE, KEY_CAPSLOCK, 0, 0, 0, 0, 0, 0, KEY_ESCAPE, 0, 0, 0, 0, KEY_SPACE, KEY_PAGEUP, KEY_PAGEDOWN, KEY_END, KEY_HOME, KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN, 0, KEY_PRINTSCREEN, 0, KEY_PRINTSCREEN, KEY_INSERT, KEY_DELETE, 0, - KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, 0, 0, 0, 0, 0, 0, - 0, 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_LWIN, KEY_RWIN, KEY_MENU, 0, 0, + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0, 0, 0, 0, 0, 0, + 0, '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', KEY_LWIN, KEY_RWIN, KEY_MENU, 0, 0, KEY_KP0, KEY_KP1, KEY_KP2, KEY_KP3, KEY_KP4, KEY_KP5, KEY_KP6, KEY_KP7, KEY_KP8, KEY_KP9, KEY_KP_MULTIPLY, KEY_KP_PLUS, 0, KEY_KP_MINUS, KEY_KP_DECIMAL, KEY_KP_DIVIDE, 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, 0, 0, 0, 0, 0, 0, 0, 0, @@ -729,14 +729,12 @@ static long win_eventMask; *-----------------------------------------------------Private details-----------------------------------------------------* *#########################################################################################################################*/ static Key Window_MapKey(KeySym key) { - if (key >= XK_F1 && key <= XK_F35) { return KEY_F1 + (key - XK_F1); } - if (key >= XK_0 && key <= XK_9) { return KEY_0 + (key - XK_0); } - if (key >= XK_A && key <= XK_Z) { return KEY_A + (key - XK_A); } - if (key >= XK_a && key <= XK_z) { return KEY_A + (key - XK_a); } + if (key >= XK_0 && key <= XK_9) { return '0' + (key - XK_0); } + if (key >= XK_A && key <= XK_Z) { return 'A' + (key - XK_A); } + if (key >= XK_a && key <= XK_z) { return 'A' + (key - XK_a); } - if (key >= XK_KP_0 && key <= XK_KP_9) { - return KEY_KP0 + (key - XK_KP_0); - } + if (key >= XK_F1 && key <= XK_F35) { return KEY_F1 + (key - XK_F1); } + if (key >= XK_KP_0 && key <= XK_KP_9) { return KEY_KP0 + (key - XK_KP_0); } switch (key) { case XK_Escape: return KEY_ESCAPE; @@ -1767,14 +1765,14 @@ static bool ctx_pendingWindowed, ctx_pendingFullscreen; *#########################################################################################################################*/ /* Sourced from https://www.meandmark.com/keycodes.html */ static uint8_t key_map[8 * 16] = { - KEY_A, KEY_S, KEY_D, KEY_F, KEY_H, KEY_G, KEY_Z, KEY_X, KEY_C, KEY_V, 0, KEY_B, KEY_Q, KEY_W, KEY_E, KEY_R, - KEY_Y, KEY_T, KEY_1, KEY_2, KEY_3, KEY_4, KEY_6, KEY_5, KEY_PLUS, KEY_9, KEY_7, KEY_MINUS, KEY_8, KEY_0, KEY_RBRACKET, KEY_O, - KEY_U, KEY_LBRACKET, KEY_I, KEY_P, KEY_ENTER, KEY_L, KEY_J, KEY_QUOTE, KEY_K, KEY_SEMICOLON, KEY_BACKSLASH, KEY_COMMA, KEY_SLASH, KEY_N, KEY_M, KEY_PERIOD, + 'A', 'S', 'D', 'F', 'H', 'G', 'Z', 'X', 'C', 'V', 0, 'B', 'Q', 'W', 'E', 'R', + 'Y', 'T', '1', '2', '3', '4', '6', '5', KEY_PLUS, '9', '7', KEY_MINUS, '8', '0', KEY_RBRACKET, 'O', + 'U', KEY_LBRACKET, 'I', 'P', KEY_ENTER, 'L', 'J', KEY_QUOTE, 'K', KEY_SEMICOLON, KEY_BACKSLASH, KEY_COMMA, KEY_SLASH, 'N', 'M', KEY_PERIOD, KEY_TAB, KEY_SPACE, KEY_TILDE, KEY_BACKSPACE, 0, KEY_ESCAPE, 0, 0, 0, KEY_CAPSLOCK, 0, 0, 0, 0, 0, 0, 0, KEY_KP_DECIMAL, 0, KEY_KP_MULTIPLY, 0, KEY_KP_PLUS, 0, 0, 0, 0, 0, KEY_KP_DIVIDE, KEY_KP_ENTER, 0, KEY_KP_MINUS, 0, - 0, KEY_KP_ENTER, KEY_KP0, KEY_KP1, KEY_KP2, KEY_KP3, KEY_KP4, KEY_KP5, KEY_KP6, KEY_KP7, 0, KEY_KP8, KEY_KP9, KEY_N, KEY_M, KEY_PERIOD, + 0, KEY_KP_ENTER, KEY_KP0, KEY_KP1, KEY_KP2, KEY_KP3, KEY_KP4, KEY_KP5, KEY_KP6, KEY_KP7, 0, KEY_KP8, KEY_KP9, 'N', 'M', KEY_PERIOD, KEY_F5, KEY_F6, KEY_F7, KEY_F3, KEY_F8, KEY_F9, 0, KEY_F11, 0, KEY_F13, 0, KEY_F14, 0, KEY_F10, 0, KEY_F12, - KEY_U, KEY_F15, KEY_INSERT, KEY_HOME, KEY_PAGEUP, KEY_DELETE, KEY_F4, KEY_END, KEY_F2, KEY_PAGEDOWN, KEY_F1, KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP, 0, + 'U', KEY_F15, KEY_INSERT, KEY_HOME, KEY_PAGEUP, KEY_DELETE, KEY_F4, KEY_END, KEY_F2, KEY_PAGEDOWN, KEY_F1, KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP, 0, }; static Key Window_MapKey(UInt32 key) { return key < Array_Elems(key_map) ? key_map[key] : 0; } /* TODO: Check these.. */