diff --git a/src/Input.c b/src/Input.c index 02f5ca84f..cc1107d19 100644 --- a/src/Input.c +++ b/src/Input.c @@ -11,7 +11,7 @@ /*########################################################################################################################* *-----------------------------------------------------------Key-----------------------------------------------------------* *#########################################################################################################################*/ -bool Key_Pressed[KEY_COUNT]; +bool Input_Pressed[INPUT_COUNT]; #define Key_Function_Names \ "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10",\ @@ -23,7 +23,7 @@ bool Key_Pressed[KEY_COUNT]; "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",\ "U", "V", "W", "X", "Y", "Z" -const char* const Key_Names[KEY_COUNT] = { +const char* const Input_Names[INPUT_COUNT] = { "None", Key_Function_Names, "ShiftLeft", "ShiftRight", "ControlLeft", "ControlRight", @@ -46,7 +46,7 @@ const char* const Key_Names[KEY_COUNT] = { }; /* TODO: Should this only be shown in GUI? not saved to disc? */ -/*const char* Key_Names[KEY_COUNT] = { +/*const char* Input_Names[INPUT_COUNT] = { "NONE", "LSHIFT", "RSHIFT", "LCONTROL", "RCONTROL", "LMENU", "RMENU", "LWIN", "RWIN", "MENU", @@ -67,9 +67,9 @@ const char* const Key_Names[KEY_COUNT] = { "XBUTTON1", "XBUTTON2", "MMOUSE" };*/ -void Key_SetPressed(Key key, bool pressed) { - bool wasPressed = Key_Pressed[key]; - Key_Pressed[key] = pressed; +void Input_SetPressed(Key key, bool pressed) { + bool wasPressed = Input_Pressed[key]; + Input_Pressed[key] = pressed; if (pressed) { Event_RaiseInput(&KeyEvents.Down, key, wasPressed); @@ -84,8 +84,8 @@ void Key_SetPressed(Key key, bool pressed) { void Key_Clear(void) { int i; - for (i = 0; i < KEY_COUNT; i++) { - if (Key_Pressed[i]) Key_SetPressed((Key)i, false); + for (i = 0; i < INPUT_COUNT; i++) { + if (Input_Pressed[i]) Input_SetPressed(i, false); } } @@ -145,7 +145,7 @@ static const char* const keybindNames[KEYBIND_COUNT] = { "DropBlock", "IDOverlay", "BreakableLiquids" }; -bool KeyBind_IsPressed(KeyBind binding) { return Key_Pressed[KeyBinds[binding]]; } +bool KeyBind_IsPressed(KeyBind binding) { return Input_Pressed[KeyBinds[binding]]; } static void KeyBind_Load(void) { String name; char nameBuffer[STRING_SIZE + 1]; @@ -158,7 +158,7 @@ static void KeyBind_Load(void) { String_Format1(&name, "key-%c", keybindNames[i]); name.buffer[name.length] = '\0'; - mapping = Options_GetEnum(name.buffer, KeyBind_Defaults[i], Key_Names, KEY_COUNT); + mapping = Options_GetEnum(name.buffer, KeyBind_Defaults[i], Input_Names, INPUT_COUNT); if (mapping != KEY_ESCAPE) KeyBinds[i] = mapping; } } @@ -173,7 +173,7 @@ static void KeyBind_Save(void) { name.length = 0; String_Format1(&name, "key-%c", keybindNames[i]); - value = String_FromReadonly(Key_Names[KeyBinds[i]]); + value = String_FromReadonly(Input_Names[KeyBinds[i]]); Options_SetString(&name, &value); } } @@ -332,7 +332,7 @@ void Hotkeys_Init(void) { if (!String_UNSAFE_Separate(&key, '&', &strKey, &strMods)) continue; if (!String_UNSAFE_Separate(&value, '&', &strMore, &strText)) continue; - trigger = Utils_ParseEnum(&strKey, KEY_NONE, Key_Names, Array_Elems(Key_Names)); + trigger = Utils_ParseEnum(&strKey, KEY_NONE, Input_Names, INPUT_COUNT); if (trigger == KEY_NONE) continue; if (!Convert_ParseUInt8(&strMods, &modifiers)) continue; if (!Convert_ParseBool(&strMore, &more)) continue; @@ -345,7 +345,7 @@ void Hotkeys_UserRemovedHotkey(Key trigger, cc_uint8 modifiers) { String key; char keyBuffer[STRING_SIZE]; String_InitArray(key, keyBuffer); - String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &modifiers); + String_Format2(&key, "hotkey-%c&%b", Input_Names[trigger], &modifiers); Options_SetString(&key, NULL); } @@ -355,7 +355,7 @@ void Hotkeys_UserAddedHotkey(Key trigger, cc_uint8 modifiers, bool moreInput, co String_InitArray(key, keyBuffer); String_InitArray(value, valueBuffer); - String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &modifiers); + String_Format2(&key, "hotkey-%c&%b", Input_Names[trigger], &modifiers); String_Format2(&value, "%t&%s", &moreInput, text); Options_SetString(&key, &value); } diff --git a/src/Input.h b/src/Input.h index 467e93b82..f4e756e84 100644 --- a/src/Input.h +++ b/src/Input.h @@ -41,17 +41,17 @@ enum Key_ { /* NOTE: RMOUSE must be before MMOUSE for PlayerClick compatibility */ KEY_XBUTTON1, KEY_XBUTTON2, KEY_LMOUSE, KEY_RMOUSE, KEY_MMOUSE, - KEY_COUNT + INPUT_COUNT }; typedef int Key; /* Simple names for each keyboard button. */ -extern const char* const Key_Names[KEY_COUNT]; +extern const char* const Input_Names[INPUT_COUNT]; -#define Key_IsWinPressed() (Key_Pressed[KEY_LWIN] || Key_Pressed[KEY_RWIN]) -#define Key_IsAltPressed() (Key_Pressed[KEY_LALT] || Key_Pressed[KEY_RALT]) -#define Key_IsControlPressed() (Key_Pressed[KEY_LCTRL] || Key_Pressed[KEY_RCTRL]) -#define Key_IsShiftPressed() (Key_Pressed[KEY_LSHIFT] || Key_Pressed[KEY_RSHIFT]) +#define Key_IsWinPressed() (Input_Pressed[KEY_LWIN] || Input_Pressed[KEY_RWIN]) +#define Key_IsAltPressed() (Input_Pressed[KEY_LALT] || Input_Pressed[KEY_RALT]) +#define Key_IsControlPressed() (Input_Pressed[KEY_LCTRL] || Input_Pressed[KEY_RCTRL]) +#define Key_IsShiftPressed() (Input_Pressed[KEY_LSHIFT] || Input_Pressed[KEY_RSHIFT]) #ifdef CC_BUILD_OSX /* osx uses CMD instead of CTRL for clipboard and stuff */ @@ -60,12 +60,12 @@ extern const char* const Key_Names[KEY_COUNT]; #define Key_IsActionPressed() Key_IsControlPressed() #endif -/* Pressed state of each keyboard button. Use Key_SetPressed to change. */ -extern bool Key_Pressed[KEY_COUNT]; +/* Pressed state of each keyboard button. Use Input_SetPressed to change. */ +extern bool Input_Pressed[INPUT_COUNT]; /* Sets the pressed state of a keyboard button. */ /* Raises KeyEvents.Up if not pressed, but was pressed before. */ /* Raises KeyEvents.Down if pressed (repeating is whether it was pressed before) */ -void Key_SetPressed(Key key, bool pressed); +void Input_SetPressed(Key key, bool pressed); /* Resets all keys to be not pressed. */ /* Raises KeyEvents.Up for each previously pressed key. */ void Key_Clear(void); diff --git a/src/InputHandler.c b/src/InputHandler.c index 2933bd55f..d07a887aa 100644 --- a/src/InputHandler.c +++ b/src/InputHandler.c @@ -30,6 +30,9 @@ static float input_fovIndex = -1.0f; static bool suppressEscape; #endif +/*########################################################################################################################* +*-----------------------------------------------------Mouse helpers-------------------------------------------------------* +*#########################################################################################################################*/ static void InputHandler_ButtonStateUpdate(MouseButton button, bool pressed) { struct Entity* p; /* defer getting the targeted entity, as it's a costly operation */ @@ -63,6 +66,183 @@ void InputHandler_OnScreensChanged(void) { } } +static bool InputHandler_TouchesSolid(BlockID b) { return Blocks.Collide[b] == COLLIDE_SOLID; } +static bool InputHandler_PushbackPlace(struct AABB* blockBB) { + struct Entity* p = &LocalPlayer_Instance.Base; + struct HacksComp* hacks = &LocalPlayer_Instance.Hacks; + Face closestFace; + bool insideMap; + + Vec3 pos = p->Position; + struct AABB playerBB; + struct LocationUpdate update; + + /* Offset position by the closest face */ + closestFace = Game_SelectedPos.Closest; + if (closestFace == FACE_XMAX) { + pos.X = blockBB->Max.X + 0.5f; + } else if (closestFace == FACE_ZMAX) { + pos.Z = blockBB->Max.Z + 0.5f; + } else if (closestFace == FACE_XMIN) { + pos.X = blockBB->Min.X - 0.5f; + } else if (closestFace == FACE_ZMIN) { + pos.Z = blockBB->Min.Z - 0.5f; + } else if (closestFace == FACE_YMAX) { + pos.Y = blockBB->Min.Y + 1 + ENTITY_ADJUSTMENT; + } else if (closestFace == FACE_YMIN) { + pos.Y = blockBB->Min.Y - p->Size.Y - ENTITY_ADJUSTMENT; + } + + /* Exclude exact map boundaries, otherwise player can get stuck outside map */ + /* Being vertically above the map is acceptable though */ + insideMap = + pos.X > 0.0f && pos.Y >= 0.0f && pos.Z > 0.0f && + pos.X < World.Width && pos.Z < World.Length; + if (!insideMap) return false; + + AABB_Make(&playerBB, &pos, &p->Size); + if (!hacks->Noclip && Entity_TouchesAny(&playerBB, InputHandler_TouchesSolid)) { + /* Don't put player inside another block */ + return false; + } + + LocationUpdate_MakePos(&update, pos, false); + p->VTABLE->SetLocation(p, &update, false); + return true; +} + +static bool InputHandler_IntersectsOthers(Vec3 pos, BlockID block) { + struct AABB blockBB, entityBB; + struct Entity* entity; + int id; + + Vec3_Add(&blockBB.Min, &pos, &Blocks.MinBB[block]); + Vec3_Add(&blockBB.Max, &pos, &Blocks.MaxBB[block]); + + for (id = 0; id < ENTITIES_SELF_ID; id++) { + entity = Entities.List[id]; + if (!entity) continue; + + Entity_GetBounds(entity, &entityBB); + entityBB.Min.Y += 1.0f / 32.0f; /* when player is exactly standing on top of ground */ + if (AABB_Intersects(&entityBB, &blockBB)) return true; + } + return false; +} + +static bool InputHandler_CheckIsFree(BlockID block) { + struct Entity* p = &LocalPlayer_Instance.Base; + struct HacksComp* hacks = &LocalPlayer_Instance.Hacks; + + Vec3 pos, nextPos; + struct AABB blockBB, playerBB; + struct LocationUpdate update; + + /* Non solid blocks (e.g. water/flowers) can always be placed on players */ + if (Blocks.Collide[block] != COLLIDE_SOLID) return true; + + IVec3_ToVec3(&pos, &Game_SelectedPos.TranslatedPos); + if (InputHandler_IntersectsOthers(pos, block)) return false; + + nextPos = LocalPlayer_Instance.Interp.Next.Pos; + Vec3_Add(&blockBB.Min, &pos, &Blocks.MinBB[block]); + Vec3_Add(&blockBB.Max, &pos, &Blocks.MaxBB[block]); + + /* NOTE: Need to also test against next position here, otherwise player can + fall through the block at feet as collision is performed against nextPos */ + Entity_GetBounds(p, &playerBB); + playerBB.Min.Y = min(nextPos.Y, playerBB.Min.Y); + + if (hacks->Noclip || !AABB_Intersects(&playerBB, &blockBB)) return true; + if (hacks->CanPushbackBlocks && hacks->PushbackPlacing && hacks->Enabled) { + return InputHandler_PushbackPlace(&blockBB); + } + + playerBB.Min.Y += 0.25f + ENTITY_ADJUSTMENT; + if (AABB_Intersects(&playerBB, &blockBB)) return false; + + /* Push player upwards when they are jumping and trying to place a block underneath them */ + nextPos.Y = pos.Y + Blocks.MaxBB[block].Y + ENTITY_ADJUSTMENT; + LocationUpdate_MakePos(&update, nextPos, false); + p->VTABLE->SetLocation(p, &update, false); + return true; +} + +static void InputHandler_DeleteBlock(void) { + IVec3 pos; + BlockID old; + /* always play delete animations, even if we aren't deleting a block */ + HeldBlockRenderer_ClickAnim(true); + + pos = Game_SelectedPos.BlockPos; + if (!Game_SelectedPos.Valid || !World_Contains(pos.X, pos.Y, pos.Z)) return; + + old = World_GetBlock(pos.X, pos.Y, pos.Z); + if (Blocks.Draw[old] == DRAW_GAS || !Blocks.CanDelete[old]) return; + + Game_ChangeBlock(pos.X, pos.Y, pos.Z, BLOCK_AIR); + Event_RaiseBlock(&UserEvents.BlockChanged, pos, old, BLOCK_AIR); +} + +static void InputHandler_PlaceBlock(void) { + IVec3 pos; + BlockID old, block; + pos = Game_SelectedPos.TranslatedPos; + if (!Game_SelectedPos.Valid || !World_Contains(pos.X, pos.Y, pos.Z)) return; + + old = World_GetBlock(pos.X, pos.Y, pos.Z); + block = Inventory_SelectedBlock; + if (AutoRotate_Enabled) block = AutoRotate_RotateBlock(block); + + if (Game_CanPick(old) || !Blocks.CanPlace[block]) return; + /* air-ish blocks can only replace over other air-ish blocks */ + if (Blocks.Draw[block] == DRAW_GAS && Blocks.Draw[old] != DRAW_GAS) return; + if (!InputHandler_CheckIsFree(block)) return; + + Game_ChangeBlock(pos.X, pos.Y, pos.Z, block); + Event_RaiseBlock(&UserEvents.BlockChanged, pos, old, block); +} + +static void InputHandler_PickBlock(void) { + IVec3 pos; + BlockID cur; + pos = Game_SelectedPos.BlockPos; + if (!World_Contains(pos.X, pos.Y, pos.Z)) return; + + cur = World_GetBlock(pos.X, pos.Y, pos.Z); + if (Blocks.Draw[cur] == DRAW_GAS) return; + if (!(Blocks.CanPlace[cur] || Blocks.CanDelete[cur])) return; + Inventory_PickBlock(cur); +} + +void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right) { + TimeMS now = DateTime_CurrentUTC_MS(); + int delta = (int)(now - input_lastClick); + + if (cooldown && delta < 250) return; /* 4 times per second */ + input_lastClick = now; + if (Gui_GetInputGrab()) return; + + if (Server.SupportsPlayerClick) { + input_pickingId = -1; + InputHandler_ButtonStateChanged(MOUSE_LEFT, left); + InputHandler_ButtonStateChanged(MOUSE_RIGHT, right); + InputHandler_ButtonStateChanged(MOUSE_MIDDLE, middle); + } + + if (left) { + InputHandler_DeleteBlock(); + } else if (right) { + InputHandler_PlaceBlock(); + } else if (middle) { + InputHandler_PickBlock(); + } +} + + +/*########################################################################################################################* +*------------------------------------------------------Key helpers--------------------------------------------------------* +*#########################################################################################################################*/ static bool InputHandler_IsShutdown(Key key) { if (key == KEY_F4 && Key_IsAltPressed()) return true; @@ -77,9 +257,9 @@ static bool InputHandler_IsShutdown(Key key) { static void InputHandler_Toggle(Key key, bool* target, const char* enableMsg, const char* disableMsg) { *target = !(*target); if (*target) { - Chat_Add2("%c. &ePress &a%c &eto disable.", enableMsg, Key_Names[key]); + Chat_Add2("%c. &ePress &a%c &eto disable.", enableMsg, Input_Names[key]); } else { - Chat_Add2("%c. &ePress &a%c &eto re-enable.", disableMsg, Key_Names[key]); + Chat_Add2("%c. &ePress &a%c &eto re-enable.", disableMsg, Input_Names[key]); } } @@ -207,163 +387,6 @@ static bool InputHandler_HandleCoreKey(Key key) { return true; } -static bool InputHandler_TouchesSolid(BlockID b) { return Blocks.Collide[b] == COLLIDE_SOLID; } -static bool InputHandler_PushbackPlace(struct AABB* blockBB) { - struct Entity* p = &LocalPlayer_Instance.Base; - struct HacksComp* hacks = &LocalPlayer_Instance.Hacks; - Face closestFace; - bool insideMap; - - Vec3 pos = p->Position; - struct AABB playerBB; - struct LocationUpdate update; - - /* Offset position by the closest face */ - closestFace = Game_SelectedPos.Closest; - if (closestFace == FACE_XMAX) { - pos.X = blockBB->Max.X + 0.5f; - } else if (closestFace == FACE_ZMAX) { - pos.Z = blockBB->Max.Z + 0.5f; - } else if (closestFace == FACE_XMIN) { - pos.X = blockBB->Min.X - 0.5f; - } else if (closestFace == FACE_ZMIN) { - pos.Z = blockBB->Min.Z - 0.5f; - } else if (closestFace == FACE_YMAX) { - pos.Y = blockBB->Min.Y + 1 + ENTITY_ADJUSTMENT; - } else if (closestFace == FACE_YMIN) { - pos.Y = blockBB->Min.Y - p->Size.Y - ENTITY_ADJUSTMENT; - } - - /* Exclude exact map boundaries, otherwise player can get stuck outside map */ - /* Being vertically above the map is acceptable though */ - insideMap = - pos.X > 0.0f && pos.Y >= 0.0f && pos.Z > 0.0f && - pos.X < World.Width && pos.Z < World.Length; - if (!insideMap) return false; - - AABB_Make(&playerBB, &pos, &p->Size); - if (!hacks->Noclip && Entity_TouchesAny(&playerBB, InputHandler_TouchesSolid)) { - /* Don't put player inside another block */ - return false; - } - - LocationUpdate_MakePos(&update, pos, false); - p->VTABLE->SetLocation(p, &update, false); - return true; -} - -static bool InputHandler_IntersectsOthers(Vec3 pos, BlockID block) { - struct AABB blockBB, entityBB; - struct Entity* entity; - int id; - - Vec3_Add(&blockBB.Min, &pos, &Blocks.MinBB[block]); - Vec3_Add(&blockBB.Max, &pos, &Blocks.MaxBB[block]); - - for (id = 0; id < ENTITIES_SELF_ID; id++) { - entity = Entities.List[id]; - if (!entity) continue; - - Entity_GetBounds(entity, &entityBB); - entityBB.Min.Y += 1.0f / 32.0f; /* when player is exactly standing on top of ground */ - if (AABB_Intersects(&entityBB, &blockBB)) return true; - } - return false; -} - -static bool InputHandler_CheckIsFree(BlockID block) { - struct Entity* p = &LocalPlayer_Instance.Base; - struct HacksComp* hacks = &LocalPlayer_Instance.Hacks; - - Vec3 pos, nextPos; - struct AABB blockBB, playerBB; - struct LocationUpdate update; - - /* Non solid blocks (e.g. water/flowers) can always be placed on players */ - if (Blocks.Collide[block] != COLLIDE_SOLID) return true; - - IVec3_ToVec3(&pos, &Game_SelectedPos.TranslatedPos); - if (InputHandler_IntersectsOthers(pos, block)) return false; - - nextPos = LocalPlayer_Instance.Interp.Next.Pos; - Vec3_Add(&blockBB.Min, &pos, &Blocks.MinBB[block]); - Vec3_Add(&blockBB.Max, &pos, &Blocks.MaxBB[block]); - - /* NOTE: Need to also test against next position here, otherwise player can - fall through the block at feet as collision is performed against nextPos */ - Entity_GetBounds(p, &playerBB); - playerBB.Min.Y = min(nextPos.Y, playerBB.Min.Y); - - if (hacks->Noclip || !AABB_Intersects(&playerBB, &blockBB)) return true; - if (hacks->CanPushbackBlocks && hacks->PushbackPlacing && hacks->Enabled) { - return InputHandler_PushbackPlace(&blockBB); - } - - playerBB.Min.Y += 0.25f + ENTITY_ADJUSTMENT; - if (AABB_Intersects(&playerBB, &blockBB)) return false; - - /* Push player upwards when they are jumping and trying to place a block underneath them */ - nextPos.Y = pos.Y + Blocks.MaxBB[block].Y + ENTITY_ADJUSTMENT; - LocationUpdate_MakePos(&update, nextPos, false); - p->VTABLE->SetLocation(p, &update, false); - return true; -} - -void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right) { - TimeMS now = DateTime_CurrentUTC_MS(); - int delta = (int)(now - input_lastClick); - IVec3 pos; - BlockID old, cur, block; - - if (cooldown && delta < 250) return; /* 4 times per second */ - input_lastClick = now; - if (Gui_GetInputGrab()) return; - - if (Server.SupportsPlayerClick) { - input_pickingId = -1; - InputHandler_ButtonStateChanged(MOUSE_LEFT, left); - InputHandler_ButtonStateChanged(MOUSE_RIGHT, right); - InputHandler_ButtonStateChanged(MOUSE_MIDDLE, middle); - } - - if (left) { - /* always play delete animations, even if we aren't deleting a block */ - HeldBlockRenderer_ClickAnim(true); - - pos = Game_SelectedPos.BlockPos; - if (!Game_SelectedPos.Valid || !World_Contains(pos.X, pos.Y, pos.Z)) return; - - old = World_GetBlock(pos.X, pos.Y, pos.Z); - if (Blocks.Draw[old] == DRAW_GAS || !Blocks.CanDelete[old]) return; - - Game_ChangeBlock(pos.X, pos.Y, pos.Z, BLOCK_AIR); - Event_RaiseBlock(&UserEvents.BlockChanged, pos, old, BLOCK_AIR); - } else if (right) { - pos = Game_SelectedPos.TranslatedPos; - if (!Game_SelectedPos.Valid || !World_Contains(pos.X, pos.Y, pos.Z)) return; - - old = World_GetBlock(pos.X, pos.Y, pos.Z); - block = Inventory_SelectedBlock; - if (AutoRotate_Enabled) block = AutoRotate_RotateBlock(block); - - if (Game_CanPick(old) || !Blocks.CanPlace[block]) return; - /* air-ish blocks can only replace over other air-ish blocks */ - if (Blocks.Draw[block] == DRAW_GAS && Blocks.Draw[old] != DRAW_GAS) return; - if (!InputHandler_CheckIsFree(block)) return; - - Game_ChangeBlock(pos.X, pos.Y, pos.Z, block); - Event_RaiseBlock(&UserEvents.BlockChanged, pos, old, block); - } else if (middle) { - pos = Game_SelectedPos.BlockPos; - if (!World_Contains(pos.X, pos.Y, pos.Z)) return; - - cur = World_GetBlock(pos.X, pos.Y, pos.Z); - if (Blocks.Draw[cur] == DRAW_GAS) return; - if (!(Blocks.CanPlace[cur] || Blocks.CanDelete[cur])) return; - Inventory_PickBlock(cur); - } -} - static void InputHandler_MouseWheel(void* obj, float delta) { struct Screen* s; int i; diff --git a/src/Menus.c b/src/Menus.c index ae98c79f6..ee5747721 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -706,7 +706,7 @@ static void EditHotkeyScreen_UpdateBaseKey(struct EditHotkeyScreen* s) { String_AppendConst(&text, "Key: press a key.."); } else { String_AppendConst(&text, "Key: "); - String_AppendConst(&text, Key_Names[s->curHotkey.Trigger]); + String_AppendConst(&text, Input_Names[s->curHotkey.Trigger]); } ButtonWidget_Set(&s->buttons[0], &text, &s->titleFont); } @@ -1414,7 +1414,7 @@ static void HotkeyListScreen_EntryClick(void* screen, void* widget) { if (String_ContainsString(&value, &shift)) flags |= HOTKEY_MOD_SHIFT; if (String_ContainsString(&value, &alt)) flags |= HOTKEY_MOD_ALT; - trigger = Utils_ParseEnum(&key, KEY_NONE, Key_Names, KEY_COUNT); + trigger = Utils_ParseEnum(&key, KEY_NONE, Input_Names, INPUT_COUNT); for (i = 0; i < HotkeysText.count; i++) { h = HotkeysList[i]; if (h.Trigger == trigger && h.Flags == flags) { original = h; break; } @@ -1439,7 +1439,7 @@ static void HotkeyListScreen_LoadEntries(struct ListScreen* s) { for (i = 0; i < HotkeysText.count; i++) { hKey = HotkeysList[i]; text.length = 0; - String_AppendConst(&text, Key_Names[hKey.Trigger]); + String_AppendConst(&text, Input_Names[hKey.Trigger]); if (hKey.Flags) { String_AppendConst(&text, " +"); @@ -1530,7 +1530,7 @@ static void KeyBindingsScreen_Update(struct KeyBindingsScreen* s, int i) { String_InitArray(text, textBuffer); String_Format2(&text, s->curI == i ? "> %c: %c <" : "%c: %c", - s->descs[i], Key_Names[KeyBinds[s->binds[i]]]); + s->descs[i], Input_Names[KeyBinds[s->binds[i]]]); ButtonWidget_Set(&s->buttons[i], &text, &s->titleFont); } @@ -1562,22 +1562,6 @@ static bool KeyBindingsScreen_KeyDown(void* screen, Key key) { return true; } -static bool KeyBindingsScreen_MouseDown(void* screen, int x, int y, MouseButton btn) { - struct KeyBindingsScreen* s = (struct KeyBindingsScreen*)screen; - int i; - - if (btn != MOUSE_RIGHT) { return Menu_MouseDown(s, x, y, btn); } - i = Menu_DoMouseDown(s, x, y, btn); - if (i == -1) return true; - - /* Reset a key binding by right clicking */ - if ((s->curI == -1 || s->curI == i) && i < s->bindsCount) { - s->curI = i; - Elem_HandlesKeyDown(s, KeyBind_Defaults[s->binds[i]]); - } - return true; -} - static void KeyBindingsScreen_ContextLost(void* screen) { struct KeyBindingsScreen* s = (struct KeyBindingsScreen*)screen; Font_Free(&s->titleFont); @@ -1648,10 +1632,10 @@ static void KeyBindingsScreen_Init(void* screen) { } static const struct ScreenVTABLE KeyBindingsScreen_VTABLE = { - KeyBindingsScreen_Init, MenuScreen_Render, Menu_NullFunc, - KeyBindingsScreen_KeyDown, Screen_TKey, Screen_TKeyPress, - KeyBindingsScreen_MouseDown, Screen_TMouse, Menu_MouseMove, Screen_TMouseScroll, - Menu_OnResize, KeyBindingsScreen_ContextLost, KeyBindingsScreen_ContextRecreated + KeyBindingsScreen_Init, MenuScreen_Render, Menu_NullFunc, + KeyBindingsScreen_KeyDown, Screen_TKey, Screen_TKeyPress, + Menu_MouseDown, Screen_TMouse, Menu_MouseMove, Screen_TMouseScroll, + Menu_OnResize, KeyBindingsScreen_ContextLost, KeyBindingsScreen_ContextRecreated }; static void KeyBindingsScreen_Show(int bindsCount, const cc_uint8* binds, const char** descs, InitKeyBindings doInit) { struct KeyBindingsScreen* s = &KeyBindingsScreen_Instance; diff --git a/src/Picking.c b/src/Picking.c index 69e899b39..cffbaacab 100644 --- a/src/Picking.c +++ b/src/Picking.c @@ -55,7 +55,6 @@ void PickedPos_SetAsInvalid(struct PickedPos* pos) { pos->Valid = false; pos->Block = BLOCK_AIR; pos->Closest = FACE_COUNT; - } static float RayTracer_Div(float a, float b) { diff --git a/src/Protocol.c b/src/Protocol.c index c6322593c..ed713d3cb 100644 --- a/src/Protocol.c +++ b/src/Protocol.c @@ -950,7 +950,7 @@ static void CPE_SetTextHotkey(cc_uint8* data) { if (keyCode > 255) return; key = Hotkeys_LWJGL[keyCode]; if (!key) return; - Platform_Log3("CPE hotkey added: %c, %b: %s", Key_Names[key], &keyMods, &action); + Platform_Log3("CPE hotkey added: %c, %b: %s", Input_Names[key], &keyMods, &action); if (!action.length) { Hotkeys_Remove(key, keyMods); diff --git a/src/Window.c b/src/Window.c index 6f39c6422..aa69dceec 100644 --- a/src/Window.c +++ b/src/Window.c @@ -105,7 +105,7 @@ static void Window_AddTouch(long id, int x, int y) { touchesCount++; Mouse_SetPosition(x, y); - Key_SetPressed(KEY_LMOUSE, true); + Input_SetPressed(KEY_LMOUSE, true); } static void Window_UpdateTouch(long id, int x, int y) { @@ -136,7 +136,7 @@ static void Window_RemoveTouch(long id, int x, int y) { touchesCount--; Mouse_SetPosition(x, y); - Key_SetPressed(KEY_LMOUSE, false); + Input_SetPressed(KEY_LMOUSE, false); return; } } @@ -266,9 +266,9 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara case WM_MOUSEMOVE: /* Set before position change, in case mouse buttons changed when outside window */ - Key_SetPressed(KEY_LMOUSE, (wParam & 0x01) != 0); - Key_SetPressed(KEY_RMOUSE, (wParam & 0x02) != 0); - Key_SetPressed(KEY_MMOUSE, (wParam & 0x10) != 0); + Input_SetPressed(KEY_LMOUSE, (wParam & 0x01) != 0); + Input_SetPressed(KEY_RMOUSE, (wParam & 0x02) != 0); + Input_SetPressed(KEY_MMOUSE, (wParam & 0x10) != 0); /* TODO: do we need to set XBUTTON1/XBUTTON2 here */ Mouse_SetPosition(LOWORD(lParam), HIWORD(lParam)); break; @@ -279,23 +279,23 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara return 0; case WM_LBUTTONDOWN: - Key_SetPressed(KEY_LMOUSE, true); break; + Input_SetPressed(KEY_LMOUSE, true); break; case WM_MBUTTONDOWN: - Key_SetPressed(KEY_MMOUSE, true); break; + Input_SetPressed(KEY_MMOUSE, true); break; case WM_RBUTTONDOWN: - Key_SetPressed(KEY_RMOUSE, true); break; + Input_SetPressed(KEY_RMOUSE, true); break; case WM_XBUTTONDOWN: - Key_SetPressed(HIWORD(wParam) == 1 ? KEY_XBUTTON1 : KEY_XBUTTON2, true); + Input_SetPressed(HIWORD(wParam) == 1 ? KEY_XBUTTON1 : KEY_XBUTTON2, true); break; case WM_LBUTTONUP: - Key_SetPressed(KEY_LMOUSE, false); break; + Input_SetPressed(KEY_LMOUSE, false); break; case WM_MBUTTONUP: - Key_SetPressed(KEY_MMOUSE, false); break; + Input_SetPressed(KEY_MMOUSE, false); break; case WM_RBUTTONUP: - Key_SetPressed(KEY_RMOUSE, false); break; + Input_SetPressed(KEY_RMOUSE, false); break; case WM_XBUTTONUP: - Key_SetPressed(HIWORD(wParam) == 1 ? KEY_XBUTTON1 : KEY_XBUTTON2, false); + Input_SetPressed(HIWORD(wParam) == 1 ? KEY_XBUTTON1 : KEY_XBUTTON2, false); break; case WM_INPUT: @@ -348,24 +348,24 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara rShiftDown = ((USHORT)GetKeyState(VK_RSHIFT)) >> 15; if (!pressed || lShiftDown != rShiftDown) { - Key_SetPressed(KEY_LSHIFT, lShiftDown); - Key_SetPressed(KEY_RSHIFT, rShiftDown); + Input_SetPressed(KEY_LSHIFT, lShiftDown); + Input_SetPressed(KEY_RSHIFT, rShiftDown); } return 0; case VK_CONTROL: - Key_SetPressed(ext ? KEY_RCTRL : KEY_LCTRL, pressed); + Input_SetPressed(ext ? KEY_RCTRL : KEY_LCTRL, pressed); return 0; case VK_MENU: - Key_SetPressed(ext ? KEY_RALT : KEY_LALT, pressed); + Input_SetPressed(ext ? KEY_RALT : KEY_LALT, pressed); return 0; case VK_RETURN: - Key_SetPressed(ext ? KEY_KP_ENTER : KEY_ENTER, pressed); + Input_SetPressed(ext ? KEY_KP_ENTER : KEY_ENTER, pressed); return 0; default: mappedKey = Window_MapKey(wParam); - if (mappedKey) Key_SetPressed(mappedKey, pressed); + if (mappedKey) Input_SetPressed(mappedKey, pressed); return 0; } } break; @@ -1024,7 +1024,7 @@ static void Window_ToggleKey(XKeyEvent* keyEvent, bool pressed) { Key key = Window_MapKey(keysym1); if (!key) key = Window_MapKey(keysym2); - if (key) Key_SetPressed(key, pressed); + if (key) Input_SetPressed(key, pressed); } static Atom Window_GetSelectionProperty(XEvent* e) { @@ -1096,21 +1096,21 @@ void Window_ProcessEvents(void) { break; case ButtonPress: - if (e.xbutton.button == 1) Key_SetPressed(KEY_LMOUSE, true); - else if (e.xbutton.button == 2) Key_SetPressed(KEY_MMOUSE, true); - else if (e.xbutton.button == 3) Key_SetPressed(KEY_RMOUSE, true); + if (e.xbutton.button == 1) Input_SetPressed(KEY_LMOUSE, true); + else if (e.xbutton.button == 2) Input_SetPressed(KEY_MMOUSE, true); + else if (e.xbutton.button == 3) Input_SetPressed(KEY_RMOUSE, true); else if (e.xbutton.button == 4) Mouse_SetWheel(Mouse_Wheel + 1); else if (e.xbutton.button == 5) Mouse_SetWheel(Mouse_Wheel - 1); - else if (e.xbutton.button == 6) Key_SetPressed(KEY_XBUTTON1, true); - else if (e.xbutton.button == 7) Key_SetPressed(KEY_XBUTTON2, true); + else if (e.xbutton.button == 6) Input_SetPressed(KEY_XBUTTON1, true); + else if (e.xbutton.button == 7) Input_SetPressed(KEY_XBUTTON2, true); break; case ButtonRelease: - if (e.xbutton.button == 1) Key_SetPressed(KEY_LMOUSE, false); - else if (e.xbutton.button == 2) Key_SetPressed(KEY_MMOUSE, false); - else if (e.xbutton.button == 3) Key_SetPressed(KEY_RMOUSE, false); - else if (e.xbutton.button == 6) Key_SetPressed(KEY_XBUTTON1, false); - else if (e.xbutton.button == 7) Key_SetPressed(KEY_XBUTTON2, false); + if (e.xbutton.button == 1) Input_SetPressed(KEY_LMOUSE, false); + else if (e.xbutton.button == 2) Input_SetPressed(KEY_MMOUSE, false); + else if (e.xbutton.button == 3) Input_SetPressed(KEY_RMOUSE, false); + else if (e.xbutton.button == 6) Input_SetPressed(KEY_XBUTTON1, false); + else if (e.xbutton.button == 7) Input_SetPressed(KEY_XBUTTON2, false); break; case MotionNotify: @@ -1562,7 +1562,7 @@ static OSStatus Window_ProcessKeyboardEvent(EventRef inEvent) { key = Window_MapKey(code); if (!key) { Platform_Log1("Ignoring unmapped key %i", &code); return 0; } - Key_SetPressed(key, kind != kEventRawKeyUp); + Input_SetPressed(key, kind != kEventRawKeyUp); return eventNotHandledErr; case kEventRawKeyModifiersChanged: @@ -1570,11 +1570,11 @@ static OSStatus Window_ProcessKeyboardEvent(EventRef inEvent) { NULL, sizeof(UInt32), NULL, &code); if (res) Logger_Abort2(res, "Getting key modifiers"); - Key_SetPressed(KEY_LCTRL, (code & 0x1000) != 0); - Key_SetPressed(KEY_LALT, (code & 0x0800) != 0); - Key_SetPressed(KEY_LSHIFT, (code & 0x0200) != 0); - Key_SetPressed(KEY_LWIN, (code & 0x0100) != 0); - Key_SetPressed(KEY_CAPSLOCK, (code & 0x0400) != 0); + Input_SetPressed(KEY_LCTRL, (code & 0x1000) != 0); + Input_SetPressed(KEY_LALT, (code & 0x0800) != 0); + Input_SetPressed(KEY_LSHIFT, (code & 0x0200) != 0); + Input_SetPressed(KEY_LWIN, (code & 0x0100) != 0); + Input_SetPressed(KEY_CAPSLOCK, (code & 0x0400) != 0); return eventNotHandledErr; } return eventNotHandledErr; @@ -1657,11 +1657,11 @@ static OSStatus Window_ProcessMouseEvent(EventRef inEvent) { switch (button) { case kEventMouseButtonPrimary: - Key_SetPressed(KEY_LMOUSE, down); break; + Input_SetPressed(KEY_LMOUSE, down); break; case kEventMouseButtonSecondary: - Key_SetPressed(KEY_RMOUSE, down); break; + Input_SetPressed(KEY_RMOUSE, down); break; case kEventMouseButtonTertiary: - Key_SetPressed(KEY_MMOUSE, down); break; + Input_SetPressed(KEY_MMOUSE, down); break; } return eventNotHandledErr; @@ -2217,22 +2217,22 @@ static Key Window_MapKey(SDL_Keycode k) { static void Window_HandleKeyEvent(const SDL_Event* e) { bool pressed = e->key.state == SDL_PRESSED; Key key = Window_MapKey(e->key.keysym.sym); - if (key) Key_SetPressed(key, pressed); + if (key) Input_SetPressed(key, pressed); } static void Window_HandleMouseEvent(const SDL_Event* e) { bool pressed = e->button.state == SDL_PRESSED; switch (e->button.button) { case SDL_BUTTON_LEFT: - Key_SetPressed(KEY_LMOUSE, pressed); break; + Input_SetPressed(KEY_LMOUSE, pressed); break; case SDL_BUTTON_MIDDLE: - Key_SetPressed(KEY_MMOUSE, pressed); break; + Input_SetPressed(KEY_MMOUSE, pressed); break; case SDL_BUTTON_RIGHT: - Key_SetPressed(KEY_RMOUSE, pressed); break; + Input_SetPressed(KEY_RMOUSE, pressed); break; case SDL_BUTTON_X1: - Key_SetPressed(KEY_XBUTTON1, pressed); break; + Input_SetPressed(KEY_XBUTTON1, pressed); break; case SDL_BUTTON_X2: - Key_SetPressed(KEY_XBUTTON2, pressed); break; + Input_SetPressed(KEY_XBUTTON2, pressed); break; } } @@ -2407,18 +2407,18 @@ static EM_BOOL Window_MouseButton(int type, const EmscriptenMouseEvent* ev, void Window_CorrectFocus(); switch (ev->button) { - case 0: Key_SetPressed(KEY_LMOUSE, down); break; - case 1: Key_SetPressed(KEY_MMOUSE, down); break; - case 2: Key_SetPressed(KEY_RMOUSE, down); break; + case 0: Input_SetPressed(KEY_LMOUSE, down); break; + case 1: Input_SetPressed(KEY_MMOUSE, down); break; + case 2: Input_SetPressed(KEY_RMOUSE, down); break; } return true; } static EM_BOOL Window_MouseMove(int type, const EmscriptenMouseEvent* ev, void* data) { /* Set before position change, in case mouse buttons changed when outside window */ - Key_SetPressed(KEY_LMOUSE, (ev->buttons & 0x01) != 0); - Key_SetPressed(KEY_RMOUSE, (ev->buttons & 0x02) != 0); - Key_SetPressed(KEY_MMOUSE, (ev->buttons & 0x04) != 0); + Input_SetPressed(KEY_LMOUSE, (ev->buttons & 0x01) != 0); + Input_SetPressed(KEY_RMOUSE, (ev->buttons & 0x02) != 0); + Input_SetPressed(KEY_MMOUSE, (ev->buttons & 0x04) != 0); Mouse_SetPosition(ev->canvasX, ev->canvasY); if (win_rawMouse) Event_RaiseMouseMove(&MouseEvents.RawMoved, ev->movementX, ev->movementY); @@ -2558,7 +2558,7 @@ static EM_BOOL Window_Key(int type, const EmscriptenKeyboardEvent* ev , void* da } } - Key_SetPressed(key, type == EMSCRIPTEN_EVENT_KEYDOWN); + Input_SetPressed(key, type == EMSCRIPTEN_EVENT_KEYDOWN); /* KeyUp always intercepted */ if (type != EMSCRIPTEN_EVENT_KEYDOWN) return true; @@ -2841,13 +2841,13 @@ static Key Window_MapKey(int code) { static void JNICALL java_processKeyDown(JNIEnv* env, jobject o, jint code) { int key = Window_MapKey(code); Platform_Log2("KEY - DOWN %i,%i", &code, &key); - if (key) Key_SetPressed(key, true); + if (key) Input_SetPressed(key, true); } static void JNICALL java_processKeyUp(JNIEnv* env, jobject o, jint code) { int key = Window_MapKey(code); Platform_Log2("KEY - UP %i,%i", &code, &key); - if (key) Key_SetPressed(key, false); + if (key) Input_SetPressed(key, false); } static void JNICALL java_processKeyChar(JNIEnv* env, jobject o, jint code) {