summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim <t4im@users.noreply.github.com>2015-01-29 18:57:34 +0100
committerTim <t4im@users.noreply.github.com>2015-01-29 19:09:59 +0100
commit9d45599872caece4413d277e9c6f14527c810186 (patch)
tree4c1acc498bd7f06b3a1686a9b0c05c5099cefc32
parent373c7951d2bb40ba0e5c08a922aa9ece6e6f7dcd (diff)
downloadpipeworks-9d45599872caece4413d277e9c6f14527c810186.tar
pipeworks-9d45599872caece4413d277e9c6f14527c810186.tar.gz
pipeworks-9d45599872caece4413d277e9c6f14527c810186.tar.bz2
pipeworks-9d45599872caece4413d277e9c6f14527c810186.tar.xz
pipeworks-9d45599872caece4413d277e9c6f14527c810186.zip
improve/style tp tube formspec and formspec handling
display text explaining private channels
-rw-r--r--teleport_tube.lua42
1 files changed, 23 insertions, 19 deletions
diff --git a/teleport_tube.lua b/teleport_tube.lua
index 5c2a7de..1118f97 100644
--- a/teleport_tube.lua
+++ b/teleport_tube.lua
@@ -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_inv_texture="pipeworks_teleport_tube_inv.png"
-local function set_teleport_tube_formspec(meta, can_receive)
- local cr = (can_receive ~= 0)
- meta:set_string("formspec","size[10.5,1;]"..
- "field[0,0.5;7,1;channel;Channel:;${channel}]"..
- "button[8,0;2.5,1;"..(cr and "cr0" or "cr1")..";"..
- (cr and "Send and Receive" or "Send only").."]")
+local function update_meta(meta, can_receive)
+ meta:set_int("can_receive", can_receive and 1 or 0)
+ local cr_state = can_receive and "on" or "off"
+ meta:set_string("formspec","size[8.6,2.2]"..
+ "field[0.6,0.6;7,1;channel;Channel:;${channel}]"..
+ "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
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)
local meta = minetest.get_meta(pos)
- meta:set_int("can_receive", 1)
- set_teleport_tube_formspec(meta, 1)
+ update_meta(meta, true)
end,
on_receive_fields = function(pos,formname,fields,sender)
if not fields.channel then
@@ -178,22 +183,22 @@ pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Se
local dirty = false
+ -- was the channel changed?
+ local channel = meta:get_string("channel")
+ if fields.channel ~= channel then
+ channel = fields.channel
+ meta:set_string("channel", channel)
+ dirty = true
+ end
+
-- 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)
+ update_meta(meta, false)
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?
- local channel = meta:get_string("channel")
- if fields.channel ~= channel then
- channel = fields.channel
- meta:set_string("channel", channel)
+ update_meta(meta, true)
dirty = true
end
@@ -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_tube(pos)
end
- set_teleport_tube_formspec(meta, can_receive)
end
end,
on_destruct = function(pos)