mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 01:26:50 -04:00
Mobile: Fix clicking onscreen delete button still placing a block (Thanks kaikai)
This commit is contained in:
parent
05ab96a615
commit
1f1b9f983d
@ -473,7 +473,7 @@ static void Game_Render3D(double delta, float t) {
|
|||||||
|
|
||||||
Selections_Render();
|
Selections_Render();
|
||||||
Entities_RenderHoveredNames();
|
Entities_RenderHoveredNames();
|
||||||
InputHandler_PickBlocks();
|
InputHandler_Tick();
|
||||||
if (!Game_HideGui) HeldBlockRenderer_Render(delta);
|
if (!Game_HideGui) HeldBlockRenderer_Render(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
src/Input.c
32
src/Input.c
@ -51,8 +51,6 @@ int Pointers_Count;
|
|||||||
cc_bool Input_TapPlace = true, Input_HoldPlace = false;
|
cc_bool Input_TapPlace = true, Input_HoldPlace = false;
|
||||||
cc_bool Input_TouchMode;
|
cc_bool Input_TouchMode;
|
||||||
|
|
||||||
static void DoDeleteBlock(void);
|
|
||||||
static void DoPlaceBlock(void);
|
|
||||||
static void MouseStatePress(int button);
|
static void MouseStatePress(int button);
|
||||||
static void MouseStateRelease(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();
|
touches[i].start = DateTime_CurrentUTC_MS();
|
||||||
/* Also set last click time, otherwise quickly tapping */
|
/* 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. */
|
/* and then another 'delete' in CheckBlockTap. */
|
||||||
input_lastClick = touches[i].start;
|
input_lastClick = touches[i].start;
|
||||||
|
|
||||||
@ -139,9 +137,11 @@ static void CheckBlockTap(int i) {
|
|||||||
pressed = input_buttonsDown[btn];
|
pressed = input_buttonsDown[btn];
|
||||||
MouseStatePress(btn);
|
MouseStatePress(btn);
|
||||||
|
|
||||||
if (btn == MOUSE_LEFT) { DoDeleteBlock(); }
|
if (btn == MOUSE_LEFT) {
|
||||||
else { DoPlaceBlock(); }
|
InputHandler_DeleteBlock();
|
||||||
|
} else {
|
||||||
|
InputHandler_PlaceBlock();
|
||||||
|
}
|
||||||
if (!pressed) MouseStateRelease(btn);
|
if (!pressed) MouseStateRelease(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,7 +700,7 @@ static cc_bool CheckIsFree(BlockID block) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DoDeleteBlock(void) {
|
void InputHandler_DeleteBlock(void) {
|
||||||
IVec3 pos;
|
IVec3 pos;
|
||||||
BlockID old;
|
BlockID old;
|
||||||
/* always play delete animations, even if we aren't deleting a block */
|
/* 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);
|
Event_RaiseBlock(&UserEvents.BlockChanged, pos, old, BLOCK_AIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DoPlaceBlock(void) {
|
void InputHandler_PlaceBlock(void) {
|
||||||
IVec3 pos;
|
IVec3 pos;
|
||||||
BlockID old, block;
|
BlockID old, block;
|
||||||
pos = Game_SelectedPos.TranslatedPos;
|
pos = Game_SelectedPos.TranslatedPos;
|
||||||
@ -735,7 +735,7 @@ static void DoPlaceBlock(void) {
|
|||||||
Event_RaiseBlock(&UserEvents.BlockChanged, pos, old, block);
|
Event_RaiseBlock(&UserEvents.BlockChanged, pos, old, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DoPickBlock(void) {
|
void InputHandler_PickBlock(void) {
|
||||||
IVec3 pos;
|
IVec3 pos;
|
||||||
BlockID cur;
|
BlockID cur;
|
||||||
pos = Game_SelectedPos.pos;
|
pos = Game_SelectedPos.pos;
|
||||||
@ -747,7 +747,7 @@ static void DoPickBlock(void) {
|
|||||||
Inventory_PickBlock(cur);
|
Inventory_PickBlock(cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler_PickBlocks(void) {
|
void InputHandler_Tick(void) {
|
||||||
cc_bool left, middle, right;
|
cc_bool left, middle, right;
|
||||||
TimeMS now = DateTime_CurrentUTC_MS();
|
TimeMS now = DateTime_CurrentUTC_MS();
|
||||||
int delta = (int)(now - input_lastClick);
|
int delta = (int)(now - input_lastClick);
|
||||||
@ -776,11 +776,11 @@ void InputHandler_PickBlocks(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (left) {
|
if (left) {
|
||||||
DoDeleteBlock();
|
InputHandler_DeleteBlock();
|
||||||
} else if (right) {
|
} else if (right) {
|
||||||
DoPlaceBlock();
|
InputHandler_PlaceBlock();
|
||||||
} else if (middle) {
|
} else if (middle) {
|
||||||
DoPickBlock();
|
InputHandler_PickBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -845,13 +845,13 @@ static cc_bool HandleBlockKey(int key) {
|
|||||||
|
|
||||||
if (key == KeyBinds[KEYBIND_DELETE_BLOCK]) {
|
if (key == KeyBinds[KEYBIND_DELETE_BLOCK]) {
|
||||||
MouseStatePress(MOUSE_LEFT);
|
MouseStatePress(MOUSE_LEFT);
|
||||||
DoDeleteBlock();
|
InputHandler_DeleteBlock();
|
||||||
} else if (key == KeyBinds[KEYBIND_PLACE_BLOCK]) {
|
} else if (key == KeyBinds[KEYBIND_PLACE_BLOCK]) {
|
||||||
MouseStatePress(MOUSE_RIGHT);
|
MouseStatePress(MOUSE_RIGHT);
|
||||||
DoPlaceBlock();
|
InputHandler_PlaceBlock();
|
||||||
} else if (key == KeyBinds[KEYBIND_PICK_BLOCK]) {
|
} else if (key == KeyBinds[KEYBIND_PICK_BLOCK]) {
|
||||||
MouseStatePress(MOUSE_MIDDLE);
|
MouseStatePress(MOUSE_MIDDLE);
|
||||||
DoPickBlock();
|
InputHandler_PickBlock();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -171,8 +171,11 @@ void StoredHotkeys_Add(int trigger, cc_uint8 modifiers, cc_bool moreInput, const
|
|||||||
|
|
||||||
cc_bool InputHandler_SetFOV(int fov);
|
cc_bool InputHandler_SetFOV(int fov);
|
||||||
cc_bool Input_HandleMouseWheel(float delta);
|
cc_bool Input_HandleMouseWheel(float delta);
|
||||||
void InputHandler_PickBlocks(void);
|
void InputHandler_Tick(void);
|
||||||
void InputHandler_OnScreensChanged(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 */
|
/* Enumeration of on-screen buttons for touch GUI */
|
||||||
#define ONSCREEN_BTN_CHAT (1 << 0)
|
#define ONSCREEN_BTN_CHAT (1 << 0)
|
||||||
|
@ -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)
|
#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_ChatClick(void* s, void* w) { ChatScreen_OpenInput(&String_Empty); }
|
||||||
static void TouchScreen_RespawnClick(void* s, void* w) { LocalPlayer_HandleRespawn(); }
|
static void TouchScreen_RespawnClick(void* s, void* w) { LocalPlayer_HandleRespawn(); }
|
||||||
static void TouchScreen_SetSpawnClick(void* s, void* w) { LocalPlayer_HandleSetSpawn(); }
|
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_CameraClick(void* s, void* w) { Camera_CycleActive(); }
|
||||||
static void TouchScreen_MoreClick(void* s, void* w) { TouchMoreScreen_Show(); }
|
static void TouchScreen_MoreClick(void* s, void* w) { TouchMoreScreen_Show(); }
|
||||||
static void TouchScreen_SwitchClick(void* s, void* w) { Inventory_SwitchHotbar(); }
|
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) {
|
static void TouchScreen_TabClick(void* s, void* w) {
|
||||||
if (TabListOverlay_Instance.active) {
|
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 },
|
{ "Speed", 0,0,0, TouchScreen_SpeedClick, &LocalPlayer_Instance.Hacks.CanSpeed },
|
||||||
{ "\xabSpeed", 0,0,0, TouchScreen_HalfClick, &LocalPlayer_Instance.Hacks.CanSpeed },
|
{ "\xabSpeed", 0,0,0, TouchScreen_HalfClick, &LocalPlayer_Instance.Hacks.CanSpeed },
|
||||||
{ "Camera", 0,0,0, TouchScreen_CameraClick, &LocalPlayer_Instance.Hacks.CanUseThirdPerson },
|
{ "Camera", 0,0,0, TouchScreen_CameraClick, &LocalPlayer_Instance.Hacks.CanUseThirdPerson },
|
||||||
{ "Delete", KEYBIND_DELETE_BLOCK, 0,0, TouchScreen_OnscreenClick },
|
{ "Delete", 0,0,0, TouchScreen_DeleteClick },
|
||||||
{ "Pick", KEYBIND_PICK_BLOCK, 0,0, TouchScreen_OnscreenClick },
|
{ "Pick", 0,0,0, TouchScreen_PickClick },
|
||||||
{ "Place", KEYBIND_PLACE_BLOCK, 0,0, TouchScreen_OnscreenClick },
|
{ "Place", 0,0,0, TouchScreen_PlaceClick },
|
||||||
{ "Hotbar", 0,0,0, TouchScreen_SwitchClick }
|
{ "Hotbar", 0,0,0, TouchScreen_SwitchClick }
|
||||||
};
|
};
|
||||||
static const struct TouchButtonDesc normDescs[1] = {
|
static const struct TouchButtonDesc normDescs[1] = {
|
||||||
|
@ -15,8 +15,6 @@ struct _WinData WindowInfo;
|
|||||||
|
|
||||||
int Display_ScaleX(int x) { return (int)(x * DisplayInfo.ScaleX); }
|
int Display_ScaleX(int x) { return (int)(x * DisplayInfo.ScaleX); }
|
||||||
int Display_ScaleY(int y) { return (int)(y * DisplayInfo.ScaleY); }
|
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
|
#if defined CC_BUILD_IOS
|
||||||
/* iOS implements these functions in external interop_ios.m file */
|
/* iOS implements these functions in external interop_ios.m file */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user