diff --git a/src/Game.c b/src/Game.c index 853fbd4a3..cd29e02c8 100644 --- a/src/Game.c +++ b/src/Game.c @@ -473,7 +473,7 @@ static void Game_Render3D(double delta, float t) { Selections_Render(); Entities_RenderHoveredNames(); - InputHandler_PickBlocks(); + InputHandler_Tick(); if (!Game_HideGui) HeldBlockRenderer_Render(delta); } diff --git a/src/Input.c b/src/Input.c index 1ce1485b8..6c38ab2be 100644 --- a/src/Input.c +++ b/src/Input.c @@ -51,8 +51,6 @@ int Pointers_Count; cc_bool Input_TapPlace = true, Input_HoldPlace = false; cc_bool Input_TouchMode; -static void DoDeleteBlock(void); -static void DoPlaceBlock(void); static void MouseStatePress(int button); static void MouseStateRelease(int button); @@ -92,7 +90,7 @@ void Input_AddTouch(long id, int x, int y) { touches[i].start = DateTime_CurrentUTC_MS(); /* Also set last click time, otherwise quickly tapping */ - /* sometimes triggers a 'delete' in InputHandler_PickBlocks, */ + /* sometimes triggers a 'delete' in InputHandler_Tick, */ /* and then another 'delete' in CheckBlockTap. */ input_lastClick = touches[i].start; @@ -139,9 +137,11 @@ static void CheckBlockTap(int i) { pressed = input_buttonsDown[btn]; MouseStatePress(btn); - if (btn == MOUSE_LEFT) { DoDeleteBlock(); } - else { DoPlaceBlock(); } - + if (btn == MOUSE_LEFT) { + InputHandler_DeleteBlock(); + } else { + InputHandler_PlaceBlock(); + } if (!pressed) MouseStateRelease(btn); } @@ -700,7 +700,7 @@ static cc_bool CheckIsFree(BlockID block) { return true; } -static void DoDeleteBlock(void) { +void InputHandler_DeleteBlock(void) { IVec3 pos; BlockID old; /* always play delete animations, even if we aren't deleting a block */ @@ -716,7 +716,7 @@ static void DoDeleteBlock(void) { Event_RaiseBlock(&UserEvents.BlockChanged, pos, old, BLOCK_AIR); } -static void DoPlaceBlock(void) { +void InputHandler_PlaceBlock(void) { IVec3 pos; BlockID old, block; pos = Game_SelectedPos.TranslatedPos; @@ -735,7 +735,7 @@ static void DoPlaceBlock(void) { Event_RaiseBlock(&UserEvents.BlockChanged, pos, old, block); } -static void DoPickBlock(void) { +void InputHandler_PickBlock(void) { IVec3 pos; BlockID cur; pos = Game_SelectedPos.pos; @@ -747,7 +747,7 @@ static void DoPickBlock(void) { Inventory_PickBlock(cur); } -void InputHandler_PickBlocks(void) { +void InputHandler_Tick(void) { cc_bool left, middle, right; TimeMS now = DateTime_CurrentUTC_MS(); int delta = (int)(now - input_lastClick); @@ -776,11 +776,11 @@ void InputHandler_PickBlocks(void) { } if (left) { - DoDeleteBlock(); + InputHandler_DeleteBlock(); } else if (right) { - DoPlaceBlock(); + InputHandler_PlaceBlock(); } else if (middle) { - DoPickBlock(); + InputHandler_PickBlock(); } } @@ -845,13 +845,13 @@ static cc_bool HandleBlockKey(int key) { if (key == KeyBinds[KEYBIND_DELETE_BLOCK]) { MouseStatePress(MOUSE_LEFT); - DoDeleteBlock(); + InputHandler_DeleteBlock(); } else if (key == KeyBinds[KEYBIND_PLACE_BLOCK]) { MouseStatePress(MOUSE_RIGHT); - DoPlaceBlock(); + InputHandler_PlaceBlock(); } else if (key == KeyBinds[KEYBIND_PICK_BLOCK]) { MouseStatePress(MOUSE_MIDDLE); - DoPickBlock(); + InputHandler_PickBlock(); } else { return false; } diff --git a/src/Input.h b/src/Input.h index bc3faba82..bbf767742 100644 --- a/src/Input.h +++ b/src/Input.h @@ -171,8 +171,11 @@ void StoredHotkeys_Add(int trigger, cc_uint8 modifiers, cc_bool moreInput, const cc_bool InputHandler_SetFOV(int fov); cc_bool Input_HandleMouseWheel(float delta); -void InputHandler_PickBlocks(void); +void InputHandler_Tick(void); void InputHandler_OnScreensChanged(void); +void InputHandler_DeleteBlock(void); +void InputHandler_PlaceBlock(void); +void InputHandler_PickBlock(void); /* Enumeration of on-screen buttons for touch GUI */ #define ONSCREEN_BTN_CHAT (1 << 0) diff --git a/src/Screens.c b/src/Screens.c index 5bc1479e7..903c0c020 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1942,13 +1942,6 @@ static struct Widget* touch_widgets[ONSCREEN_MAX_BTNS + TOUCH_EXTRA_BTNS + 2] = }; #define TOUCH_MAX_VERTICES (THUMBSTICKWIDGET_MAX + TOUCH_MAX_BTNS * BUTTONWIDGET_MAX) -static void TouchScreen_OnscreenClick(void* screen, void* widget) { - struct TouchScreen* s = (struct TouchScreen*)screen; - int i = Screen_Index(screen, widget); - int key = KeyBinds[s->onscreenDescs[i]->bind]; - Input_Set(key, !Input_Pressed[key]); -} - static void TouchScreen_ChatClick(void* s, void* w) { ChatScreen_OpenInput(&String_Empty); } static void TouchScreen_RespawnClick(void* s, void* w) { LocalPlayer_HandleRespawn(); } static void TouchScreen_SetSpawnClick(void* s, void* w) { LocalPlayer_HandleSetSpawn(); } @@ -1957,6 +1950,9 @@ static void TouchScreen_NoclipClick(void* s, void* w) { LocalPlayer_HandleNocl static void TouchScreen_CameraClick(void* s, void* w) { Camera_CycleActive(); } static void TouchScreen_MoreClick(void* s, void* w) { TouchMoreScreen_Show(); } static void TouchScreen_SwitchClick(void* s, void* w) { Inventory_SwitchHotbar(); } +static void TouchScreen_DeleteClick(void* s, void* w) { InputHandler_DeleteBlock(); } /* TODO: also Send CPEClick packet */ +static void TouchScreen_PlaceClick(void* s, void* w) { InputHandler_PlaceBlock(); } +static void TouchScreen_PickClick(void* s, void* w) { InputHandler_PickBlock(); } static void TouchScreen_TabClick(void* s, void* w) { if (TabListOverlay_Instance.active) { @@ -1991,9 +1987,9 @@ static const struct TouchButtonDesc onscreenDescs[ONSCREEN_MAX_BTNS] = { { "Speed", 0,0,0, TouchScreen_SpeedClick, &LocalPlayer_Instance.Hacks.CanSpeed }, { "\xabSpeed", 0,0,0, TouchScreen_HalfClick, &LocalPlayer_Instance.Hacks.CanSpeed }, { "Camera", 0,0,0, TouchScreen_CameraClick, &LocalPlayer_Instance.Hacks.CanUseThirdPerson }, - { "Delete", KEYBIND_DELETE_BLOCK, 0,0, TouchScreen_OnscreenClick }, - { "Pick", KEYBIND_PICK_BLOCK, 0,0, TouchScreen_OnscreenClick }, - { "Place", KEYBIND_PLACE_BLOCK, 0,0, TouchScreen_OnscreenClick }, + { "Delete", 0,0,0, TouchScreen_DeleteClick }, + { "Pick", 0,0,0, TouchScreen_PickClick }, + { "Place", 0,0,0, TouchScreen_PlaceClick }, { "Hotbar", 0,0,0, TouchScreen_SwitchClick } }; static const struct TouchButtonDesc normDescs[1] = { diff --git a/src/Window.c b/src/Window.c index 3c75d984d..67c68a76b 100644 --- a/src/Window.c +++ b/src/Window.c @@ -15,8 +15,6 @@ struct _WinData WindowInfo; int Display_ScaleX(int x) { return (int)(x * DisplayInfo.ScaleX); } int Display_ScaleY(int y) { return (int)(y * DisplayInfo.ScaleY); } -#define Display_CentreX(width) (DisplayInfo.X + (DisplayInfo.Width - width) / 2) -#define Display_CentreY(height) (DisplayInfo.Y + (DisplayInfo.Height - height) / 2) #if defined CC_BUILD_IOS /* iOS implements these functions in external interop_ios.m file */