mirror of
https://github.com/minetest-mods/warps.git
synced 2025-03-20 11:10:33 +01:00
Allow selecting the warp destination from a dropdown or textbox
This commit is contained in:
parent
9e12709ccb
commit
286454bce5
55
init.lua
55
init.lua
@ -241,6 +241,34 @@ minetest.register_chatcommand("warp", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local function prepare_dropdown(x,y,w,h,curr_dest)
|
||||||
|
local dd = string.format("dropdown[%f,%f;%f,%f;ddwarp;", x, y, w, h)
|
||||||
|
local sel = 0
|
||||||
|
for idx, warp in ipairs(warps) do
|
||||||
|
local warpname = warp.name
|
||||||
|
dd = dd .. warpname .. ","
|
||||||
|
if curr_dest == warpname then
|
||||||
|
sel = idx
|
||||||
|
end
|
||||||
|
end
|
||||||
|
dd = dd .. ";"..tostring(sel).."]"
|
||||||
|
return dd
|
||||||
|
end
|
||||||
|
|
||||||
|
local function prepare_formspec(dest)
|
||||||
|
local custdest
|
||||||
|
if not lookup_warp(dest) then
|
||||||
|
custdest = dest
|
||||||
|
else
|
||||||
|
custdest = ""
|
||||||
|
end
|
||||||
|
s_formspec = "size[4.5,3]label[0.7,0;Warp destination]"
|
||||||
|
s_formspec = s_formspec .. "field[1,2.2;3,0.2;destination;Future destination;"..custdest.."]"
|
||||||
|
.."button_exit[0.7,2.7;3,0.5;proceed;Proceed]"
|
||||||
|
..prepare_dropdown(0.7,0.4,3,1, dest)
|
||||||
|
return s_formspec
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("warps:warpstone", {
|
minetest.register_node("warps:warpstone", {
|
||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
mesh = "warps_warpstone.obj",
|
mesh = "warps_warpstone.obj",
|
||||||
@ -259,8 +287,7 @@ minetest.register_node("warps:warpstone", {
|
|||||||
},
|
},
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("formspec",
|
meta:set_string("formspec", prepare_formspec(""))
|
||||||
"field[destination;Warp Destination;]")
|
|
||||||
meta:set_string("infotext", "Uninitialized Warp Stone")
|
meta:set_string("infotext", "Uninitialized Warp Stone")
|
||||||
end,
|
end,
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
@ -268,15 +295,27 @@ minetest.register_node("warps:warpstone", {
|
|||||||
minetest.chat_send_player(sender:get_player_name(), "You do not have permission to modify warp stones")
|
minetest.chat_send_player(sender:get_player_name(), "You do not have permission to modify warp stones")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if not fields.destination then
|
if not (fields.destination and fields.quit) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local ddwarp = fields.ddwarp
|
||||||
|
local is_custom_dest = false
|
||||||
|
local dest
|
||||||
|
if fields.destination == "" and fields.ddwarp then
|
||||||
|
dest = fields.ddwarp
|
||||||
|
else
|
||||||
|
dest = fields.destination
|
||||||
|
end
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("formspec",
|
local s_formspec, formspec_help
|
||||||
"field[destination;Warp Destination;" .. fields.destination .. "]")
|
|
||||||
meta:set_string("infotext", "Warp stone to " .. fields.destination)
|
meta:set_string("formspec", prepare_formspec(dest))
|
||||||
meta:set_string("warps_destination", fields.destination)
|
meta:set_string("infotext", "Warp stone to " .. dest)
|
||||||
minetest.log("action", sender:get_player_name() .. " changed warp stone to \"" .. fields.destination .. "\"")
|
meta:set_string("warps_destination", dest)
|
||||||
|
minetest.log("action", sender:get_player_name() .. " changed warp stone at "
|
||||||
|
.. minetest.pos_to_string(pos) .. " to \"" .. dest .. "\"")
|
||||||
end,
|
end,
|
||||||
on_punch = function(pos, node, puncher, pointed_thingo)
|
on_punch = function(pos, node, puncher, pointed_thingo)
|
||||||
if puncher:get_player_control().sneak and
|
if puncher:get_player_control().sneak and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user