mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Touchscreen: Allow mods to swap the meaning of short and long taps (punch with single tap) (#14087)
This works through a new field "touch_interaction" in item definitions. The two most important use cases are: - Punching players/entities with short tap instead of long tap (enabled by default) - Making items usable that require holding the place button (e.g. bows and shields in MC-like games)
This commit is contained in:
parent
8cbd629010
commit
404a063fdf
10 changed files with 288 additions and 108 deletions
|
@ -138,6 +138,20 @@ void read_item_definition(lua_State* L, int index,
|
|||
def.place_param2 = rangelim(place_param2, 0, U8_MAX);
|
||||
|
||||
getboolfield(L, index, "wallmounted_rotate_vertical", def.wallmounted_rotate_vertical);
|
||||
|
||||
lua_getfield(L, index, "touch_interaction");
|
||||
if (!lua_isnil(L, -1)) {
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
|
||||
TouchInteraction &inter = def.touch_interaction;
|
||||
inter.pointed_nothing = (TouchInteractionMode)getenumfield(L, -1, "pointed_nothing",
|
||||
es_TouchInteractionMode, inter.pointed_nothing);
|
||||
inter.pointed_node = (TouchInteractionMode)getenumfield(L, -1, "pointed_node",
|
||||
es_TouchInteractionMode, inter.pointed_node);
|
||||
inter.pointed_object = (TouchInteractionMode)getenumfield(L, -1, "pointed_object",
|
||||
es_TouchInteractionMode, inter.pointed_object);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -199,6 +213,16 @@ void push_item_definition_full(lua_State *L, const ItemDefinition &i)
|
|||
lua_setfield(L, -2, "node_placement_prediction");
|
||||
lua_pushboolean(L, i.wallmounted_rotate_vertical);
|
||||
lua_setfield(L, -2, "wallmounted_rotate_vertical");
|
||||
|
||||
lua_createtable(L, 0, 3);
|
||||
const TouchInteraction &inter = i.touch_interaction;
|
||||
lua_pushstring(L, es_TouchInteractionMode[inter.pointed_nothing].str);
|
||||
lua_setfield(L, -2,"pointed_nothing");
|
||||
lua_pushstring(L, es_TouchInteractionMode[inter.pointed_node].str);
|
||||
lua_setfield(L, -2,"pointed_node");
|
||||
lua_pushstring(L, es_TouchInteractionMode[inter.pointed_object].str);
|
||||
lua_setfield(L, -2,"pointed_object");
|
||||
lua_setfield(L, -2, "touch_interaction");
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue