From 551b470b161632e548249f19e5b212baf92a6c67 Mon Sep 17 00:00:00 2001 From: cheapie Date: Thu, 15 Sep 2016 14:54:28 -0500 Subject: [PATCH] Add touchscreen (WIP) --- init.lua | 243 ++++++++++++++++++++++++++++++++ textures/digistuff_ts_bg.png | Bin 0 -> 1735 bytes textures/digistuff_ts_front.png | Bin 0 -> 1806 bytes 3 files changed, 243 insertions(+) create mode 100644 textures/digistuff_ts_bg.png create mode 100644 textures/digistuff_ts_front.png diff --git a/init.lua b/init.lua index 276caf9..92bb3fe 100644 --- a/init.lua +++ b/init.lua @@ -20,6 +20,207 @@ digistuff.update_panel_formspec = function (pos,dispstr) meta:set_string("text",dispstr) end +digistuff.update_ts_formspec = function (pos) + local meta = minetest.get_meta(pos) + local fs = "size[10,8]".. + "background[0,0;0,0;digistuff_ts_bg.png;true]" + if meta:get_int("init") == 0 then + fs = fs.."field[3.75,3;3,1;channel;Channel;]".. + "button_exit[4,3.75;2,1;save;Save]" + else + local data = minetest.deserialize(meta:get_string("data")) or {} + for _,field in pairs(data) do + if field.type == "image" then + fs = fs..string.format("image[%s,%s;%s,%s;%s]",field.X,field.Y,field.W,field.H,field.texture_name) + elseif field.type == "field" then + fs = fs..string.format("field[%s,%s;%s,%s;%s;%s;%s]",field.X,field.Y,field.W,field.H,field.name,field.label,field.default) + elseif field.type == "pwdfield" then + fs = fs..string.format("pwdfield[%s,%s;%s,%s;%s;%s]",field.X,field.Y,field.W,field.H,field.name,field.label) + elseif field.type == "textarea" then + fs = fs..string.format("textarea[%s,%s;%s,%s;%s;%s;%s]",field.X,field.Y,field.W,field.H,field.name,field.label,field.default) + elseif field.type == "label" then + fs = fs..string.format("label[%s,%s;%s]",field.X,field.Y,field.label) + elseif field.type == "vertlabel" then + fs = fs..string.format("vertlabel[%s,%s;%s]",field.X,field.Y,field.label) + elseif field.type == "button" then + fs = fs..string.format("button[%s,%s;%s,%s;%s;%s]",field.X,field.Y,field.W,field.H,field.name,field.label) + elseif field.type == "button_exit" then + fs = fs..string.format("button_exit[%s,%s;%s,%s;%s;%s]",field.X,field.Y,field.W,field.H,field.name,field.label) + elseif field.type == "image_button" then + 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) + end + end + end + meta:set_string("formspec",fs) +end + +digistuff.ts_on_receive_fields = function (pos, formname, fields, sender) + local meta = minetest.get_meta(pos) + local setchan = meta:get_string("channel") + local playername = sender:get_player_name() + local locked = meta:get_int("locked") == 1 + local can_bypass = minetest.check_player_privs(playername,{protection_bypass=true}) + local is_protected = minetest.is_protected(pos,playername) + if (locked and is_protected) and not can_bypass then + minetest.record_protection_violation(pos,playername) + minetest.chat_send_player(playername,"You are not authorized to use this screen.") + return + end + local init = meta:get_int("init") == 1 + if not init then + if fields.save then + meta:set_string("channel",fields.channel) + meta:set_int("init",1) + digistuff.update_ts_formspec(pos) + end + else + digiline:receptor_send(pos, digiline.rules.default, setchan, fields) + end +end + +digistuff.ts_on_digiline_receive = function (pos, node, channel, msg) + local meta = minetest.get_meta(pos) + local setchan = meta:get_string("channel") + if channel ~= setchan then return end + if type(msg) ~= "table" then return end + local data = minetest.deserialize(meta:get_string("data")) or {} + if msg.command == "clear" then + data = {} + elseif msg.command == "addimage" then + for _,i in pairs({"X","Y","W","H"}) do + if not msg[i] or type(msg[i]) ~= "number" then + return + end + end + if not msg.texture_name or type(msg.texture_name) ~= "string" then + return + end + local field = {type="image",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,texture_name=minetest.formspec_escape(msg.texture_name)} + table.insert(data,field) + elseif msg.command == "addfield" then + for _,i in pairs({"X","Y","W","H"}) do + if not msg[i] or type(msg[i]) ~= "number" then + return + end + end + for _,i in pairs({"name","label","default"}) do + if not msg[i] or type(msg[i]) ~= "string" then + return + end + end + local field = {type="field",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label),default=minetest.formspec_escape(msg.default)} + table.insert(data,field) + elseif msg.command == "addpwdfield" then + for _,i in pairs({"X","Y","W","H"}) do + if not msg[i] or type(msg[i]) ~= "number" then + return + end + end + for _,i in pairs({"name","label"}) do + if not msg[i] or type(msg[i]) ~= "string" then + return + end + end + local field = {type="pwdfield",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label)} + table.insert(data,field) + elseif msg.command == "addtextarea" then + for _,i in pairs({"X","Y","W","H"}) do + if not msg[i] or type(msg[i]) ~= "number" then + return + end + end + for _,i in pairs({"name","label","default"}) do + if not msg[i] or type(msg[i]) ~= "string" then + return + end + end + local field = {type="textarea",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label),default=minetest.formspec_escape(msg.default)} + table.insert(data,field) + elseif msg.command == "addlabel" then + for _,i in pairs({"X","Y"}) do + if not msg[i] or type(msg[i]) ~= "number" then + return + end + end + if not msg.label or type(msg.label) ~= "string" then + return + end + local field = {type="label",X=msg.X,Y=msg.Y,label=minetest.formspec_escape(msg.label)} + table.insert(data,field) + elseif msg.command == "addvertlabel" then + for _,i in pairs({"X","Y"}) do + if not msg[i] or type(msg[i]) ~= "number" then + return + end + end + if not msg.label or type(msg.label) ~= "string" then + return + end + local field = {type="vertlabel",X=msg.X,Y=msg.Y,label=minetest.formspec_escape(msg.label)} + table.insert(data,field) + elseif msg.command == "addbutton" then + for _,i in pairs({"X","Y","W","H"}) do + if not msg[i] or type(msg[i]) ~= "number" then + return + end + end + for _,i in pairs({"name","label"}) do + if not msg[i] or type(msg[i]) ~= "string" then + return + end + end + local field = {type="button",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label)} + table.insert(data,field) + elseif msg.command == "addbutton_exit" then + for _,i in pairs({"X","Y","W","H"}) do + if not msg[i] or type(msg[i]) ~= "number" then + return + end + end + for _,i in pairs({"name","label"}) do + if not msg[i] or type(msg[i]) ~= "string" then + return + end + end + local field = {type="button_exit",X=msg.X,Y=msg.Y,W=msg.W,H=msg.H,name=minetest.formspec_escape(msg.name),label=minetest.formspec_escape(msg.label)} + table.insert(data,field) + elseif msg.command == "addimage_button" then + for _,i in pairs({"X","Y","W","H"}) do + if not msg[i] or type(msg[i]) ~= "number" then + return + end + end + for _,i in pairs({"image","name","label"}) do + if not msg[i] or type(msg[i]) ~= "string" then + return + end + end + local field = {type="image_button",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 == "addimage_button_exit" then + for _,i in pairs({"X","Y","W","H"}) do + if not msg[i] or type(msg[i]) ~= "number" then + return + end + end + for _,i in pairs({"image","name","label"}) do + if not msg[i] or type(msg[i]) ~= "string" then + return + end + 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 == "lock" then + meta:set_int("locked",1) + elseif msg.command == "unlock" then + meta:set_int("locked",0) + end + meta:set_string("data",minetest.serialize(data)) + digistuff.update_ts_formspec(pos) +end + digistuff.panel_on_digiline_receive = function (pos, node, channel, msg) local meta = minetest.get_meta(pos) local setchan = meta:get_string("channel") @@ -397,3 +598,45 @@ minetest.register_craft({ {"","digistuff:button",""} } }) + +minetest.register_craft({ + output = "digistuff:touchscreen", + recipe = { + {"mesecons_luacontroller:luacontroller0000","default:glass","default:glass"}, + {"default:glass","digilines:lcd","default:glass"}, + {"default:glass","default:glass","default:glass"} + } +}) + +minetest.register_node("digistuff:touchscreen", { + description = "Digilines Touchscreen", + groups = {cracky=3}, + on_construct = function(pos) + digistuff.update_ts_formspec(pos,true) + end, + drawtype = "nodebox", + tiles = { + "digistuff_panel_back.png", + "digistuff_panel_back.png", + "digistuff_panel_back.png", + "digistuff_panel_back.png", + "digistuff_panel_back.png", + "digistuff_ts_front.png" + }, + paramtype = "light", + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = { + { -0.5, -0.5, 0.4, 0.5, 0.5, 0.5 } + } + }, + on_receive_fields = digistuff.ts_on_receive_fields, + digiline = + { + receptor = {}, + effector = { + action = digistuff.ts_on_digiline_receive + }, + }, +}) diff --git a/textures/digistuff_ts_bg.png b/textures/digistuff_ts_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..87c54f2e6e2a8774a41ac4edde2f78d0902301b7 GIT binary patch literal 1735 zcmV;&1~~bNP)004jp1^@s6jALRO00006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru;0X^C6bmT-(D48O03B&m zSad^gZEa<4bN~PV002XBWnpw>WFU8GbZ8()Nlj2>E@cM*00t{bL_t(|+U=dqappJ- zM7vcAXR?_MVI0+@<$QV%BuL7hJ+3f^_sZq^{v<+B3nVC#^2e`_#F1nvk!>ZC9F339 z_m&)KelAHFZ^mymekXZ+Q@@wx`QFOhXKEL<;rz^sq*>_r%iKnX4bs@(vPboA+N8tY zVUH|j+ETw&GR>_|bC@*C92-v7CyLjRu46d;km;w|=PuRDZ;#?mcPx9)ZPuYHj=pX= ze5~zn?ea4%RXqHj!%r?dGLLEdW}j*=cWw8a9;@@LrI&puUi#UR7`EQ)w?5ohulISI zwjTzU@$&>^iN%Ls>*SS~=I^GUs=z42i20eVU8wf!RceL}wF`TQai1<9;@tr1l%92)|lF5E?dUM%W7wK`mjAP03#FoAGF3E?8 z4qw{)0$Ro8aan!6%<6Agb^7`UNadeQKUP2~n^M6kb!?;jyDa(r`?mnz;^Wtcr0DjR zw|@NifoI@<=kxP(MZ-Ja8y^6#U|F~GXa@tlLS|$BLVVE4g$tlrfW$y(6`-HJivaJn z1S<4529t&I*SB zFSh{|-L84D0BHXc#lLut2TX{7&=CE`Fu?0vU>4w2{Uy3kA2g*P zk~D_oqd{mBAmW3TD!2qV7Eniq&=3NnF)4{G7`m$9Tg=LY##H!5eb5#IV}@fvuL!S4 zg$(dA7bEhaGYh%SM|Ax zGz8&o#`=JFY$6~u#Xqx1IrPf##tG1)y%G3sauDch19}M%prQI@aUy8v8l5mm5Sj#d zvspJq&`}3R z9+Q&7vyz}80}qd!YGg8`wb1{Sm8;BUx+0s6S;gn_OYxRMZnhE|{?>1H4T zv;{zOCj>ex;A9L)1$e&#j#3Y-2Iy)9vN#bm=D_u&Bx+%3f{tkD6(F@Qv{l2I^MVK8~sRA~SYlY4#SWHZZ=4zPnfY8cVppr=;@O~4p1ZbX=1Z@huhrvlC)~mxJJ1A(aRSEv-P)4Fj$9FauJdmy4kY&=mY6Nq0TD8sOCg#H07+9&?k1 z96vul@eI6_fQ<2g{`t?(NS0^6jN;uZlNzp{EnDr!EGd!ayPaBFHP<+@w1!;Q{g%|* zJs;T~w*#x_Nb%VJ_-uc_SM&PAI38=-w6`yNYUaVR>pZ4>f4z$L{%vjNOgDWUP42_H z^18~WV^0J2an%OrHqrKK`N?P1b=a?C-(Nrb_SG(b*ydffm;0s-Uus65Uh~q1=lriF$K=OFcD#0NGRj{1d$=L+iHG=>%jUpl=ZJ8g7jTXX d?NE~x{R@><^?E7f+jal|002ovPDHLkV1k4^FD?K8 literal 0 HcmV?d00001 diff --git a/textures/digistuff_ts_front.png b/textures/digistuff_ts_front.png new file mode 100644 index 0000000000000000000000000000000000000000..bd4c3264bfa8eaff2742a85abf1ebcff2c2dbd39 GIT binary patch literal 1806 zcmV+p2l4ocP)004jp1^@s6jALRO00006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru;0X^CDJ7o4m4E;M03B&m zSad^gZEa<4bN~PV002XBWnpw>WFU8GbZ8()Nlj2>E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