improve/style tp tube formspec and formspec handling

display text explaining private channels
This commit is contained in:
Tim 2015-01-29 18:57:34 +01:00
parent 373c7951d2
commit 9d45599872

View File

@ -114,12 +114,18 @@ local teleport_end_textures={"pipeworks_teleport_tube_end.png","pipeworks_telepo
local teleport_short_texture="pipeworks_teleport_tube_short.png" local teleport_short_texture="pipeworks_teleport_tube_short.png"
local teleport_inv_texture="pipeworks_teleport_tube_inv.png" local teleport_inv_texture="pipeworks_teleport_tube_inv.png"
local function set_teleport_tube_formspec(meta, can_receive) local function update_meta(meta, can_receive)
local cr = (can_receive ~= 0) meta:set_int("can_receive", can_receive and 1 or 0)
meta:set_string("formspec","size[10.5,1;]".. local cr_state = can_receive and "on" or "off"
"field[0,0.5;7,1;channel;Channel:;${channel}]".. meta:set_string("formspec","size[8.6,2.2]"..
"button[8,0;2.5,1;"..(cr and "cr0" or "cr1")..";".. "field[0.6,0.6;7,1;channel;Channel:;${channel}]"..
(cr and "Send and Receive" or "Send only").."]") "label[7.3,0;Receive]"..
"image_button[7.3,0.3;1,1;pipeworks_button_" .. cr_state .. ".png;cr" .. (can_receive and 0 or 1) .. ";;;false;pipeworks_button_interm.png]"..
"label[0.3,1.3;channels are public by default]" ..
"label[0.3,1.6;use <player>:<channel> for fully private channels]" ..
"label[0.3,1.9;use <player>\\;<channel> for private receivers]" ..
default.gui_bg..
default.gui_bg_img)
end end
pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Segment",teleport_plain_textures, pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Segment",teleport_plain_textures,
@ -146,8 +152,7 @@ pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Se
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("can_receive", 1) update_meta(meta, true)
set_teleport_tube_formspec(meta, 1)
end, end,
on_receive_fields = function(pos,formname,fields,sender) on_receive_fields = function(pos,formname,fields,sender)
if not fields.channel then if not fields.channel then
@ -178,17 +183,6 @@ pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Se
local dirty = false local dirty = false
-- test if a can_receive button was pressed
if fields.cr0 and can_receive ~= 0 then
can_receive = 0
meta:set_int("can_receive", can_receive)
dirty = true
elseif fields.cr1 and can_receive ~= 1 then
can_receive = 1
meta:set_int("can_receive", can_receive)
dirty = true
end
-- was the channel changed? -- was the channel changed?
local channel = meta:get_string("channel") local channel = meta:get_string("channel")
if fields.channel ~= channel then if fields.channel ~= channel then
@ -197,6 +191,17 @@ pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Se
dirty = true dirty = true
end end
-- test if a can_receive button was pressed
if fields.cr0 and can_receive ~= 0 then
can_receive = 0
update_meta(meta, false)
dirty = true
elseif fields.cr1 and can_receive ~= 1 then
can_receive = 1
update_meta(meta, true)
dirty = true
end
-- save if we changed something, handle the empty channel while we're at it -- save if we changed something, handle the empty channel while we're at it
if dirty then if dirty then
if channel ~= "" then if channel ~= "" then
@ -205,7 +210,6 @@ pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Se
-- remove empty channel tubes, to not have to search through them -- remove empty channel tubes, to not have to search through them
remove_tube(pos) remove_tube(pos)
end end
set_teleport_tube_formspec(meta, can_receive)
end end
end, end,
on_destruct = function(pos) on_destruct = function(pos)