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
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]

@ -9098,15 +9098,16 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and
touch_interaction = {
-- Only affects touchscreen clients.
-- 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)
-- * "short_dig_long_place" (short tap = dig, long tap = place)
-- The field to be used is selected according to the current
-- `pointed_thing`.
pointed_nothing = "long_dig_short_place",
pointed_node = "long_dig_short_place",
pointed_object = "short_dig_long_place",
pointed_nothing = "user",
pointed_node = "user",
pointed_object = "user",
},
sound = {

@ -3280,8 +3280,10 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
if (pointed != runData.pointed_old)
infostream << "Pointing at " << pointed.dump() << std::endl;
if (g_touchscreengui)
g_touchscreengui->applyContextControls(selected_def.touch_interaction.getMode(pointed));
if (g_touchscreengui) {
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,
// 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("fixed_virtual_joystick", "false");
settings->setDefault("virtual_joystick_triggers_aux1", "false");
settings->setDefault("touch_punch_gesture", "short_tap");
#ifdef ENABLE_TOUCH
settings->setDefault("clickable_chat_weblinks", "false");
#else

@ -1105,11 +1105,11 @@ void TouchScreenGUI::applyContextControls(const TouchInteractionMode &mode)
// Since the pointed thing has already been determined when this function
// 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_place_pressed = false;
u64 now = porting::getTimeMs();
// 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.
// 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()
{
pointed_nothing = LONG_DIG_SHORT_PLACE;
pointed_node = LONG_DIG_SHORT_PLACE;
// Map punching to single tap by default.
pointed_object = SHORT_DIG_LONG_PLACE;
pointed_nothing = TouchInteractionMode_USER;
pointed_node = TouchInteractionMode_USER;
pointed_object = TouchInteractionMode_USER;
}
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:
return pointed_nothing;
result = pointed_nothing;
break;
case POINTEDTHING_NODE:
return pointed_node;
result = pointed_node;
break;
case POINTEDTHING_OBJECT:
return pointed_object;
result = pointed_object;
break;
default:
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

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

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