From bd9ab16762fdcf9519cd0f29030d26e3b46a8ee1 Mon Sep 17 00:00:00 2001 From: grorp Date: Wed, 25 Sep 2024 18:30:59 +0200 Subject: [PATCH 1/5] Add touch_interaction to (cross)bow and spyglass --- mods/ITEMS/mcl_bows/bow.lua | 2 ++ mods/ITEMS/mcl_bows/crossbow.lua | 3 +++ mods/ITEMS/mcl_spyglass/init.lua | 1 + 3 files changed, 6 insertions(+) diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 34784ab07..88bea6444 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -169,6 +169,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula return itemstack end, groups = {weapon=1,weapon_ranged=1,bow=1,cannot_block=1,enchantability=1}, + touch_interaction = "short_dig_long_place", _mcl_uses = 385, }) @@ -235,6 +236,7 @@ for level=0, 2 do on_place = function(itemstack) return itemstack end, + touch_interaction = "short_dig_long_place", _mcl_uses = 385, }) end diff --git a/mods/ITEMS/mcl_bows/crossbow.lua b/mods/ITEMS/mcl_bows/crossbow.lua index b6dc31dd0..0810e6a8c 100644 --- a/mods/ITEMS/mcl_bows/crossbow.lua +++ b/mods/ITEMS/mcl_bows/crossbow.lua @@ -159,6 +159,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula return itemstack end, groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1}, + touch_interaction = "short_dig_long_place", _mcl_uses = 326, }) @@ -194,6 +195,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula return itemstack end, groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1,not_in_creative_inventory=1}, + touch_interaction = "short_dig_long_place", _mcl_uses = 326, }) @@ -257,6 +259,7 @@ for level=0, 2 do on_place = function(itemstack) return itemstack end, + touch_interaction = "short_dig_long_place", _mcl_uses = 385, }) end diff --git a/mods/ITEMS/mcl_spyglass/init.lua b/mods/ITEMS/mcl_spyglass/init.lua index afa7adaf4..c0854d3b6 100644 --- a/mods/ITEMS/mcl_spyglass/init.lua +++ b/mods/ITEMS/mcl_spyglass/init.lua @@ -6,6 +6,7 @@ minetest.register_tool("mcl_spyglass:spyglass",{ inventory_image = "mcl_spyglass.png", stack_max = 1, _mcl_toollike_wield = true, + touch_interaction = "short_dig_long_place", }) minetest.register_craft({ From cb624fe1d95c642209e2ecefc7bc5bb6106d967f Mon Sep 17 00:00:00 2001 From: grorp Date: Wed, 25 Sep 2024 19:31:27 +0200 Subject: [PATCH 2/5] Creative inventory: Make the whole tab button clickable Previously, only the tab icon was clickable. Clicking next to the icon would just close the inventory. The icon is still kept clickable too since that gives a nicer press animation. I didn't end up using image_button because that resulted in a different image size and position, even with the exact same coordinates. --- mods/HUD/mcl_inventory/creative.lua | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 4ddbd0823..7ae4a1098 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -566,8 +566,10 @@ function mcl_inventory.set_creative_formspec(player) bg_img = "crafting_creative_inactive" .. button_bg_postfix[this_tab] .. ".png" end return table.concat({ - "style[" .. this_tab .. ";border=false;bgimg=;bgimg_pressed=;noclip=true]", - "image[" .. offset[this_tab] .. ";1.5,1.44;" .. bg_img .. "]", + "style[" .. this_tab .. ";border=false;noclip=true;bgimg=;bgimg_pressed=]", + "style[" .. this_tab .. "_outer;border=false;noclip=true;bgimg=" .. bg_img .. + ";bgimg_pressed=" .. bg_img .. "]", + "button[" .. offset[this_tab] .. ";1.5,1.44;" .. this_tab .. "_outer;]", "item_image_button[" .. boffset[this_tab] .. ";1,1;" .. tab_icon[this_tab] .. ";" .. this_tab .. ";]", }) end @@ -581,8 +583,6 @@ function mcl_inventory.set_creative_formspec(player) "formspec_version[6]", "size[13,8.75]", - "style_type[image;noclip=true]", - -- Hotbar mcl_formspec.get_itemslot_bg_v4(0.375, 7.375, 9, 1), "list[current_player;main;0.375,7.375;9,1;]", @@ -655,54 +655,54 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local name = player:get_player_name() - if fields.blocks then + if fields.blocks or fields.blocks_outer then if players[name].page == "blocks" then return end set_inv_page("blocks", player) page = "blocks" - elseif fields.deco then + elseif fields.deco or fields.deco_outer then if players[name].page == "deco" then return end set_inv_page("deco", player) page = "deco" - elseif fields.redstone then + elseif fields.redstone or fields.redstone_outer then if players[name].page == "redstone" then return end set_inv_page("redstone", player) page = "redstone" - elseif fields.rail then + elseif fields.rail or fields.rail_outer then if players[name].page == "rail" then return end set_inv_page("rail", player) page = "rail" - elseif fields.misc then + elseif fields.misc or fields.misc_outer then if players[name].page == "misc" then return end set_inv_page("misc", player) page = "misc" - elseif fields.nix then + elseif fields.nix or fields.nix_outer then set_inv_page("all", player) page = "nix" - elseif fields.food then + elseif fields.food or fields.food_outer then if players[name].page == "food" then return end set_inv_page("food", player) page = "food" - elseif fields.tools then + elseif fields.tools or fields.tools_outer then if players[name].page == "tools" then return end set_inv_page("tools", player) page = "tools" - elseif fields.combat then + elseif fields.combat or fields.combat_outer then if players[name].page == "combat" then return end set_inv_page("combat", player) page = "combat" - elseif fields.mobs then + elseif fields.mobs or fields.mobs_outer then if players[name].page == "mobs" then return end set_inv_page("mobs", player) page = "mobs" - elseif fields.brew then + elseif fields.brew or fields.brew_outer then if players[name].page == "brew" then return end set_inv_page("brew", player) page = "brew" - elseif fields.matr then + elseif fields.matr or fields.matr_outer then if players[name].page == "matr" then return end set_inv_page("matr", player) page = "matr" - elseif fields.inv then + elseif fields.inv or fields.inv_outer then if players[name].page == "inv" then return end page = "inv" elseif fields.search == "" and not fields.creative_next and not fields.creative_prev then From 02b354f54ac9894237ee987558f9d56098a4a58b Mon Sep 17 00:00:00 2001 From: grorp Date: Wed, 25 Sep 2024 19:53:20 +0200 Subject: [PATCH 3/5] Avoid tab buttons going off-screen with high scaling values --- mods/HUD/mcl_inventory/creative.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 7ae4a1098..0effcc1bc 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -566,8 +566,8 @@ function mcl_inventory.set_creative_formspec(player) bg_img = "crafting_creative_inactive" .. button_bg_postfix[this_tab] .. ".png" end return table.concat({ - "style[" .. this_tab .. ";border=false;noclip=true;bgimg=;bgimg_pressed=]", - "style[" .. this_tab .. "_outer;border=false;noclip=true;bgimg=" .. bg_img .. + "style[" .. this_tab .. ";border=false;bgimg=;bgimg_pressed=]", + "style[" .. this_tab .. "_outer;border=false;bgimg=" .. bg_img .. ";bgimg_pressed=" .. bg_img .. "]", "button[" .. offset[this_tab] .. ";1.5,1.44;" .. this_tab .. "_outer;]", "item_image_button[" .. boffset[this_tab] .. ";1,1;" .. tab_icon[this_tab] .. ";" .. this_tab .. ";]", @@ -581,7 +581,13 @@ function mcl_inventory.set_creative_formspec(player) local formspec = table.concat({ "formspec_version[6]", - "size[13,8.75]", + -- Original formspec height was 8.75, increased to include tab buttons. + -- This avoids tab buttons going off-screen with high scaling values. + "size[13,11.43]", + + "no_prepend[]", mcl_vars.gui_nonbg, mcl_vars.gui_bg_color, + "background9[0,1.34;13,8.75;mcl_base_textures_background9.png;;7]", + "container[0,1.34]", -- Hotbar mcl_formspec.get_itemslot_bg_v4(0.375, 7.375, 9, 1), @@ -638,6 +644,7 @@ function mcl_inventory.set_creative_formspec(player) "set_focus[search;true]", }) end + formspec = formspec .. "container_end[]" if pagenum then formspec = formspec .. "p" .. tostring(pagenum) end player:set_inventory_formspec(formspec) end From 3954acdfb7c86970a03f00d37dff6403e74c4879 Mon Sep 17 00:00:00 2001 From: grorp Date: Wed, 25 Sep 2024 20:56:59 +0200 Subject: [PATCH 4/5] Creative inventory: padding[-0.015,-0.015] on mobile - less wasted screen space - matches old layout --- mods/HUD/mcl_inventory/creative.lua | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 0effcc1bc..ece965156 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -418,6 +418,18 @@ minetest.register_on_joinplayer(function(player) end end) +---@param player mt.PlayerObjectRef +local function is_touch_enabled(playername) + -- Minetest < 5.7.0 support + if not minetest.get_player_window_information then + return false + end + local window = minetest.get_player_window_information(playername) + -- Always return a boolean (not nil) to avoid false-negatives when + -- comparing to a boolean later. + return window and window.touch_controls or false +end + ---@param player mt.PlayerObjectRef function mcl_inventory.set_creative_formspec(player) local playername = player:get_player_name() @@ -579,11 +591,17 @@ function mcl_inventory.set_creative_formspec(player) caption = "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, filtername[name])) .. "]" end + local touch_enabled = is_touch_enabled(playername) + players[playername].last_touch_enabled = touch_enabled + local formspec = table.concat({ "formspec_version[6]", -- Original formspec height was 8.75, increased to include tab buttons. -- This avoids tab buttons going off-screen with high scaling values. "size[13,11.43]", + -- Use as much space as possible on mobile - the tab buttons are a lot + -- of padding already. + touch_enabled and "padding[-0.015,-0.015]" or "", "no_prepend[]", mcl_vars.gui_nonbg, mcl_vars.gui_bg_color, "background9[0,1.34;13,8.75;mcl_base_textures_background9.png;;7]", @@ -825,3 +843,17 @@ minetest.register_on_player_inventory_action(function(player, action, inventory, player:get_inventory():set_stack("main", inventory_info.index, stack) end end) + +-- This is necessary because get_player_window_information may return nil in +-- on_joinplayer. +-- (Also, Minetest plans to add support for toggling touchscreen mode in-game.) +mcl_player.register_globalstep_slow(function(player) + local name = player:get_player_name() + + if minetest.is_creative_enabled(name) then + local touch_enabled = is_touch_enabled(name) + if touch_enabled ~= players[name].last_touch_enabled then + mcl_inventory.set_creative_formspec(player) + end + end +end) From 88c3c4558bf2e5bfcd7aa08863c779ec2dcff63b Mon Sep 17 00:00:00 2001 From: grorp Date: Thu, 17 Oct 2024 14:05:51 +0200 Subject: [PATCH 5/5] Fix for VoxeLibre --- mods/HUD/mcl_inventory/creative.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index ece965156..18b3b4c5e 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -847,13 +847,15 @@ end) -- This is necessary because get_player_window_information may return nil in -- on_joinplayer. -- (Also, Minetest plans to add support for toggling touchscreen mode in-game.) -mcl_player.register_globalstep_slow(function(player) - local name = player:get_player_name() +minetest.register_globalstep(function(dtime) + for _, player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() - if minetest.is_creative_enabled(name) then - local touch_enabled = is_touch_enabled(name) - if touch_enabled ~= players[name].last_touch_enabled then - mcl_inventory.set_creative_formspec(player) + if minetest.is_creative_enabled(name) then + local touch_enabled = is_touch_enabled(name) + if touch_enabled ~= players[name].last_touch_enabled then + mcl_inventory.set_creative_formspec(player) + end end end end)