Re-add "long tap to punch" as a client-side setting

This commit is contained in:
Gregor Parzefall 2024-03-24 22:35:55 +01:00 committed by grorp
parent e8a8525bcd
commit 517f1602aa
8 changed files with 54 additions and 19 deletions

@ -185,6 +185,19 @@ fixed_virtual_joystick (Fixed virtual joystick) bool false
# Requires: touchscreen_gui # Requires: touchscreen_gui
virtual_joystick_triggers_aux1 (Virtual joystick triggers Aux1 button) bool false virtual_joystick_triggers_aux1 (Virtual joystick triggers Aux1 button) bool false
# The gesture for for punching players/entities.
# This can be overridden by games and mods.
#
# * short_tap
# Easy to use and well-known from other games that shall not be named.
#
# * long_tap
# Known from the classic Minetest mobile controls.
# Combat is more or less impossible.
#
# Requires: touchscreen_gui
touch_punch_gesture (Punch gesture) enum short_tap short_tap,long_tap
[Graphics and Audio] [Graphics and Audio]

@ -9098,15 +9098,16 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and
touch_interaction = { touch_interaction = {
-- Only affects touchscreen clients. -- Only affects touchscreen clients.
-- Defines the meaning of short and long taps with the item in hand. -- Defines the meaning of short and long taps with the item in hand.
-- The fields in this table have two valid values: -- The fields in this table can be set to the following values:
-- * "user" (meaning depends on client-side settings)
-- * "long_dig_short_place" (long tap = dig, short tap = place) -- * "long_dig_short_place" (long tap = dig, short tap = place)
-- * "short_dig_long_place" (short tap = dig, long tap = place) -- * "short_dig_long_place" (short tap = dig, long tap = place)
-- The field to be used is selected according to the current -- The field to be used is selected according to the current
-- `pointed_thing`. -- `pointed_thing`.
pointed_nothing = "long_dig_short_place", pointed_nothing = "user",
pointed_node = "long_dig_short_place", pointed_node = "user",
pointed_object = "short_dig_long_place", pointed_object = "user",
}, },
sound = { sound = {

@ -3280,8 +3280,10 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
if (pointed != runData.pointed_old) if (pointed != runData.pointed_old)
infostream << "Pointing at " << pointed.dump() << std::endl; infostream << "Pointing at " << pointed.dump() << std::endl;
if (g_touchscreengui) if (g_touchscreengui) {
g_touchscreengui->applyContextControls(selected_def.touch_interaction.getMode(pointed)); auto mode = selected_def.touch_interaction.getMode(pointed.type);
g_touchscreengui->applyContextControls(mode);
}
// Note that updating the selection mesh every frame is not particularly efficient, // Note that updating the selection mesh every frame is not particularly efficient,
// but the halo rendering code is already inefficient so there's no point in optimizing it here // but the halo rendering code is already inefficient so there's no point in optimizing it here

@ -490,6 +490,7 @@ void set_default_settings()
settings->setDefault("touch_use_crosshair", "false"); settings->setDefault("touch_use_crosshair", "false");
settings->setDefault("fixed_virtual_joystick", "false"); settings->setDefault("fixed_virtual_joystick", "false");
settings->setDefault("virtual_joystick_triggers_aux1", "false"); settings->setDefault("virtual_joystick_triggers_aux1", "false");
settings->setDefault("touch_punch_gesture", "short_tap");
#ifdef ENABLE_TOUCH #ifdef ENABLE_TOUCH
settings->setDefault("clickable_chat_weblinks", "false"); settings->setDefault("clickable_chat_weblinks", "false");
#else #else

@ -1105,11 +1105,11 @@ void TouchScreenGUI::applyContextControls(const TouchInteractionMode &mode)
// Since the pointed thing has already been determined when this function // Since the pointed thing has already been determined when this function
// is called, we cannot use this function to update the shootline. // is called, we cannot use this function to update the shootline.
sanity_check(mode != TouchInteractionMode_USER);
u64 now = porting::getTimeMs();
bool target_dig_pressed = false; bool target_dig_pressed = false;
bool target_place_pressed = false; bool target_place_pressed = false;
u64 now = porting::getTimeMs();
// If the meanings of short and long taps have been swapped, abort any ongoing // If the meanings of short and long taps have been swapped, abort any ongoing
// short taps because they would do something else than the player expected. // short taps because they would do something else than the player expected.
// Long taps don't need this, they're adjusted to the swapped meanings instead. // Long taps don't need this, they're adjusted to the swapped meanings instead.

@ -40,24 +40,37 @@ with this program; if not, write to the Free Software Foundation, Inc.,
TouchInteraction::TouchInteraction() TouchInteraction::TouchInteraction()
{ {
pointed_nothing = LONG_DIG_SHORT_PLACE; pointed_nothing = TouchInteractionMode_USER;
pointed_node = LONG_DIG_SHORT_PLACE; pointed_node = TouchInteractionMode_USER;
// Map punching to single tap by default. pointed_object = TouchInteractionMode_USER;
pointed_object = SHORT_DIG_LONG_PLACE;
} }
TouchInteractionMode TouchInteraction::getMode(const PointedThing &pointed) const TouchInteractionMode TouchInteraction::getMode(PointedThingType pointed_type) const
{ {
switch (pointed.type) { TouchInteractionMode result;
switch (pointed_type) {
case POINTEDTHING_NOTHING: case POINTEDTHING_NOTHING:
return pointed_nothing; result = pointed_nothing;
break;
case POINTEDTHING_NODE: case POINTEDTHING_NODE:
return pointed_node; result = pointed_node;
break;
case POINTEDTHING_OBJECT: case POINTEDTHING_OBJECT:
return pointed_object; result = pointed_object;
break;
default: default:
FATAL_ERROR("Invalid PointedThingType given to TouchInteraction::getMode"); FATAL_ERROR("Invalid PointedThingType given to TouchInteraction::getMode");
} }
if (result == TouchInteractionMode_USER) {
if (pointed_type == POINTEDTHING_OBJECT)
result = g_settings->get("touch_punch_gesture") == "long_tap" ?
LONG_DIG_SHORT_PLACE : SHORT_DIG_LONG_PLACE;
else
result = LONG_DIG_SHORT_PLACE;
}
return result;
} }
void TouchInteraction::serialize(std::ostream &os) const void TouchInteraction::serialize(std::ostream &os) const

@ -30,10 +30,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "texture_override.h" // TextureOverride #include "texture_override.h" // TextureOverride
#include "tool.h" #include "tool.h"
#include "util/pointabilities.h" #include "util/pointabilities.h"
#include "util/pointedthing.h"
class IGameDef; class IGameDef;
class Client; class Client;
struct ToolCapabilities; struct ToolCapabilities;
struct PointedThing;
#ifndef SERVER #ifndef SERVER
#include "client/texturesource.h" #include "client/texturesource.h"
struct ItemMesh; struct ItemMesh;
@ -57,6 +58,7 @@ enum TouchInteractionMode : u8
{ {
LONG_DIG_SHORT_PLACE, LONG_DIG_SHORT_PLACE,
SHORT_DIG_LONG_PLACE, SHORT_DIG_LONG_PLACE,
TouchInteractionMode_USER, // Meaning depends on client-side settings
TouchInteractionMode_END, // Dummy for validity check TouchInteractionMode_END, // Dummy for validity check
}; };
@ -67,7 +69,9 @@ struct TouchInteraction
TouchInteractionMode pointed_object; TouchInteractionMode pointed_object;
TouchInteraction(); TouchInteraction();
TouchInteractionMode getMode(const PointedThing &pointed) const; // 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;
void serialize(std::ostream &os) const; void serialize(std::ostream &os) const;
void deSerialize(std::istream &is); void deSerialize(std::istream &is);
}; };

@ -37,5 +37,6 @@ struct EnumString es_TouchInteractionMode[] =
{ {
{LONG_DIG_SHORT_PLACE, "long_dig_short_place"}, {LONG_DIG_SHORT_PLACE, "long_dig_short_place"},
{SHORT_DIG_LONG_PLACE, "short_dig_long_place"}, {SHORT_DIG_LONG_PLACE, "short_dig_long_place"},
{TouchInteractionMode_USER, "user"},
{0, NULL}, {0, NULL},
}; };