From 5356079c8a3bcf640e6c0cf73d7fe096bc1403d2 Mon Sep 17 00:00:00 2001 From: cheapie Date: Tue, 27 Sep 2016 21:26:51 -0500 Subject: Add dropdown --- init.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/init.lua b/init.lua index 490cff0..4f4666d 100644 --- a/init.lua +++ b/init.lua @@ -50,6 +50,15 @@ digistuff.update_ts_formspec = function (pos) fs = fs..string.format("image_button[%s,%s;%s,%s;%s;%s;%s]",field.X,field.Y,field.W,field.H,field.image,field.name,field.label) elseif field.type == "image_button_exit" then fs = fs..string.format("image_button_exit[%s,%s;%s,%s;%s;%s;%s]",field.X,field.Y,field.W,field.H,field.image,field.name,field.label) + elseif field.type == "dropdown" then + local choices = "" + for _,i in ipairs(field.choices) do + if type(i) == "string" then + choices = choices..minetest.formspec_escape(i).."," + end + end + choices = string.sub(choices,1,-2) + fs = fs..string.format("dropdown[%s,%s;%s,%s;%s;%s;%s]",field.X,field.Y,field.W,field.H,field.name,choices,field.selected_id) end end end @@ -207,6 +216,20 @@ digistuff.process_command = function (meta, data, msg) end local field = {type="image_button_exit",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,image=minetest.formspec_escape(msg.image),name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label)} table.insert(data,field) + elseif msg.command == "adddropdown" then + for _,i in pairs({"X","Y","W","H","selected_id"}) do + if not msg[i] or type(msg[i]) ~= "number" then + return + end + end + if not msg.name or type(msg.name) ~= "string" then + return + end + if not msg.choices or type(msg.choices) ~= "table" or #msg.choices < 1 then + return + end + local field = {type="dropdown",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=msg.name,selected_id=msg.selected_id,choices=msg.choices} + table.insert(data,field) elseif msg.command == "lock" then meta:set_int("locked",1) elseif msg.command == "unlock" then -- cgit v1.2.3