From 6bdd5c67737c38db596762e3272ac5eae772c9d5 Mon Sep 17 00:00:00 2001 From: grorp Date: Thu, 12 Sep 2024 23:41:47 +0200 Subject: [PATCH] Only apply "touch_punch_gesture" when wielded item has no on_use callback (#15098) --- doc/lua_api.md | 10 +++++++++- src/client/game.cpp | 2 +- src/itemdef.cpp | 7 +++++-- src/itemdef.h | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 46bdd09ce..b4be08feb 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -9223,9 +9223,17 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and -- If specified as a table, the field to be used is selected according to -- the current `pointed_thing`. -- There are three possible TouchInteractionMode values: - -- * "user" (meaning depends on client-side settings) -- * "long_dig_short_place" (long tap = dig, short tap = place) -- * "short_dig_long_place" (short tap = dig, long tap = place) + -- * "user": + -- * For `pointed_object`: Equivalent to "short_dig_long_place" if the + -- client-side setting "touch_punch_gesture" is "short_tap" (the + -- default value) and the item is able to punch (i.e. has no on_use + -- callback defined). + -- Equivalent to "long_dig_short_place" otherwise. + -- * For `pointed_node` and `pointed_nothing`: + -- Equivalent to "long_dig_short_place". + -- * The behavior of "user" may change in the future. -- The default value is "user". sound = { diff --git a/src/client/game.cpp b/src/client/game.cpp index 701504a31..c0b342336 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -3349,7 +3349,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud) infostream << "Pointing at " << pointed.dump() << std::endl; if (g_touchscreengui) { - auto mode = selected_def.touch_interaction.getMode(pointed.type); + auto mode = selected_def.touch_interaction.getMode(selected_def, pointed.type); g_touchscreengui->applyContextControls(mode); // applyContextControls may change dig/place input. // Update again so that TOSERVER_INTERACT packets have the correct controls set. diff --git a/src/itemdef.cpp b/src/itemdef.cpp index ad2ed4847..220c6fbb6 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -45,7 +45,8 @@ TouchInteraction::TouchInteraction() pointed_object = TouchInteractionMode_USER; } -TouchInteractionMode TouchInteraction::getMode(PointedThingType pointed_type) const +TouchInteractionMode TouchInteraction::getMode(const ItemDefinition &selected_def, + PointedThingType pointed_type) const { TouchInteractionMode result; switch (pointed_type) { @@ -63,7 +64,9 @@ TouchInteractionMode TouchInteraction::getMode(PointedThingType pointed_type) co } if (result == TouchInteractionMode_USER) { - if (pointed_type == POINTEDTHING_OBJECT) + if (pointed_type == POINTEDTHING_OBJECT && !selected_def.usable) + // Only apply when we're actually able to punch the object, i.e. when + // the selected item has no on_use callback defined. result = g_settings->get("touch_punch_gesture") == "long_tap" ? LONG_DIG_SHORT_PLACE : SHORT_DIG_LONG_PLACE; else diff --git a/src/itemdef.h b/src/itemdef.h index 782dad816..4ef5ce094 100644 --- a/src/itemdef.h +++ b/src/itemdef.h @@ -71,7 +71,8 @@ struct TouchInteraction TouchInteraction(); // Returns the right mode for the pointed thing and resolves any occurrence // of TouchInteractionMode_USER into an actual mode. - TouchInteractionMode getMode(PointedThingType pointed_type) const; + TouchInteractionMode getMode(const ItemDefinition &selected_def, + PointedThingType pointed_type) const; void serialize(std::ostream &os) const; void deSerialize(std::istream &is); };